org.drools.repository
Class RulesRepository

java.lang.Object
  extended by org.drools.repository.RulesRepository

public class RulesRepository
extends Object

RulesRepository is the class that defines the behavior for the JBoss Rules (drools) rule repository based upon the JCR specification (JSR-170).

An instance of this class is capable of storing rules used by the JBoss Rule engine. It also provides a versioning capability for rules. Rules can be imported from specified files. The RulesRepository is also capable of storing DSL content. Rules can be explicitly tied to a particular DSL node within the repository, and this reference can either follow the head version, or a specific version of the DSL node.

Rules can be tagged. Tags are stored in a separate area of the repository, and can be added on demand. Rules can have 0 or more tags. Tags are intended to help provide a means for searching for specific types of rules quickly, even when they aren't all part of the same rulepackage.

Rules can be associated with 0 or 1 states. States are created in a seperate area of the repository. States are intended to help track the progress of a rule as it traverses its life- cycle. (e.g. draft, approved, deprecated, etc.)

The RulesRepository provides versioning of rules, rule packages, and DSLs. This versioning works in a strictly linear fashion, with one version having at most 1 predecessor version (or none, if it is the first version), and at most 1 successor version (or none, if it is the most recently checked-in version). The JCR specification supports a more complicated versioning system, and if there is sufficient demand, we can modify our versioning scheme to be better aligned with JCR's versioning abilities.


Nested Class Summary
static class RulesRepository.DateQuery
           
 
Field Summary
static String CONFIGURATION_AREA
           
static String DEFAULT_PACKAGE
           
static String DEFAULT_WORKSPACE
           
static String DO_NOT_INSTALL_SAMPLE_NODE
          The name of the node to store user's preference if want to install the sample repository
static String DROOLS_URI
           
static String GLOBAL_AREA
           
static String METADATA_TYPE_AREA
          The name of the meta data area within the JCR repository
static String MODULE_AREA
          The name of the module area of the repository
static String MODULE_SNAPSHOT_AREA
          The name of the module snapshot area of the repository
static String PERSPECTIVES_CONFIGURATION_AREA
           
static String RULES_REPOSITORY_NAME
          The name of the rules repository within the JCR repository
static String SCHEMA_AREA
          The name of the schema area within the JCR repository
static String STATE_AREA
          The name of the state area of the repository
static String TAG_AREA
          The name of the tag area of the repository
static String WORKSPACE_AREA
          The name of the workspace area within the JCR repository
 
Constructor Summary
RulesRepository(javax.jcr.Session session)
          This requires a JCR session be setup, and the repository be configured.
 
