Skip to content

Commit

Permalink
added bpmn and cmmn parse handler
Browse files Browse the repository at this point in the history
  • Loading branch information
WelschChristopher committed Jan 10, 2025
1 parent 0bb70dd commit 5f4c121
Show file tree
Hide file tree
Showing 17 changed files with 822 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.flowable.cmmn.engine.impl.parser.CmmnActivityBehaviorFactory;
import org.flowable.cmmn.engine.impl.parser.CmmnParseResult;
import org.flowable.cmmn.engine.impl.parser.CmmnParserImpl;
import org.flowable.cmmn.model.BaseElement;
import org.flowable.cmmn.model.FormAwareServiceTask;
import org.flowable.cmmn.model.HttpServiceTask;
import org.flowable.cmmn.model.ImplementationType;
import org.flowable.cmmn.model.PlanItem;
Expand All @@ -33,7 +35,7 @@ public class ServiceTaskParseHandler extends AbstractPlanItemParseHandler<Servic

@Override
public Collection<Class<? extends BaseElement>> getHandledTypes() {
return Collections.singletonList(ServiceTask.class);
return Set.of(ServiceTask.class, FormAwareServiceTask.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
*/
package org.flowable.engine.impl.bpmn.parser.handler;

import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.BaseElement;
import org.flowable.bpmn.model.FormAwareServiceTask;
import org.flowable.bpmn.model.ImplementationType;
import org.flowable.bpmn.model.ServiceTask;
import org.flowable.engine.impl.bpmn.behavior.WebServiceActivityBehavior;
Expand All @@ -33,6 +36,11 @@ public Class<? extends BaseElement> getHandledType() {
return ServiceTask.class;
}

@Override
public Set<Class<? extends BaseElement>> getHandledTypes() {
return Set.of(ServiceTask.class, FormAwareServiceTask.class);
}

@Override
protected void executeParse(BpmnParse bpmnParse, ServiceTask serviceTask) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.flowable.engine.test.bpmn.servicetask;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntity;
import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntityManager;
import org.flowable.engine.impl.test.PluggableFlowableTestCase;
import org.flowable.engine.test.Deployment;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;

public class FormAwareServiceTaskDelegateExpressionTest extends PluggableFlowableTestCase {

@Test
@Deployment
public void testDelegateExpression() {
String processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("delegateBean", new DummyTestDelegateBean())
.start()
.getProcessInstanceId();

assertThat(runtimeService.getVariables(processId))
.containsOnly(entry("executed", true));

assertThat(taskService.createTaskQuery().singleResult()).isNotNull();

}

@Test
@Deployment(resources = "org/flowable/engine/test/bpmn/servicetask/FormAwareServiceTaskDelegateExpressionTest.testDelegateExpression.bpmn20.xml")
public void testDelegateExpressionActivityInstanceQuery() {
String processId = managementService.executeCommand(new Command<>() {

@Override
public String execute(CommandContext commandContext) {
String processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("delegateBean", new DummyTestDelegateBean())
.start()
.getProcessInstanceId();

ActivityInstanceEntityManager activityInstanceEntityManager = processEngineConfiguration.getActivityInstanceEntityManager();

List<ActivityInstanceEntity> activityInstances = activityInstanceEntityManager.findActivityInstancesByProcessInstanceId(processId, true);
assertThat(activityInstances).hasSize(5);
Map<String, List<ActivityInstanceEntity>> activityInstanceMap = activityInstances.stream()
.collect(Collectors.groupingBy(ActivityInstanceEntity::getActivityId));
assertThat(activityInstanceMap).containsKey("theStart");
assertThat(activityInstanceMap.get("theStart")).hasSize(1);
assertThat(activityInstanceMap.get("theStart").get(0).getEndTime()).isNotNull();
assertThat(activityInstanceMap.get("theStart").get(0).getTransactionOrder()).isEqualTo(1);

assertThat(activityInstanceMap).containsKey("service1");
assertThat(activityInstanceMap.get("service1")).hasSize(1);
assertThat(activityInstanceMap.get("service1").get(0).getEndTime()).isNotNull();
assertThat(activityInstanceMap.get("service1").get(0).getTransactionOrder()).isEqualTo(3);

assertThat(activityInstanceMap).containsKey("usertask1");
assertThat(activityInstanceMap.get("usertask1")).hasSize(1);
assertThat(activityInstanceMap.get("usertask1").get(0).getEndTime()).isNull();
assertThat(activityInstanceMap.get("usertask1").get(0).getTransactionOrder()).isEqualTo(5);

return processId;
}

});

assertThat(runtimeService.getVariables(processId))
.containsOnly(entry("executed", true));

Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
assertThat(task).isNotNull();

managementService.executeCommand(new Command<Void>() {

@Override
public Void execute(CommandContext commandContext) {
taskService.complete(task.getId());

ActivityInstanceEntityManager activityInstanceEntityManager = processEngineConfiguration.getActivityInstanceEntityManager();

List<ActivityInstanceEntity> activityInstances = activityInstanceEntityManager.findActivityInstancesByProcessInstanceId(processId, true);
assertThat(activityInstances).hasSize(7);
Map<String, List<ActivityInstanceEntity>> activityInstanceMap = activityInstances.stream().collect(Collectors.groupingBy(ActivityInstanceEntity::getActivityId));
assertThat(activityInstanceMap).containsKey("usertask1");
assertThat(activityInstanceMap.get("usertask1")).hasSize(1);
assertThat(activityInstanceMap.get("usertask1").get(0).getEndTime()).isNotNull();
assertThat(activityInstanceMap.get("usertask1").get(0).getTransactionOrder()).isEqualTo(5);

assertThat(activityInstanceMap).containsKey("theEnd");
assertThat(activityInstanceMap.get("theEnd")).hasSize(1);
assertThat(activityInstanceMap.get("theEnd").get(0).getEndTime()).isNotNull();
assertThat(activityInstanceMap.get("theEnd").get(0).getTransactionOrder()).isEqualTo(2);

return null;
}

});
}

@Test
@Deployment
public void testDelegateExpressionPassThrough() {
String processId = managementService.executeCommand(new Command<>() {

@Override
public String execute(CommandContext commandContext) {
String processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("delegateBean", new DummyTestDelegateBean())
.start()
.getProcessInstanceId();

ActivityInstanceEntityManager activityInstanceEntityManager = processEngineConfiguration.getActivityInstanceEntityManager();

List<ActivityInstanceEntity> activityInstances = activityInstanceEntityManager.findActivityInstancesByProcessInstanceId(processId, true);
assertThat(activityInstances).hasSize(5);

ActivityInstanceEntity activityInstance = activityInstances.get(0);
assertThat(activityInstance.getActivityId()).isEqualTo("theStart");
assertThat(activityInstance.getEndTime()).isNotNull();
assertThat(activityInstance.getTransactionOrder()).isEqualTo(1);

activityInstance = activityInstances.get(1);
assertThat(activityInstance.getActivityType()).isEqualTo("sequenceFlow");
assertThat(activityInstance.getActivityId()).isEqualTo("_flow_theStart__service1");
assertThat(activityInstance.getTransactionOrder()).isEqualTo(2);

activityInstance = activityInstances.get(2);
assertThat(activityInstance.getActivityId()).isEqualTo("service1");
assertThat(activityInstance.getEndTime()).isNotNull();
assertThat(activityInstance.getTransactionOrder()).isEqualTo(3);

activityInstance = activityInstances.get(3);
assertThat(activityInstance.getActivityType()).isEqualTo("sequenceFlow");
assertThat(activityInstance.getActivityId()).isEqualTo("_flow_service1__theEnd");
assertThat(activityInstance.getTransactionOrder()).isEqualTo(4);

activityInstance = activityInstances.get(4);
assertThat(activityInstance.getActivityId()).isEqualTo("theEnd");
assertThat(activityInstance.getEndTime()).isNotNull();
assertThat(activityInstance.getTransactionOrder()).isEqualTo(5);

return processId;
}

});

managementService.executeCommand(new Command<Void>() {

@Override
public Void execute(CommandContext commandContext) {
ActivityInstanceEntityManager activityInstanceEntityManager = processEngineConfiguration.getActivityInstanceEntityManager();

List<ActivityInstanceEntity> activityInstances = activityInstanceEntityManager.findActivityInstancesByProcessInstanceId(processId, true);
assertThat(activityInstances).isEmpty();

return null;
}
});
}

@Test
@Deployment
public void testDelegateExpressionWithSkipExpression() {
// Global property enabled, but local says false -> do not skip
String processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("_FLOWABLE_SKIP_EXPRESSION_ENABLED", true)
.transientVariable("delegateBean", new DummyTestDelegateBean())
.transientVariable("shouldSkip", false)
.start()
.getProcessInstanceId();

assertThat(runtimeService.getVariables(processId))
.containsOnly(
entry("executed", true)
);

assertThat(taskService.createTaskQuery().processInstanceId(processId).singleResult()).isNotNull();

// Global property enabled, but local says true -> do skip
processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("_FLOWABLE_SKIP_EXPRESSION_ENABLED", true)
.transientVariable("delegateBean", new DummyTestDelegateBean())
.transientVariable("shouldSkip", true)
.start()
.getProcessInstanceId();

assertThat(runtimeService.getVariables(processId)).isEmpty();

assertThat(taskService.createTaskQuery().processInstanceId(processId).singleResult()).isNotNull();

// Global property not enabled, but local says true -> do not skip
processId = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("process")
.transientVariable("delegateBean", new DummyTestDelegateBean())
.transientVariable("shouldSkip", true)
.start()
.getProcessInstanceId();

assertThat(runtimeService.getVariables(processId))
.containsOnly(
entry("executed", true)
);

assertThat(taskService.createTaskQuery().processInstanceId(processId).singleResult()).isNotNull();
}
}
Loading

0 comments on commit 5f4c121

Please sign in to comment.