use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class AbstractActivitiTestCase method createOneTaskTestProcess.
/**
* Since the 'one task process' is used everywhere the actual process content doesn't matter, instead of copying around the BPMN 2.0 xml one could use this methodwhich gives a {@link BpmnModel}
* version of the same process back.
*/
public BpmnModel createOneTaskTestProcess() {
BpmnModel model = new BpmnModel();
org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
model.addProcess(process);
process.setId("oneTaskProcess");
process.setName("The one task process");
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
process.addFlowElement(startEvent);
UserTask userTask = new UserTask();
userTask.setName("The Task");
userTask.setId("theTask");
userTask.setAssignee("kermit");
process.addFlowElement(userTask);
EndEvent endEvent = new EndEvent();
endEvent.setId("theEnd");
process.addFlowElement(endEvent);
process.addFlowElement(new SequenceFlow("start", "theTask"));
process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
return model;
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class ExecutionGraphUtil method isReachable.
/**
* Verifies if the element with the given source identifier can reach the element with the target identifier through following sequence flow.
*/
public static boolean isReachable(String processDefinitionId, String sourceElementId, String targetElementId) {
// Fetch source and target elements
Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
FlowElement sourceFlowElement = process.getFlowElement(sourceElementId, true);
FlowNode sourceElement = null;
if (sourceFlowElement instanceof FlowNode) {
sourceElement = (FlowNode) sourceFlowElement;
} else if (sourceFlowElement instanceof SequenceFlow) {
sourceElement = (FlowNode) ((SequenceFlow) sourceFlowElement).getTargetFlowElement();
}
FlowElement targetFlowElement = process.getFlowElement(targetElementId, true);
FlowNode targetElement = null;
if (targetFlowElement instanceof FlowNode) {
targetElement = (FlowNode) targetFlowElement;
} else if (targetFlowElement instanceof SequenceFlow) {
targetElement = (FlowNode) ((SequenceFlow) targetFlowElement).getTargetFlowElement();
}
if (sourceElement == null) {
throw new ActivitiException("Invalid sourceElementId '" + sourceElementId + "': no element found for this id n process definition '" + processDefinitionId + "'");
}
if (targetElement == null) {
throw new ActivitiException("Invalid targetElementId '" + targetElementId + "': no element found for this id n process definition '" + processDefinitionId + "'");
}
Set<String> visitedElements = new HashSet<String>();
return isReachable(process, sourceElement, targetElement, visitedElements);
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class ExecutionGraphUtil method isReachable.
public static boolean isReachable(Process process, FlowNode sourceElement, FlowNode targetElement, Set<String> visitedElements) {
// No outgoing seq flow: could be the end of eg . the process or an embedded subprocess
if (sourceElement.getOutgoingFlows().size() == 0) {
visitedElements.add(sourceElement.getId());
FlowElementsContainer parentElement = process.findParent(sourceElement);
if (parentElement instanceof SubProcess) {
sourceElement = (SubProcess) parentElement;
} else {
return false;
}
}
if (sourceElement.getId().equals(targetElement.getId())) {
return true;
}
// To avoid infinite looping, we must capture every node we visit
// and check before going further in the graph if we have already
// visited the node.
visitedElements.add(sourceElement.getId());
List<SequenceFlow> sequenceFlows = sourceElement.getOutgoingFlows();
if (sequenceFlows != null && sequenceFlows.size() > 0) {
for (SequenceFlow sequenceFlow : sequenceFlows) {
String targetRef = sequenceFlow.getTargetRef();
FlowNode sequenceFlowTarget = (FlowNode) process.getFlowElement(targetRef, true);
if (sequenceFlowTarget != null && !visitedElements.contains(sequenceFlowTarget.getId())) {
boolean reachable = isReachable(process, sequenceFlowTarget, targetElement, visitedElements);
if (reachable) {
return true;
}
}
}
}
return false;
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class TestProcessUtil method createOneTaskProcess.
public static org.activiti.bpmn.model.Process createOneTaskProcess() {
org.activiti.bpmn.model.Process process = new org.activiti.bpmn.model.Process();
process.setId("oneTaskProcess");
process.setName("The one task process");
StartEvent startEvent = new StartEvent();
startEvent.setId("start");
process.addFlowElement(startEvent);
UserTask userTask = new UserTask();
userTask.setName("The Task");
userTask.setId("theTask");
userTask.setAssignee("kermit");
process.addFlowElement(userTask);
EndEvent endEvent = new EndEvent();
endEvent.setId("theEnd");
process.addFlowElement(endEvent);
process.addFlowElement(new SequenceFlow("start", "theTask"));
process.addFlowElement(new SequenceFlow("theTask", "theEnd"));
return process;
}
use of org.activiti.bpmn.model.SequenceFlow in project Activiti by Activiti.
the class BpmnJsonConverter method convertToJson.
public ObjectNode convertToJson(BpmnModel model, Map<String, ModelInfo> formKeyMap, Map<String, ModelInfo> decisionTableKeyMap) {
ObjectNode modelNode = objectMapper.createObjectNode();
double maxX = 0.0;
double maxY = 0.0;
for (GraphicInfo flowInfo : model.getLocationMap().values()) {
if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
maxX = flowInfo.getX() + flowInfo.getWidth();
}
if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
maxY = flowInfo.getY() + flowInfo.getHeight();
}
}
maxX += 50;
maxY += 50;
if (maxX < 1485) {
maxX = 1485;
}
if (maxY < 700) {
maxY = 700;
}
modelNode.set("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
modelNode.put("resourceId", "canvas");
ObjectNode stencilNode = objectMapper.createObjectNode();
stencilNode.put("id", "BPMNDiagram");
modelNode.set("stencil", stencilNode);
ObjectNode stencilsetNode = objectMapper.createObjectNode();
stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
modelNode.set("stencilset", stencilsetNode);
ArrayNode shapesArrayNode = objectMapper.createArrayNode();
Process mainProcess = null;
if (model.getPools().size() > 0) {
mainProcess = model.getProcess(model.getPools().get(0).getId());
} else {
mainProcess = model.getMainProcess();
}
ObjectNode propertiesNode = objectMapper.createObjectNode();
if (StringUtils.isNotEmpty(mainProcess.getId())) {
propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
}
if (StringUtils.isNotEmpty(mainProcess.getName())) {
propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
}
if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
}
if (!mainProcess.isExecutable()) {
propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
}
if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
}
BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);
BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);
if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
}
modelNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);
boolean poolHasDI = false;
if (model.getPools().size() > 0) {
for (Pool pool : model.getPools()) {
GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());
if (graphicInfo != null) {
poolHasDI = true;
break;
}
}
}
if (model.getPools().size() > 0 && poolHasDI) {
for (Pool pool : model.getPools()) {
GraphicInfo poolGraphicInfo = model.getGraphicInfo(pool.getId());
if (poolGraphicInfo == null) {
continue;
}
ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL, poolGraphicInfo.getX() + poolGraphicInfo.getWidth(), poolGraphicInfo.getY() + poolGraphicInfo.getHeight(), poolGraphicInfo.getX(), poolGraphicInfo.getY());
shapesArrayNode.add(poolNode);
ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());
if (!pool.isExecutable()) {
poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
}
if (StringUtils.isNotEmpty(pool.getName())) {
poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
}
poolNode.set(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);
ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
poolNode.set(EDITOR_CHILD_SHAPES, laneShapesArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
poolNode.set("outgoing", outgoingArrayNode);
Process process = model.getProcess(pool.getId());
if (process != null) {
Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();
for (Lane lane : process.getLanes()) {
GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());
if (laneGraphicInfo == null) {
continue;
}
ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE, laneGraphicInfo.getX() + laneGraphicInfo.getWidth() - poolGraphicInfo.getX(), laneGraphicInfo.getY() + laneGraphicInfo.getHeight() - poolGraphicInfo.getY(), laneGraphicInfo.getX() - poolGraphicInfo.getX(), laneGraphicInfo.getY() - poolGraphicInfo.getY());
laneShapesArrayNode.add(laneNode);
ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());
if (StringUtils.isNotEmpty(lane.getName())) {
lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
}
laneNode.set(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);
ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
laneNode.set(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
laneNode.set("outgoing", objectMapper.createArrayNode());
laneMap.put(lane.getId(), elementShapesArrayNode);
}
for (FlowElement flowElement : process.getFlowElements()) {
Lane laneForElement = null;
GraphicInfo laneGraphicInfo = null;
FlowElement lookForElement = null;
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
} else {
lookForElement = flowElement;
}
for (Lane lane : process.getLanes()) {
if (lane.getFlowReferences().contains(lookForElement.getId())) {
laneGraphicInfo = model.getGraphicInfo(lane.getId());
if (laneGraphicInfo != null) {
laneForElement = lane;
}
break;
}
}
if (flowElement instanceof SequenceFlow || laneForElement != null) {
processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()), formKeyMap, decisionTableKeyMap, laneGraphicInfo.getX(), laneGraphicInfo.getY());
}
}
processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(pool.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
processMessageFlows(model, shapesArrayNode);
} else {
processFlowElements(model.getMainProcess(), model, shapesArrayNode, formKeyMap, decisionTableKeyMap, 0.0, 0.0);
processMessageFlows(model, shapesArrayNode);
}
modelNode.set(EDITOR_CHILD_SHAPES, shapesArrayNode);
return modelNode;
}
Aggregations