use of bpsim.BPSimDataType in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshall.
/**
* NOTE:
* This method has been added for Stunner support. Stunner bpmn parser provides a custom JsonGenerator that
* is used instead of the one used in jbpm-designer-backend.
*/
public void marshall(JsonGenerator generator, Definitions def, String preProcessingData) throws IOException {
if (def.getRelationships() != null && def.getRelationships().size() > 0) {
// current support for single relationship
Relationship relationship = def.getRelationships().get(0);
for (ExtensionAttributeValue extattrval : relationship.getExtensionValues()) {
FeatureMap extensionElements = extattrval.getValue();
@SuppressWarnings("unchecked") List<BPSimDataType> bpsimExtensions = (List<BPSimDataType>) extensionElements.get(BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, true);
if (bpsimExtensions != null && bpsimExtensions.size() > 0) {
BPSimDataType processAnalysis = bpsimExtensions.get(0);
if (processAnalysis.getScenario() != null && processAnalysis.getScenario().size() > 0) {
_simulationScenario = processAnalysis.getScenario().get(0);
}
}
}
}
if (preProcessingData == null || preProcessingData.length() < 1) {
preProcessingData = "ReadOnlyService";
}
// this is a temp way to determine if
// coordinate system changes are necessary
String bpmn2Exporter = def.getExporter();
String bpmn2ExporterVersion = def.getExporterVersion();
boolean haveExporter = bpmn2Exporter != null && bpmn2ExporterVersion != null;
if (_simulationScenario != null && !haveExporter) {
coordianteManipulation = false;
}
marshallDefinitions(def, generator, preProcessingData);
// generator.close(); FIXME: can we remove this from here?
}
use of bpsim.BPSimDataType 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 bpsim.BPSimDataType in project kie-wb-common by kiegroup.
the class DefinitionResolver method initSimulationParameters.
private Map<String, ElementParameters> initSimulationParameters(Definitions definitions) {
Map<String, ElementParameters> simulationParameters = new HashMap<>();
List<Relationship> relationships = definitions.getRelationships();
if (relationships.isEmpty()) {
return Collections.emptyMap();
}
FeatureMap value = relationships.get(0).getExtensionValues().get(0).getValue();
Object simData = value.get(BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, true);
List<BPSimDataType> bpsimExtensions = (List<BPSimDataType>) simData;
Scenario scenario = bpsimExtensions.get(0).getScenario().get(0);
for (ElementParameters parameters : scenario.getElementParameters()) {
simulationParameters.put(parameters.getElementRef(), parameters);
}
return simulationParameters;
}
use of bpsim.BPSimDataType in project kie-wb-common by kiegroup.
the class ProcessPropertyWriter method getRelationship.
public Relationship getRelationship() {
Relationship relationship = bpmn2.createRelationship();
relationship.setType(defaultRelationshipType);
BPSimDataType simDataType = bpsim.createBPSimDataType();
// currently support single scenario
Scenario defaultScenario = bpsim.createScenario();
ScenarioParameters scenarioParameters = bpsim.createScenarioParameters();
// single scenario suppoert
defaultScenario.setId("default");
// single scenario support
defaultScenario.setName("Simulationscenario");
defaultScenario.setScenarioParameters(scenarioParameters);
simDataType.getScenario().add(defaultScenario);
ExtensionAttributeValue extensionElement = bpmn2.createExtensionAttributeValue();
relationship.getExtensionValues().add(extensionElement);
FeatureMap.Entry extensionElementEntry = new EStructuralFeatureImpl.SimpleFeatureMapEntry((EStructuralFeature.Internal) BpsimPackage.Literals.DOCUMENT_ROOT__BP_SIM_DATA, simDataType);
relationship.getExtensionValues().get(0).getValue().add(extensionElementEntry);
defaultScenario.getElementParameters().addAll(simulationParameters);
return relationship;
}
use of bpsim.BPSimDataType in project jbpm by kiegroup.
the class BpsimTest method testBpsimData.
@SuppressWarnings("unchecked")
public void testBpsimData() throws Exception {
// write
XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
inResource.setEncoding("UTF-8");
DocumentRoot documentRoot = BpsimFactory.eINSTANCE.createDocumentRoot();
BPSimDataType bpsimData = BpsimFactory.eINSTANCE.createBPSimDataType();
Scenario defaultScenario = BpsimFactory.eINSTANCE.createScenario();
defaultScenario.setId("default");
defaultScenario.setName("Scenario");
ScenarioParameters scenarioParams = BpsimFactory.eINSTANCE.createScenarioParameters();
scenarioParams.setBaseTimeUnit(TimeUnit.S);
defaultScenario.setScenarioParameters(scenarioParams);
ElementParameters elementParams = BpsimFactory.eINSTANCE.createElementParameters();
TimeParameters elementTimeParams = BpsimFactory.eINSTANCE.createTimeParameters();
Parameter processingTimeParameter = BpsimFactory.eINSTANCE.createParameter();
UniformDistributionType uniformDistrobutionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
uniformDistrobutionType.setMin(180.0);
uniformDistrobutionType.setMax(600.0);
processingTimeParameter.getParameterValue().add(uniformDistrobutionType);
elementTimeParams.setProcessingTime(processingTimeParameter);
elementParams.setTimeParameters(elementTimeParams);
defaultScenario.getElementParameters().add(elementParams);
bpsimData.getScenario().add(defaultScenario);
documentRoot.setBPSimData(bpsimData);
inResource.getContents().add(documentRoot);
StringWriter stringWriter = new StringWriter();
inResource.save(stringWriter, null);
assertNotNull(stringWriter.getBuffer().toString());
if (stringWriter.getBuffer().toString().length() < 1) {
fail("generated xml is empty");
}
// read
XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
outResource.setEncoding("UTF-8");
Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
outResource.load(is, options);
DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
assertNotNull(outRoot.getBPSimData());
BPSimDataType outAnalysisData = outRoot.getBPSimData();
assertEquals(outAnalysisData.getScenario().size(), 1);
Scenario outScenario = outAnalysisData.getScenario().get(0);
assertEquals(outScenario.getElementParameters().size(), 1);
assertEquals(outScenario.getId(), "default");
assertEquals(outScenario.getName(), "Scenario");
assertNotNull(outScenario.getScenarioParameters());
assertNotNull(outScenario.getElementParameters());
assertEquals(outScenario.getElementParameters().size(), 1);
ElementParameters outElementParamType = outScenario.getElementParameters().get(0);
assertNotNull(outElementParamType.getTimeParameters());
TimeParameters outTimeParams = outElementParamType.getTimeParameters();
assertNotNull(outTimeParams.getProcessingTime());
assertEquals(outTimeParams.getProcessingTime().getParameterValue().size(), 1);
UniformDistributionType outDistributionType = (UniformDistributionType) outTimeParams.getProcessingTime().getParameterValue().get(0);
assertEquals(outDistributionType.getMax(), 600.0);
assertEquals(outDistributionType.getMin(), 180.0);
}
Aggregations