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

Code
Comments
Other
Rev Date Author Line
6042 03 Apr 12 nicklas 1 /**
6042 03 Apr 12 nicklas 2   $Id$
6042 03 Apr 12 nicklas 3
6042 03 Apr 12 nicklas 4   Copyright (C) 2012 Nicklas Nordborg
6042 03 Apr 12 nicklas 5
6042 03 Apr 12 nicklas 6   This file is part of BASE - BioArray Software Environment.
6042 03 Apr 12 nicklas 7   Available at http://base.thep.lu.se/
6042 03 Apr 12 nicklas 8
6042 03 Apr 12 nicklas 9   BASE is free software; you can redistribute it and/or
6042 03 Apr 12 nicklas 10   modify it under the terms of the GNU General Public License
6042 03 Apr 12 nicklas 11   as published by the Free Software Foundation; either version 3
6042 03 Apr 12 nicklas 12   of the License, or (at your option) any later version.
6042 03 Apr 12 nicklas 13
6042 03 Apr 12 nicklas 14   BASE is distributed in the hope that it will be useful,
6042 03 Apr 12 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
6042 03 Apr 12 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6042 03 Apr 12 nicklas 17   GNU General Public License for more details.
6042 03 Apr 12 nicklas 18
6042 03 Apr 12 nicklas 19   You should have received a copy of the GNU General Public License
6042 03 Apr 12 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
6042 03 Apr 12 nicklas 21 */
6042 03 Apr 12 nicklas 22 package net.sf.basedb.util.overview.validator;
6042 03 Apr 12 nicklas 23
6042 03 Apr 12 nicklas 24 import net.sf.basedb.core.BioPlate;
6042 03 Apr 12 nicklas 25 import net.sf.basedb.core.BioPlateType;
6042 03 Apr 12 nicklas 26 import net.sf.basedb.core.DbControl;
6042 03 Apr 12 nicklas 27 import net.sf.basedb.core.Item;
6042 03 Apr 12 nicklas 28 import net.sf.basedb.core.ItemSubtype;
6042 03 Apr 12 nicklas 29 import net.sf.basedb.core.MeasuredBioMaterial;
6042 03 Apr 12 nicklas 30 import net.sf.basedb.core.PermissionDeniedException;
6042 03 Apr 12 nicklas 31 import net.sf.basedb.util.overview.Fix;
6042 03 Apr 12 nicklas 32 import net.sf.basedb.util.overview.OverviewContext;
6042 03 Apr 12 nicklas 33 import net.sf.basedb.util.overview.Validator;
6042 03 Apr 12 nicklas 34 import net.sf.basedb.util.overview.Node;
6042 03 Apr 12 nicklas 35
6042 03 Apr 12 nicklas 36 /**
6042 03 Apr 12 nicklas 37   Validator implementation for bioplates. Validation rules:
6042 03 Apr 12 nicklas 38   <ul>
6042 03 Apr 12 nicklas 39   <li>Missing bioplate: {@link Validator#MISSING_BIOPLATE}
6042 03 Apr 12 nicklas 40   <li>Access denied: {@link Validator#DENIED_BIOPLATE}
6042 03 Apr 12 nicklas 41   </ul>
6042 03 Apr 12 nicklas 42
6042 03 Apr 12 nicklas 43   @author Nicklas
6042 03 Apr 12 nicklas 44   @since 3.2
6042 03 Apr 12 nicklas 45   @base.modified $Date$
6042 03 Apr 12 nicklas 46 */
6042 03 Apr 12 nicklas 47 public class BioPlateValidator
6042 03 Apr 12 nicklas 48   extends NameableNodeValidator<BioPlate>
6042 03 Apr 12 nicklas 49 {
6042 03 Apr 12 nicklas 50   
6042 03 Apr 12 nicklas 51   public BioPlateValidator()
6042 03 Apr 12 nicklas 52   {
6042 03 Apr 12 nicklas 53     super(Validator.MISSING_BIOPLATE, Validator.DENIED_BIOPLATE);
6042 03 Apr 12 nicklas 54   }
6042 03 Apr 12 nicklas 55
6042 03 Apr 12 nicklas 56   /* 
6042 03 Apr 12 nicklas 57     From BasicValidator class
6042 03 Apr 12 nicklas 58     -------------------------
6042 03 Apr 12 nicklas 59   */
6042 03 Apr 12 nicklas 60   @Override
6042 03 Apr 12 nicklas 61   public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) 
6042 03 Apr 12 nicklas 62   {
6042 03 Apr 12 nicklas 63     super.postValidate(dc, context, node, parentNode);
6042 03 Apr 12 nicklas 64
6042 03 Apr 12 nicklas 65     if (parentNode != null)
6042 03 Apr 12 nicklas 66     {
6042 03 Apr 12 nicklas 67       Item parentType = parentNode.getItemType();
6042 03 Apr 12 nicklas 68
6042 03 Apr 12 nicklas 69       if (parentType == Item.SAMPLE || parentType == Item.EXTRACT)
6042 03 Apr 12 nicklas 70       {
6042 03 Apr 12 nicklas 71         checkBioMaterialInWell(dc, context, node, parentNode);
6042 03 Apr 12 nicklas 72       }
6042 03 Apr 12 nicklas 73     }
6042 03 Apr 12 nicklas 74   }
6042 03 Apr 12 nicklas 75   
6042 03 Apr 12 nicklas 76   /**
6042 03 Apr 12 nicklas 77     @return Suggested fix is to put the biomaterial on a bioplate.
6042 03 Apr 12 nicklas 78   */
6042 03 Apr 12 nicklas 79   @Override
6042 03 Apr 12 nicklas 80   protected Fix getMissingItemFix(DbControl dc, Node bioMaterialNode)
6042 03 Apr 12 nicklas 81   {
6042 03 Apr 12 nicklas 82     return new Fix("Put biomaterial on a bioplate", bioMaterialNode.getItem());
6042 03 Apr 12 nicklas 83   }
6042 03 Apr 12 nicklas 84   // ----------------------------
6042 03 Apr 12 nicklas 85   
6042 03 Apr 12 nicklas 86   /**
6042 03 Apr 12 nicklas 87     Check that the main type and subtype of the biomaterial is matching the
6042 03 Apr 12 nicklas 88     requirements of the bioplate type. 
6042 03 Apr 12 nicklas 89   */
6042 03 Apr 12 nicklas 90   public static void checkBioMaterialInWell(DbControl dc, OverviewContext context, Node plateNode, Node bioMaterialNode)
6042 03 Apr 12 nicklas 91   {
6042 03 Apr 12 nicklas 92     MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialNode.getItem(dc);
6042 03 Apr 12 nicklas 93     BioPlate plate = (BioPlate)plateNode.getItem(dc);
6042 03 Apr 12 nicklas 94     
6042 03 Apr 12 nicklas 95     try
6042 03 Apr 12 nicklas 96     {
6042 03 Apr 12 nicklas 97       BioPlateType plateType = plate.getBioPlateType();
6042 03 Apr 12 nicklas 98       
6042 03 Apr 12 nicklas 99       // Check main biomaterial type
6042 03 Apr 12 nicklas 100       Item expectedBioMaterialType = plateType.getBioMaterialType();
6042 03 Apr 12 nicklas 101       Item bioMaterialType = bioMaterial.getType();
6042 03 Apr 12 nicklas 102       if (expectedBioMaterialType != null && expectedBioMaterialType != bioMaterialType)
6042 03 Apr 12 nicklas 103       {
6042 03 Apr 12 nicklas 104         context.createFailure(Validator.INCORRECT_BIOMATERIAL_TYPE, bioMaterialNode, 
6042 03 Apr 12 nicklas 105           "Bioplate '" + plate.getName() + "' should not be used for " + expectedBioMaterialType.name() + " items",
6042 03 Apr 12 nicklas 106           new Fix("Move '" + bioMaterial.getName() + "' to another plate", bioMaterial));
6042 03 Apr 12 nicklas 107       }
6042 03 Apr 12 nicklas 108       
6042 03 Apr 12 nicklas 109       // Check biomaterial subtype
6042 03 Apr 12 nicklas 110       ItemSubtype expectedSubtype = plateType.getItemSubtype();
6042 03 Apr 12 nicklas 111       ItemSubtype subtype = bioMaterial.getItemSubtype();
6042 03 Apr 12 nicklas 112       
6042 03 Apr 12 nicklas 113       if (expectedSubtype != null && !expectedSubtype.equals(subtype))
6042 03 Apr 12 nicklas 114       {
6042 03 Apr 12 nicklas 115         Fix subtypeFix = new Fix("Change subtype of '" + bioMaterial.getName() + "' to '" + expectedSubtype.getName() + "'", bioMaterial);
6042 03 Apr 12 nicklas 116         Fix plateFix = new Fix("Change biomaterial subtype of '" + plateType.getName() + "' to '" + subtype.getName() + "'", plateType);
6042 03 Apr 12 nicklas 117         if (bioMaterialType == Item.SAMPLE)
6042 03 Apr 12 nicklas 118         {
6042 03 Apr 12 nicklas 119           context.createFailure(Validator.INCORRECT_SAMPLE_TYPE, bioMaterialNode, "Expected a sample with subtype: " + expectedSubtype.getName(),
6042 03 Apr 12 nicklas 120             subtypeFix, plateFix);
6042 03 Apr 12 nicklas 121         }
6042 03 Apr 12 nicklas 122         else
6042 03 Apr 12 nicklas 123         {
6042 03 Apr 12 nicklas 124           context.createFailure(Validator.INCORRECT_EXTRACT_TYPE, bioMaterialNode, "Expected an extract with subtype: " + expectedSubtype.getName(),
6042 03 Apr 12 nicklas 125             subtypeFix, plateFix);
6042 03 Apr 12 nicklas 126         }
6042 03 Apr 12 nicklas 127       }
6042 03 Apr 12 nicklas 128     }
6042 03 Apr 12 nicklas 129     catch (PermissionDeniedException ex)
6042 03 Apr 12 nicklas 130     {}
6042 03 Apr 12 nicklas 131   }
6042 03 Apr 12 nicklas 132
6042 03 Apr 12 nicklas 133 }