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

Code
Comments
Other
Rev Date Author Line
7861 21 Oct 20 nicklas 1 /**
7861 21 Oct 20 nicklas 2   $Id$
7861 21 Oct 20 nicklas 3
7861 21 Oct 20 nicklas 4   Copyright (C) 2020 Nicklas Nordborg
7861 21 Oct 20 nicklas 5
7861 21 Oct 20 nicklas 6   This file is part of BASE - BioArray Software Environment.
7861 21 Oct 20 nicklas 7   Available at http://base.thep.lu.se/
7861 21 Oct 20 nicklas 8
7861 21 Oct 20 nicklas 9   BASE is free software; you can redistribute it and/or
7861 21 Oct 20 nicklas 10   modify it under the terms of the GNU General Public License
7861 21 Oct 20 nicklas 11   as published by the Free Software Foundation; either version 3
7861 21 Oct 20 nicklas 12   of the License, or (at your option) any later version.
7861 21 Oct 20 nicklas 13
7861 21 Oct 20 nicklas 14   BASE is distributed in the hope that it will be useful,
7861 21 Oct 20 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
7861 21 Oct 20 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7861 21 Oct 20 nicklas 17   GNU General Public License for more details.
7861 21 Oct 20 nicklas 18
7861 21 Oct 20 nicklas 19   You should have received a copy of the GNU General Public License
7861 21 Oct 20 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
7861 21 Oct 20 nicklas 21 */
7861 21 Oct 20 nicklas 22 package net.sf.basedb.util.overview.loader;
7861 21 Oct 20 nicklas 23
7861 21 Oct 20 nicklas 24 import net.sf.basedb.core.BasicItem;
7861 21 Oct 20 nicklas 25 import net.sf.basedb.core.DbControl;
7861 21 Oct 20 nicklas 26 import net.sf.basedb.core.File;
7861 21 Oct 20 nicklas 27 import net.sf.basedb.core.Item;
7861 21 Oct 20 nicklas 28 import net.sf.basedb.core.PermissionDeniedException;
7861 21 Oct 20 nicklas 29 import net.sf.basedb.core.Protocol;
7861 21 Oct 20 nicklas 30 import net.sf.basedb.util.overview.Node;
7861 21 Oct 20 nicklas 31 import net.sf.basedb.util.overview.OverviewContext;
7861 21 Oct 20 nicklas 32 import net.sf.basedb.util.overview.node.ChildNodeDirection;
7861 21 Oct 20 nicklas 33 import net.sf.basedb.util.overview.node.NameableNameGenerator;
7861 21 Oct 20 nicklas 34 import net.sf.basedb.util.overview.node.NodeFactory;
7861 21 Oct 20 nicklas 35
7861 21 Oct 20 nicklas 36 /**
7861 21 Oct 20 nicklas 37   Node loader implementation for files. Files must be loaded as
7861 21 Oct 20 nicklas 38   property nodes. It can't be a root node or a forward/reverse-loading 
7861 21 Oct 20 nicklas 39   node. The property node itself is created as a property-loading node
7861 21 Oct 20 nicklas 40   that loads the annotations when asked to load it's children.
7861 21 Oct 20 nicklas 41   
7861 21 Oct 20 nicklas 42   @author Nicklas
7861 21 Oct 20 nicklas 43   @since 3.17
7861 21 Oct 20 nicklas 44 */
7861 21 Oct 20 nicklas 45 public class FileLoader
7861 21 Oct 20 nicklas 46   extends BasicItemNodeLoader<File>
7861 21 Oct 20 nicklas 47 {
7861 21 Oct 20 nicklas 48
7861 21 Oct 20 nicklas 49   public FileLoader()
7861 21 Oct 20 nicklas 50   {
7861 21 Oct 20 nicklas 51     super(Item.FILE, DENY_ROOT_NODE, 
7861 21 Oct 20 nicklas 52         new NameableNameGenerator<File>("file", "File"));
7861 21 Oct 20 nicklas 53   }
7861 21 Oct 20 nicklas 54   
7861 21 Oct 20 nicklas 55   /*
7861 21 Oct 20 nicklas 56     From the NodeLoader interface
7861 21 Oct 20 nicklas 57     ------------------------------
7861 21 Oct 20 nicklas 58   */
7861 21 Oct 20 nicklas 59   @Override
7861 21 Oct 20 nicklas 60   public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode)
7861 21 Oct 20 nicklas 61   {
7861 21 Oct 20 nicklas 62     File file = null;
7861 21 Oct 20 nicklas 63     boolean denied = false;
7861 21 Oct 20 nicklas 64     try
7861 21 Oct 20 nicklas 65     {
7861 21 Oct 20 nicklas 66       BasicItem parentItem = parentNode.getItem(dc);
7861 21 Oct 20 nicklas 67       if (parentItem instanceof Protocol)
7861 21 Oct 20 nicklas 68       {
7861 21 Oct 20 nicklas 69         file = ((Protocol)parentItem).getFile();
7861 21 Oct 20 nicklas 70       }
7861 21 Oct 20 nicklas 71       // If there are more items that link to files we should add them here
7861 21 Oct 20 nicklas 72     }
7861 21 Oct 20 nicklas 73     catch (PermissionDeniedException ex)
7861 21 Oct 20 nicklas 74     {
7861 21 Oct 20 nicklas 75       denied = true;
7861 21 Oct 20 nicklas 76     }
7861 21 Oct 20 nicklas 77     
7861 21 Oct 20 nicklas 78     NodeFactory<File> nf = getNodeFactory(dc, context);
7861 21 Oct 20 nicklas 79     Node fileNode = createItemNode(nf, file, file, denied, 
7861 21 Oct 20 nicklas 80         parentNode, ChildNodeDirection.PROPERTY);
7861 21 Oct 20 nicklas 81     return fileNode;
7861 21 Oct 20 nicklas 82   }
7861 21 Oct 20 nicklas 83   // -----------------------------------
7861 21 Oct 20 nicklas 84   /*
7861 21 Oct 20 nicklas 85     From the AbstractNodeLoader class
7861 21 Oct 20 nicklas 86     ----------------------------------
7861 21 Oct 20 nicklas 87   */
7861 21 Oct 20 nicklas 88   /**
7861 21 Oct 20 nicklas 89     Loads annotations for the given file node.
7861 21 Oct 20 nicklas 90     @see RawBioAssayLoader#createForwardNode(DbControl, OverviewContext, Node)
7861 21 Oct 20 nicklas 91   */
7861 21 Oct 20 nicklas 92   @Override
7861 21 Oct 20 nicklas 93   protected void loadPropertyChildNodes(DbControl dc, OverviewContext context, Node fileNode)
7861 21 Oct 20 nicklas 94   {
7861 21 Oct 20 nicklas 95     getNodeLoader(context, Item.ANNOTATION).createPropertyNode(dc, context, fileNode);
7861 21 Oct 20 nicklas 96   }
7861 21 Oct 20 nicklas 97   // -------------------------------------
7861 21 Oct 20 nicklas 98 }