Skip to content

Commit

Permalink
feat(form): parse camunda form definition on user tasks
Browse files Browse the repository at this point in the history
Related to CAM-13660
  • Loading branch information
mboskamp committed Jul 15, 2021
1 parent b1bd383 commit 0c1156b
Show file tree
Hide file tree
Showing 19 changed files with 968 additions and 63 deletions.
Expand Up @@ -184,19 +184,19 @@ public class BpmnParse extends Parse {
protected DeploymentEntity deployment;

/** The end result of the parsing: a list of process definition. */
protected List<ProcessDefinitionEntity> processDefinitions = new ArrayList<ProcessDefinitionEntity>();
protected List<ProcessDefinitionEntity> processDefinitions = new ArrayList<>();

/** Mapping of found errors in BPMN 2.0 file */
protected Map<String, Error> errors = new HashMap<String, Error>();
protected Map<String, Error> errors = new HashMap<>();

/** Mapping of found escalation elements */
protected Map<String, Escalation> escalations = new HashMap<String, Escalation>();
protected Map<String, Escalation> escalations = new HashMap<>();

/**
* Mapping from a process definition key to his containing list of job
* declarations
**/
protected Map<String, List<JobDeclaration<?, ?>>> jobDeclarations = new HashMap<String, List<JobDeclaration<?, ?>>>();
protected Map<String, List<JobDeclaration<?, ?>>> jobDeclarations = new HashMap<>();

/** A map for storing sequence flow based on their id during parsing. */
protected Map<String, TransitionImpl> sequenceFlows;
Expand All @@ -205,10 +205,10 @@ public class BpmnParse extends Parse {
* A list of all element IDs. This allows us to parse only what we actually
* support but still validate the references among elements we do not support.
*/
protected List<String> elementIds = new ArrayList<String>();
protected List<String> elementIds = new ArrayList<>();

/** A map for storing the process references of participants */
protected Map<String, String> participantProcesses = new HashMap<String, String>();
protected Map<String, String> participantProcesses = new HashMap<>();

/**
* Mapping containing values stored during the first phase of parsing since
Expand All @@ -218,18 +218,18 @@ public class BpmnParse extends Parse {
* means that this map doesn't need to be re-initialized for each new process
* definition.
*/
protected Map<String, MessageDefinition> messages = new HashMap<String, MessageDefinition>();
protected Map<String, SignalDefinition> signals = new HashMap<String, SignalDefinition>();
protected Map<String, MessageDefinition> messages = new HashMap<>();
protected Map<String, SignalDefinition> signals = new HashMap<>();

// Members
protected ExpressionManager expressionManager;
protected List<BpmnParseListener> parseListeners;
protected Map<String, XMLImporter> importers = new HashMap<String, XMLImporter>();
protected Map<String, String> prefixs = new HashMap<String, String>();
protected Map<String, XMLImporter> importers = new HashMap<>();
protected Map<String, String> prefixs = new HashMap<>();
protected String targetNamespace;

private Map<String, String> eventLinkTargets = new HashMap<String, String>();
private Map<String, String> eventLinkSources = new HashMap<String, String>();
private Map<String, String> eventLinkTargets = new HashMap<>();
private Map<String, String> eventLinkSources = new HashMap<>();

/**
* Constructor to be called by the {@link BpmnParser}.
Expand Down Expand Up @@ -530,7 +530,7 @@ public void parseCollaboration() {
*/
public ProcessDefinitionEntity parseProcess(Element processElement) {
// reset all mappings that are related to one process definition
sequenceFlows = new HashMap<String, TransitionImpl>();
sequenceFlows = new HashMap<>();

ProcessDefinitionEntity processDefinition = new ProcessDefinitionEntity();

Expand Down Expand Up @@ -638,7 +638,7 @@ public void parseScope(Element scopeElement, ScopeImpl parentScope) {
// parseProperties(processElement);

// filter activities that must be parsed separately
List<Element> activityElements = new ArrayList<Element>(scopeElement.elements());
List<Element> activityElements = new ArrayList<>(scopeElement.elements());
Map<String, Element> intermediateCatchEvents = filterIntermediateCatchEvents(activityElements);
activityElements.removeAll(intermediateCatchEvents.values());
Map<String, Element> compensationHandlers = filterCompensationHandlers(activityElements);
Expand All @@ -664,7 +664,7 @@ public void parseScope(Element scopeElement, ScopeImpl parentScope) {
}

protected HashMap<String, Element> filterIntermediateCatchEvents(List<Element> activityElements) {
HashMap<String, Element> intermediateCatchEvents = new HashMap<String, Element>();
HashMap<String, Element> intermediateCatchEvents = new HashMap<>();
for(Element activityElement : activityElements) {
if (activityElement.getTagName().equals(ActivityTypes.INTERMEDIATE_EVENT_CATCH)) {
intermediateCatchEvents.put(activityElement.attribute("id"), activityElement);
Expand All @@ -674,7 +674,7 @@ protected HashMap<String, Element> filterIntermediateCatchEvents(List<Element> a
}

protected HashMap<String, Element> filterCompensationHandlers(List<Element> activityElements) {
HashMap<String, Element> compensationHandlers = new HashMap<String, Element>();
HashMap<String, Element> compensationHandlers = new HashMap<>();
for(Element activityElement : activityElements) {
if (isCompensationHandler(activityElement)) {
compensationHandlers.put(activityElement.attribute("id"), activityElement);
Expand Down Expand Up @@ -839,7 +839,7 @@ protected void parseAssociationOfCompensationBoundaryEvent(Element associationEl

protected void parseCompensationHandlers(ScopeImpl parentScope, Map<String, Element> compensationHandlers) {
// compensation handlers attached to compensation boundary events should be already parsed
for (Element compensationHandler : new HashSet<Element>(compensationHandlers.values())) {
for (Element compensationHandler : new HashSet<>(compensationHandlers.values())) {
parseActivity(compensationHandler, null, parentScope);
}
compensationHandlers.clear();
Expand All @@ -857,7 +857,7 @@ protected void parseCompensationHandlers(ScopeImpl parentScope, Map<String, Elem
*/
public void parseStartEvents(Element parentElement, ScopeImpl scope) {
List<Element> startEventElements = parentElement.elements("startEvent");
List<ActivityImpl> startEventActivities = new ArrayList<ActivityImpl>();
List<ActivityImpl> startEventActivities = new ArrayList<>();
if (startEventElements.size() > 0) {
for (Element startEventElement : startEventElements) {

Expand Down Expand Up @@ -1236,7 +1236,7 @@ protected void addEventSubscriptionJobDeclaration(EventSubscriptionJobDeclaratio
List<EventSubscriptionJobDeclaration> jobDeclarationsForActivity = (List<EventSubscriptionJobDeclaration>) activity.getProperty(PROPERTYNAME_EVENT_SUBSCRIPTION_JOB_DECLARATION);

if (jobDeclarationsForActivity == null) {
jobDeclarationsForActivity = new ArrayList<EventSubscriptionJobDeclaration>();
jobDeclarationsForActivity = new ArrayList<>();
activity.setProperty(PROPERTYNAME_EVENT_SUBSCRIPTION_JOB_DECLARATION, jobDeclarationsForActivity);
}

Expand Down Expand Up @@ -1379,7 +1379,7 @@ public void validateExclusiveGateway(ActivityImpl activity) {
String defaultSequenceFlow = (String) activity.getProperty("default");
boolean hasDefaultFlow = defaultSequenceFlow != null && defaultSequenceFlow.length() > 0;

ArrayList<PvmTransition> flowsWithoutCondition = new ArrayList<PvmTransition>();
ArrayList<PvmTransition> flowsWithoutCondition = new ArrayList<>();
for (PvmTransition flow : activity.getOutgoingTransitions()) {
Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow);
Expand Down Expand Up @@ -1918,7 +1918,7 @@ protected void removeMessageJobDeclarationWithJobConfiguration(ActivityImpl acti

public String parseDocumentation(Element element) {
List<Element> docElements = element.elements("documentation");
List<String> docStrings = new ArrayList<String>();
List<String> docStrings = new ArrayList<>();
for (Element e : docElements) {
docStrings.add(e.getText());
}
Expand Down Expand Up @@ -2003,7 +2003,7 @@ public ActivityImpl parseEventBasedGateway(Element eventBasedGwElement, Element
List<Element> sequenceFlows = parentElement.elements("sequenceFlow");

// collect all siblings in a map
Map<String, Element> siblingsMap = new HashMap<String, Element>();
Map<String, Element> siblingsMap = new HashMap<>();
List<Element> siblings = parentElement.elements();
for (Element sibling : siblings) {
siblingsMap.put(sibling.attribute("id"), sibling);
Expand Down Expand Up @@ -2321,7 +2321,7 @@ protected ParameterValueProvider parseTopic(Element element, String topicAttribu
protected void addMessageJobDeclarationToActivity(MessageJobDeclaration messageJobDeclaration, ActivityImpl activity) {
List<MessageJobDeclaration> messageJobDeclarations = (List<MessageJobDeclaration>) activity.getProperty(PROPERTYNAME_MESSAGE_JOB_DECLARATION);
if (messageJobDeclarations == null) {
messageJobDeclarations = new ArrayList<MessageJobDeclaration>();
messageJobDeclarations = new ArrayList<>();
activity.setProperty(PROPERTYNAME_MESSAGE_JOB_DECLARATION, messageJobDeclarations);
}
messageJobDeclarations.add(messageJobDeclaration);
Expand All @@ -2332,7 +2332,7 @@ protected void addJobDeclarationToProcessDefinition(JobDeclaration<?, ?> jobDecl

List<JobDeclaration<?, ?>> containingJobDeclarations = jobDeclarations.get(key);
if (containingJobDeclarations == null) {
containingJobDeclarations = new ArrayList<JobDeclaration<?, ?>>();
containingJobDeclarations = new ArrayList<>();
jobDeclarations.put(key, containingJobDeclarations);
}

Expand Down Expand Up @@ -2434,7 +2434,7 @@ protected void validateFieldDeclarationsForShell(Element serviceTaskElement, Lis
}

public List<FieldDeclaration> parseFieldDeclarations(Element element) {
List<FieldDeclaration> fieldDeclarations = new ArrayList<FieldDeclaration>();
List<FieldDeclaration> fieldDeclarations = new ArrayList<>();

Element elementWithFieldInjections = element.element("extensionElements");
if (elementWithFieldInjections == null) { // Custom extensions will just
Expand Down Expand Up @@ -2646,12 +2646,27 @@ public TaskDefinition parseTaskDefinition(Element taskElement, String taskDefini
taskDefinition.setKey(taskDefinitionKey);
processDefinition.getTaskDefinitions().put(taskDefinitionKey, taskDefinition);

String formKeyAttribute = taskElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "formKey");

String formKeyAttribute = taskElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "formKey");
if (formKeyAttribute != null) {
taskDefinition.setFormKey(expressionManager.createExpression(formKeyAttribute));
}

String formRefAttribute = taskElement.attributeNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "formRef");
if(formRefAttribute != null) {
taskDefinition.setCamundaFormDefinitionKey(expressionManager.createExpression(formRefAttribute));
String formRefBindingAttribute = taskElement.attributeNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "formRefBinding");
if(formRefBindingAttribute != null) {
taskDefinition.setCamundaFormDefinitionBinding(formRefBindingAttribute);
}
if(formRefBindingAttribute.equals(DefaultTaskFormHandler.FORM_REF_BINDING_VERSION)) {
String formRefVersionAttribute = taskElement.attributeNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "formRefVersion");
if(formRefVersionAttribute != null) {
taskDefinition.setCamundaFormDefinitionVersion(expressionManager.createExpression(formRefVersionAttribute));
}
}
}

String name = taskElement.attribute("name");
if (name != null) {
taskDefinition.setNameExpression(expressionManager.createExpression(name));
Expand Down Expand Up @@ -2788,7 +2803,7 @@ protected void parseUserTaskCustomExtensions(Element taskElement, ActivityImpl a
* @return the entries of the comma separated list, trimmed.
*/
protected List<String> parseCommaSeparatedList(String s) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
if (s != null && !"".equals(s)) {

StringCharacterIterator iterator = new StringCharacterIterator(s);
Expand Down Expand Up @@ -3149,7 +3164,7 @@ public List<CamundaErrorEventDefinition> parseCamundaErrorEventDefinitions(Activ
definition.setErrorCode(error == null ? errorRef : error.getErrorCode());
setErrorCodeVariableOnErrorEventDefinition(errorEventDefinitionElement, definition);
setErrorMessageVariableOnErrorEventDefinition(errorEventDefinitionElement, definition);

errorEventDefinitions.add(definition);
}
}
Expand Down Expand Up @@ -3240,7 +3255,7 @@ protected void parseTimerStartEventDefinition(Element timerEventDefinition, Acti

List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) processDefinition.getProperty(PROPERTYNAME_START_TIMER);
if (timerDeclarations == null) {
timerDeclarations = new ArrayList<TimerDeclarationImpl>();
timerDeclarations = new ArrayList<>();
processDefinition.setProperty(PROPERTYNAME_START_TIMER, timerDeclarations);
}
timerDeclarations.add(timerDeclaration);
Expand Down Expand Up @@ -3525,7 +3540,7 @@ protected void addTimerListenerDeclaration(String listenerId, ScopeImpl scope, T
protected void addVariableDeclaration(ScopeImpl scope, VariableDeclaration variableDeclaration) {
List<VariableDeclaration> variableDeclarations = (List<VariableDeclaration>) scope.getProperty(PROPERTYNAME_VARIABLE_DECLARATIONS);
if (variableDeclarations == null) {
variableDeclarations = new ArrayList<VariableDeclaration>();
variableDeclarations = new ArrayList<>();
scope.setProperty(PROPERTYNAME_VARIABLE_DECLARATIONS, variableDeclarations);
}
variableDeclarations.add(variableDeclaration);
Expand Down Expand Up @@ -3621,7 +3636,7 @@ protected ConditionalEventDefinition parseConditionalEventDefinition(Element ele

final String variableEvents = element.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "variableEvents");
final List<String> variableEventsList = parseCommaSeparatedList(variableEvents);
conditionalEventDefinition.setVariableEvents(new HashSet<String>(variableEventsList));
conditionalEventDefinition.setVariableEvents(new HashSet<>(variableEventsList));

for (String variableEvent : variableEventsList) {
if (!VARIABLE_EVENTS.contains(variableEvent)) {
Expand Down Expand Up @@ -4406,7 +4421,7 @@ public void parseBPMNEdge(Element bpmnEdgeElement) {
TransitionImpl sequenceFlow = sequenceFlows.get(sequenceFlowId);
List<Element> waypointElements = bpmnEdgeElement.elementsNS(OMG_DI_NS, "waypoint");
if (waypointElements.size() >= 2) {
List<Integer> waypoints = new ArrayList<Integer>();
List<Integer> waypoints = new ArrayList<>();
for (Element waypointElement : waypointElements) {
waypoints.add(parseDoubleAttribute(waypointElement, "x", waypointElement.attribute("x"), true).intValue());
waypoints.add(parseDoubleAttribute(waypointElement, "y", waypointElement.attribute("y"), true).intValue());
Expand Down

0 comments on commit 0c1156b

Please sign in to comment.