use of org.activiti.bpmn.model.ServiceTask in project Activiti by Activiti.
the class MapExceptionConverterTest method validateModel.
private void validateModel(BpmnModel model) {
// check service task with andChildren Set to True
FlowElement flowElement = model.getMainProcess().getFlowElement("servicetaskWithAndTrueAndChildren");
assertNotNull(flowElement);
assertTrue(flowElement instanceof ServiceTask);
assertEquals("servicetaskWithAndTrueAndChildren", flowElement.getId());
ServiceTask serviceTask = (ServiceTask) flowElement;
assertNotNull(serviceTask.getMapExceptions());
assertEquals(3, serviceTask.getMapExceptions().size());
// check a normal mapException, with hasChildren == true
assertEquals("myErrorCode1", serviceTask.getMapExceptions().get(0).getErrorCode());
assertEquals("com.activiti.Something1", serviceTask.getMapExceptions().get(0).getClassName());
assertTrue(serviceTask.getMapExceptions().get(0).isAndChildren());
// check a normal mapException, with hasChildren == false
assertEquals("myErrorCode2", serviceTask.getMapExceptions().get(1).getErrorCode());
assertEquals("com.activiti.Something2", serviceTask.getMapExceptions().get(1).getClassName());
assertFalse(serviceTask.getMapExceptions().get(1).isAndChildren());
// check a normal mapException, with no hasChildren Defined, default should
// be false
assertEquals("myErrorCode3", serviceTask.getMapExceptions().get(2).getErrorCode());
assertEquals("com.activiti.Something3", serviceTask.getMapExceptions().get(2).getClassName());
assertFalse(serviceTask.getMapExceptions().get(2).isAndChildren());
// if no map exception is defined, getMapException should return a not null
// empty list
FlowElement flowElement1 = model.getMainProcess().getFlowElement("servicetaskWithNoMapException");
assertNotNull(flowElement1);
assertTrue(flowElement1 instanceof ServiceTask);
assertEquals("servicetaskWithNoMapException", flowElement1.getId());
ServiceTask serviceTask1 = (ServiceTask) flowElement1;
assertNotNull(serviceTask1.getMapExceptions());
assertEquals(0, serviceTask1.getMapExceptions().size());
}
use of org.activiti.bpmn.model.ServiceTask in project Activiti by Activiti.
the class MapExceptionConverterTest method testMapExceptionWithNoExceptionClass.
@Test
public void testMapExceptionWithNoExceptionClass() throws Exception {
resourceName = "mapException/mapExceptionNoExceptionClass.bpmn";
BpmnModel bpmnModel = readXMLFile();
FlowElement flowElement = bpmnModel.getMainProcess().getFlowElement("servicetaskWithAndTrueAndChildren");
assertNotNull(flowElement);
assertTrue(flowElement instanceof ServiceTask);
assertEquals("servicetaskWithAndTrueAndChildren", flowElement.getId());
ServiceTask serviceTask = (ServiceTask) flowElement;
assertNotNull(serviceTask.getMapExceptions());
assertEquals(1, serviceTask.getMapExceptions().size());
assertNotNull(serviceTask.getMapExceptions().get(0).getClassName());
assertEquals(0, serviceTask.getMapExceptions().get(0).getClassName().length());
}
use of org.activiti.bpmn.model.ServiceTask in project Activiti by Activiti.
the class FieldExtensionParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (!accepts(parentElement))
return;
FieldExtension extension = new FieldExtension();
BpmnXMLUtil.addXMLLocation(extension, xtr);
extension.setFieldName(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_NAME));
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING))) {
extension.setStringValue(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING));
} else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION))) {
extension.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION));
} else {
boolean readyWithFieldExtension = false;
try {
while (readyWithFieldExtension == false && xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) {
extension.setStringValue(xtr.getElementText().trim());
} else if (xtr.isStartElement() && ATTRIBUTE_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
extension.setExpression(xtr.getElementText().trim());
} else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
readyWithFieldExtension = true;
}
}
} catch (Exception e) {
LOGGER.warn("Error parsing field extension child elements", e);
}
}
if (parentElement instanceof ActivitiListener) {
((ActivitiListener) parentElement).getFieldExtensions().add(extension);
} else if (parentElement instanceof ServiceTask) {
((ServiceTask) parentElement).getFieldExtensions().add(extension);
} else {
((SendTask) parentElement).getFieldExtensions().add(extension);
}
}
use of org.activiti.bpmn.model.ServiceTask in project Activiti by Activiti.
the class ServiceTaskXMLConverter method writeExtensionChildElements.
@Override
protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
ServiceTask serviceTask = (ServiceTask) element;
if (!serviceTask.getCustomProperties().isEmpty()) {
for (CustomProperty customProperty : serviceTask.getCustomProperties()) {
if (StringUtils.isEmpty(customProperty.getSimpleValue())) {
continue;
}
if (didWriteExtensionStartElement == false) {
xtw.writeStartElement(ELEMENT_EXTENSIONS);
didWriteExtensionStartElement = true;
}
xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD, ACTIVITI_EXTENSIONS_NAMESPACE);
xtw.writeAttribute(ATTRIBUTE_FIELD_NAME, customProperty.getName());
if ((customProperty.getSimpleValue().contains("${") || customProperty.getSimpleValue().contains("#{")) && customProperty.getSimpleValue().contains("}")) {
xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION, ACTIVITI_EXTENSIONS_NAMESPACE);
} else {
xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING, ACTIVITI_EXTENSIONS_NAMESPACE);
}
xtw.writeCData(customProperty.getSimpleValue());
xtw.writeEndElement();
xtw.writeEndElement();
}
} else {
didWriteExtensionStartElement = FieldExtensionExport.writeFieldExtensions(serviceTask.getFieldExtensions(), didWriteExtensionStartElement, xtw);
}
return didWriteExtensionStartElement;
}
use of org.activiti.bpmn.model.ServiceTask in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertToJson.
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
this.model = model;
this.processor = processor;
this.subProcessX = subProcessX;
this.subProcessY = subProcessY;
this.shapesArrayNode = shapesArrayNode;
GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
String stencilId = null;
if (baseElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) baseElement;
if ("mail".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MAIL;
} else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_CAMEL;
} else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MULE;
} else {
stencilId = getStencilId(baseElement);
}
} else {
stencilId = getStencilId(baseElement);
}
flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
shapesArrayNode.add(flowElementNode);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getName())) {
propertiesNode.put(PROPERTY_NAME, flowElement.getName());
}
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
}
}
convertElementToJson(propertiesNode, baseElement);
flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
if (baseElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) baseElement;
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(flowNode.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
}
propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
if (activity.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
if (loopDef.isSequential() == false) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
} else {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
}
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
}
if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
}
if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
}
if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
}
}
}
if (activity instanceof UserTask) {
BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
}
BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, propertiesNode);
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
createDataAssociation(dataAssociation, true, activity);
}
}
}
if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
createDataAssociation(dataAssociation, false, activity);
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
}
}
}
for (Artifact artifact : container.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
}
}
}
if (baseElement instanceof DataStoreReference) {
for (Process process : model.getProcesses()) {
processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
}
}
flowElementNode.put("outgoing", outgoingArrayNode);
}
Aggregations