Class DefaultWorkflowValidationContext
- java.lang.Object
-
- de.xima.fc.workflow.processor.logic.validation.DefaultWorkflowValidationContext
-
- All Implemented Interfaces:
IBaseEnvironmentData
,IWorkflowValidationEnvironmentData
,IBaseWorkflowEnvironmentData
,IWorkflowGlobalHandlerValidationContext
,IWorkflowHandlerValidationContext
,IWorkflowLocalBeanValidationContext
,IWorkflowLocalHandlerValidationContext
,IWorkflowLocalValidationContext
,IWorkflowValidationContext
,AutoCloseable
public class DefaultWorkflowValidationContext extends Object implements IWorkflowLocalHandlerValidationContext, IWorkflowLocalBeanValidationContext, IWorkflowGlobalHandlerValidationContext, AutoCloseable
Default (mainly POJO) implementation of theIWorkflowLocalHandlerValidationContext
andIWorkflowGlobalHandlerValidationContext
. Can also be used as aIWorkflowLocalBeanValidationContext
. Contains additional methods meant only for theWorkflowValidator
implementation.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description DefaultWorkflowValidationContext(WorkflowValidationParams params)
Creates a new internal workflow validation context with the given parameters.
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.xima.fc.interfaces.workflow.validation.IWorkflowGlobalHandlerValidationContext
getNodeByUuid, getTriggerByUuid
-
Methods inherited from interface de.xima.fc.interfaces.workflow.validation.IWorkflowHandlerValidationContext
getLocalizedMessage
-
-
-
-
Constructor Detail
-
DefaultWorkflowValidationContext
public DefaultWorkflowValidationContext(WorkflowValidationParams params)
Creates a new internal workflow validation context with the given parameters.- Parameters:
params
- Configuration for the validation process.
-
-
Method Detail
-
addElementValidationMessage
public void addElementValidationMessage(ElementKey key, IWorkflowValidationMessage message)
Adds a validation message for the given workflow element.- Parameters:
key
- Key of the workflow element for which to add the message.message
- Message to add.
-
addGlobalValidationMessage
public void addGlobalValidationMessage(ElementKey key, IWorkflowValidationMessage message)
Description copied from interface:IWorkflowGlobalHandlerValidationContext
Adds a validations message for the workflow element with the given key.- Specified by:
addGlobalValidationMessage
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
key
- Key of the element to which the validation result applies.message
- Validation message to add.
-
addProcessValidationMessage
public void addProcessValidationMessage(IWorkflowValidationMessage message)
Adds a validation message for the given process.- Parameters:
message
- Message to add.
-
addTaskValidationMessage
public void addTaskValidationMessage(UUID key, IWorkflowValidationMessage message)
Adds a validation message for the given workflow task.- Parameters:
key
- Key of the workflow element for which to add the message.message
- Message to add.
-
addUnhandledException
public void addUnhandledException(Throwable exception)
Adds an unhandled exception to this workflow validation context. Usually called when an exception occurred during the validation of a certain node or trigger. This should not prevent other nodes and triggers from being validated.- Parameters:
exception
- The unhandled exception that occurred.
-
appendElementValidationResult
public void appendElementValidationResult(ElementKey key, IWorkflowElementValidationResult result)
- Parameters:
key
- Key of the workflow element for which to set the validation result.result
- The validation result to register for the given element.
-
appendProcessValidationResult
public void appendProcessValidationResult(IWorkflowElementValidationResult result)
- Parameters:
result
- The validation result to register for the process.
-
appendTaskValidationResult
public void appendTaskValidationResult(UUID key, IWorkflowElementValidationResult result)
- Parameters:
key
- Key of the workflow element for which to set the validation result.result
- The validation result to register for the given element.
-
associateValue
public <T> T associateValue(Object key, Function<IWorkflowLocalValidationContext,T> supplier)
Description copied from interface:IWorkflowLocalValidationContext
Associates the given value for the duration of the workflow validation process. Once validation is done, the values are discarded.- Specified by:
associateValue
in interfaceIWorkflowLocalValidationContext
- Type Parameters:
T
- Type of the associate value.- Parameters:
key
- Key for the association.supplier
- Supplier that produces the value when not yet present.- Returns:
- The associated value.
-
buildResult
public IWorkflowValidationResult buildResult()
Called after validation is done. Collects all validation messages added during the validation process and returns them.- Returns:
- The validation result representing the current state of this context.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
getAvailabilityCheck
public WorkflowElementAvailabilityCheck getAvailabilityCheck()
- Returns:
- Checker for checking whether a workflow element is available to the current user and client.
-
getBeanValidator
public IWorkflowBeanValidator getBeanValidator()
- Specified by:
getBeanValidator
in interfaceIWorkflowLocalHandlerValidationContext
- Returns:
- An instance of the bean validator that may be used to validate the properties model of a workflow element.
Bean validation is not required, but recommended, as it can be used in the UI as well. Consider adding the mixin
IBeanValidatingElement
which automatically delegates to the bean validator.
-
getClient
public Mandant getClient()
- Specified by:
getClient
in interfaceIBaseEnvironmentData
- Returns:
- The
Mandant
of the current context.
-
getCurrentElementKey
public ElementKey getCurrentElementKey()
- Specified by:
getCurrentElementKey
in interfaceIWorkflowLocalBeanValidationContext
- Returns:
- The
ElementKey
of the current workflow node or trigger that is currently being checked in the current workflow process.null
when no such element key exists.
-
getCurrentResourceBundle
public ResourceBundle getCurrentResourceBundle()
Description copied from interface:IWorkflowHandlerValidationContext
Resolves the resource bundle to be used for the workflow element that is currently being validated. This resource bundle takes into account the default resource bundle offered by FORMCYCLE, as well as the custom resource bundle indicated byIElementHandler.getResourceBundle(Locale)
.Please note as this depends upon the workflow element currently being validated, you should not store references to the returned bundle, always call this method directly.
- Specified by:
getCurrentResourceBundle
in interfaceIWorkflowHandlerValidationContext
- Returns:
- The current resource bundle containing all messages of the custom FORMCYCLE resources and the custom resources of the node or trigger handler.
-
getElementIndex
public WorkflowElementIndex getElementIndex()
- Returns:
- The element index for quickly accessing workflow element by their key.
-
getEntityContext
public IEntityContext getEntityContext()
- Specified by:
getEntityContext
in interfaceIBaseEnvironmentData
- Returns:
- The current entity context that may be used for database interactions.
-
getFlowAnalysis
public IWorkflowFlowAnalysis getFlowAnalysis()
- Specified by:
getFlowAnalysis
in interfaceIWorkflowGlobalHandlerValidationContext
- Returns:
- A handler for querying data about the execution of the workflow task being validated, such as whether a certain node is reachable from another node.
-
getGroups
public Set<EWorkflowValidationGroup> getGroups()
- Returns:
- Groups to validate.
-
getLocale
public Locale getLocale()
- Specified by:
getLocale
in interfaceIBaseEnvironmentData
- Returns:
- The locale to use for locale-sensitive actions.
-
getNodeByUuid
public IWorkflowElementWithDeserializedModel<?,WorkflowNode> getNodeByUuid(NodeKey key, String nodeType)
- Specified by:
getNodeByUuid
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
key
- Key of a node to find.nodeType
- Expected type of the node. Pass null or the empty string to return the node irrespective of its type.- Returns:
- The node with the given key and the given type in the current workflow process.
null
when no such node exists.
-
getNodesByType
public Collection<IWorkflowElementWithDeserializedModel<?,WorkflowNode>> getNodesByType(String nodeType)
- Specified by:
getNodesByType
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
nodeType
- Expected type of the node. Pass null or the empty string to return the all nodes.- Returns:
- All nodes of the given type, or all nodes when no type is given.
-
getProject
public Projekt getProject()
- Specified by:
getProject
in interfaceIBaseWorkflowEnvironmentData
- Returns:
- The current project to which the workflow belongs.
-
getProvider
public IWorkflowProvider getProvider()
- Specified by:
getProvider
in interfaceIWorkflowValidationContext
- Returns:
- The provider for accessing various contextual data, such as a list of all users or user groups.
-
getTriggerByUuid
public IWorkflowElementWithDeserializedModel<?,WorkflowTrigger> getTriggerByUuid(TriggerKey key, String triggerType)
- Specified by:
getTriggerByUuid
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
key
- Key of a trigger to find.triggerType
- Expected type of the trigger. Pass null or the empty string to return the trigger irrespective of its type.- Returns:
- The trigger with the given key and the given type in the current workflow process.
null
when no such node exists.
-
getTriggersByType
public Collection<IWorkflowElementWithDeserializedModel<?,WorkflowTrigger>> getTriggersByType(String triggerType)
- Specified by:
getTriggersByType
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
triggerType
- Expected type of the trigger. Pass null or the empty string to return the all triggers.- Returns:
- All triggers of the given type, or all triggers when no type is given.
-
getUser
public Benutzer getUser()
- Specified by:
getUser
in interfaceIBaseEnvironmentData
- Returns:
- The user of the active context that should be used for protocol entries etc.
-
getWorkflowBeanValidator
public WorkflowBeanValidator getWorkflowBeanValidator()
- Returns:
- The bean validator to be used for the workflow validation process.
-
getWorkflowResouceBundleLocator
public WorkflowResourceBundleLocator.MutableWorkflowResourceBundleLocator getWorkflowResouceBundleLocator()
- Returns:
- The resource bundle locator to be used for the workflow validation process.
-
getWorkflowVersion
public WorkflowVersion getWorkflowVersion()
- Specified by:
getWorkflowVersion
in interfaceIBaseWorkflowEnvironmentData
- Returns:
- The current workflow version that is being validated.
-
hasGroup
public boolean hasGroup(EWorkflowValidationGroup group)
- Parameters:
group
- Group to check- Returns:
- Whether the group should be validated.
-
markElementValidated
public void markElementValidated(ElementKey key)
Marks the given element as having been validated, regardless of whether it is valid or invalid. This exists to keep track of the elements that were validated and the elements for which validation was skipped.- Parameters:
key
- Key of the validated element.
-
markElementValidationFailed
public void markElementValidationFailed(ElementKey key)
Marks the given element as being invalid.- Parameters:
key
- Key of the invalid element.
-
markGlobalValidationFailed
public void markGlobalValidationFailed(ElementKey key)
Description copied from interface:IWorkflowGlobalHandlerValidationContext
Marks the given workflow element as invalid, when validation failed.- Specified by:
markGlobalValidationFailed
in interfaceIWorkflowGlobalHandlerValidationContext
- Parameters:
key
- Key of the element to mark as invalid.
-
markProcessValidated
public void markProcessValidated()
Marks the given process as having been validated.
-
markProcessValidationFailed
public void markProcessValidationFailed()
Marks the process as being invalid.
-
markTaskValidated
public void markTaskValidated(UUID key)
Marks the given task as having been validated, regardless of whether it is valid or invalid. This exists to keep track of the tasks that were validated and the tasks for which validation was skipped.- Parameters:
key
- Key of the validated task.
-
markTaskValidationFailed
public void markTaskValidationFailed(UUID key)
Marks the given task as being invalid.- Parameters:
key
- Key of the invalid task.
-
resultBuilder
public IWorkflowElementValidationResultBuilder resultBuilder()
- Specified by:
resultBuilder
in interfaceIWorkflowLocalValidationContext
- Returns:
- Builder for creating the result that needs to be returned by
IElementHandler#validateLocal
. This is provided for convenience, you can also create your own implementation ofIWorkflowElementValidationResult
.
-
setCurrentElementKey
public void setCurrentElementKey(ElementKey currentElementKey)
- Parameters:
currentElementKey
- TheNodeKey
of the current workflow node or trigger that is currently being checked.
-
-