src/core/net/sf/basedb/util/overview/loader/ProtocolLoader.java

Code
Comments
Other
Rev Date Author Line
4740 05 Feb 09 nicklas 1 /**
4740 05 Feb 09 nicklas 2   $Id$
4740 05 Feb 09 nicklas 3
4740 05 Feb 09 nicklas 4   Copyright (C) 2008 Nicklas Nordborg
4740 05 Feb 09 nicklas 5
4740 05 Feb 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4740 05 Feb 09 nicklas 7   Available at http://base.thep.lu.se/
4740 05 Feb 09 nicklas 8
4740 05 Feb 09 nicklas 9   BASE is free software; you can redistribute it and/or
4740 05 Feb 09 nicklas 10   modify it under the terms of the GNU General Public License
4740 05 Feb 09 nicklas 11   as published by the Free Software Foundation; either version 3
4740 05 Feb 09 nicklas 12   of the License, or (at your option) any later version.
4740 05 Feb 09 nicklas 13
4740 05 Feb 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4740 05 Feb 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4740 05 Feb 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4740 05 Feb 09 nicklas 17   GNU General Public License for more details.
4740 05 Feb 09 nicklas 18
4740 05 Feb 09 nicklas 19   You should have received a copy of the GNU General Public License
4740 05 Feb 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4740 05 Feb 09 nicklas 21 */
4740 05 Feb 09 nicklas 22 package net.sf.basedb.util.overview.loader;
4740 05 Feb 09 nicklas 23
4740 05 Feb 09 nicklas 24 import net.sf.basedb.core.Annotatable;
4740 05 Feb 09 nicklas 25 import net.sf.basedb.core.BasicItem;
6210 06 Dec 12 nicklas 26 import net.sf.basedb.core.BioPlateEvent;
4740 05 Feb 09 nicklas 27 import net.sf.basedb.core.DbControl;
4740 05 Feb 09 nicklas 28 import net.sf.basedb.core.Item;
4740 05 Feb 09 nicklas 29 import net.sf.basedb.core.PermissionDeniedException;
4740 05 Feb 09 nicklas 30 import net.sf.basedb.core.Protocol;
6959 01 Oct 15 nicklas 31 import net.sf.basedb.core.RootRawBioAssay;
4740 05 Feb 09 nicklas 32 import net.sf.basedb.util.overview.Node;
4740 05 Feb 09 nicklas 33 import net.sf.basedb.util.overview.OverviewContext;
4740 05 Feb 09 nicklas 34 import net.sf.basedb.util.overview.node.ChildNodeDirection;
4740 05 Feb 09 nicklas 35 import net.sf.basedb.util.overview.node.NameableNameGenerator;
4740 05 Feb 09 nicklas 36 import net.sf.basedb.util.overview.node.NodeFactory;
4740 05 Feb 09 nicklas 37
4740 05 Feb 09 nicklas 38 /**
4740 05 Feb 09 nicklas 39   Node loader implementation for protocols. Protocols must be loaded as
4740 05 Feb 09 nicklas 40   property nodes. It can't be a root node or a forward/reverse-loading 
4740 05 Feb 09 nicklas 41   node. The property node itself is created as a property-loading node
4740 05 Feb 09 nicklas 42   that loads the protocol parameters when asked to load it's children.
4740 05 Feb 09 nicklas 43   
4740 05 Feb 09 nicklas 44   @author Nicklas
4740 05 Feb 09 nicklas 45   @version 2.10
4740 05 Feb 09 nicklas 46   @base.modified $Date$
4740 05 Feb 09 nicklas 47 */
4740 05 Feb 09 nicklas 48 public class ProtocolLoader
4740 05 Feb 09 nicklas 49   extends BasicItemNodeLoader<Protocol>
4740 05 Feb 09 nicklas 50 {
4740 05 Feb 09 nicklas 51
4740 05 Feb 09 nicklas 52   public ProtocolLoader()
4740 05 Feb 09 nicklas 53   {
4740 05 Feb 09 nicklas 54     super(Item.PROTOCOL, DENY_ROOT_NODE, 
4740 05 Feb 09 nicklas 55         new NameableNameGenerator<Protocol>("protocol", "Protocol"));
4740 05 Feb 09 nicklas 56   }
4740 05 Feb 09 nicklas 57   
4740 05 Feb 09 nicklas 58   /*
4740 05 Feb 09 nicklas 59     From the NodeLoader interface
4740 05 Feb 09 nicklas 60     ------------------------------
4740 05 Feb 09 nicklas 61   */
4740 05 Feb 09 nicklas 62   @Override
4740 05 Feb 09 nicklas 63   public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
4740 05 Feb 09 nicklas 64   {
4740 05 Feb 09 nicklas 65     Protocol protocol = null;
4740 05 Feb 09 nicklas 66     boolean denied = false;
4740 05 Feb 09 nicklas 67     try
4740 05 Feb 09 nicklas 68     {
4740 05 Feb 09 nicklas 69       BasicItem parentItem = parentNode.getItem(dc);
6959 01 Oct 15 nicklas 70       if (parentItem instanceof RootRawBioAssay)
6959 01 Oct 15 nicklas 71       {
6959 01 Oct 15 nicklas 72         // The parent may be a root raw bioasay if the overview starts at the
6959 01 Oct 15 nicklas 73         // experiment level
6959 01 Oct 15 nicklas 74         parentItem = ((RootRawBioAssay)parentItem).getRawBioAssay();
6959 01 Oct 15 nicklas 75       }
4740 05 Feb 09 nicklas 76       if (parentItem instanceof Annotatable)
4740 05 Feb 09 nicklas 77       {
4740 05 Feb 09 nicklas 78         protocol = ((Annotatable)parentItem).getProtocol();
4740 05 Feb 09 nicklas 79       }
6210 06 Dec 12 nicklas 80       else if (parentItem instanceof BioPlateEvent)
6210 06 Dec 12 nicklas 81       {
6210 06 Dec 12 nicklas 82         protocol = ((BioPlateEvent)parentItem).getProtocol();
6210 06 Dec 12 nicklas 83       }
4740 05 Feb 09 nicklas 84       // If there are non-annotatable items with a protocol
4740 05 Feb 09 nicklas 85       // we should add more cases here
4740 05 Feb 09 nicklas 86     }
4740 05 Feb 09 nicklas 87     catch (PermissionDeniedException ex)
4740 05 Feb 09 nicklas 88     {
4740 05 Feb 09 nicklas 89       denied = true;
4740 05 Feb 09 nicklas 90     }
4740 05 Feb 09 nicklas 91     
4740 05 Feb 09 nicklas 92     NodeFactory<Protocol> nf = getNodeFactory(dc, context);
4770 19 Feb 09 nicklas 93     Node protocolNode = createItemNode(nf, protocol, null, denied, 
4740 05 Feb 09 nicklas 94         parentNode, ChildNodeDirection.PROPERTY);
4770 19 Feb 09 nicklas 95     // NOTE! The protocol node can't be cached since validation results
4770 19 Feb 09 nicklas 96     // for protocol parameters depend on the annotation on the parent
4770 19 Feb 09 nicklas 97     // item. Eg. each use of a protocol is different
4740 05 Feb 09 nicklas 98     return protocolNode;
4740 05 Feb 09 nicklas 99   }
4740 05 Feb 09 nicklas 100   // -----------------------------------
4740 05 Feb 09 nicklas 101   /*
4740 05 Feb 09 nicklas 102     From the AbstractNodeLoader class
4740 05 Feb 09 nicklas 103     ----------------------------------
4740 05 Feb 09 nicklas 104   */
4740 05 Feb 09 nicklas 105   /**
4939 20 May 09 nicklas 106     Loads annotations and protocol parameters for the given protocol node.
4740 05 Feb 09 nicklas 107     @see RawBioAssayLoader#createForwardNode(DbControl, OverviewContext, Node)
4740 05 Feb 09 nicklas 108   */
4740 05 Feb 09 nicklas 109   @Override
4740 05 Feb 09 nicklas 110   protected void loadPropertyChildNodes(DbControl dc, OverviewContext context, Node protocolNode)
4740 05 Feb 09 nicklas 111   {
7861 21 Oct 20 nicklas 112     getNodeLoader(context, Item.FILE).createPropertyNode(dc, context, protocolNode);
4939 20 May 09 nicklas 113     getNodeLoader(context, Item.ANNOTATION).createPropertyNode(dc, context, protocolNode);
4740 05 Feb 09 nicklas 114     getNodeLoader(context, "PROTOCOL.PARAMETER").createPropertyNode(dc, context, protocolNode);
4740 05 Feb 09 nicklas 115   }
4740 05 Feb 09 nicklas 116   // -------------------------------------
4740 05 Feb 09 nicklas 117 }