use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class ExclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("exclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
Double probabilitySum = 0d;
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.parseDouble(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Exclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
probabilitySum += branchingProbability;
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
if (probabilitySum <= 0) {
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", where the sum of probabilities is negative or zero.");
}
if (probabilitySum > 1) {
// XXX imprecision by IEEE 754 floating point representation
throw new ScyllaValidationException("Simulation configuration defines branching probabilities for exclusive gateway " + identifier + ", exceeding 1 in total.");
}
// complete probabilities with the default flow probability
if (probabilitySum > 0 && probabilitySum <= 1) {
Map<String, String> gatewayAttributes = processModel.getNodeAttributes().get(nodeId);
String defaultFlowIdentifier = gatewayAttributes.get("default");
if (defaultFlowIdentifier != null) {
double probabilityOfDefaultFlow = 1 - probabilitySum;
int defaultFlowNodeId = processModel.getIdentifiersToNodeIds().get(defaultFlowIdentifier);
if (!branchingProbabilities.containsKey(defaultFlowNodeId)) {
branchingProbabilities.put(defaultFlowNodeId, probabilityOfDefaultFlow);
} else {
branchingProbabilities.put(defaultFlowNodeId, branchingProbabilities.get(defaultFlowNodeId) + probabilityOfDefaultFlow);
}
;
}
}
try {
if (branchingProbabilities.keySet().size() != processModel.getIdsOfNextNodes(nodeId).size()) {
throw new ScyllaValidationException("Number of branching probabilities defined in simulation configuration " + "does not match to number of outgoing flows of exclusive gateway " + identifier + ".");
}
} catch (NodeNotFoundException e) {
throw new ScyllaValidationException("Node not found: " + e.getMessage());
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class InclusiveGatewaySCParserPlugin method parse.
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
Namespace simNamespace = sim.getNamespace();
ProcessModel processModel = simulationInput.getProcessModel();
for (Element el : sim.getChildren()) {
String elementName = el.getName();
if (elementName.equals("inclusiveGateway")) {
String identifier = el.getAttributeValue("id");
if (identifier == null) {
DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
// no matching element in process, so skip definition
continue;
}
Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
if (nodeId == null) {
DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
// no matching element in process, so skip definition
continue;
}
List<Element> outgoingSequenceFlows = el.getChildren("outgoingSequenceFlow", simNamespace);
if (outgoingSequenceFlows.size() > 0) {
Map<Integer, Double> branchingProbabilities = new HashMap<Integer, Double>();
for (Element elem : outgoingSequenceFlows) {
Integer nodeIdOfSequenceFlow = processModel.getIdentifiersToNodeIds().get(elem.getAttributeValue("id"));
if (nodeIdOfSequenceFlow != null) {
Double branchingProbability = Double.valueOf(elem.getChildText("branchingProbability", simNamespace));
if (branchingProbability < 0 || branchingProbability > 1) {
throw new ScyllaValidationException("Inclusive gateway branching probability for " + identifier + " is out of bounds [0,1].");
}
branchingProbabilities.put(nodeIdOfSequenceFlow, branchingProbability);
}
}
BranchingBehavior branchingBehavior = new BranchingBehavior(branchingProbabilities);
branchingBehaviors.put(nodeId, branchingBehavior);
}
}
}
HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
extensionAttributes.put("branchingBehaviors", branchingBehaviors);
return extensionAttributes;
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class SimulationTest method beforeParsingSimconfig.
protected void beforeParsingSimconfig(Element simConfigRoot) {
Namespace simNamespace = simConfigRoot.getNamespace();
List<Element> simElements = simConfigRoot.getChildren("simulationConfiguration", simNamespace);
for (Element simElement : simElements) {
String id = simElement.getAttributeValue("id");
simConfigRoots.put(id, simElement);
beforeParsingSims.getOrDefault(id, Collections.emptyList()).forEach(Runnable::run);
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class SimulationTest method beforeParsingModels.
protected void beforeParsingModels(Element modelRoot) {
Namespace bpmnNamespace = modelRoot.getNamespace();
List<Element> processElements = modelRoot.getChildren("process", bpmnNamespace);
for (Element process : processElements) {
String id = process.getAttributeValue("id");
processRoots.put(id, process);
beforeParsingModels.getOrDefault(id, Collections.emptyList()).forEach(Runnable::run);
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project scylla by bptlab.
the class SimulationConfigurationParserPluggable method runPlugins.
public static void runPlugins(SimulationManager simEnvironment, SimulationConfiguration simulationConfiguration, Document document) throws ScyllaValidationException {
Namespace simNamespace = document.getRootElement().getNamespace();
List<Element> simElements = document.getRootElement().getChildren("simulationConfiguration", simNamespace);
Element sim = simElements.get(0);
String processRef = sim.getAttributeValue("processRef");
ProcessModel processModel = simEnvironment.getProcessModels().get(processRef);
runPluginsPerSC(simEnvironment, simulationConfiguration, processModel, sim);
}
Aggregations