org.drools.repository
Class ModuleItem

java.lang.Object
  extended by org.drools.repository.Item
      extended by org.drools.repository.VersionableItem
          extended by org.drools.repository.ModuleItem

public class ModuleItem
extends VersionableItem

A ModuleItem object aggregates a set of assets (for example, rules). This is advantageous for systems using the JBoss Rules engine where the application might make use of many related assets.

A ModuleItem refers to module nodes within the RulesRepository. It contains the "master copy" of assets (which may be linked into other module or other types of containers). This is a container "node".


Field Summary
static String ASSET_FOLDER_NAME
          This is the name of the asset "subfolder" where assets are kept for this package.
static String CATEGORY_RULE_KEYS_PROPERTY_NAME
           
static String CATEGORY_RULE_VALUES_PROPERTY_NAME
           
static String DEPENDENCIES_PROPERTY_NAME
           
static String EXTERNAL_URI_PROPERTY_NAME
           
static String HEADER_PROPERTY_NAME
           
static String MODULE_FORMAT
          The dublin core format attribute.
static String MODULE_TYPE_NAME
          The name of the module node type
static String WORKSPACE_PROPERTY_NAME
           
 
Fields inherited from class org.drools.repository.VersionableItem
CATEGORY_PROPERTY_NAME, CHECKIN_COMMENT, CONTENT_PROPERTY_ARCHIVE_FLAG, COVERAGE_PROPERTY_NAME, CREATOR_PROPERTY_NAME, DEFAULT_CONTENT_FORMAT, DESCRIPTION_PROPERTY_NAME, FORMAT_PROPERTY_NAME, LAST_CONTRIBUTOR_PROPERTY_NAME, LAST_MODIFIED_PROPERTY_NAME, PUBLISHER_PROPERTY_NAME, RELATION_PROPERTY_NAME, RIGHTS_PROPERTY_NAME, SOURCE_PROPERTY_NAME, STATE_PROPERTY_NAME, SUBJECT_PROPERTY_NAME, TITLE_PROPERTY_NAME, TYPE_PROPERTY_NAME, VALID_PROPERTY_NAME, VERSION_NUMBER_PROPERTY_NAME
 
Fields inherited from class org.drools.repository.Item
node, rulesRepository
 
Constructor Summary
ModuleItem(RulesRepository rulesRepository, javax.jcr.Node node)
          Constructs an object of type ModuleItem corresponding the specified node
 
Method Summary
 AssetItem addAsset(String assetName, String description)
          Adds an asset to the current module with no category (not recommended !).
 AssetItem addAsset(String assetName, String description, String initialCategory, String format)
          This adds an asset to the current physical module (you can move it later).
 AssetItem addAssetImportedFromGlobalArea(String sharedAssetName)
          This adds an asset which is imported from global area.
 void addWorkspace(String workspace)
          This adds a workspace
 void changeStatus(String newState)
          This will change the status of this module, and all the contained assets.
 boolean containsAsset(String name)
          Returns true if this module contains an asset of the given name.
 String[] convertStringToArray(String tagName)
           
 ModuleItem createSubModule(String subModuleName)
          Creates a nested package.
static String[] decodeDependencyPath(String dependencyPath)
           
static String encodeDependencyPath(String dependencyPath, String dependencyVersion)
           
