public class GenericOverview extends java.lang.Object implements OverviewContext
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();
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,Node> |
allNodes |
private static boolean |
debug |
private java.util.List<Failure> |
failures |
private static org.slf4j.Logger |
log |
private NodeCache<java.lang.Object> |
nodeCache |
private BasicItemNodeLoaderFactory |
nodeLoaderFactory |
private BasicItemNodeValidatorFactory |
nodeValidatorFactory |
private java.util.Map<java.lang.Object,java.lang.Object> |
objectCache |
private Project |
project |
private BasicItem |
rootItem |
private Node |
rootNode |
private SnapshotManager |
snapshotManager |
private ValidationOptions |
validationOptions |
Constructor and Description |
---|
GenericOverview(DbControl dc,
BasicItem rootItem,
Project project)
Create a new generic overview.
|
Modifier and Type | Method and Description |
---|---|
private void |
cacheChildNodes(Node node) |
Failure |
createFailure(Validator validator,
Node node,
java.lang.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.
|
java.lang.Object |
getCachedObject(java.lang.Object cacheKey)
Retreive an object stored in the overview cache.
|
java.util.List<Failure> |
getFailures()
Get a list containing all validation failures.
|
Node |
getNode(java.lang.String nodeId)
Get the node with the given ID.
|
NodeCache<java.lang.Object> |
getNodeCache()
This overview implementation doesn't currently support node caching.
|
NodeLoaderFactory<BasicItem,java.lang.Object> |
getNodeLoaderFactory()
Get the current node loader factory.
|
NodeValidatorFactory<BasicItem,java.lang.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> |
initQuery(ItemQuery<I> query,
Order... sortby)
Initialise a query with "global options" and optionally a sort
order.
|
<I extends BasicItem> |
initQuery(ItemQuery<I> query,
java.lang.String sortby)
Same as
initQuery(ItemQuery, Order...) but easier to use when
sorting the items in ascending order by a single column. |
void |
reset(DbControl dc)
Reset the overview and re-create the root node.
|
void |
setCachedObject(java.lang.Object cacheKey,
java.lang.Object value)
Store an auxilliary object in the overview cache.
|
void |
updateFailureCountOnNodes()
Updates the failure count (warnings and errors) on all nodes.
|
private static final org.slf4j.Logger log
private static final boolean debug
private final ValidationOptions validationOptions
private final BasicItemNodeLoaderFactory nodeLoaderFactory
private final BasicItemNodeValidatorFactory nodeValidatorFactory
private final Project project
private final BasicItem rootItem
private SnapshotManager snapshotManager
private Node rootNode
private java.util.Map<java.lang.String,Node> allNodes
private java.util.Map<java.lang.Object,java.lang.Object> objectCache
private java.util.List<Failure> failures
private NodeCache<java.lang.Object> nodeCache
public GenericOverview(DbControl dc, BasicItem rootItem, Project project)
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)public NodeLoaderFactory<BasicItem,java.lang.Object> getNodeLoaderFactory()
BasicItemNodeLoaderFactory
but may change in
(=be configurable) in future releases.getNodeLoaderFactory
in interface OverviewContext
public NodeValidatorFactory<BasicItem,java.lang.Object> getNodeValidatorFactory()
BasicItemNodeValidatorFactory
but may change in
(=be configurable) in future releases.getNodeValidatorFactory
in interface OverviewContext
public SnapshotManager getSnapshotManager()
getSnapshotManager
in interface OverviewContext
public Project getProject()
getProject
in interface OverviewContext
public java.lang.Object getCachedObject(java.lang.Object cacheKey)
getCachedObject
in interface OverviewContext
cacheKey
- The key to use for cache lookupOverviewContext.setCachedObject(Object, Object)
public void setCachedObject(java.lang.Object cacheKey, java.lang.Object value)
setCachedObject
in interface OverviewContext
cacheKey
- The key to store the value undervalue
- The value to store in the cache, or null to
remove the entryOverviewContext.getCachedObject(Object)
public NodeCache<java.lang.Object> getNodeCache()
getNodeCache
in interface OverviewContext
public Failure createFailure(Validator validator, Node node, java.lang.String message, Fix... fixes)
createFailure
in interface OverviewContext
validator
- The validation rule that failsnode
- The node that was validatedmessage
- An optional message, if null the message from
Validator.getFailureSummary()
is usedfixes
- Optional fixes that may be used to correct the problempublic <I extends BasicItem> ItemQuery<I> initQuery(ItemQuery<I> query, Order... sortby)
AbstractEntityQuery.include(java.util.Collection)
to Include.ALL
,
but this may change/be configurable in the future.initQuery
in interface OverviewContext
query
- The query that should be initialisedsortby
- An array with Order objects (may be null)OverviewContext.initQuery(ItemQuery, Order...)
public <I extends BasicItem> ItemQuery<I> initQuery(ItemQuery<I> query, java.lang.String sortby)
initQuery(ItemQuery, Order...)
but easier to use when
sorting the items in ascending order by a single column.initQuery
in interface OverviewContext
query
- The query that should be initialisedsortby
- The property name to sort by (may be null)public BasicItem getRootItem()
public Node getRootNode()
public void expand(DbControl dc, Node node, boolean recursive)
Node.isChildrenLoaded()
== true) this method does nothing.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 childrenpublic ValidationOptions getValidationOptions()
getValidationOptions
in interface OverviewContext
public void updateFailureCountOnNodes()
reset(DbControl)
method instead.public void reset(DbControl dc)
dc
- A DbControl to use for database access.public java.util.List<Failure> getFailures()
public Node getNode(java.lang.String nodeId)
nodeId
- The ID of the nodeprivate void cacheChildNodes(Node node)