src/core/net/sf/basedb/util/overview/validator/DerivedBioAssayValidator.java

Code
Comments
Other
Rev Date Author Line
5807 14 Oct 11 nicklas 1 /**
5807 14 Oct 11 nicklas 2   $Id$
5807 14 Oct 11 nicklas 3
5807 14 Oct 11 nicklas 4   Copyright (C) 2011 Nicklas Nordborg
5807 14 Oct 11 nicklas 5
5807 14 Oct 11 nicklas 6   This file is part of BASE - BioArray Software Environment.
5807 14 Oct 11 nicklas 7   Available at http://base.thep.lu.se/
5807 14 Oct 11 nicklas 8
5807 14 Oct 11 nicklas 9   BASE is free software; you can redistribute it and/or
5807 14 Oct 11 nicklas 10   modify it under the terms of the GNU General Public License
5807 14 Oct 11 nicklas 11   as published by the Free Software Foundation; either version 3
5807 14 Oct 11 nicklas 12   of the License, or (at your option) any later version.
5807 14 Oct 11 nicklas 13
5807 14 Oct 11 nicklas 14   BASE is distributed in the hope that it will be useful,
5807 14 Oct 11 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
5807 14 Oct 11 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5807 14 Oct 11 nicklas 17   GNU General Public License for more details.
5807 14 Oct 11 nicklas 18
5807 14 Oct 11 nicklas 19   You should have received a copy of the GNU General Public License
5807 14 Oct 11 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
5807 14 Oct 11 nicklas 21 */
5807 14 Oct 11 nicklas 22 package net.sf.basedb.util.overview.validator;
5807 14 Oct 11 nicklas 23
6098 03 Sep 12 nicklas 24 import java.util.List;
6098 03 Sep 12 nicklas 25
5807 14 Oct 11 nicklas 26 import net.sf.basedb.core.DbControl;
5807 14 Oct 11 nicklas 27 import net.sf.basedb.core.DerivedBioAssay;
5807 14 Oct 11 nicklas 28 import net.sf.basedb.core.Extract;
5807 14 Oct 11 nicklas 29 import net.sf.basedb.core.Item;
5807 14 Oct 11 nicklas 30 import net.sf.basedb.core.ItemSubtype;
5807 14 Oct 11 nicklas 31 import net.sf.basedb.core.PermissionDeniedException;
5807 14 Oct 11 nicklas 32 import net.sf.basedb.core.PhysicalBioAssay;
6098 03 Sep 12 nicklas 33 import net.sf.basedb.core.RawBioAssay;
5807 14 Oct 11 nicklas 34 import net.sf.basedb.util.overview.Fix;
5807 14 Oct 11 nicklas 35 import net.sf.basedb.util.overview.NodeAttribute;
5807 14 Oct 11 nicklas 36 import net.sf.basedb.util.overview.OverviewContext;
5807 14 Oct 11 nicklas 37 import net.sf.basedb.util.overview.Validator;
5807 14 Oct 11 nicklas 38 import net.sf.basedb.util.overview.Node;
5807 14 Oct 11 nicklas 39 import net.sf.basedb.util.overview.Node.Type;
5807 14 Oct 11 nicklas 40 import net.sf.basedb.util.overview.node.ChildNodeDirection;
5807 14 Oct 11 nicklas 41
5807 14 Oct 11 nicklas 42 /**
5807 14 Oct 11 nicklas 43   Validator implementation for derived bioassays. Validation rules:
5807 14 Oct 11 nicklas 44   <ul>
5807 14 Oct 11 nicklas 45   <li>Missing item: {@link Validator#MISSING_DERIVEDBIOASSAY}
5807 14 Oct 11 nicklas 46   <li>Access denied: {@link Validator#DENIED_DERIVEDBIOASSAY}
5807 14 Oct 11 nicklas 47   <li>Parent extract mismatch: {@link Validator#PARENT_EXTRACT_MISMATCH}
5807 14 Oct 11 nicklas 48   <li>Incorrect related subtypes: {@link Validator#INCORRECT_DERIVEDBIOASSAY_TYPE},
5807 14 Oct 11 nicklas 49     {@link Validator#INCORRECT_PHYSICALBIOASSAY_TYPE}, {@link Validator#INCORRECT_EXTRACT_TYPE}
5807 14 Oct 11 nicklas 50   </ul>
5807 14 Oct 11 nicklas 51
5807 14 Oct 11 nicklas 52   @author Nicklas
5807 14 Oct 11 nicklas 53   @version 2.10
5807 14 Oct 11 nicklas 54   @base.modified $Date: 2009-02-16 20:29:47 +0100 (må, 16 feb 2009) $
5807 14 Oct 11 nicklas 55 */
5807 14 Oct 11 nicklas 56 public class DerivedBioAssayValidator
5807 14 Oct 11 nicklas 57   extends NameableNodeValidator<DerivedBioAssay>
5807 14 Oct 11 nicklas 58 {
5807 14 Oct 11 nicklas 59   
5807 14 Oct 11 nicklas 60   public DerivedBioAssayValidator()
5807 14 Oct 11 nicklas 61   {
5807 14 Oct 11 nicklas 62     super(Validator.MISSING_DERIVEDBIOASSAY, Validator.DENIED_DERIVEDBIOASSAY);
5807 14 Oct 11 nicklas 63   }
5807 14 Oct 11 nicklas 64
5807 14 Oct 11 nicklas 65   /* 
5807 14 Oct 11 nicklas 66     From BasicValidator class
5807 14 Oct 11 nicklas 67     -------------------------
5807 14 Oct 11 nicklas 68   */
5807 14 Oct 11 nicklas 69   /**
5807 14 Oct 11 nicklas 70     If the parent raw bioassay has a link to an extract, we ignore the missing
5807 14 Oct 11 nicklas 71     derived bioassay.
5807 14 Oct 11 nicklas 72     @since 3.0
5807 14 Oct 11 nicklas 73   */
5807 14 Oct 11 nicklas 74   @Override
5807 14 Oct 11 nicklas 75   public boolean preMissingItem(DbControl dc, OverviewContext context, Node parentNode)
5807 14 Oct 11 nicklas 76   {
5807 14 Oct 11 nicklas 77     if (parentNode.hasAttribute(NodeAttribute.EXTRACT)) return false;
5807 14 Oct 11 nicklas 78     return super.preMissingItem(dc, context, parentNode);
5807 14 Oct 11 nicklas 79   }
5807 14 Oct 11 nicklas 80   
5807 14 Oct 11 nicklas 81   /**
5807 14 Oct 11 nicklas 82     @return Suggested fix is to add a derived bioassay as parent to the raw bioassay.
5807 14 Oct 11 nicklas 83   */
5807 14 Oct 11 nicklas 84   @Override
5807 14 Oct 11 nicklas 85   protected Fix getMissingItemFix(DbControl dc, Node rawBioAssayNode)
5807 14 Oct 11 nicklas 86   {
5807 14 Oct 11 nicklas 87     return new Fix("Add parent bioassay to raw bioassay", rawBioAssayNode.getItem());
5807 14 Oct 11 nicklas 88   }
5807 14 Oct 11 nicklas 89   
5807 14 Oct 11 nicklas 90   @Override
5807 14 Oct 11 nicklas 91   public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) 
5807 14 Oct 11 nicklas 92   {
5807 14 Oct 11 nicklas 93     super.postValidate(dc, context, node, parentNode);
6098 03 Sep 12 nicklas 94
6098 03 Sep 12 nicklas 95     // Load node and parent information
6098 03 Sep 12 nicklas 96     DerivedBioAssay bioAssay = (DerivedBioAssay)node.getItem(dc);
6098 03 Sep 12 nicklas 97     DerivedBioAssay parentBioAssay = null;
6098 03 Sep 12 nicklas 98     RawBioAssay parentRawBioAssay = null;
5807 14 Oct 11 nicklas 99     
5807 14 Oct 11 nicklas 100     if (parentNode != null)
5807 14 Oct 11 nicklas 101     {
5807 14 Oct 11 nicklas 102       Node parentItemNode = parentNode.getNodeType() == Type.ITEM ? parentNode : parentNode.getParent();
5807 14 Oct 11 nicklas 103       Item parentType = parentItemNode.getItemType();
5807 14 Oct 11 nicklas 104
5807 14 Oct 11 nicklas 105       if (parentType == Item.PHYSICALBIOASSAY)
5807 14 Oct 11 nicklas 106       {
5807 14 Oct 11 nicklas 107         checkPhysicalBioAssaySubtype(dc, context, node, parentItemNode);
5807 14 Oct 11 nicklas 108       }
5807 14 Oct 11 nicklas 109       else if (parentType == Item.DERIVEDBIOASSAY)
5807 14 Oct 11 nicklas 110       {
5807 14 Oct 11 nicklas 111         if (node.getChildNodeDirection() == ChildNodeDirection.FORWARD)
5807 14 Oct 11 nicklas 112         {
5807 14 Oct 11 nicklas 113           checkDerivedBioAssaySubtype(dc, context, node, parentItemNode);
5807 14 Oct 11 nicklas 114         }
5807 14 Oct 11 nicklas 115         else
5807 14 Oct 11 nicklas 116         {
5807 14 Oct 11 nicklas 117           checkDerivedBioAssaySubtype(dc, context, parentItemNode, node);
5807 14 Oct 11 nicklas 118         }
6098 03 Sep 12 nicklas 119         parentBioAssay = (DerivedBioAssay)parentItemNode.getItem(dc);
5807 14 Oct 11 nicklas 120       }
6098 03 Sep 12 nicklas 121       else if (parentType == Item.RAWBIOASSAY)
6098 03 Sep 12 nicklas 122       {
6098 03 Sep 12 nicklas 123         parentRawBioAssay = (RawBioAssay)parentItemNode.getItem(dc);
6098 03 Sep 12 nicklas 124       }
5807 14 Oct 11 nicklas 125     }
6098 03 Sep 12 nicklas 126
6098 03 Sep 12 nicklas 127     // Load parent extracts and physical bioassays
5807 14 Oct 11 nicklas 128     Extract extract = null;
5807 14 Oct 11 nicklas 129     Extract parentBioAssayExtract = null;
6098 03 Sep 12 nicklas 130     List<PhysicalBioAssay> physicalBioAssays = null;
5807 14 Oct 11 nicklas 131     try
5807 14 Oct 11 nicklas 132     {
5807 14 Oct 11 nicklas 133       extract = bioAssay.getExtract();
6098 03 Sep 12 nicklas 134       physicalBioAssays = PhysicalBioAssayValidator.getPhysicalBioAssays(dc, context, bioAssay);
6098 03 Sep 12 nicklas 135       if (parentBioAssay != null) parentBioAssayExtract = parentBioAssay.getExtract();
6098 03 Sep 12 nicklas 136       if (parentRawBioAssay != null) parentBioAssayExtract = parentRawBioAssay.getParentExtract();
5807 14 Oct 11 nicklas 137     }
5807 14 Oct 11 nicklas 138     catch (PermissionDeniedException ex)
6098 03 Sep 12 nicklas 139     {}    
5807 14 Oct 11 nicklas 140     
6098 03 Sep 12 nicklas 141     // Check that the extract is part of at least one of the parent physical bioassays
6098 03 Sep 12 nicklas 142     if (extract != null && physicalBioAssays != null && physicalBioAssays.size() > 0)
5807 14 Oct 11 nicklas 143     {
6098 03 Sep 12 nicklas 144       boolean found = false;
6098 03 Sep 12 nicklas 145       for (PhysicalBioAssay pba : physicalBioAssays)
5807 14 Oct 11 nicklas 146       {
6098 03 Sep 12 nicklas 147         if (PhysicalBioAssayValidator.getAllParentExtracts(dc, context, pba).contains(extract))
6098 03 Sep 12 nicklas 148         {
6098 03 Sep 12 nicklas 149           found = true;
6098 03 Sep 12 nicklas 150           break;
6098 03 Sep 12 nicklas 151         }
5807 14 Oct 11 nicklas 152       }
6098 03 Sep 12 nicklas 153       
6098 03 Sep 12 nicklas 154       if (!found)
6098 03 Sep 12 nicklas 155       {
6098 03 Sep 12 nicklas 156         if (physicalBioAssays.size() == 1)
6098 03 Sep 12 nicklas 157         {
6098 03 Sep 12 nicklas 158           PhysicalBioAssay pba = physicalBioAssays.get(0);
6098 03 Sep 12 nicklas 159           context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, 
6098 03 Sep 12 nicklas 160             "The extract '" + extract.getName() + "' is not a parent to the physical bioassay: " + 
6098 03 Sep 12 nicklas 161               pba.getName(),
6098 03 Sep 12 nicklas 162             new Fix("Change extract on bioassay", bioAssay),
6098 03 Sep 12 nicklas 163             new Fix("Change extracts on physical bioassay", pba)
6098 03 Sep 12 nicklas 164           );
6098 03 Sep 12 nicklas 165         }
6098 03 Sep 12 nicklas 166         else
6098 03 Sep 12 nicklas 167         {
6098 03 Sep 12 nicklas 168           context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, 
6098 03 Sep 12 nicklas 169               "The extract '" + extract.getName() + "' is not a parent to any of the physical bioassays",
6098 03 Sep 12 nicklas 170               new Fix("Change extract on bioassay", bioAssay)
6098 03 Sep 12 nicklas 171             );
6098 03 Sep 12 nicklas 172         }
6098 03 Sep 12 nicklas 173       }
5807 14 Oct 11 nicklas 174     }
6098 03 Sep 12 nicklas 175
6098 03 Sep 12 nicklas 176     // Check that extract is related to the extract on the parent node
6098 03 Sep 12 nicklas 177     if (extract != null && parentBioAssayExtract != null)
5807 14 Oct 11 nicklas 178     {
6098 03 Sep 12 nicklas 179       if (!ExtractValidator.isRelated(dc, context, extract, parentBioAssayExtract) && !ExtractValidator.isRelated(dc, context, parentBioAssayExtract, extract))
5807 14 Oct 11 nicklas 180       {
6098 03 Sep 12 nicklas 181         if (parentBioAssay != null)
6098 03 Sep 12 nicklas 182         {
6098 03 Sep 12 nicklas 183           context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, 
6098 03 Sep 12 nicklas 184             "The bioassay '" + parentBioAssay.getName() + "' has unrelated extract: " + 
6098 03 Sep 12 nicklas 185               parentBioAssayExtract.getName(), 
6098 03 Sep 12 nicklas 186             new Fix("Change extract of " + bioAssay.getName(), bioAssay),
6098 03 Sep 12 nicklas 187             new Fix("Change extract of " + parentBioAssay.getName(), parentBioAssay)
6098 03 Sep 12 nicklas 188           );
6098 03 Sep 12 nicklas 189         }
6098 03 Sep 12 nicklas 190         if (parentRawBioAssay != null)
6098 03 Sep 12 nicklas 191         {
6098 03 Sep 12 nicklas 192           context.createFailure(Validator.PARENT_EXTRACT_MISMATCH, node, 
6098 03 Sep 12 nicklas 193               "The raw bioassay '" + parentRawBioAssay.getName() + "' has unrelated extract: " + 
6098 03 Sep 12 nicklas 194                 parentBioAssayExtract.getName(), 
6098 03 Sep 12 nicklas 195               new Fix("Change extract of " + bioAssay.getName(), bioAssay),
6098 03 Sep 12 nicklas 196               new Fix("Change extract of " + parentRawBioAssay.getName(), parentRawBioAssay)
6098 03 Sep 12 nicklas 197             );
6098 03 Sep 12 nicklas 198         }
5807 14 Oct 11 nicklas 199       }
5807 14 Oct 11 nicklas 200     }
5807 14 Oct 11 nicklas 201   }
5807 14 Oct 11 nicklas 202   // ----------------------------
5807 14 Oct 11 nicklas 203
5807 14 Oct 11 nicklas 204   /**
5807 14 Oct 11 nicklas 205     Check the subtype of the physical bioassay that is the parent to a derived bioassay. Given that
5807 14 Oct 11 nicklas 206     the derived bioassay has a non-null subtype, which has a related PHYISICALBIOASSAY subtype, this
5807 14 Oct 11 nicklas 207     method checks if the physical bioassay has the same subtype. If there is no related
5807 14 Oct 11 nicklas 208     subtype for the derived bioassay, any subtype for the physical bioassay is accepted.
5807 14 Oct 11 nicklas 209   */
5807 14 Oct 11 nicklas 210   public static void checkPhysicalBioAssaySubtype(DbControl dc, OverviewContext context, Node derivedBioAssayNode, Node physicalBioAssayNode)
5807 14 Oct 11 nicklas 211   {
5807 14 Oct 11 nicklas 212     DerivedBioAssay dba = (DerivedBioAssay)derivedBioAssayNode.getItem(dc);
5807 14 Oct 11 nicklas 213     PhysicalBioAssay pba = (PhysicalBioAssay)physicalBioAssayNode.getItem(dc);
5807 14 Oct 11 nicklas 214     
5807 14 Oct 11 nicklas 215     try
5807 14 Oct 11 nicklas 216     {
5807 14 Oct 11 nicklas 217       ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, dba, Item.PHYSICALBIOASSAY, Item.DERIVEDBIOASSAY);
5807 14 Oct 11 nicklas 218       ItemSubtype subtype = pba.getItemSubtype();
5807 14 Oct 11 nicklas 219       
5807 14 Oct 11 nicklas 220       if (expectedSubtype != null && !expectedSubtype.equals(subtype))
5807 14 Oct 11 nicklas 221       {
5807 14 Oct 11 nicklas 222         ItemSubtype mySubtype = dba.getItemSubtype();
5807 14 Oct 11 nicklas 223         Fix subtypeFix = subtype == null ? null : 
5807 14 Oct 11 nicklas 224           new Fix("Change related physical bioassay subtype of '" + mySubtype.getName() + "' to '" + subtype.getName() + "'", mySubtype);
5807 14 Oct 11 nicklas 225         if (expectedSubtype.getMainItemType() == Item.PHYSICALBIOASSAY)
5807 14 Oct 11 nicklas 226         {
5807 14 Oct 11 nicklas 227           context.createFailure(Validator.INCORRECT_PHYSICALBIOASSAY_TYPE, derivedBioAssayNode, 
5807 14 Oct 11 nicklas 228               "Expected a physical bioassay with subtype: " + expectedSubtype.getName(),
5807 14 Oct 11 nicklas 229               new Fix("Change subtype of '" + pba.getName() + "' to '" + expectedSubtype.getName() + "'", pba),
5807 14 Oct 11 nicklas 230               new Fix("Change subtype of '" + derivedBioAssayNode.getTitle() + "'", dba),
5807 14 Oct 11 nicklas 231               subtypeFix
5807 14 Oct 11 nicklas 232             );
5807 14 Oct 11 nicklas 233         }
5807 14 Oct 11 nicklas 234         else
5807 14 Oct 11 nicklas 235         {
5807 14 Oct 11 nicklas 236           context.createFailure(Validator.INCORRECT_PHYSICALBIOASSAY_TYPE, derivedBioAssayNode, 
5807 14 Oct 11 nicklas 237               "Expected a parent bioassay with subtype: " + expectedSubtype.getName(),
5807 14 Oct 11 nicklas 238               new Fix("Change subtype of '" + derivedBioAssayNode.getTitle() + "'", dba),
5807 14 Oct 11 nicklas 239               subtypeFix
5807 14 Oct 11 nicklas 240             );
5807 14 Oct 11 nicklas 241         }
5807 14 Oct 11 nicklas 242       }
5807 14 Oct 11 nicklas 243     }
5807 14 Oct 11 nicklas 244     catch (PermissionDeniedException ex)
5807 14 Oct 11 nicklas 245     {}
5807 14 Oct 11 nicklas 246   }
5807 14 Oct 11 nicklas 247
5807 14 Oct 11 nicklas 248   /**
5807 14 Oct 11 nicklas 249     Check the subtype of the derived bioassay that is the parent to a child derived bioassay. Given that
5807 14 Oct 11 nicklas 250     the child bioassay has a non-null subtype, which has a related DERIVEDBIOASSAY subtype, this
5807 14 Oct 11 nicklas 251     method checks if the parent bioassay has the same subtype. If there is no related
5807 14 Oct 11 nicklas 252     subtype for the child bioassay, any subtype for the parent bioassay is accepted.
5807 14 Oct 11 nicklas 253   */
5807 14 Oct 11 nicklas 254   public static void checkDerivedBioAssaySubtype(DbControl dc, OverviewContext context, Node childNode, Node parentNode)
5807 14 Oct 11 nicklas 255   {
5807 14 Oct 11 nicklas 256     DerivedBioAssay child = (DerivedBioAssay)childNode.getItem(dc);
5807 14 Oct 11 nicklas 257     DerivedBioAssay parent = (DerivedBioAssay)parentNode.getItem(dc);
5807 14 Oct 11 nicklas 258     
5807 14 Oct 11 nicklas 259     try
5807 14 Oct 11 nicklas 260     {
5807 14 Oct 11 nicklas 261       ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, child, Item.DERIVEDBIOASSAY, Item.PHYSICALBIOASSAY);
5807 14 Oct 11 nicklas 262       ItemSubtype subtype = parent.getItemSubtype();
5807 14 Oct 11 nicklas 263       
5807 14 Oct 11 nicklas 264       if (expectedSubtype != null && !expectedSubtype.equals(subtype))
5807 14 Oct 11 nicklas 265       {
5807 14 Oct 11 nicklas 266         ItemSubtype mySubtype = child.getItemSubtype();
5807 14 Oct 11 nicklas 267         Fix subtypeFix = subtype == null || subtype.equals(mySubtype) ? null : 
5807 14 Oct 11 nicklas 268           new Fix("Change related derived bioassay subtype of '" + mySubtype.getName() + "' to '" + subtype.getName() + "'", mySubtype);
5807 14 Oct 11 nicklas 269         if (expectedSubtype.getMainItemType() == Item.DERIVEDBIOASSAY)
5807 14 Oct 11 nicklas 270         {
5807 14 Oct 11 nicklas 271           context.createFailure(Validator.INCORRECT_DERIVEDBIOASSAY_TYPE, childNode, 
5807 14 Oct 11 nicklas 272             "Expected a parent bioassay with subtype: " + expectedSubtype.getName(),
5807 14 Oct 11 nicklas 273             new Fix("Change subtype of '" + parent.getName() + "' to '" + expectedSubtype.getName() + "'", parent),
5807 14 Oct 11 nicklas 274             new Fix("Change subtype of '" + childNode.getTitle() + "'", child),
5807 14 Oct 11 nicklas 275             subtypeFix
5807 14 Oct 11 nicklas 276           );
5807 14 Oct 11 nicklas 277         }
5807 14 Oct 11 nicklas 278         else
5807 14 Oct 11 nicklas 279         {
5807 14 Oct 11 nicklas 280           context.createFailure(Validator.INCORRECT_DERIVEDBIOASSAY_TYPE, childNode, 
5807 14 Oct 11 nicklas 281             "Expected a physical bioassay with subtype: " + expectedSubtype.getName(),
5807 14 Oct 11 nicklas 282             new Fix("Change subtype of '" + childNode.getTitle() + "'", child),
5807 14 Oct 11 nicklas 283             subtypeFix
5807 14 Oct 11 nicklas 284           );
5807 14 Oct 11 nicklas 285         }
5807 14 Oct 11 nicklas 286       }
5807 14 Oct 11 nicklas 287     }
5807 14 Oct 11 nicklas 288     catch (PermissionDeniedException ex)
5807 14 Oct 11 nicklas 289     {}
5807 14 Oct 11 nicklas 290   }
5807 14 Oct 11 nicklas 291
5807 14 Oct 11 nicklas 292   
5807 14 Oct 11 nicklas 293   /**
5807 14 Oct 11 nicklas 294     Check the subtype of the extract that is the linked with a derived bioassay. Given that
5807 14 Oct 11 nicklas 295     the bioassay has a non-null subtype, which has a related EXTRACT subtype, this
5807 14 Oct 11 nicklas 296     method checks if the extract has the same subtype. If there is no related
5807 14 Oct 11 nicklas 297     subtype for the bioassay, any subtype for the extract is accepted.
5807 14 Oct 11 nicklas 298   */
5807 14 Oct 11 nicklas 299   public static void checkExtractSubtype(DbControl dc, OverviewContext context, Node bioAssayNode, Node extractNode)
5807 14 Oct 11 nicklas 300   {
5807 14 Oct 11 nicklas 301     DerivedBioAssay bioAssay = (DerivedBioAssay)bioAssayNode.getItem(dc);
5807 14 Oct 11 nicklas 302     Extract extract = (Extract)extractNode.getItem(dc);
5807 14 Oct 11 nicklas 303     
5807 14 Oct 11 nicklas 304     try
5807 14 Oct 11 nicklas 305     {
5807 14 Oct 11 nicklas 306       ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.EXTRACT, 0);
5807 14 Oct 11 nicklas 307       ItemSubtype subtype = extract.getItemSubtype();
5807 14 Oct 11 nicklas 308       
5807 14 Oct 11 nicklas 309       if (expectedSubtype != null && !expectedSubtype.equals(subtype))
5807 14 Oct 11 nicklas 310       {
5807 14 Oct 11 nicklas 311         ItemSubtype mySubtype = bioAssay.getItemSubtype();
5807 14 Oct 11 nicklas 312         Fix subtypeFix = subtype == null ? null : 
5807 14 Oct 11 nicklas 313           new Fix("Change related extract subtype of '" + mySubtype.getName() + 
5807 14 Oct 11 nicklas 314             "' to '" + subtype.getName() + "'", mySubtype);
5807 14 Oct 11 nicklas 315         context.createFailure(Validator.INCORRECT_EXTRACT_TYPE, bioAssayNode, 
5807 14 Oct 11 nicklas 316           "Expected an extract with subtype: " + expectedSubtype.getName(), 
5807 14 Oct 11 nicklas 317           new Fix("Change subtype of '" + extract.getName() + "' to '" + expectedSubtype.getName() + "'", extract),
5807 14 Oct 11 nicklas 318           new Fix("Change subtype or extract of '" + bioAssayNode.getTitle() + "'", bioAssay),
5807 14 Oct 11 nicklas 319           subtypeFix
5807 14 Oct 11 nicklas 320         );
5807 14 Oct 11 nicklas 321       }
5807 14 Oct 11 nicklas 322     }
5807 14 Oct 11 nicklas 323     catch (PermissionDeniedException ex)
5807 14 Oct 11 nicklas 324     {}
5807 14 Oct 11 nicklas 325   }
5807 14 Oct 11 nicklas 326
5807 14 Oct 11 nicklas 327
5807 14 Oct 11 nicklas 328 }