Method Summary
protected static javax.jcr.Node addNodeIfNew(javax.jcr.Node parent, String nodeName, String type)
          Will add a node named 'nodeName' of type 'type' to 'parent' if such a node does not already exist.
 boolean containsModule(String name)
          This returns true if the repository contains the specified module name.
 boolean containsSnapshot(String moduleName, String snapshotName)
           
 String copyAsset(String uuidSource, String destinationModule, String destinationName)
          This will copy an assets content to the new location.
 String copyModule(String sourceModuleName, String destModuleName)
          Copy a package to the target name.
 void copyModuleSnapshot(String moduleName, String snapshotName, String newName)
          Copies a snapshot to the new location/label.
 ModuleItem createModule(String name, String description)
          Adds a module to the repository.
 ModuleItem createModule(String name, String description, String format)
          Adds a module to the repository.
 ModuleItem createModule(String name, String description, String format, String[] workspace, String checkInComment)
          Adds a module to the repository.
 void createModuleSnapshot(String moduleName, String snapshotName)
          This will copy the module to the snapshot area.
 StateItem createState(String name)
          Create a status node of the given name.
 ModuleItem createSubModule(String name, String description, String parentModule)
          Adds a Sub module to the repository.
 javax.jcr.Node createWorkspace(String workspace)
          Create a status node of the given name.
 byte[] dumpModuleFromRepositoryXml(String moduleName)
           
 byte[] exportModuleFromRepository(String moduleName)
           
 void exportRepositoryToStream(OutputStream output)
           
 AssetItemIterator findArchivedAssets()
           
 AssetItemPageResult findAssetsByCategory(String categoryTag, boolean seekArchivedAsset, int skip, int numRowsToReturn)
          This will retrieve a list of RuleItem objects - that are allocated to the provided category.
 AssetItemPageResult findAssetsByCategory(String categoryTag, boolean seekArchivedAsset, int skip, int numRowsToReturn, RepositoryFilter filter)
          This will retrieve a list of RuleItem objects - that are allocated to the provided category.
 AssetItemPageResult findAssetsByCategory(String categoryTag, int skip, int numRowsToReturn)
           
 AssetItemIterator findAssetsByName(String name)
           
 AssetItemIterator findAssetsByName(String name, boolean seekArchived)
          This will search assets, looking for matches against the name.
 AssetItemIterator findAssetsByName(String name, boolean seekArchived, boolean isCaseSensitive)
          This will search assets, looking for matches against the name.
 AssetItemPageResult findAssetsByState(String stateName, boolean seekArchivedAsset, int skip, int numRowsToReturn)
          Finds the AssetItem's linked to the requested state.
 AssetItemPageResult findAssetsByState(String stateName, boolean seekArchivedAsset, int skip, int numRowsToReturn, RepositoryFilter filter)
          Finds the AssetItem's linked to the requested state.
 javax.jcr.Node getAreaNode(String areaName)
           
 javax.jcr.Session getSession()
           
 StateItem getState(String name)
          Gets a StateItem for the specified state name.
 void importPackageToRepository(byte[] byteArray, boolean importAsNew)
           
 void importRepository(InputStream in)
          Import the repository from a stream.
 void importRulesRepositoryFromStream(InputStream instream)
          Clean and import the repository.
 boolean isDoNotInstallSample()
           
 boolean isModuleArchived(String name)
          Check if module is archived.
 ModuleIterator listModules()
           
 String[] listModuleSnapshots(String moduleName)
          Return a list of the snapshots available for the given module name.
 StateItem[] listStates()
           
 String[] listWorkspaces()
           
 AssetItem loadAssetByUUID(String uuid)
          Loads an asset by its UUID (generally the fastest way to load something).
 CategoryItem loadCategory(String tagName)
          This will return a category for the given category path.
 ModuleItem loadDefaultModule()
          This will return or create the default module for assets that have no home yet.
 ModuleItem loadGlobalArea()
          This will return the global area for assets that can be shared.
 VersionableItem loadItemByUUID(String uuid)
          Similar to above.
 ModuleItem loadModule(String name)
          Loads a Module for the specified module name.
 ModuleItem loadModule(String name, long versionNumber)
          Loads a Module for the specified module name and version.
 ModuleItem loadModuleByUUID(String uuid)
          Similar to above.
 ModuleItem loadModuleSnapshot(String moduleName, String snapshotName)
           
 StateItem loadState(String name)
           
 void logout()
          Explicitly logout of the underlying JCR repository.
 void moveRuleItemModule(String newModule, String uuid, String explanation)
          This moves an asset from one module to another, preserving history etc etc.
 AssetItemIterator query(Map<String,String[]> params, boolean seekArchived, RulesRepository.DateQuery[] dates)
          This will do a general predicate search.
 AssetItemIterator queryFullText(String qry, boolean seekArchived)
          This will search assets, looking for matches against the name.
 void removeModuleSnapshot(String moduleName, String snapshotName)
          This will remove the specified snapshot.
 void removeWorkspace(String workspace)
           
 String renameAsset(String uuid, String newAssetName)
          This will rename an asset and apply the change immediately.
 void renameCategory(String originalPath, String newName)
          Rename a category.
 String renameModule(String uuid, String newModuleName)
          This will rename a module and apply the change immediately.
 void renameState(String oldName, String newName)
           
 void restoreHistoricalAsset(AssetItem versionToRestore, AssetItem headVersion, String comment)
          This will restore the historical version, save, and check it in as a new version with the given comment.
 void save()
          Save any pending changes.
 void setDoNotInstallSample()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PACKAGE

public static final String DEFAULT_PACKAGE
See Also:
Constant Field Values

DEFAULT_WORKSPACE

public static final String DEFAULT_WORKSPACE
See Also:
Constant Field Values

DROOLS_URI

public static final String DROOLS_URI
See Also:
Constant Field Values

MODULE_AREA

public static final String MODULE_AREA
The name of the module area of the repository

See Also:
Constant Field Values

GLOBAL_AREA

public static final String GLOBAL_AREA
See Also:
Constant Field Values

MODULE_SNAPSHOT_AREA

public static final String MODULE_SNAPSHOT_AREA
The name of the module snapshot area of the repository

See Also:
Constant Field Values

TAG_AREA

public static final String TAG_AREA
The name of the tag area of the repository

See Also:
Constant Field Values

STATE_AREA

public static final String STATE_AREA
The name of the state area of the repository

