src/core/net/sf/basedb/util/overview/loader/AnnotationLoader.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
6939 21 Aug 15 nicklas 24 import java.util.Collections;
5132 14 Oct 09 nicklas 25 import java.util.List;
5132 14 Oct 09 nicklas 26
4740 05 Feb 09 nicklas 27 import net.sf.basedb.core.Annotatable;
4740 05 Feb 09 nicklas 28 import net.sf.basedb.core.Annotation;
7859 20 Oct 20 nicklas 29 import net.sf.basedb.core.AnyToAny;
4740 05 Feb 09 nicklas 30 import net.sf.basedb.core.DbControl;
7859 20 Oct 20 nicklas 31 import net.sf.basedb.core.FileSetMember;
4740 05 Feb 09 nicklas 32 import net.sf.basedb.core.Item;
4740 05 Feb 09 nicklas 33 import net.sf.basedb.core.PermissionDeniedException;
4740 05 Feb 09 nicklas 34 import net.sf.basedb.core.Protocol;
5132 14 Oct 09 nicklas 35 import net.sf.basedb.core.snapshot.AnnotationSnapshot;
5132 14 Oct 09 nicklas 36 import net.sf.basedb.core.snapshot.SnapshotManager;
4740 05 Feb 09 nicklas 37 import net.sf.basedb.util.overview.OverviewContext;
4740 05 Feb 09 nicklas 38 import net.sf.basedb.util.overview.node.AnnotationNameGenerator;
4740 05 Feb 09 nicklas 39 import net.sf.basedb.util.overview.node.ChildNodeDirection;
4740 05 Feb 09 nicklas 40 import net.sf.basedb.util.overview.Node;
4740 05 Feb 09 nicklas 41 import net.sf.basedb.util.overview.node.NodeFactory;
4740 05 Feb 09 nicklas 42
4740 05 Feb 09 nicklas 43 /**
4740 05 Feb 09 nicklas 44   Node loader implementation for annotations. Annotations are
4740 05 Feb 09 nicklas 45   loaded as an end-point folder node with one child entry
4740 05 Feb 09 nicklas 46   for each annotation. It can never be root node or a forward/reverse-loading 
4740 05 Feb 09 nicklas 47   node.
4740 05 Feb 09 nicklas 48
4740 05 Feb 09 nicklas 49   @author Nicklas
4740 05 Feb 09 nicklas 50   @version 2.10
4740 05 Feb 09 nicklas 51   @base.modified $Date$
4740 05 Feb 09 nicklas 52 */
4740 05 Feb 09 nicklas 53 public class AnnotationLoader
4740 05 Feb 09 nicklas 54   extends BasicItemNodeLoader<Annotation>
4740 05 Feb 09 nicklas 55 {
4740 05 Feb 09 nicklas 56
7860 20 Oct 20 nicklas 57   /**
7860 20 Oct 20 nicklas 58     Get the annotatable item from the node. This is in most cases
7860 20 Oct 20 nicklas 59     the {@link Node#getItem()} item, but can also be the target
7860 20 Oct 20 nicklas 60     item of an {@link AnyToAny} node or the file of a {@link FileSetMember}
7860 20 Oct 20 nicklas 61     node.
7860 20 Oct 20 nicklas 62     @since 3.17
4740 05 Feb 09 nicklas 63   */
7860 20 Oct 20 nicklas 64   public static Annotatable getAnnotatableFromNode(DbControl dc, Node node)
4740 05 Feb 09 nicklas 65   {
7860 20 Oct 20 nicklas 66     Annotatable annotatable = null;
7860 20 Oct 20 nicklas 67     Item nodeType = node.getItemType();
7859 20 Oct 20 nicklas 68     try
7859 20 Oct 20 nicklas 69     {
7860 20 Oct 20 nicklas 70       if (nodeType == Item.ANYTOANY)
7859 20 Oct 20 nicklas 71       {
7859 20 Oct 20 nicklas 72         // The parent item is the 'to' target of the any-to-any
7860 20 Oct 20 nicklas 73         AnyToAny any = (AnyToAny)node.getItem(dc);
7860 20 Oct 20 nicklas 74         annotatable = (Annotatable)any.getTo();
7859 20 Oct 20 nicklas 75       }
7860 20 Oct 20 nicklas 76       else if (nodeType == Item.FILESETMEMBER)
7859 20 Oct 20 nicklas 77       {
7859 20 Oct 20 nicklas 78         // The parent item is the 'file' item
7860 20 Oct 20 nicklas 79         FileSetMember member = (FileSetMember)node.getItem(dc);
7860 20 Oct 20 nicklas 80         annotatable = member.getFile();
7859 20 Oct 20 nicklas 81       }
7859 20 Oct 20 nicklas 82       else
7859 20 Oct 20 nicklas 83       {
7860 20 Oct 20 nicklas 84         annotatable = (Annotatable)node.getItem(dc);
7859 20 Oct 20 nicklas 85       }
7859 20 Oct 20 nicklas 86     }
7859 20 Oct 20 nicklas 87     catch (PermissionDeniedException ex)
7859 20 Oct 20 nicklas 88     {}
7860 20 Oct 20 nicklas 89     return annotatable;
7860 20 Oct 20 nicklas 90   }
7860 20 Oct 20 nicklas 91   
7860 20 Oct 20 nicklas 92   public AnnotationLoader()
7860 20 Oct 20 nicklas 93   {
7860 20 Oct 20 nicklas 94     super(Item.ANNOTATION, DENY_ROOT_NODE, new AnnotationNameGenerator());
7860 20 Oct 20 nicklas 95   }
7859 20 Oct 20 nicklas 96
7860 20 Oct 20 nicklas 97   /*
7860 20 Oct 20 nicklas 98     From the NodeLoader interface
7860 20 Oct 20 nicklas 99     ------------------------------
7860 20 Oct 20 nicklas 100   */
7860 20 Oct 20 nicklas 101   @Override
7860 20 Oct 20 nicklas 102   public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
7860 20 Oct 20 nicklas 103   {
7860 20 Oct 20 nicklas 104     NodeFactory<Annotation> nf = getNodeFactory(dc, context);
7860 20 Oct 20 nicklas 105     Annotatable parent = getAnnotatableFromNode(dc, parentNode);
7860 20 Oct 20 nicklas 106
4740 05 Feb 09 nicklas 107     Node folderNode = null;
7859 20 Oct 20 nicklas 108     if (parent != null && parent.isAnnotated())
4740 05 Feb 09 nicklas 109     {
4740 05 Feb 09 nicklas 110       // Load the protocol, if any, so that we can ignore annotations
4740 05 Feb 09 nicklas 111       // that are protocol parameters
4740 05 Feb 09 nicklas 112       Protocol protocol = null;
4740 05 Feb 09 nicklas 113       try
4740 05 Feb 09 nicklas 114       {
4740 05 Feb 09 nicklas 115         protocol = parent.getProtocol();
4740 05 Feb 09 nicklas 116       }
4740 05 Feb 09 nicklas 117       catch (PermissionDeniedException ex)
4740 05 Feb 09 nicklas 118       {}
4740 05 Feb 09 nicklas 119       
4740 05 Feb 09 nicklas 120       folderNode = new Node("annotations", "Annotations", parentNode, ChildNodeDirection.NONE);
5132 14 Oct 09 nicklas 121       SnapshotManager snapshotManager = context.getSnapshotManager();
6939 21 Aug 15 nicklas 122       
5132 14 Oct 09 nicklas 123       List<AnnotationSnapshot> all = snapshotManager.findAnnotations(dc, parent, null, true);
6939 21 Aug 15 nicklas 124       Collections.sort(all, AnnotationSnapshot.sortByAnnotationType(dc));
5132 14 Oct 09 nicklas 125       for (AnnotationSnapshot a : all)
4740 05 Feb 09 nicklas 126       {
6939 21 Aug 15 nicklas 127         Annotation ann = a.getThisAnnotation(dc);
5014 25 Jun 09 martin 128         // Annotations that are protocol parameters are handled by ProtocolParameterLoader        
6939 21 Aug 15 nicklas 129         if (a.getSource() == Annotation.Source.PRIMARY && protocol != null && protocol.isParameter(a.getAnnotationType(dc)))
5014 25 Jun 09 martin 130         {
5014 25 Jun 09 martin 131           /* #### CONTINUE-STATEMENT #### */
5014 25 Jun 09 martin 132           continue;        
5014 25 Jun 09 martin 133         }
5132 14 Oct 09 nicklas 134         createItemNode(nf, ann, null, false, folderNode, ChildNodeDirection.NONE);
4740 05 Feb 09 nicklas 135       }
6939 21 Aug 15 nicklas 136       //folderNode.sortChildren(null);
4740 05 Feb 09 nicklas 137     }
4740 05 Feb 09 nicklas 138     postValidateFolder(nf, folderNode, parentNode, false);
4740 05 Feb 09 nicklas 139     return folderNode;
4740 05 Feb 09 nicklas 140   }
4740 05 Feb 09 nicklas 141   // --------------------------------
4740 05 Feb 09 nicklas 142 }