Class GenericOverview

java.lang.Object
net.sf.basedb.util.overview.GenericOverview
All Implemented Interfaces:
OverviewContext

public class GenericOverview extends Object implements OverviewContext
Implementation for holding a generic overview of items. The overview can be rooted on all main items that have a NodeLoader implementation that supports it.

This class is currently hardcoded to use a BasicItemNodeLoaderFactory and BasicItemNodeValidatorFactory as factories for the node loaders and validators. This may change in future releases. Use getNodeLoaderFactory() and getNodeValidatorFactory() to get access to the factories.

The root item of the overview is specified in the constructor, as is a project that will be used for validating against project defaults. We recommend that the currently active project is used.

The overview has been designed to support lazy loading. To begin with the overview will only contain the root item. Use expand(DbControl, Node, boolean) to expand a node. If the recursive parameter is true the loading will continue until the "end" is reached, otherwise only the immediate children will be loaded. Note! The lazy loading functionality has not yet been tested (as of BASE 2.10) and may not work in all cases due to bugs in the code. To create an overview and load the entire tree in one go, use:

DbControl dc = ...
BasicItem item = ...
Project project = ...
GenericOverview go = new GenericOverview(dc, item, project);
go.expand(go.getRootNode().getId(), dc, true);
go.updateFailureCountOnNodes();
Version:
2.10
Author:
Nicklas
Last modified
$Date: 2017-03-02 08:28:36 +0100 (to, 02 mar 2017) $
  • Field Details

  • Constructor Details

    • GenericOverview

      public GenericOverview(DbControl dc, BasicItem rootItem, Project project)
      Create a new generic overview.
      Parameters:
      dc - A DbControl to use for database access
      rootItem - The root item of the overview
      project - A project to use for validation of project default (we recommend that the currently active project is used)
  • Method Details

    • getNodeLoaderFactory

      public NodeLoaderFactory<BasicItem,Object> getNodeLoaderFactory()
      Get the current node loader factory. NOTE! This is currently (BASE 2.10) hardcoded to be a BasicItemNodeLoaderFactory but may change in (=be configurable) in future releases.
      Specified by:
      getNodeLoaderFactory in interface OverviewContext
      Returns:
      A node loader factory
    • getNodeValidatorFactory

      public NodeValidatorFactory<BasicItem,Object> getNodeValidatorFactory()
      Get the current node validator factory. NOTE! This is currently (BASE 2.10) hardcoded to be a BasicItemNodeValidatorFactory but may change in (=be configurable) in future releases.
      Specified by:
      getNodeValidatorFactory in interface OverviewContext
      Returns:
      A node loader factory
    • getSnapshotManager

      public SnapshotManager getSnapshotManager()
      Get the current snapshot manager.
      Specified by:
      getSnapshotManager in interface OverviewContext
      Since:
      2.14
    • getProject

      public Project getProject()
      Get the project of this overview is using for validating against project defaults (may be null).
      Specified by:
      getProject in interface OverviewContext
      Returns:
      A project, or null
    • getCachedObject

      public Object getCachedObject(Object cacheKey)
      Retreive an object stored in the overview cache.
      Specified by:
      getCachedObject in interface OverviewContext
      Parameters:
      cacheKey - The key to use for cache lookup
      Returns:
      The object, or null if no object has been cached with the given key
      See Also:
    • setCachedObject

      public void setCachedObject(Object cacheKey, Object value)
      Store an auxilliary object in the overview cache. This is a service provided by the overview implementation that can be used by node loaders and/or validators to store information that may be needed again in the future and is expensive to retreive (eg. from the database). This is for example used to store annotation types that have been marked as "Required by MIAME", parents to annotatable items and more.
      Specified by:
      setCachedObject in interface OverviewContext
      Parameters:
      cacheKey - The key to store the value under
      value - The value to store in the cache, or null to remove the entry
      See Also:
    • getNodeCache

      public NodeCache<Object> getNodeCache()
      This overview implementation doesn't currently support node caching.
      Specified by:
      getNodeCache in interface OverviewContext
      Returns:
      A node cache, or null if the current overview doesn't want to use a cache
    • createFailure

      public Failure createFailure(Validator validator, Node node, String message, Fix... fixes)
      Register a failure of a validation rule.
      Specified by:
      createFailure in interface OverviewContext
      Parameters:
      validator - The validation rule that fails
      node - The node that was validated
      message - An optional message, if null the message from Validator.getFailureSummary() is used
      fixes - Optional fixes that may be used to correct the problem
    • initQuery

      public <I extends BasicItem> ItemQuery<I> initQuery(ItemQuery<I> query, Order... sortby)
      Initialise a query with "global options" and optionally a sort order. Note! The "global options" currently includes setting AbstractEntityQuery.include(java.util.Collection) to Include.ALL, but this may change/be configurable in the future.
      Specified by:
      initQuery in interface OverviewContext
      Parameters:
      query - The query that should be initialised
      sortby - An array with Order objects (may be null)
      Returns:
      The same query object
      See Also:
    • initQuery

      public <I extends BasicItem> ItemQuery<I> initQuery(ItemQuery<I> query, String sortby)
      Same as initQuery(ItemQuery, Order...) but easier to use when sorting the items in ascending order by a single column.
      Specified by:
      initQuery in interface OverviewContext
      Parameters:
      query - The query that should be initialised
      sortby - The property name to sort by (may be null)
      Returns:
      The same query object
    • getRootItem

      public BasicItem getRootItem()
      Get the root item of this overview.
    • getRootNode

      public Node getRootNode()
      Get the root node.
    • expand

      public void expand(DbControl dc, Node node, boolean recursive)
      Load children of a node. If the children has already been loaded (Node.isChildrenLoaded() == true) this method does nothing.
      Parameters:
      dc - The DbControl to use for database access
      node - The node to expand
      recursive - TRUE if children should be loaded recursively, FALSE to only load the immediate children
    • getValidationOptions

      public ValidationOptions getValidationOptions()
      Get the validation options currently in use.
      Specified by:
      getValidationOptions in interface OverviewContext
    • updateFailureCountOnNodes

      public void updateFailureCountOnNodes()
      Updates the failure count (warnings and errors) on all nodes. This method should be called if the validation options has changed. If the struture or information of the experiment has changed use the reset(DbControl) method instead.
    • reset

      public void reset(DbControl dc)
      Reset the overview and re-create the root node.
      Parameters:
      dc - A DbControl to use for database access.
    • getFailures

      public List<Failure> getFailures()
      Get a list containing all validation failures.
      Returns:
      A list (may be null)
    • getNode

      public Node getNode(String nodeId)
      Get the node with the given ID.
      Parameters:
      nodeId - The ID of the node
      Returns:
      A node or null if no node with the ID exists
    • createRootNode

      private Node createRootNode(DbControl dc, BasicItem root)
    • cacheChildNodes

      private void cacheChildNodes(Node node)