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 aNodeLoader
implementation that supports it.This class is currently hardcoded to use a
BasicItemNodeLoaderFactory
andBasicItemNodeValidatorFactory
as factories for the node loaders and validators. This may change in future releases. UsegetNodeLoaderFactory()
andgetNodeValidatorFactory()
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 therecursive
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 Summary
Fields Modifier and Type Field Description private Map<String,Node>
allNodes
private static boolean
debug
private List<Failure>
failures
private static org.slf4j.Logger
log
private NodeCache<Object>
nodeCache
private BasicItemNodeLoaderFactory
nodeLoaderFactory
private BasicItemNodeValidatorFactory
nodeValidatorFactory
private Map<Object,Object>
objectCache
private Project
project
private BasicItem
rootItem
private Node
rootNode
private SnapshotManager
snapshotManager
private ValidationOptions
validationOptions
-
Constructor Summary
Constructors Constructor Description GenericOverview(DbControl dc, BasicItem rootItem, Project project)
Create a new generic overview.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
cacheChildNodes(Node node)
Failure
createFailure(Validator validator, Node node, String message, Fix... fixes)
Register a failure of a validation rule.private Node
createRootNode(DbControl dc, BasicItem root)
void
expand(DbControl dc, Node node, boolean recursive)
Load children of a node.Object
getCachedObject(Object cacheKey)
Retreive an object stored in the overview cache.List<Failure>
getFailures()
Get a list containing all validation failures.Node
getNode(String nodeId)
Get the node with the given ID.NodeCache<Object>
getNodeCache()
This overview implementation doesn't currently support node caching.NodeLoaderFactory<BasicItem,Object>
getNodeLoaderFactory()
Get the current node loader factory.NodeValidatorFactory<BasicItem,Object>
getNodeValidatorFactory()
Get the current node validator factory.Project
getProject()
Get the project of this overview is using for validating against project defaults (may be null).BasicItem
getRootItem()
Get the root item of this overview.Node
getRootNode()
Get the root node.SnapshotManager
getSnapshotManager()
Get the current snapshot manager.ValidationOptions
getValidationOptions()
Get the validation options currently in use.<I extends BasicItem>
ItemQuery<I>initQuery(ItemQuery<I> query, String sortby)
Same asinitQuery(ItemQuery, Order...)
but easier to use when sorting the items in ascending order by a single column.<I extends BasicItem>
ItemQuery<I>initQuery(ItemQuery<I> query, Order... sortby)
Initialise a query with "global options" and optionally a sort order.void
reset(DbControl dc)
Reset the overview and re-create the root node.void
setCachedObject(Object cacheKey, Object value)
Store an auxilliary object in the overview cache.void
updateFailureCountOnNodes()
Updates the failure count (warnings and errors) on all nodes.
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
debug
private static final boolean debug
-
validationOptions
private final ValidationOptions validationOptions
-
nodeLoaderFactory
private final BasicItemNodeLoaderFactory nodeLoaderFactory
-
nodeValidatorFactory
private final BasicItemNodeValidatorFactory nodeValidatorFactory
-
project
private final Project project
-
rootItem
private final BasicItem rootItem
-
snapshotManager
private SnapshotManager snapshotManager
-
rootNode
private Node rootNode
-
-
Constructor Detail
-
GenericOverview
public GenericOverview(DbControl dc, BasicItem rootItem, Project project)
Create a new generic overview.- Parameters:
dc
- A DbControl to use for database accessrootItem
- The root item of the overviewproject
- A project to use for validation of project default (we recommend that the currently active project is used)
-
-
Method Detail
-
getNodeLoaderFactory
public NodeLoaderFactory<BasicItem,Object> getNodeLoaderFactory()
Get the current node loader factory. NOTE! This is currently (BASE 2.10) hardcoded to be aBasicItemNodeLoaderFactory
but may change in (=be configurable) in future releases.- Specified by:
getNodeLoaderFactory
in interfaceOverviewContext
- 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 aBasicItemNodeValidatorFactory
but may change in (=be configurable) in future releases.- Specified by:
getNodeValidatorFactory
in interfaceOverviewContext
- Returns:
- A node loader factory
-
getSnapshotManager
public SnapshotManager getSnapshotManager()
Get the current snapshot manager.- Specified by:
getSnapshotManager
in interfaceOverviewContext
- 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 interfaceOverviewContext
- Returns:
- A project, or null
-
getCachedObject
public Object getCachedObject(Object cacheKey)
Retreive an object stored in the overview cache.- Specified by:
getCachedObject
in interfaceOverviewContext
- 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:
OverviewContext.setCachedObject(Object, Object)
-
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 interfaceOverviewContext
- Parameters:
cacheKey
- The key to store the value undervalue
- The value to store in the cache, or null to remove the entry- See Also:
OverviewContext.getCachedObject(Object)
-
getNodeCache
public NodeCache<Object> getNodeCache()
This overview implementation doesn't currently support node caching.- Specified by:
getNodeCache
in interfaceOverviewContext
- 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 interfaceOverviewContext
- Parameters:
validator
- The validation rule that failsnode
- The node that was validatedmessage
- An optional message, if null the message fromValidator.getFailureSummary()
is usedfixes
- 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 settingAbstractEntityQuery.include(java.util.Collection)
toInclude.ALL
, but this may change/be configurable in the future.- Specified by:
initQuery
in interfaceOverviewContext
- Parameters:
query
- The query that should be initialisedsortby
- An array with Order objects (may be null)- Returns:
- The same query object
- See Also:
OverviewContext.initQuery(ItemQuery, Order...)
-
initQuery
public <I extends BasicItem> ItemQuery<I> initQuery(ItemQuery<I> query, String sortby)
Same asinitQuery(ItemQuery, Order...)
but easier to use when sorting the items in ascending order by a single column.- Specified by:
initQuery
in interfaceOverviewContext
- Parameters:
query
- The query that should be initialisedsortby
- 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 accessnode
- The node to expandrecursive
- 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 interfaceOverviewContext
-
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 thereset(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
-
cacheChildNodes
private void cacheChildNodes(Node node)
-
-