use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method unmarshallItem.
public BaseElement unmarshallItem(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
String resourceId = null;
Map<String, String> properties = null;
String stencil = null;
List<BaseElement> childElements = new ArrayList<BaseElement>();
List<String> outgoing = new ArrayList<String>();
while (parser.nextToken() != JsonToken.END_OBJECT) {
String fieldname = parser.getCurrentName();
parser.nextToken();
if ("resourceId".equals(fieldname)) {
resourceId = parser.getText();
} else if ("properties".equals(fieldname)) {
properties = unmarshallProperties(parser);
} else if ("stencil".equals(fieldname)) {
// "stencil":{"id":"Task"},
parser.nextToken();
parser.nextToken();
stencil = parser.getText();
parser.nextToken();
} else if ("childShapes".equals(fieldname)) {
while (parser.nextToken() != JsonToken.END_ARRAY) {
// open the
// object
// the childShapes element is a json array. We opened the
// array.
childElements.add(unmarshallItem(parser, preProcessingData));
}
} else if ("bounds".equals(fieldname)) {
// bounds: {"lowerRight":{"x":484.0,"y":198.0},"upperLeft":{"x":454.0,"y":168.0}}
parser.nextToken();
parser.nextToken();
parser.nextToken();
parser.nextToken();
Integer x2 = parser.getIntValue();
parser.nextToken();
parser.nextToken();
Integer y2 = parser.getIntValue();
parser.nextToken();
parser.nextToken();
parser.nextToken();
parser.nextToken();
parser.nextToken();
Integer x1 = parser.getIntValue();
parser.nextToken();
parser.nextToken();
Integer y1 = parser.getIntValue();
parser.nextToken();
parser.nextToken();
Bounds b = DcFactory.eINSTANCE.createBounds();
b.setX(x1);
b.setY(y1);
b.setWidth(x2 - x1);
b.setHeight(y2 - y1);
this._bounds.put(resourceId, b);
} else if ("dockers".equals(fieldname)) {
// "dockers":[{"x":50,"y":40},{"x":353.5,"y":115},{"x":353.5,"y":152},{"x":50,"y":40}],
List<Point> dockers = new ArrayList<Point>();
JsonToken nextToken = parser.nextToken();
boolean end = JsonToken.END_ARRAY.equals(nextToken);
while (!end) {
nextToken = parser.nextToken();
nextToken = parser.nextToken();
Integer x = parser.getIntValue();
parser.nextToken();
parser.nextToken();
Integer y = parser.getIntValue();
Point point = DcFactory.eINSTANCE.createPoint();
point.setX(x);
point.setY(y);
dockers.add(point);
parser.nextToken();
nextToken = parser.nextToken();
end = JsonToken.END_ARRAY.equals(nextToken);
}
this._dockers.put(resourceId, dockers);
} else if ("outgoing".equals(fieldname)) {
while (parser.nextToken() != JsonToken.END_ARRAY) {
// {resourceId: oryx_1AAA8C9A-39A5-42FC-8ED1-507A7F3728EA}
parser.nextToken();
parser.nextToken();
outgoing.add(parser.getText());
parser.nextToken();
}
// pass on the array
parser.skipChildren();
} else if ("target".equals(fieldname)) {
// we already collected that info with the outgoing field.
parser.skipChildren();
// "target": {
// "resourceId": "oryx_A75E7546-DF71-48EA-84D3-2A8FD4A47568"
// }
// add to the map:
// parser.nextToken(); // resourceId:
// parser.nextToken(); // the value we want to save
// targetId = parser.getText();
// parser.nextToken(); // }, closing the object
}
}
properties.put("resourceId", resourceId);
boolean customElement = isCustomElement(properties.get("tasktype"), preProcessingData);
BaseElement baseElt = this.createBaseElement(stencil, properties.get("tasktype"), customElement);
// register the sequence flow targets.
if (baseElt instanceof SequenceFlow) {
_sequenceFlowTargets.addAll(outgoing);
}
_outgoingFlows.put(baseElt, outgoing);
_objMap.put(baseElt, // keep the object around to do connections
resourceId);
_idMap.put(resourceId, baseElt);
// baseElt.setId(resourceId); commented out as bpmn2 seems to create
// duplicate ids right now.
applyProperties(baseElt, properties, preProcessingData);
if (baseElt instanceof Definitions) {
Process rootLevelProcess = null;
if (childElements == null || childElements.size() < 1) {
if (rootLevelProcess == null) {
rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
// set the properties and item definitions first
if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
String[] vardefs = properties.get("vardefs").split(",\\s*");
for (String vardef : vardefs) {
Property prop = Bpmn2Factory.eINSTANCE.createProperty();
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
// check if we define a structure ref in the definition
if (vardef.contains(":")) {
String[] vardefParts = vardef.split(":\\s*");
prop.setId(vardefParts[0]);
itemdef.setId("_" + prop.getId() + "Item");
boolean haveKPI = false;
String kpiValue = "";
if (vardefParts.length == 3) {
itemdef.setStructureRef(vardefParts[1]);
if (vardefParts[2].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[2];
}
}
if (vardefParts.length == 2) {
if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
if (vardefParts[1].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[1];
}
} else {
itemdef.setStructureRef(vardefParts[1]);
}
}
if (haveKPI) {
Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
}
} else {
prop.setId(vardef);
itemdef.setId("_" + prop.getId() + "Item");
}
prop.setItemSubjectRef(itemdef);
rootLevelProcess.getProperties().add(prop);
((Definitions) baseElt).getRootElements().add(itemdef);
}
}
if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
rootLevelProcess.getAnyAttribute().add(extensionEntry);
}
if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
}
rootLevelProcess.setId(properties.get("id"));
applyProcessProperties(rootLevelProcess, properties);
((Definitions) baseElt).getRootElements().add(rootLevelProcess);
}
} else {
for (BaseElement child : childElements) {
// } else {
if (child instanceof SequenceFlow) {
// for some reason sequence flows are placed as root elements.
// find if the target has a container, and if we can use it:
List<String> ids = _outgoingFlows.get(child);
FlowElementsContainer container = null;
for (String id : ids) {
// yes, we iterate, but we'll take the first in the list that will work.
Object obj = _idMap.get(id);
if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) {
container = (FlowElementsContainer) ((EObject) obj).eContainer();
break;
}
}
if (container != null) {
container.getFlowElements().add((SequenceFlow) child);
continue;
}
}
if (child instanceof Task || child instanceof SequenceFlow || child instanceof Gateway || child instanceof Event || child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess || child instanceof Lane || child instanceof CallActivity || child instanceof TextAnnotation) {
if (rootLevelProcess == null) {
rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
// set the properties and item definitions first
if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
String[] vardefs = properties.get("vardefs").split(",\\s*");
for (String vardef : vardefs) {
Property prop = Bpmn2Factory.eINSTANCE.createProperty();
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
// check if we define a structure ref in the definition
if (vardef.contains(":")) {
String[] vardefParts = vardef.split(":\\s*");
prop.setId(vardefParts[0]);
itemdef.setId("_" + prop.getId() + "Item");
boolean haveKPI = false;
String kpiValue = "";
if (vardefParts.length == 3) {
itemdef.setStructureRef(vardefParts[1]);
if (vardefParts[2].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[2];
}
}
if (vardefParts.length == 2) {
if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
if (vardefParts[1].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[1];
}
} else {
itemdef.setStructureRef(vardefParts[1]);
}
}
if (haveKPI) {
Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
}
} else {
prop.setId(vardef);
itemdef.setId("_" + prop.getId() + "Item");
}
prop.setItemSubjectRef(itemdef);
rootLevelProcess.getProperties().add(prop);
((Definitions) baseElt).getRootElements().add(itemdef);
}
}
if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
rootLevelProcess.getAnyAttribute().add(extensionEntry);
}
if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
}
rootLevelProcess.setId(properties.get("id"));
applyProcessProperties(rootLevelProcess, properties);
((Definitions) baseElt).getRootElements().add(rootLevelProcess);
}
}
if (child instanceof Task) {
rootLevelProcess.getFlowElements().add((Task) child);
} else if (child instanceof CallActivity) {
rootLevelProcess.getFlowElements().add((CallActivity) child);
} else if (child instanceof RootElement) {
((Definitions) baseElt).getRootElements().add((RootElement) child);
} else if (child instanceof SequenceFlow) {
rootLevelProcess.getFlowElements().add((SequenceFlow) child);
} else if (child instanceof Gateway) {
rootLevelProcess.getFlowElements().add((Gateway) child);
} else if (child instanceof Event) {
rootLevelProcess.getFlowElements().add((Event) child);
} else if (child instanceof TextAnnotation) {
rootLevelProcess.getFlowElements().add((TextAnnotation) child);
} else if (child instanceof Artifact) {
rootLevelProcess.getArtifacts().add((Artifact) child);
} else if (child instanceof DataObject) {
// bubble up data objects
// rootLevelProcess.getFlowElements().add(0, (DataObject) child);
rootLevelProcess.getFlowElements().add((DataObject) child);
// ItemDefinition def = ((DataObject) child).getItemSubjectRef();
// if (def != null) {
// if (def.eResource() == null) {
// ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def);
// }
// Import imported = def.getImport();
// if (imported != null && imported.eResource() == null) {
// ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported);
// }
// }
} else if (child instanceof SubProcess) {
rootLevelProcess.getFlowElements().add((SubProcess) child);
} else if (child instanceof Lane) {
// lanes handled later
} else {
_logger.error("Don't know what to do of " + child);
}
// }
}
}
} else if (baseElt instanceof Process) {
for (BaseElement child : childElements) {
if (child instanceof Lane) {
if (((Process) baseElt).getLaneSets().isEmpty()) {
((Process) baseElt).getLaneSets().add(Bpmn2Factory.eINSTANCE.createLaneSet());
}
((Process) baseElt).getLaneSets().get(0).getLanes().add((Lane) child);
addLaneFlowNodes((Process) baseElt, (Lane) child);
} else if (child instanceof Artifact) {
((Process) baseElt).getArtifacts().add((Artifact) child);
} else {
_logger.error("Don't know what to do of " + child);
}
}
} else if (baseElt instanceof SubProcess) {
for (BaseElement child : childElements) {
if (child instanceof FlowElement) {
((SubProcess) baseElt).getFlowElements().add((FlowElement) child);
} else if (child instanceof Artifact) {
((SubProcess) baseElt).getArtifacts().add((Artifact) child);
} else {
_logger.error("Subprocess - don't know what to do of " + child);
}
}
} else if (baseElt instanceof Message) {
// we do not support base-element messages from the json. They are created dynamically for events that use them.
} else if (baseElt instanceof Lane) {
for (BaseElement child : childElements) {
if (child instanceof FlowNode) {
((Lane) baseElt).getFlowNodeRefs().add((FlowNode) child);
} else // }
if (child instanceof Artifact) {
_artifacts.add((Artifact) child);
} else {
_logger.error("Don't know what to do of " + childElements);
}
}
_lanes.add((Lane) baseElt);
} else {
if (!childElements.isEmpty()) {
_logger.error("Don't know what to do of " + childElements + " with " + baseElt);
}
}
return baseElt;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.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.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project kie-wb-common by kiegroup.
the class DefaultProfileImpl method createMarshaller.
public IDiagramMarshaller createMarshaller() {
return new IDiagramMarshaller() {
public String parseModel(String jsonModel, String preProcessingData) {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
// Definitions def;
Resource res;
try {
res = unmarshaller.unmarshall(jsonModel, preProcessingData);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Map saveMap = new HashMap();
saveMap.put(XMLResource.OPTION_ENCODING, "UTF-8");
saveMap.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
saveMap.put(XMLResource.OPTION_DISABLE_NOTIFY, true);
saveMap.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
res.save(outputStream, saveMap);
return outputStream.toString();
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return "";
}
public Definitions getDefinitions(String jsonModel, String preProcessingData) {
try {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
JBPMBpmn2ResourceImpl res = (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
return (Definitions) res.getContents().get(0);
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return null;
}
public Resource getResource(String jsonModel, String preProcessingData) {
try {
Bpmn2JsonUnmarshaller unmarshaller = new Bpmn2JsonUnmarshaller();
return (JBPMBpmn2ResourceImpl) unmarshaller.unmarshall(jsonModel, preProcessingData);
} catch (JsonParseException e) {
_logger.error(e.getMessage(), e);
} catch (IOException e) {
_logger.error(e.getMessage(), e);
}
return null;
}
};
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project kie-wb-common by kiegroup.
the class JBPMXMLSaveImpl method traverse.
@Override
public void traverse(List<? extends EObject> contents) {
for (EObject e : contents) {
if (e instanceof Definitions) {
List<RootElement> roots = ((Definitions) e).getRootElements();
Process p = null;
for (RootElement root : roots) {
if (root instanceof Process) {
p = (Process) root;
}
}
if (p != null) {
((Definitions) e).getRootElements().remove(p);
((Definitions) e).getRootElements().add(p);
}
}
}
super.traverse(contents);
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.Definitions in project kie-wb-common by kiegroup.
the class Bpmn2UnMarshaller method unmarshall.
public Graph unmarshall(final String content) throws IOException {
final XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://" + UUID.uuid() + ".xml"));
outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.setEncoding("UTF-8");
final Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.load(new BufferedInputStream(new ByteArrayInputStream(content.getBytes("UTF-8"))), options);
final DocumentRoot root = (DocumentRoot) outResource.getContents().get(0);
final Definitions definitions = root.getDefinitions();
return unmarshall(definitions, null);
}
Aggregations