See Also:
Constant Field Values

CONFIGURATION_AREA

public static final String CONFIGURATION_AREA
See Also:
Constant Field Values

PERSPECTIVES_CONFIGURATION_AREA

public static final String PERSPECTIVES_CONFIGURATION_AREA
See Also:
Constant Field Values

SCHEMA_AREA

public static final String SCHEMA_AREA
The name of the schema area within the JCR repository

See Also:
Constant Field Values

METADATA_TYPE_AREA

public static final String METADATA_TYPE_AREA
The name of the meta data area within the JCR repository

See Also:
Constant Field Values

WORKSPACE_AREA

public static final String WORKSPACE_AREA
The name of the workspace area within the JCR repository

See Also:
Constant Field Values

DO_NOT_INSTALL_SAMPLE_NODE

public static final String DO_NOT_INSTALL_SAMPLE_NODE
The name of the node to store user's preference if want to install the sample repository

See Also:
Constant Field Values

RULES_REPOSITORY_NAME

public static final String RULES_REPOSITORY_NAME
The name of the rules repository within the JCR repository

See Also:
Constant Field Values
Constructor Detail

RulesRepository

public RulesRepository(javax.jcr.Session session)
This requires a JCR session be setup, and the repository be configured.

Method Detail

addNodeIfNew

protected static javax.jcr.Node addNodeIfNew(javax.jcr.Node parent,
                                             String nodeName,
                                             String type)
                                      throws RulesRepositoryException
Will add a node named 'nodeName' of type 'type' to 'parent' if such a node does not already exist.

Parameters:
parent - the parent node to add the new node to
nodeName - the name of the new node
type - the type of the new node
Returns:
a reference to the Node object that is created by the addition, or, if the node already existed, a reference to the pre-existant node.
Throws:
RulesRepositoryException

logout

@PreDestroy
public void logout()
Explicitly logout of the underlying JCR repository.


getAreaNode

public javax.jcr.Node getAreaNode(String areaName)
                           throws RulesRepositoryException
Throws:
RulesRepositoryException

copyAsset

public String copyAsset(String uuidSource,
                        String destinationModule,
                        String destinationName)
This will copy an assets content to the new location.

Returns:
the UUID of the new asset.

loadModule

public ModuleItem loadModule(String name)
                      throws RulesRepositoryException
Loads a Module for the specified module name. Will throw an exception if the specified module does not exist.

Parameters:
name - the name of the module to load
Returns:
a ModuleItem object
Throws:
RulesRepositoryException

loadModule

public ModuleItem loadModule(String name,
                             long versionNumber)
                      throws RulesRepositoryException
Loads a Module for the specified module name and version. Will throw an exception if the specified module does not exist.

Parameters:
name - the name of the module to load
versionNumber -
Returns:
a ModuleItem object
Throws:
RulesRepositoryException

loadState

public StateItem loadState(String name)
                    throws RulesRepositoryException
Throws:
RulesRepositoryException

containsModule

public boolean containsModule(String name)
This returns true if the repository contains the specified module name.


isModuleArchived

public boolean isModuleArchived(String name)
Check if module is archived.


containsSnapshot

public boolean containsSnapshot(String moduleName,
                                String snapshotName)

loadModuleSnapshot

public ModuleItem loadModuleSnapshot(String moduleName,
                                     String snapshotName)

createModuleSnapshot

public void createModuleSnapshot(String moduleName,
                                 String snapshotName)
This will copy the module to the snapshot area. Creating a copy for deployment, etc.


removeModuleSnapshot

public void removeModuleSnapshot(String moduleName,
                                 String snapshotName)
This will remove the specified snapshot.


copyModuleSnapshot

public void copyModuleSnapshot(String moduleName,
                               String snapshotName,
                               String newName)
Copies a snapshot to the new location/label. If one exists at that location, it will be replaced.

Parameters:
moduleName - The name of the module.
snapshotName - The label of the source snapshot
newName - The new label. The old one is left intact.

loadDefaultModule

public ModuleItem loadDefaultModule()
                             throws RulesRepositoryException
This will return or create the default module for assets that have no home yet.

Throws:
RulesRepositoryException

loadGlobalArea

public ModuleItem loadGlobalArea()
                          throws RulesRepositoryException
This will return the global area for assets that can be shared.

Throws:
RulesRepositoryException

loadModuleByUUID

public ModuleItem loadModuleByUUID(String uuid)
                            throws RulesRepositoryException
Similar to above. Loads a ModuleItem for the specified uuid.

