use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class EventJavaTest method testStartEventWithExecutionListener.
public void testStartEventWithExecutionListener() throws Exception {
BpmnModel bpmnModel = new BpmnModel();
Process process = new Process();
process.setId("simpleProcess");
process.setName("Very simple process");
bpmnModel.getProcesses().add(process);
StartEvent startEvent = new StartEvent();
startEvent.setId("startEvent1");
TimerEventDefinition timerDef = new TimerEventDefinition();
timerDef.setTimeDuration("PT5M");
startEvent.getEventDefinitions().add(timerDef);
ActivitiListener listener = new ActivitiListener();
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
listener.setImplementation("${test}");
listener.setEvent("end");
startEvent.getExecutionListeners().add(listener);
process.addFlowElement(startEvent);
UserTask task = new UserTask();
task.setId("reviewTask");
task.setAssignee("kermit");
process.addFlowElement(task);
SequenceFlow flow1 = new SequenceFlow();
flow1.setId("flow1");
flow1.setSourceRef("startEvent1");
flow1.setTargetRef("reviewTask");
process.addFlowElement(flow1);
EndEvent endEvent = new EndEvent();
endEvent.setId("endEvent1");
process.addFlowElement(endEvent);
byte[] xml = new BpmnXMLConverter().convertToXML(bpmnModel);
new BpmnXMLConverter().validateModel(new InputStreamSource(new ByteArrayInputStream(xml)));
Deployment deployment = repositoryService.createDeployment().name("test").addString("test.bpmn20.xml", new String(xml)).deploy();
repositoryService.deleteDeployment(deployment.getId());
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class BpmnJsonConverterUtil method parseListeners.
protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) {
if (listenersNode == null)
return;
listenersNode = validateIfNodeIsTextual(listenersNode);
for (JsonNode listenerNode : listenersNode) {
listenerNode = validateIfNodeIsTextual(listenerNode);
JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT);
if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) {
ActivitiListener listener = new ActivitiListener();
listener.setEvent(eventNode.asText());
if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode));
} else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode));
} else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) {
listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode));
}
JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS);
if (fieldsNode != null) {
for (JsonNode fieldNode : fieldsNode) {
JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME);
if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) {
FieldExtension fieldExtension = new FieldExtension();
fieldExtension.setFieldName(nameNode.asText());
fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode));
if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode));
}
if (StringUtils.isEmpty(fieldExtension.getStringValue())) {
fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode));
}
listener.getFieldExtensions().add(fieldExtension);
}
}
}
if (element instanceof Process) {
((Process) element).getExecutionListeners().add(listener);
} else if (element instanceof SequenceFlow) {
((SequenceFlow) element).getExecutionListeners().add(listener);
} else if (element instanceof UserTask) {
if (isTaskListener) {
((UserTask) element).getTaskListeners().add(listener);
} else {
((UserTask) element).getExecutionListeners().add(listener);
}
} else if (element instanceof FlowElement) {
((FlowElement) element).getExecutionListeners().add(listener);
}
}
}
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class UserTaskParseHandler method parseTaskDefinition.
public TaskDefinition parseTaskDefinition(BpmnParse bpmnParse, UserTask userTask, String taskDefinitionKey, ProcessDefinitionEntity processDefinition) {
TaskFormHandler taskFormHandler = new DefaultTaskFormHandler();
taskFormHandler.parseConfiguration(userTask.getFormProperties(), userTask.getFormKey(), bpmnParse.getDeployment(), processDefinition);
TaskDefinition taskDefinition = new TaskDefinition(taskFormHandler);
taskDefinition.setKey(taskDefinitionKey);
processDefinition.getTaskDefinitions().put(taskDefinitionKey, taskDefinition);
ExpressionManager expressionManager = bpmnParse.getExpressionManager();
if (StringUtils.isNotEmpty(userTask.getName())) {
taskDefinition.setNameExpression(expressionManager.createExpression(userTask.getName()));
}
if (StringUtils.isNotEmpty(userTask.getDocumentation())) {
taskDefinition.setDescriptionExpression(expressionManager.createExpression(userTask.getDocumentation()));
}
if (StringUtils.isNotEmpty(userTask.getAssignee())) {
taskDefinition.setAssigneeExpression(expressionManager.createExpression(userTask.getAssignee()));
}
if (StringUtils.isNotEmpty(userTask.getOwner())) {
taskDefinition.setOwnerExpression(expressionManager.createExpression(userTask.getOwner()));
}
for (String candidateUser : userTask.getCandidateUsers()) {
taskDefinition.addCandidateUserIdExpression(expressionManager.createExpression(candidateUser));
}
for (String candidateGroup : userTask.getCandidateGroups()) {
taskDefinition.addCandidateGroupIdExpression(expressionManager.createExpression(candidateGroup));
}
// Task listeners
for (ActivitiListener taskListener : userTask.getTaskListeners()) {
taskDefinition.addTaskListener(taskListener.getEvent(), createTaskListener(bpmnParse, taskListener, userTask.getId()));
}
// Due date
if (StringUtils.isNotEmpty(userTask.getDueDate())) {
taskDefinition.setDueDateExpression(expressionManager.createExpression(userTask.getDueDate()));
}
// Business calendar name
if (StringUtils.isNotEmpty(userTask.getBusinessCalendarName())) {
taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(userTask.getBusinessCalendarName()));
} else {
taskDefinition.setBusinessCalendarNameExpression(expressionManager.createExpression(DueDateBusinessCalendar.NAME));
}
// Category
if (StringUtils.isNotEmpty(userTask.getCategory())) {
taskDefinition.setCategoryExpression(expressionManager.createExpression(userTask.getCategory()));
}
// Priority
if (StringUtils.isNotEmpty(userTask.getPriority())) {
taskDefinition.setPriorityExpression(expressionManager.createExpression(userTask.getPriority()));
}
if (StringUtils.isNotEmpty(userTask.getFormKey())) {
taskDefinition.setFormKeyExpression(expressionManager.createExpression(userTask.getFormKey()));
}
// CustomUserIdentityLinks
for (String customUserIdentityLinkType : userTask.getCustomUserIdentityLinks().keySet()) {
Set<Expression> userIdentityLinkExpression = new HashSet<Expression>();
for (String userIdentityLink : userTask.getCustomUserIdentityLinks().get(customUserIdentityLinkType)) {
userIdentityLinkExpression.add(expressionManager.createExpression(userIdentityLink));
}
taskDefinition.addCustomUserIdentityLinkExpression(customUserIdentityLinkType, userIdentityLinkExpression);
}
// CustomGroupIdentityLinks
for (String customGroupIdentityLinkType : userTask.getCustomGroupIdentityLinks().keySet()) {
Set<Expression> groupIdentityLinkExpression = new HashSet<Expression>();
for (String groupIdentityLink : userTask.getCustomGroupIdentityLinks().get(customGroupIdentityLinkType)) {
groupIdentityLinkExpression.add(expressionManager.createExpression(groupIdentityLink));
}
taskDefinition.addCustomGroupIdentityLinkExpression(customGroupIdentityLinkType, groupIdentityLinkExpression);
}
if (StringUtils.isNotEmpty(userTask.getSkipExpression())) {
taskDefinition.setSkipExpression(expressionManager.createExpression(userTask.getSkipExpression()));
}
return taskDefinition;
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class SubProcessConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof StartEvent);
assertEquals("start1", flowElement.getId());
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("userTask1", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertTrue(userTask.getCandidateUsers().size() == 1);
assertTrue(userTask.getCandidateGroups().size() == 1);
assertTrue(userTask.getFormProperties().size() == 2);
flowElement = model.getMainProcess().getFlowElement("subprocess1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
assertEquals("subprocess1", flowElement.getId());
SubProcess subProcess = (SubProcess) flowElement;
assertTrue(subProcess.getLoopCharacteristics().isSequential());
assertEquals("10", subProcess.getLoopCharacteristics().getLoopCardinality());
assertEquals("${assignee == \"\"}", subProcess.getLoopCharacteristics().getCompletionCondition());
assertTrue(subProcess.getFlowElements().size() == 5);
assertEquals(1, subProcess.getExecutionListeners().size());
ActivitiListener listenerSubProcess = subProcess.getExecutionListeners().get(0);
assertEquals("SubProcessTestClass", listenerSubProcess.getImplementation());
assertEquals(ImplementationType.IMPLEMENTATION_TYPE_CLASS, listenerSubProcess.getImplementationType());
assertEquals("start", listenerSubProcess.getEvent());
flowElement = model.getMainProcess().getFlowElement("boundaryEvent1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof BoundaryEvent);
assertEquals("boundaryEvent1", flowElement.getId());
BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
assertNotNull(boundaryEvent.getAttachedToRef());
assertEquals("subprocess1", boundaryEvent.getAttachedToRef().getId());
assertEquals(1, boundaryEvent.getEventDefinitions().size());
assertTrue(boundaryEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition);
assertEquals(1, model.getMainProcess().getExecutionListeners().size());
ActivitiListener listenerMainProcess = model.getMainProcess().getExecutionListeners().get(0);
assertEquals("TestClass", listenerMainProcess.getImplementation());
assertEquals(ImplementationType.IMPLEMENTATION_TYPE_CLASS, listenerMainProcess.getImplementationType());
assertEquals("start", listenerMainProcess.getEvent());
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class CustomExtensionsConverterTest method validateExecutionListeners.
protected void validateExecutionListeners(List<ActivitiListener> listeners) {
assertEquals(3, listeners.size());
ActivitiListener listener = (ActivitiListener) listeners.get(0);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType()));
assertEquals("org.test.TestClass", listener.getImplementation());
assertEquals("start", listener.getEvent());
listener = (ActivitiListener) listeners.get(1);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
assertEquals("${testExpression}", listener.getImplementation());
assertEquals("end", listener.getEvent());
listener = (ActivitiListener) listeners.get(2);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
assertEquals("${delegateExpression}", listener.getImplementation());
assertEquals("start", listener.getEvent());
}
Aggregations