src/core/net/sf/basedb/util/overview/loader/DataFileLoader.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
4740 05 Feb 09 nicklas 25 import java.util.List;
4740 05 Feb 09 nicklas 26
4740 05 Feb 09 nicklas 27 import net.sf.basedb.core.DbControl;
4740 05 Feb 09 nicklas 28 import net.sf.basedb.core.FileSet;
4740 05 Feb 09 nicklas 29 import net.sf.basedb.core.FileSetMember;
4740 05 Feb 09 nicklas 30 import net.sf.basedb.core.FileStoreEnabled;
4740 05 Feb 09 nicklas 31 import net.sf.basedb.core.Item;
4740 05 Feb 09 nicklas 32 import net.sf.basedb.core.ItemQuery;
6959 01 Oct 15 nicklas 33 import net.sf.basedb.core.RootRawBioAssay;
4740 05 Feb 09 nicklas 34 import net.sf.basedb.util.overview.OverviewContext;
4740 05 Feb 09 nicklas 35 import net.sf.basedb.util.overview.node.ChildNodeDirection;
4740 05 Feb 09 nicklas 36 import net.sf.basedb.util.overview.node.FileSetMemberNameGenerator;
4740 05 Feb 09 nicklas 37 import net.sf.basedb.util.overview.Node;
4740 05 Feb 09 nicklas 38 import net.sf.basedb.util.overview.node.NodeFactory;
4740 05 Feb 09 nicklas 39
4740 05 Feb 09 nicklas 40 /**
4740 05 Feb 09 nicklas 41   Node loader implementation for data files. Data files are
4740 05 Feb 09 nicklas 42   normally loaded as an end-point folder node with one child entry
4740 05 Feb 09 nicklas 43   for each data file. The exception is if there is only one file,
4740 05 Feb 09 nicklas 44   in which case the file node itself is loaded. It can never be
4740 05 Feb 09 nicklas 45   root node or a forward/reverse-loading node.
4740 05 Feb 09 nicklas 46   
4740 05 Feb 09 nicklas 47   @author Nicklas
4740 05 Feb 09 nicklas 48   @version 2.10
4740 05 Feb 09 nicklas 49   @base.modified $Date$
4740 05 Feb 09 nicklas 50 */
4740 05 Feb 09 nicklas 51 public class DataFileLoader
4740 05 Feb 09 nicklas 52   extends BasicItemNodeLoader<FileSetMember>
4740 05 Feb 09 nicklas 53 {
4740 05 Feb 09 nicklas 54   
4740 05 Feb 09 nicklas 55   public DataFileLoader()
4740 05 Feb 09 nicklas 56   {
4740 05 Feb 09 nicklas 57     super(Item.FILESETMEMBER, DENY_ROOT_NODE, new FileSetMemberNameGenerator());
4740 05 Feb 09 nicklas 58   }
4740 05 Feb 09 nicklas 59   
4740 05 Feb 09 nicklas 60   /*
4740 05 Feb 09 nicklas 61     From the NodeLoader interface
4740 05 Feb 09 nicklas 62     ------------------------------
4740 05 Feb 09 nicklas 63   */
4740 05 Feb 09 nicklas 64   @Override
4740 05 Feb 09 nicklas 65   public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
4740 05 Feb 09 nicklas 66   {
4740 05 Feb 09 nicklas 67     NodeFactory<FileSetMember> nf = getNodeFactory(dc, context);
4740 05 Feb 09 nicklas 68     Node folderNode = null;
4740 05 Feb 09 nicklas 69
6959 01 Oct 15 nicklas 70     Item parentType = parentNode.getItemType();
6959 01 Oct 15 nicklas 71     FileStoreEnabled parent = null;
6959 01 Oct 15 nicklas 72     if (parentType == Item.ROOTRAWBIOASSAY)
6959 01 Oct 15 nicklas 73     {
6959 01 Oct 15 nicklas 74       // The parent may be a root raw bioasay if the overview starts at the
6959 01 Oct 15 nicklas 75       // experiment level
6959 01 Oct 15 nicklas 76       RootRawBioAssay root = (RootRawBioAssay)parentNode.getItem(dc);
6959 01 Oct 15 nicklas 77       parent = root.getRawBioAssay();
6959 01 Oct 15 nicklas 78     }
6959 01 Oct 15 nicklas 79     else
6959 01 Oct 15 nicklas 80     {
6959 01 Oct 15 nicklas 81       parent = (FileStoreEnabled)parentNode.getItem(dc);
6959 01 Oct 15 nicklas 82     }
6959 01 Oct 15 nicklas 83     
4750 11 Feb 09 nicklas 84     if (parent.hasFileSet())
4740 05 Feb 09 nicklas 85     {
4750 11 Feb 09 nicklas 86       FileSet fs = parent.getFileSet();
4750 11 Feb 09 nicklas 87       ItemQuery<FileSetMember> query = context.initQuery(fs.getMembers(), "dataFileType.name");
4750 11 Feb 09 nicklas 88       List<FileSetMember> files = query.list(dc);
4750 11 Feb 09 nicklas 89       if (files.size() > 1)
4750 11 Feb 09 nicklas 90       {
4750 11 Feb 09 nicklas 91         folderNode = new Node("files", "Data files", parentNode, ChildNodeDirection.NONE);
4750 11 Feb 09 nicklas 92       }
4750 11 Feb 09 nicklas 93       else 
4750 11 Feb 09 nicklas 94       {
4750 11 Feb 09 nicklas 95         folderNode = parentNode;
4750 11 Feb 09 nicklas 96       }
4750 11 Feb 09 nicklas 97       for (FileSetMember member : files)
4750 11 Feb 09 nicklas 98       {
7859 20 Oct 20 nicklas 99         createItemNode(nf, member, member, false, folderNode, ChildNodeDirection.PROPERTY);
4750 11 Feb 09 nicklas 100       }
4740 05 Feb 09 nicklas 101     }
4740 05 Feb 09 nicklas 102     postValidateFolder(nf, folderNode, parentNode, false);
4740 05 Feb 09 nicklas 103     return folderNode;
4740 05 Feb 09 nicklas 104   }
4740 05 Feb 09 nicklas 105   // -----------------------------------
7859 20 Oct 20 nicklas 106   /**
7859 20 Oct 20 nicklas 107     Loads property nodes of files. 
7859 20 Oct 20 nicklas 108     <ul>
7859 20 Oct 20 nicklas 109     <li>Annotations: {@link AnnotationLoader#createPropertyNode(DbControl, OverviewContext, Node)}
7859 20 Oct 20 nicklas 110     </ul>
7859 20 Oct 20 nicklas 111     @since 3.17
7859 20 Oct 20 nicklas 112   */
7859 20 Oct 20 nicklas 113   @Override
7859 20 Oct 20 nicklas 114   protected void loadPropertyChildNodes(DbControl dc, OverviewContext context, Node memberNode)
7859 20 Oct 20 nicklas 115   {
7859 20 Oct 20 nicklas 116     getNodeLoader(context, Item.ANNOTATION).createPropertyNode(dc, context, memberNode);
7859 20 Oct 20 nicklas 117   }
7859 20 Oct 20 nicklas 118
4740 05 Feb 09 nicklas 119 }