use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class FeedbackStepDefinitionConverter method createSelectPeopleUserTask.
protected UserTask createSelectPeopleUserTask(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion, Map<String, BaseElement> processElements) {
UserTask selectPeopleUserTask = new UserTask();
selectPeopleUserTask.setId(conversion.getUniqueNumberedId(ConversionConstants.USER_TASK_ID_PREFIX));
selectPeopleUserTask.setName(getSelectPeopleTaskName());
selectPeopleUserTask.setAssignee(feedbackStepDefinition.getFeedbackInitiator());
addFlowElement(conversion, selectPeopleUserTask, true);
processElements.put(SELECT_PEOPLE_USER_TASK, selectPeopleUserTask);
// TODO: work out form such that it can be used in Activiti Explorer, ie. add correct form properties
// The following is just a a bit of a dummy form property
FormProperty feedbackProvidersProperty = new FormProperty();
feedbackProvidersProperty.setId(VARIABLE_FEEDBACK_PROVIDERS);
feedbackProvidersProperty.setName("Who needs to provide feedback?");
feedbackProvidersProperty.setRequired(true);
// TODO: we need some kind of 'people' property type here
feedbackProvidersProperty.setType("string");
selectPeopleUserTask.setFormProperties(Arrays.asList(feedbackProvidersProperty));
// that injects these variables into the process (instead of having it provided by the end user in a form)
if (feedbackStepDefinition.getFeedbackProviders() != null && !feedbackStepDefinition.getFeedbackProviders().isEmpty()) {
if (selectPeopleUserTask.getTaskListeners() == null) {
selectPeopleUserTask.setTaskListeners(new ArrayList<ActivitiListener>());
}
ActivitiListener taskListener = new ActivitiListener();
taskListener.setEvent("complete");
taskListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
taskListener.setImplementation("org.activiti.engine.impl.bpmn.listener.ScriptTaskListener");
FieldExtension languageField = new FieldExtension();
languageField.setFieldName("language");
languageField.setStringValue("JavaScript");
FieldExtension scriptField = new FieldExtension();
scriptField.setFieldName("script");
StringBuilder script = new StringBuilder();
if (JvmUtil.isJDK8()) {
script.append("load(\"nashorn:mozilla_compat.js\");");
}
script.append("importPackage (java.util); var feedbackProviders = new ArrayList();" + System.getProperty("line.separator"));
for (String feedbackProvider : feedbackStepDefinition.getFeedbackProviders()) {
script.append("feedbackProviders.add('" + feedbackProvider + "');" + System.getProperty("line.separator"));
}
script.append("task.getExecution().setVariable('" + VARIABLE_FEEDBACK_PROVIDERS + "', feedbackProviders);" + System.getProperty("line.separator"));
scriptField.setStringValue(script.toString());
taskListener.setFieldExtensions(Arrays.asList(languageField, scriptField));
selectPeopleUserTask.getTaskListeners().add(taskListener);
}
return selectPeopleUserTask;
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class ServiceTaskConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("servicetask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof ServiceTask);
assertEquals("servicetask", flowElement.getId());
ServiceTask serviceTask = (ServiceTask) flowElement;
assertEquals("servicetask", serviceTask.getId());
assertEquals("Service task", serviceTask.getName());
List<FieldExtension> fields = serviceTask.getFieldExtensions();
assertEquals(2, fields.size());
FieldExtension field = (FieldExtension) fields.get(0);
assertEquals("testField", field.getFieldName());
assertEquals("test", field.getStringValue());
field = (FieldExtension) fields.get(1);
assertEquals("testField2", field.getFieldName());
assertEquals("${test}", field.getExpression());
List<ActivitiListener> listeners = serviceTask.getExecutionListeners();
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());
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class UserTaskConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("usertask", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("usertask", userTask.getId());
assertEquals("User task", userTask.getName());
assertEquals("testKey", userTask.getFormKey());
assertEquals("40", userTask.getPriority());
assertEquals("2012-11-01", userTask.getDueDate());
assertEquals("defaultCategory", userTask.getCategory());
assertEquals("gonzo", userTask.getOwner());
assertEquals("kermit", userTask.getAssignee());
assertEquals(2, userTask.getCandidateUsers().size());
assertTrue(userTask.getCandidateUsers().contains("kermit"));
assertTrue(userTask.getCandidateUsers().contains("fozzie"));
assertEquals(2, userTask.getCandidateGroups().size());
assertTrue(userTask.getCandidateGroups().contains("management"));
assertTrue(userTask.getCandidateGroups().contains("sales"));
List<FormProperty> formProperties = userTask.getFormProperties();
assertEquals(2, formProperties.size());
FormProperty formProperty = formProperties.get(0);
assertEquals("formId", formProperty.getId());
assertEquals("formName", formProperty.getName());
assertEquals("string", formProperty.getType());
assertEquals("variable", formProperty.getVariable());
assertEquals("${expression}", formProperty.getExpression());
formProperty = formProperties.get(1);
assertEquals("formId2", formProperty.getId());
assertEquals("anotherName", formProperty.getName());
assertEquals("long", formProperty.getType());
assertTrue(StringUtils.isEmpty(formProperty.getVariable()));
assertTrue(StringUtils.isEmpty(formProperty.getExpression()));
List<ActivitiListener> listeners = userTask.getTaskListeners();
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("create", listener.getEvent());
assertEquals(2, listener.getFieldExtensions().size());
assertEquals("testField", listener.getFieldExtensions().get(0).getFieldName());
assertEquals("test", listener.getFieldExtensions().get(0).getStringValue());
listener = (ActivitiListener) listeners.get(1);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
assertEquals("${someExpression}", listener.getImplementation());
assertEquals("assignment", listener.getEvent());
listener = (ActivitiListener) listeners.get(2);
assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
assertEquals("${someDelegateExpression}", listener.getImplementation());
assertEquals("complete", listener.getEvent());
flowElement = model.getMainProcess().getFlowElement("start");
assertTrue(flowElement instanceof StartEvent);
StartEvent startEvent = (StartEvent) flowElement;
assertTrue(startEvent.getOutgoingFlows().size() == 1);
flowElement = model.getMainProcess().getFlowElement("flow1");
assertTrue(flowElement instanceof SequenceFlow);
SequenceFlow flow = (SequenceFlow) flowElement;
assertEquals("flow1", flow.getId());
assertNotNull(flow.getSourceRef());
assertNotNull(flow.getTargetRef());
}
use of org.activiti.bpmn.model.ActivitiListener in project Activiti by Activiti.
the class BpmnJsonConverterUtil method convertListenersToJson.
public static void convertListenersToJson(List<ActivitiListener> listeners, boolean isExecutionListener, ObjectNode propertiesNode) {
String propertyName = null;
String valueName = null;
if (isExecutionListener) {
propertyName = PROPERTY_EXECUTION_LISTENERS;
valueName = "executionListeners";
} else {
propertyName = PROPERTY_TASK_LISTENERS;
valueName = "taskListeners";
}
ObjectNode listenersNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
for (ActivitiListener listener : listeners) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_LISTENER_EVENT, listener.getEvent());
if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType())) {
propertyItemNode.put(PROPERTY_LISTENER_CLASS_NAME, listener.getImplementation());
} else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType())) {
propertyItemNode.put(PROPERTY_LISTENER_EXPRESSION, listener.getImplementation());
} else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType())) {
propertyItemNode.put(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listener.getImplementation());
}
if (CollectionUtils.isNotEmpty(listener.getFieldExtensions())) {
ArrayNode fieldsArray = objectMapper.createArrayNode();
for (FieldExtension fieldExtension : listener.getFieldExtensions()) {
ObjectNode fieldNode = objectMapper.createObjectNode();
fieldNode.put(PROPERTY_FIELD_NAME, fieldExtension.getFieldName());
if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) {
fieldNode.put(PROPERTY_FIELD_STRING_VALUE, fieldExtension.getStringValue());
}
if (StringUtils.isNotEmpty(fieldExtension.getExpression())) {
fieldNode.put(PROPERTY_FIELD_EXPRESSION, fieldExtension.getExpression());
}
fieldsArray.add(fieldNode);
}
propertyItemNode.put(PROPERTY_LISTENER_FIELDS, fieldsArray);
}
itemsNode.add(propertyItemNode);
}
listenersNode.put(valueName, itemsNode);
propertiesNode.put(propertyName, listenersNode);
}
Aggregations