Parameters:
uuid - the uuid of the module to load
Returns:
a ModuleItem object
Throws:
RulesRepositoryException

loadItemByUUID

public VersionableItem loadItemByUUID(String uuid)
                               throws RulesRepositoryException
Similar to above. Loads a ModuleItem or an AssetItem for the specified uuid.

Parameters:
uuid - the uuid of the module or asset to load
Returns:
a VersionableItem object
Throws:
RulesRepositoryException

restoreHistoricalAsset

public void restoreHistoricalAsset(AssetItem versionToRestore,
                                   AssetItem headVersion,
                                   String comment)
This will restore the historical version, save, and check it in as a new version with the given comment.

Parameters:
versionToRestore -
headVersion -
comment -

loadAssetByUUID

public AssetItem loadAssetByUUID(String uuid)
Loads an asset by its UUID (generally the fastest way to load something).


createModule

public ModuleItem createModule(String name,
                               String description)
                        throws RulesRepositoryException
Adds a module to the repository.

Parameters:
name - what to name the node added
description - what description to use for the node
Returns:
a ModuleItem, encapsulating the created node
Throws:
RulesRepositoryException

createModule

public ModuleItem createModule(String name,
                               String description,
                               String format)
                        throws RulesRepositoryException
Adds a module to the repository.

Parameters:
name - what to name the node added
description - what description to use for the node
format - module format.
Returns:
a ModuleItem, encapsulating the created node
Throws:
RulesRepositoryException

createModule

public ModuleItem createModule(String name,
                               String description,
                               String format,
                               String[] workspace,
                               String checkInComment)
                        throws RulesRepositoryException
Adds a module to the repository.

Parameters:
name - what to name the node added
description - what description to use for the node
format - module format.
workspace - the initial workspaces that this module belongs to.
Returns:
a ModuleItem, encapsulating the created node
Throws:
RulesRepositoryException

createSubModule

public ModuleItem createSubModule(String name,
                                  String description,
                                  String parentModule)
                           throws RulesRepositoryException
Adds a Sub module to the repository.

Parameters:
name - what to name the node added
description - what description to use for the node
parentModule - parent node under which this new package will be created
Returns:
a PackageItem, encapsulating the created node
Throws:
RulesRepositoryException

getState

public StateItem getState(String name)
                   throws RulesRepositoryException
Gets a StateItem for the specified state name. If a node for the specified state does not yet exist, one is first created.

Parameters:
name - the name of the state to get
Returns:
a StateItem object encapsulating the retrieved node
Throws:
RulesRepositoryException

createState

public StateItem createState(String name)
Create a status node of the given name.


listWorkspaces

public String[] listWorkspaces()
                        throws RulesRepositoryException
Throws:
RulesRepositoryException

createWorkspace

public javax.jcr.Node createWorkspace(String workspace)
Create a status node of the given name.


removeWorkspace

public void removeWorkspace(String workspace)

loadCategory

public CategoryItem loadCategory(String tagName)
                          throws RulesRepositoryException
This will return a category for the given category path.

Parameters:
tagName - the name of the tag to get. If the tag to get is within a hierarchy of tag nodes, specify the full path to the tag node of interest (e.g. if you want to get back 'child-tag', use "parent-tag/child-tag")
Returns:
a TagItem object encapsulating the node for the tag in the repository
Throws:
RulesRepositoryException

findAssetsByCategory

public AssetItemPageResult findAssetsByCategory(String categoryTag,
                                                boolean seekArchivedAsset,
                                                int skip,
                                                int numRowsToReturn)
                                         throws RulesRepositoryException
This will retrieve a list of RuleItem objects - that are allocated to the provided category. Only the latest versions of each RuleItem will be returned (you will have to delve into the assets deepest darkest history yourself... mahahahaha).

Throws:
RulesRepositoryException

findAssetsByCategory

public AssetItemPageResult findAssetsByCategory(String categoryTag,
                                                boolean seekArchivedAsset,
                                                int skip,
                                                int numRowsToReturn,
                                                RepositoryFilter filter)
                                         throws RulesRepositoryException
This will retrieve a list of RuleItem objects - that are allocated to the provided category. Only the latest versions of each RuleItem will be returned (you will have to delve into the assets deepest darkest history yourself... mahahahaha).

Pass in startRow of 0 to start at zero, numRowsToReturn can be set to -1 should you want it all.

Parameters:
filter - an AssetItem filter
Throws:
RulesRepositoryException

findAssetsByState

