Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions bundles/nl.asml.matala.bpmn4s/src/nl/asml/matala/bpmn4s/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public static void compile(String inputModel, boolean simulation, String outputF
@Override
protected String repr(Element el) {
return el.getId();
}
}
@Override
protected String getFullyQualifiedName(Element el) {
return repr(el);
}
@Override
protected String getCompiledXorName(String xorId) {
return repr(model.getElementById(xorId));
Expand Down Expand Up @@ -161,8 +165,7 @@ protected List<String> getFlowActions(String component) {
Element c = model.getElementById(component);
ArrayList<String> result = new ArrayList<String>();
for (Element source: model.elements.values()) {
if ((isAPlace(source.getId()) || model.isActivity(source.getId()))
&& isParentComponent( c, source)) {
if (isAPlace(source.getId()) && isParentComponent( c, source)) {
for(Edge e: source.getAllOutputs()) {
String sourceId = e.getSrc();
String targetId = e.getTar();
Expand Down Expand Up @@ -277,7 +280,8 @@ static void makeDataNode(BpmnModelInstance modelInst, ItemAwareElement elem, Ele
String origin = getOriginDataReference(elem);
node.setOriginDataNodeId(origin != null ? origin : id);
node.setParent(getParentId(elem));
node.setComponent(getParentComponents(elem));
node.setFullyQualifiedName(getFullyQualifiedName(elem));
node.setParentComponents(getParentComponents(elem));
String datatyperef = elem.getAttributeValueNs("http://bpmn4s", "dataTypeRef");
DataType dt = getExtensionElementById(modelInst, DataType.class, datatyperef);
String dtname = dt != null? dt.getAttributeValue("name"): datatyperef;
Expand Down Expand Up @@ -475,7 +479,8 @@ public static void makeActionNode(BpmnModelInstance modelInst, BaseElement elem,
node.setId(id);
if (elem instanceof FlowNode) {
node.setParent(getParentId(elem));
node.setComponent(getParentComponents(elem));
node.setFullyQualifiedName(getFullyQualifiedName(elem));
node.setParentComponents(getParentComponents(elem));
node.setGuard(elem.getAttributeValueNs("http://bpmn4s", "guard"));
node.setStepType(elem.getAttributeValueNs("http://bpmn4s", "stepType"));
}
Expand All @@ -491,9 +496,6 @@ public static void makeActionNode(BpmnModelInstance modelInst, BaseElement elem,
contextTypeName = contextTypeId;
}
}
if(contextInit != null && contextInit.strip().startsWith("=")) {
contextInit = contextInit.substring(1); // FIXME due to issues with bpmn4s editor lsp integration
}
node.setContext(contextName != null ? contextName : "",
contextTypeName != null ? contextTypeName : "",
contextInit != null ? contextInit : "");
Expand Down Expand Up @@ -555,6 +557,25 @@ static ArrayList<String> getParentComponents (ModelElementInstance elem) {
return result;
}

/*
* Note that we use the separator <@> which is not allowed
* in the editor ids but is a allowed in pspec ids.
*/
static String getFullyQualifiedName (ModelElementInstance elem) {
ArrayList<String> parentsList = new ArrayList<String>();
ModelElementInstance parent = elem.getParentElement();
// FIXME: there must be a more robust way to check the type of an element than comparing to a string
while(parent != null &&
("subProcess".equals(parent.getElementType().getTypeName()) ||
"process".equals(parent.getElementType().getTypeName())))
{
parentsList.add(0, getName(parent));
parent = parent.getParentElement();
}
String result = "";
result = String.join("@", parentsList) + "@" + getName(elem);
return result;
}

static String getParentId(ModelElementInstance elem) {
ModelElementInstance parent = elem.getParentElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public static <E> E getOrDefault(List<E> list, int index,E defaultValue) {
return index <= list.size() - 1 ? list.get(index) : defaultValue;
}

protected String getFullyQualifiedName(Element el) {
return sanitize(el.getFullyQualifiedName());
}

private String fabSpecDescription(String cId) {
ArrayList<String> desc = new ArrayList<String>();
Expand All @@ -459,7 +462,7 @@ private String fabSpecDescription(String cId) {
String task = "";
// Name of context as defined by user at front end:
String compCtxName = model.getElementById(cId).getContextName();
task += "action\t\t\t" + sanitize(repr(node)) + "\n";
task += "action\t\t\t" + getFullyQualifiedName(node) + "\n";
// STEP TYPE
String stepConf = "";
if (model.isComposeTask(node.getId())) {
Expand Down Expand Up @@ -571,7 +574,7 @@ protected Map<String, String> buildReplaceMap (Element transition) {

/**
* In simulation mode, some flows between bpmn4s elements introduce transitions in the CPN.
* Imagine a flow between to XOR gates for instance. In general, if two elements are connected with a flow
* Imagine a flow between two XOR gates for instance. In general, if two elements are connected with a flow
* and their CPN semantics is a place, then a transition needs to be added. For test generation, we optimize
* the model such that this flows do not exist anymore, so that we reduce spurious non-determinism.
*/
Expand All @@ -596,7 +599,7 @@ protected ArrayList<String> getInputOutputIds(Element elem) {


/**
* Fetch the names of components that poses a RUN task.
* Fetch the names of components that contain a RUN task.
* @return List with components names
*/
private ArrayList<String> listSUTcomponents () {
Expand Down Expand Up @@ -809,7 +812,7 @@ void writeToFile (Path filename, String text) {
* but PSpec is more restrictive so we replace them.
*/
protected String sanitize(String str) {
String result = str.replaceAll("\\p{Zs}+", "").replace(".", "");
String result = str.replaceAll("\\p{Zs}+", "").replace(".", "").replace("-","");
return result;
}

Expand Down Expand Up @@ -863,12 +866,11 @@ protected String compile(String elId) {

/**
* Get the identifier of a bpmn4s Element <el>
* While the compiler for test generation (this) returns the name of the element,
* the compiler for simulation will return the element's id.
* Return a sanitized version of the elemnt's name chosen by the modeler.
* The compiler for simulation overrides this method and returns the element's id.
*/
protected String repr(Element el) {
// Logging.logDebug(el.getId());
return el.getName();
return sanitize(el.getName());
}

private String getOriginDataNode(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Context {
List<Edge> flowInputs = new ArrayList<Edge>();
List<Edge> flowOutputs = new ArrayList<Edge>();
String parent = "";
ArrayList<String> components = new ArrayList<String>();
String fqname = "";
ArrayList<String> parentComponents = new ArrayList<String>();
String init = "";
String stepType;

Expand Down Expand Up @@ -133,12 +134,12 @@ public String getParent () {
return parent;
}

public void setComponent (ArrayList<String> cname) {
components = cname;
public void setParentComponents (ArrayList<String> cname) {
parentComponents = cname;
}

public ArrayList<String> getParentComponents () {
return components;
return parentComponents;
}

public void setContext(String name, String dataType, String init) {
Expand Down Expand Up @@ -259,8 +260,7 @@ public boolean isReferenceData() {
public String toString() {
return String.format("Element named %s with id %s and type %s", this.name, this.id, this.type);
}



private static <T> List<T> listConcat(List<T> list1, List<T> list2) {
return Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList());
}
Expand All @@ -272,5 +272,13 @@ public List<Edge> getAllInputs() {
public List<Edge> getAllOutputs() {
return listConcat(flowOutputs, dataOutputs);
}

public void setFullyQualifiedName(String name) {
this.fqname = name;
}

public String getFullyQualifiedName () {
return fqname;
}

}