use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method addSimulation.
public void addSimulation(Definitions def) {
Relationship relationship = Bpmn2Factory.eINSTANCE.createRelationship();
relationship.getSources().add(def);
relationship.getTargets().add(def);
relationship.setType(defaultRelationshipType);
BPSimDataType simDataType = BpsimFactory.eINSTANCE.createBPSimDataType();
// currently support single scenario
Scenario defaultScenario = BpsimFactory.eINSTANCE.createScenario();
// single scenario suppoert
defaultScenario.setId("default");
// single scenario support
defaultScenario.setName("Simulationscenario");
defaultScenario.setScenarioParameters(_simulationScenarioParameters);
if (_simulationElementParameters.size() > 0) {
Iterator<String> iter = _simulationElementParameters.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
ElementParameters etype = BpsimFactory.eINSTANCE.createElementParameters();
etype.setElementRef(key);
List<EObject> params = _simulationElementParameters.get(key);
for (EObject np : params) {
if (np instanceof ControlParameters) {
etype.setControlParameters((ControlParameters) np);
} else if (np instanceof CostParameters) {
etype.setCostParameters((CostParameters) np);
} else if (np instanceof PriorityParameters) {
etype.setPriorityParameters((PriorityParameters) np);
} else if (np instanceof ResourceParameters) {
etype.setResourceParameters((ResourceParameters) np);
} else if (np instanceof TimeParameters) {
etype.setTimeParameters((TimeParameters) np);
}
}
defaultScenario.getElementParameters().add(etype);
}
}
simDataType.getScenario().add(defaultScenario);
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
relationship.getExtensionValues().add(extensionElement);
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, simDataType);
relationship.getExtensionValues().get(0).getValue().add(extensionElementEntry);
def.getRelationships().add(relationship);
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitGroups.
public void revisitGroups(Definitions def) {
List<RootElement> rootElements = def.getRootElements();
Category defaultCat = Bpmn2Factory.eINSTANCE.createCategory();
defaultCat.setName("default");
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
List<Artifact> processArtifacts = process.getArtifacts();
if (processArtifacts != null) {
for (Artifact ar : processArtifacts) {
if (ar instanceof Group) {
Group group = (Group) ar;
Iterator<FeatureMap.Entry> iter = group.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("categoryval")) {
CategoryValue catval = Bpmn2Factory.eINSTANCE.createCategoryValue();
catval.setValue((String) entry.getValue());
defaultCat.getCategoryValue().add(catval);
group.setCategoryValueRef(catval);
}
}
}
}
}
}
}
// only add category if it includes at least one categoryvalue
if (defaultCat.getCategoryValue() != null && defaultCat.getCategoryValue().size() > 0) {
rootElements.add(defaultCat);
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method unmarshall.
/**
* NOTE: This method has been set protected for Stunner support. Stunner bpmn implementation provides a custom JsonParser that
* is used instead of the one used in jbpm-designer-backend.
* <p>
* Start unmarshalling using the parser.
* @param parser
* @param preProcessingData
* @return the root element of a bpmn2 document.
* @throws JsonParseException
* @throws IOException
*/
protected Bpmn2Resource unmarshall(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
try {
// open the object
parser.nextToken();
ResourceSet rSet = new ResourceSetImpl();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
Bpmn2Resource bpmn2 = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2"));
rSet.getResources().add(bpmn2);
_currentResource = bpmn2;
if (preProcessingData == null || preProcessingData.length() < 1) {
preProcessingData = "ReadOnlyService";
}
// do the unmarshalling now:
Definitions def = (Definitions) unmarshallItem(parser, preProcessingData);
def.setExporter("jBPM Designer");
def.setExporterVersion("6.2.0");
revisitUserTasks(def);
revisitServiceTasks(def);
revisitMessages(def);
revisitCatchEvents(def);
revisitThrowEvents(def);
revisitLanes(def);
revisitSubProcessItemDefs(def);
revisitArtifacts(def);
revisitGroups(def);
revisitTaskAssociations(def);
revisitSendReceiveTasks(def);
reconnectFlows();
revisitGateways(def);
revisitCatchEventsConvertToBoundary(def);
revisitBoundaryEventsPositions(def);
createDiagram(def);
updateIDs(def);
revisitDataObjects(def);
revisitAssociationsIoSpec(def);
revisitWsdlImports(def);
revisitMultiInstanceTasks(def);
addSimulation(def);
revisitItemDefinitions(def);
revisitProcessDoc(def);
revisitDI(def);
revisitSignalRef(def);
orderDiagramElements(def);
// return def;
_currentResource.getContents().add(def);
return _currentResource;
} catch (Exception e) {
_logger.error(e.getMessage());
return _currentResource;
} finally {
parser.close();
_objMap.clear();
_idMap.clear();
_outgoingFlows.clear();
_sequenceFlowTargets.clear();
_bounds.clear();
_currentResource = null;
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method setSendReceiveTasksInfo.
public void setSendReceiveTasksInfo(FlowElementsContainer container, Definitions def, List<Message> toAddMessages, List<ItemDefinition> toAddItemDefinitions) {
List<FlowElement> flowElements = container.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof ReceiveTask) {
ReceiveTask rt = (ReceiveTask) fe;
rt.setMessageRef(extractMessage(rt, toAddMessages, toAddItemDefinitions));
} else if (fe instanceof SendTask) {
SendTask st = (SendTask) fe;
st.setMessageRef(extractMessage(st, toAddMessages, toAddItemDefinitions));
} else if (fe instanceof FlowElementsContainer) {
setSendReceiveTasksInfo((FlowElementsContainer) fe, def, toAddMessages, toAddItemDefinitions);
}
}
}
use of org.eclipse.bpmn2.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method createDiagram.
private void createDiagram(Definitions def) {
for (RootElement rootElement : def.getRootElements()) {
if (rootElement instanceof Process) {
Process process = (Process) rootElement;
BpmnDiFactory factory = BpmnDiFactory.eINSTANCE;
BPMNDiagram diagram = factory.createBPMNDiagram();
BPMNPlane plane = factory.createBPMNPlane();
plane.setBpmnElement(process);
diagram.setPlane(plane);
// first process flowNodes
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof FlowNode) {
createBpmnShapeForElement(factory, plane, flowElement);
if (flowElement instanceof BoundaryEvent) {
createDockersForBoundaryEvent((BoundaryEvent) flowElement);
}
// check if its a subprocess
if (flowElement instanceof SubProcess) {
createSubProcessDiagram(plane, flowElement, factory);
}
} else if (flowElement instanceof DataObject) {
createBpmnShapeForElement(factory, plane, flowElement);
} else if (flowElement instanceof SequenceFlow) {
createBpmnEdgeForSequenceFlow(factory, plane, (SequenceFlow) flowElement);
}
}
// then process artifacts
if (process.getArtifacts() != null) {
List<Association> incompleteAssociations = new ArrayList<Association>();
for (Artifact artifact : process.getArtifacts()) {
// if (artifact instanceof TextAnnotation || artifact instanceof Group) {
if (artifact instanceof Group) {
createBpmnShapeForElement(factory, plane, artifact);
}
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (association.getSourceRef() != null && association.getTargetRef() != null) {
createBpmnEdgeForAssociation(factory, plane, association);
} else {
incompleteAssociations.add(association);
}
}
}
if (!incompleteAssociations.isEmpty()) {
for (Association incompleteAssociation : incompleteAssociations) {
process.getArtifacts().remove(incompleteAssociation);
}
}
}
// finally process lanes
if (process.getLaneSets() != null && process.getLaneSets().size() > 0) {
for (LaneSet ls : process.getLaneSets()) {
for (Lane lane : ls.getLanes()) {
createBpmnShapeForElement(factory, plane, lane);
}
}
}
def.getDiagrams().add(diagram);
}
}
}
Aggregations