public AssetItemPageResult findAssetsByState(String stateName,
                                             boolean seekArchivedAsset,
                                             int skip,
                                             int numRowsToReturn)
                                      throws RulesRepositoryException
Finds the AssetItem's linked to the requested state. Similar to finding by category.

Throws:
RulesRepositoryException

findAssetsByState

public AssetItemPageResult findAssetsByState(String stateName,
                                             boolean seekArchivedAsset,
                                             int skip,
                                             int numRowsToReturn,
                                             RepositoryFilter filter)
                                      throws RulesRepositoryException
Finds the AssetItem's linked to the requested state. Similar to finding by category.

Parameters:
filter - an AssetItem filter
Throws:
RulesRepositoryException

findAssetsByCategory

public AssetItemPageResult findAssetsByCategory(String categoryTag,
                                                int skip,
                                                int numRowsToReturn)
                                         throws RulesRepositoryException
Throws:
RulesRepositoryException

exportRepositoryToStream

public void exportRepositoryToStream(OutputStream output)

exportModuleFromRepository

public byte[] exportModuleFromRepository(String moduleName)
                                  throws IOException,
                                         javax.jcr.PathNotFoundException,
                                         javax.jcr.RepositoryException
Throws:
IOException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

dumpModuleFromRepositoryXml

public byte[] dumpModuleFromRepositoryXml(String moduleName)
                                   throws javax.jcr.PathNotFoundException,
                                          IOException,
                                          javax.jcr.RepositoryException
Throws:
javax.jcr.PathNotFoundException
IOException
javax.jcr.RepositoryException

importRepository

public void importRepository(InputStream in)
Import the repository from a stream.


importRulesRepositoryFromStream

public void importRulesRepositoryFromStream(InputStream instream)
Clean and import the repository. Will run any needed migrations as well.


importPackageToRepository

public void importPackageToRepository(byte[] byteArray,
                                      boolean importAsNew)

listModules

public ModuleIterator listModules()
Returns:
an Iterator which will provide RulePackageItem's. This will show aLL the modules, only returning latest versions, by default.

getSession

public javax.jcr.Session getSession()
Returns:
The JCR session that this repository is using.

save

public void save()
Save any pending changes.


moveRuleItemModule

public void moveRuleItemModule(String newModule,
                               String uuid,
                               String explanation)
This moves an asset from one module to another, preserving history etc etc.

Parameters:
newModule - The destination module.
uuid - The UUID of the asset
explanation - The reason (which will be added as the checkin message).

renameAsset

public String renameAsset(String uuid,
                          String newAssetName)
This will rename an asset and apply the change immediately.

Returns:
the UUID of the new asset

renameCategory

public void renameCategory(String originalPath,
                           String newName)
Rename a category.

Parameters:
originalPath - The full path to the category.
newName - The new name (just the name, not the path).

renameState

public void renameState(String oldName,
                        String newName)

renameModule

public String renameModule(String uuid,
                           String newModuleName)
This will rename a module and apply the change immediately.

Returns:
the UUID of the module

listModuleSnapshots

public String[] listModuleSnapshots(String moduleName)
Return a list of the snapshots available for the given module name.


findArchivedAssets

public AssetItemIterator findArchivedAssets()

findAssetsByName

public AssetItemIterator findAssetsByName(String name,
                                          boolean seekArchived)
This will search assets, looking for matches against the name.


findAssetsByName

public AssetItemIterator findAssetsByName(String name,
                                          boolean seekArchived,
                                          boolean isCaseSensitive)
This will search assets, looking for matches against the name.

Parameters:
name - The search text
seekArchived - True is Archived Assets should be included
isCaseSensitive - True is the search is case-sensitive

queryFullText

public AssetItemIterator queryFullText(String qry,
                                       boolean seekArchived)
This will search assets, looking for matches against the name.


query

public AssetItemIterator query(Map<String,String[]> params,
                               boolean seekArchived,
                               RulesRepository.DateQuery[] dates)
This will do a general predicate search.

Parameters:
params - - a map of field to a list of possible values (which are or-ed together if there is more then one).
seekArchived - - include archived stuff in the results.

findAssetsByName

public AssetItemIterator findAssetsByName(String name)

listStates

public StateItem[] listStates()
Returns:
A list of statii in the system.

copyModule

public String copyModule(String sourceModuleName,
                         String destModuleName)
Copy a package to the target name.


isDoNotInstallSample

public boolean isDoNotInstallSample()
                             throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

setDoNotInstallSample

public void setDoNotInstallSample()
                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.