public class StateModel extends Object
<p>Represents the internal case engine model.</p> <p>It is built using the static case model (from the CMMN XML) as a template.
Constructor and Description |
---|
StateModel(String clientId,
Map<String,String> clientProperties,
PersistenceListeners persistenceListeners)
Constructor used to restore an existing state model.
|
StateModel(String clientId,
PersistenceListeners persistenceListeners)
Convenience constructor used in unit tests.
|
StateModel(String clientId,
String parentCaseId,
Map<String,String> clientProperties,
TransitionData transitionData,
PersistenceListeners persistenceListeners)
Create a new state model for a new case, consisting of a
casePlanModel and its caseFile . |
Modifier and Type | Method and Description |
---|---|
void |
applyVisitor(CaseFileItemInstanceVisitor visitor) |
void |
applyVisitor(PlanItemVisitor visitor,
TransitionData transitionData)
Apply a
PlanItemVisitor to the state model (@link this#casePlanModel}). |
void |
applyVisitor(PlannableItemVisitor visitor,
TransitionData transitionData)
Apply a
PlannableItemVisitor to the state model (@link this#casePlanModel}). |
static StreamSource |
createStreamSourceFromXml(String cmmnXml)
Helper to create a JAX stream source for XML unmarshalling.
|
static Unmarshaller |
createUnmarshaller()
Helper to crate a JAX XML unmarshaller
|
PlanItem |
findPlanItem(String planItemId)
See JavaDoc of
Stage.findPlanItem(String) |
List<AvailableAction> |
getAvailableActions(TransitionData transitionData,
EngineListeners engineListeners)
Get a sorted list of the currently available actions of this state model.
|
CaseFile |
getCaseFile() |
CaseFileItem |
getCaseFileItemById(String caseFileItemId) |
HashMap<String,CaseFileItemInstance> |
getCaseFileItemInstances() |
List<CaseFileItem> |
getCaseFileItems(String definitionType) |
CasePlanModel |
getCasePlanModel() |
Map<String,String> |
getClientProperties() |
List<CurrentState> |
getCurrentStates(TransitionData transitionData,
EngineListeners engineListeners)
Get a sorted list of the current states (milestones and stages) of this state model.
|
HashMap<String,PlanItem> |
getLatestPlanItemInstances() |
HashMap<String,PlanItem> |
getPlanItemInstances() |
List<PlanItem> |
getPlanItemInstances(Class<? extends PlanItem> planItemType,
boolean singleInstanceMode,
TransitionData transitionData) |
List<Map<String,Object>> |
getPlanItemProperties(Class<? extends PlanItem> planItemType,
boolean singleInstanceMode,
String[] properties,
TransitionData transitionData,
EvaluationListeners evaluationListeners)
Create a list of maps containing information about the plan items selected by this method.
|
Map<String,Object> |
getPlanItemProperties(String planItemId,
String[] properties,
TransitionData transitionData,
EvaluationListeners evaluationListeners)
Create a map containing information about the plan item selected by this method.
|
PlannableItemPool |
getPlannableItemPool() |
TransitionDataCache |
getTransitionDataCache(PersistenceListeners persistenceListeners) |
void |
handleCaseFileItemTransition(String sourceCaseFileItemId,
CaseFileItemTransition caseFileItemTransition,
TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners) |
void |
handleCaseMigration(String oldCmmnXml,
String newCmmnXml,
Map<String,String> clientProperties,
TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners)
Migrate this state model in place from an old CMMN model (XML) to a new model.
|
void |
handleDiscretionaryItemPlanning(String sourcePlanItemId,
TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners) |
void |
handlePlanItemTransition(String sourcePlanItemId,
PlanItemTransition planItemTransition,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners)
Strictly used for unit testing only.
|
void |
handlePlanItemTransition(String sourcePlanItemId,
PlanItemTransition planItemTransition,
TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners)
Trigger a state transition in the state model.
|
void |
handleStateUpdate(TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners)
Re-evaluate the model upon an external state update.
|
void |
log(String suffix) |
void |
registerNewInstance(PlanItem planItem)
Register a particular plan item instance as created.
|
void |
restore(PersistenceListeners persistenceListeners)
Restore a state model from storage.
|
void |
startCase(TransitionData transitionData,
EngineListeners engineListeners,
PersistenceListeners persistenceListeners)
Start the case.
|
void |
storeState(PersistenceListeners persistenceListeners)
Store the current state of the model if dirty.
|
String |
toString() |
public StateModel(String clientId, String parentCaseId, Map<String,String> clientProperties, TransitionData transitionData, PersistenceListeners persistenceListeners) throws JAXBException, IOException
Create a new state model for a new case, consisting of a casePlanModel
and its caseFile
.
clientId
- client id.parentCaseId
- parent case id. Only set for cases created as case tasksclientProperties
- client properties.transitionData
- transition data.persistenceListeners
- persistence listeners.JAXBException
- if the case XML received via the persistenceListeners
could not be un-marshaled.IOException
- if the case XML received via the persistenceListeners
could not be un-marshaled.public StateModel(String clientId, Map<String,String> clientProperties, PersistenceListeners persistenceListeners) throws JAXBException, IOException
Constructor used to restore an existing state model.
clientId
- client id.persistenceListeners
- persistence listeners.JAXBException
- if the case XML received via the persistenceListeners
could not be un-marshaled.IOException
- if the case XML received via the persistenceListeners
could not be un-marshaled.public StateModel(String clientId, PersistenceListeners persistenceListeners) throws JAXBException, IOException
Convenience constructor used in unit tests.
clientId
- client id.persistenceListeners
- persistence listeners.JAXBException
- if the case XML received via the persistenceListeners
could not be un-marshaled.IOException
- if the case XML received via the persistenceListeners
could not be un-marshaled.public void startCase(TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
Start the case.
transitionData
- transition dataengineListeners
- engine listenerspublic void restore(PersistenceListeners persistenceListeners) throws IOException
Restore a state model from storage.
persistenceListeners
- the object providing the PersistenceListeners.storeCaseState(String, Map, String)
method which serves the JSON string containing the state data.IOException
- if the state model could not be restored via the passed persistenceListeners
.public TransitionDataCache getTransitionDataCache(PersistenceListeners persistenceListeners)
public void registerNewInstance(PlanItem planItem)
Register a particular plan item instance as created.
public void handlePlanItemTransition(String sourcePlanItemId, PlanItemTransition planItemTransition, TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
Trigger a state transition in the state model.
sourcePlanItemId
- identifies the plan item upon which to apply the transition.planItemTransition
- the transition to be applied.transitionData
- transition data.engineListeners
- a callback object allowing the state engine to trigger actions in the calling client based on results (if any) from the executed transition.persistenceListeners
- the interface providing the hook to store the state JSON string in the client system.public void handlePlanItemTransition(String sourcePlanItemId, PlanItemTransition planItemTransition, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
Strictly used for unit testing only.
public void handleCaseFileItemTransition(String sourceCaseFileItemId, CaseFileItemTransition caseFileItemTransition, TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
public void handleDiscretionaryItemPlanning(String sourcePlanItemId, TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
public void handleStateUpdate(TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
Re-evaluate the model upon an external state update.
transitionData
- transition data.engineListeners
- a callback object allowing the state engine to trigger actions in the calling client based on results (if any) from the executed transition.public void handleCaseMigration(String oldCmmnXml, String newCmmnXml, Map<String,String> clientProperties, TransitionData transitionData, EngineListeners engineListeners, PersistenceListeners persistenceListeners)
Migrate this state model in place from an old CMMN model (XML) to a new model. There are two main steps in such a migration:
<ol>
<li>The old state information is re-mapped to the new model. This is done by re-mapping model IDs as necessary
(they may have changed in the new model) and making the structure of the old state information compatible to the
structure of the new state information. The result is a pre-liminary version of the state that’s compatible with the
new model but needs more work</li>
<li>In this second step, the case represented by this state model is then effectively re-started, using the
new model to dictate the structure and the run-time state prepared in the above step to initialize plan item
state from the old case. Some key code of this second step is executed in
Stage.createChild(PlannableItem, TransitionData, EventSources, EngineListeners, PersistenceListeners)
</li>
</ol>
public List<CurrentState> getCurrentStates(TransitionData transitionData, EngineListeners engineListeners)
Get a sorted list of the current states (milestones and stages) of this state model.
transitionData
- optional evaluation context.engineListeners
- client code implementation callbacks.public List<AvailableAction> getAvailableActions(TransitionData transitionData, EngineListeners engineListeners)
Get a sorted list of the currently available actions of this state model.
transitionData
- optional evaluation context.engineListeners
- client code implementation callbacks.public List<PlanItem> getPlanItemInstances(Class<? extends PlanItem> planItemType, boolean singleInstanceMode, TransitionData transitionData)
public Map<String,Object> getPlanItemProperties(String planItemId, String[] properties, TransitionData transitionData, EvaluationListeners evaluationListeners)
Create a map containing information about the plan item selected by this method.
planItemId
- the plan item Id.properties
- the properties to get from the selected plan item.transitionData
- the transition data.evaluationListeners
- provides the call-back method used to extract a property from a plan item by name.properties
parameter, the map will contain a key/value entry, the key being the property name as
passed in, the value being the object resulting from reading the property on the plan item.
Returns null
if there is no plan item for the passed planItemId
.public List<Map<String,Object>> getPlanItemProperties(Class<? extends PlanItem> planItemType, boolean singleInstanceMode, String[] properties, TransitionData transitionData, EvaluationListeners evaluationListeners)
Create a list of maps containing information about the plan items selected by this method.
planItemType
- used to select/filter the plan items by type.singleInstanceMode
- determines whether to only return the highest instance of a given plan item model element or all instances.properties
- the properties to get from each selected plan item.transitionData
- the transition data.evaluationListeners
- provides the call-back method used to extract a property from a plan item by name.properties
parameter, the map will contain a key/value entry, the key being the property name as
passed in, the value being the object resulting from reading the property on the plan item.public List<CaseFileItem> getCaseFileItems(String definitionType)
public void log(String suffix)
public void storeState(PersistenceListeners persistenceListeners) throws IOException
Store the current state of the model if dirty.
persistenceListeners
- the interface providing the hooks to store the state JSON string to persistent storage.IOException
- if the store operation fails.public PlanItem findPlanItem(String planItemId)
See JavaDoc of Stage.findPlanItem(String)
planItemId
- plan item idpublic CaseFileItem getCaseFileItemById(String caseFileItemId)
public HashMap<String,PlanItem> getPlanItemInstances()
public HashMap<String,PlanItem> getLatestPlanItemInstances()
public HashMap<String,CaseFileItemInstance> getCaseFileItemInstances()
public CasePlanModel getCasePlanModel()
public CaseFile getCaseFile()
public void applyVisitor(PlanItemVisitor visitor, TransitionData transitionData)
Apply a PlanItemVisitor
to the state model (@link this#casePlanModel}).
visitor
- the visitor to be applied. E.g. a logging visitor or a visitor to extract the state model’s state.transitionData
- optional evaluation context.public void applyVisitor(PlannableItemVisitor visitor, TransitionData transitionData)
Apply a PlannableItemVisitor
to the state model (@link this#casePlanModel}).
visitor
- the visitor to be applied. E.g. a visitor for discretionary item planning.transitionData
- optional evaluation context.public void applyVisitor(CaseFileItemInstanceVisitor visitor)
public PlannableItemPool getPlannableItemPool()
public static Unmarshaller createUnmarshaller()
Helper to crate a JAX XML unmarshaller
RuntimeException
- if the unmarshaller could not be created.public static StreamSource createStreamSourceFromXml(String cmmnXml)
Helper to create a JAX stream source for XML unmarshalling.
cmmnXml
- CMMN XML.Copyright © 2010 - 2019 edorasware ag. All Rights Reserved.