static void ensureMixinType(AssetItem assetItem, String mixin)
           
 Iterator<AssetItem> getAssets()
          Return an iterator for the rules in this module
 Iterator<AssetItem> getAssetsWithStatus(StateItem state)
          This will return a list of assets for a given state.
 Iterator<AssetItem> getAssetsWithStatus(StateItem state, StateItem ignoreState)
          This will return a list of assets for a given state.
 HashMap<String,String> getCategoryRules()
           
 String getCategoryRules(boolean keys)
           
 byte[] getCompiledBinaryBytes()
          This is a convenience method for returning the binary data as a byte array.
 String[] getDependencies()
          To avoid updating dependency attribute for every asset operation like adding/renaming/deleting etc, we calculate dependency path on the fly.
 String getExternalURI()
           
 ModuleHistoryIterator getHistory()
           
 String getName()
          Return the name of the module.
 ModuleItem getPrecedingVersion()
          Clients of this method can cast the resulting object to the type of object they are calling the method on (e.g.
 String getSnapshotName()
          returns the name of the snapshot, if this module is really a snapshot.
 ModuleItem getSucceedingVersion()
          Clients of this method can cast the resulting object to the type of object they are calling the method on (e.g.
 String[] getWorkspaces()
           
 boolean isBinaryUpToDate()
          Return true if the binary is "up to date".
 boolean isSnapshot()
           
 AssetItemIterator listArchivedAssets()
           
 AssetItemIterator listAssetsByFormat(List<String> formatInList)
           
 AssetItemIterator listAssetsByFormat(String... formats)
          This will load an iterator for assets of the given format type.
 AssetItemIterator listAssetsNotOfFormat(String[] formats)
           
 AssetItemIterator listAssetsWithVersionsSpecifiedByDependenciesByFormat(String... assetFormats)
           
 ModuleIterator listSubModules()
          Returns a ModuleIterator of its children
 AssetItem loadAsset(String name)
          Load a specific asset by name.
 AssetItem loadAsset(String name, long versionNumber)
          Load a specific asset by name.
 AssetItemIterator queryAssets(String fieldPredicates)
           
 AssetItemIterator queryAssets(String fieldPredicates, boolean seekArchived)
          This will query any assets stored under this module.
 void remove()
          This will permanently delete this module.
 void removeWorkspace(String workspace)
          This removes a workspace
 void setCatRules(String map)
           
 String toString()
          Nicely formats the information contained by the node that this object encapsulates
 void updateBinaryUpToDate(boolean status)
          Set this to indicate if the binary is up to date, or not.
 void updateCategoryRules(String keys, String values)
           
 void updateCheckinComment(String comment)
          Update the checkin comment.
 ModuleItem updateCompiledBinary(InputStream data)
           
 void updateDependency(String dependencyPath)
           
 void updateExternalURI(String uri)
           
 void updateWorkspace(String[] workspace)
          This sets the Workspace
 
Methods inherited from class org.drools.repository.VersionableItem
archiveItem, checkin, checkIsUpdateable, checkout, checkout, getBooleanProperty, getCheckinComment, getCoverage, getCreatedDate, getCreator, getDescription, getExternalRelation, getExternalSource, getFormat, getLastContributor, getLastModified, getLongProperty, getPrecedingVersionNode, getPublisher, getRealContentFromVersion, getRights, getState, getStateDescription, getStringProperty, getStringPropertyArray, getSubject, getSucceedingVersionNode, getTitle, getType, getUUID, getValid, getVersionContentNode, getVersionManager, getVersionNumber, getVersionSnapshotUUID, isArchived, isHistoricalVersion, sameState, updateCoverage, updateDescription, updateExternalRelation, updateExternalSource, updateFormat, updatePublisher, updateRights, updateState, updateState, updateStringArrayProperty, updateStringProperty, updateStringProperty, updateSubject, updateTitle, updateType, updateValid, updateValid
 
Methods inherited from class org.drools.repository.Item
equals, getNode, getRulesRepository, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ASSET_FOLDER_NAME

public static final String ASSET_FOLDER_NAME
This is the name of the asset "subfolder" where assets are kept for this package.

See Also:
Constant Field Values

MODULE_FORMAT

public static final String MODULE_FORMAT
The dublin core format attribute.

See Also:
Constant Field Values

MODULE_TYPE_NAME

public static final String MODULE_TYPE_NAME
The name of the module node type

See Also:
Constant Field Values

HEADER_PROPERTY_NAME

public static final String HEADER_PROPERTY_NAME
See Also:
Constant Field Values

EXTERNAL_URI_PROPERTY_NAME

public static final String EXTERNAL_URI_PROPERTY_NAME
See Also:
Constant Field Values

CATEGORY_RULE_KEYS_PROPERTY_NAME

public static final String CATEGORY_RULE_KEYS_PROPERTY_NAME
See Also:
Constant Field Values

CATEGORY_RULE_VALUES_PROPERTY_NAME

public static final String CATEGORY_RULE_VALUES_PROPERTY_NAME
See Also:
Constant Field Values

WORKSPACE_PROPERTY_NAME

public static final String WORKSPACE_PROPERTY_NAME
See Also:
Constant Field Values

DEPENDENCIES_PROPERTY_NAME

public static final String DEPENDENCIES_PROPERTY_NAME
See Also:
Constant Field Values
Constructor Detail

ModuleItem

public ModuleItem(RulesRepository rulesRepository,
                  javax.jcr.Node node)
           throws RulesRepositoryException
Constructs an object of type ModuleItem corresponding the specified node

Parameters:
rulesRepository - the rulesRepository that instantiated this object
node - the node to which this object corresponds
Throws:
RulesRepositoryException
Method Detail

getName

public String getName()
Return the name of the module.

Overrides:
getName in class VersionableItem
Returns:
the name of the node that this item encapsultes

isSnapshot

public boolean isSnapshot()
Returns:
true if this module is actually a snapshot.

updateBinaryUpToDate

public void updateBinaryUpToDate(boolean status)
Set this to indicate if the binary is up to date, or not.


isBinaryUpToDate

public boolean isBinaryUpToDate()
Return true if the binary is "up to date".

Returns:

getSnapshotName

public String getSnapshotName()
returns the name of the snapshot, if this module is really a snapshot. If it is not, it will just return the name of the module, so use wisely !


getWorkspaces

public String[] getWorkspaces()
                       throws RulesRepositoryException
Returns:
the workspace this module belongs to.
Throws:
RulesRepositoryException

updateWorkspace

public void updateWorkspace(String[] workspace)
This sets the Workspace

Parameters:
workspace -

addWorkspace

public void addWorkspace(String workspace)
This adds a workspace

Parameters:
workspace -

removeWorkspace

public void removeWorkspace(String workspace)
This removes a workspace

Parameters:
workspace -

addAsset

public AssetItem addAsset(String assetName,
                          String description)
Adds an asset to the current module with no category (not recommended !). Without categories, its going to be hard to find rules later on (unless modules are enough for you).


addAsset

public AssetItem addAsset(String assetName,
                          String description,
                          String initialCategory,
                          String format)
This adds an asset to the current physical module (you can move it later). With the given category.

This will NOT check the asset in, just create the basic record.

Parameters:
assetName - The name of the asset (the file name minus the extension)
description - A description of the asset.
initialCategory - The initial category the asset is placed in (can belong to multiple ones later).
format - The dublin core format (which also determines what editor is used) - this is effectively the file extension.

addAssetImportedFromGlobalArea

public AssetItem addAssetImportedFromGlobalArea(String sharedAssetName)
This adds an asset which is imported from global area.

This will NOT check the asset in, just create the basic record.

Parameters:
sharedAssetName - The name of the imported asset

ensureMixinType

public static void ensureMixinType(AssetItem assetItem,
                                   String mixin)
                            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

remove

public void remove()
This will permanently delete this module.


getDependencies

public String[] getDependencies()
To avoid updating dependency attribute for every asset operation like adding/renaming/deleting etc, we calculate dependency path on the fly.

Returns:
String[] The dependency path.

updateDependency

public void updateDependency(String dependencyPath)

encodeDependencyPath

public static String encodeDependencyPath(String dependencyPath,
                                          String dependencyVersion)

decodeDependencyPath

public static String[] decodeDependencyPath(String dependencyPath)

getAssets

public Iterator<AssetItem> getAssets()
Return an iterator for the rules in this module


queryAssets

public AssetItemIterator queryAssets(String fieldPredicates,
                                     boolean seekArchived)
This will query any assets stored under this module. For example, you can pass in "drools:format = 'drl'" to get a list of only a certain type of asset.

Parameters:
fieldPredicates - A predicate string (SQL style).
Returns:
A list of matches.

queryAssets

public AssetItemIterator queryAssets(String fieldPredicates)

listArchivedAssets

public AssetItemIterator listArchivedAssets()

listAssetsByFormat

public AssetItemIterator listAssetsByFormat(List<String> formatInList)

listAssetsWithVersionsSpecifiedByDependenciesByFormat

public AssetItemIterator listAssetsWithVersionsSpecifiedByDependenciesByFormat(String... assetFormats)
Returns:
The header contents as pertains to a package of rule assets.

listAssetsByFormat

public AssetItemIterator listAssetsByFormat(String... formats)
This will load an iterator for assets of the given format type.


listAssetsNotOfFormat

public AssetItemIterator listAssetsNotOfFormat(String[] formats)

loadAsset

public AssetItem loadAsset(String name)
Load a specific asset by name.


loadAsset

public AssetItem loadAsset(String name,
                           long versionNumber)
Load a specific asset by name.


containsAsset

public boolean containsAsset(String name)
Returns true if this module contains an asset of the given name.


toString

public String toString()
Nicely formats the information contained by the node that this object encapsulates

Overrides:
toString in class Object

getHistory

public ModuleHistoryIterator getHistory()
Specified by:
getHistory in class VersionableItem
Returns:
An iterator over the nodes history.

getPrecedingVersion

public ModuleItem getPrecedingVersion()
                               throws RulesRepositoryException
Description copied from class: VersionableItem
Clients of this method can cast the resulting object to the type of object they are calling the method on (e.g.
           RuleItem item;
           ...
           RuleItem predcessor = (RuleItem) item.getPrecedingVersion();
         

Specified by:
getPrecedingVersion in class VersionableItem
Returns:
a VersionableItem object encapsulating the predessor node of this node in the version history, or null if no predecessor version exists
Throws:
RulesRepositoryException

getSucceedingVersion

public ModuleItem getSucceedingVersion()
                                throws RulesRepositoryException
Description copied from class: VersionableItem
Clients of this method can cast the resulting object to the type of object they are calling the method on (e.g.
           RuleItem item;
           ...
           RuleItem successor = (RuleItem) item.getSucceedingVersion();
         

Specified by:
getSucceedingVersion in class VersionableItem
Returns:
a VersionableItem object encapsulating the successor node of this node in the version history.
Throws:
RulesRepositoryException

getAssetsWithStatus

public Iterator<AssetItem> getAssetsWithStatus(StateItem state,
                                               StateItem ignoreState)
This will return a list of assets for a given state. It works through the assets that belong to this module, and if they are not in the correct state, walks backwards until it finds one in the correct state.

If it walks all the way back up the versions looking for the "latest" version with the appropriate state, and can't find one, that asset is not included in the result.

This will exclude any items that have the "ignoreState" set (so for example, retired items, invalid items etc).

Parameters:
state - The state of assets to retrieve.
ignoreState - The statuses to not include in the results (it will look at the status of the latest one).

getAssetsWithStatus

public Iterator<AssetItem> getAssetsWithStatus(StateItem state)
This will return a list of assets for a given state. It works through the assets that belong to this module, and if they are not in the correct state, walks backwards until it finds one in the correct state.

If it walks all the way back up the versions looking for the "latest" version with the appropriate state, and can't find one, that asset is not included in the result.


getExternalURI

public String getExternalURI()
Returns:
The external URI which will be used to sync this module to an external resource. Generally this will resolve to a directory in (for example) Subversion - with each asset being a file (with the format property as the file extension).

updateExternalURI

public void updateExternalURI(String uri)

setCatRules

public void setCatRules(String map)

updateCategoryRules

public void updateCategoryRules(String keys,
                                String values)
                         throws RulesRepositoryException
Throws:
RulesRepositoryException

convertStringToArray

public String[] convertStringToArray(String tagName)

getCategoryRules

public HashMap<String,String> getCategoryRules()

getCategoryRules

public String getCategoryRules(boolean keys)

updateCheckinComment

public void updateCheckinComment(String comment)
Update the checkin comment.


changeStatus

public void changeStatus(String newState)
This will change the status of this module, and all the contained assets. No new versions are created of anything.

Parameters:
newState - The status tag to change it to.

updateCompiledBinary

public ModuleItem updateCompiledBinary(InputStream data)

getCompiledBinaryBytes

public byte[] getCompiledBinaryBytes()
This is a convenience method for returning the binary data as a byte array.


createSubModule

public ModuleItem createSubModule(String subModuleName)
                           throws javax.jcr.RepositoryException
Creates a nested package.

Throws:
javax.jcr.RepositoryException

listSubModules

public ModuleIterator listSubModules()
Returns a ModuleIterator of its children

Returns:
a ModuleIterator of its children


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