Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.File;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.concurrent.Callable;

import io.process.analytics.tools.bpmn.generator.BPMNLayoutGenerator.ExportType;
Expand Down Expand Up @@ -54,7 +53,6 @@ public class App implements Callable<Integer> {
private File[] inputFiles;

public static void main(String[] args) throws Exception {

int exitCode = runApp(args);
System.exit(exitCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import static io.process.analytics.tools.bpmn.generator.export.BPMNExporter.defaultBpmnExporter;
import static io.process.analytics.tools.bpmn.generator.internal.BpmnInOut.defaultBpmnInOut;

import java.io.File;
import java.io.IOException;

import io.process.analytics.tools.bpmn.generator.algo.ShapeLayouter;
import io.process.analytics.tools.bpmn.generator.algo.ShapeSorter;
import io.process.analytics.tools.bpmn.generator.converter.BpmnToAlgoModelConverter;
import io.process.analytics.tools.bpmn.generator.export.ASCIIExporter;
import io.process.analytics.tools.bpmn.generator.export.SVGExporter;
import io.process.analytics.tools.bpmn.generator.input.CSVtoBPMN;
import io.process.analytics.tools.bpmn.generator.internal.BpmnInOut;
import io.process.analytics.tools.bpmn.generator.internal.FileUtils;
import io.process.analytics.tools.bpmn.generator.internal.generated.model.TDefinitions;
import io.process.analytics.tools.bpmn.generator.model.Diagram;
import io.process.analytics.tools.bpmn.generator.model.Grid;
Expand Down Expand Up @@ -93,20 +89,17 @@ private String exportToSvg(LayoutSortedDiagram diagram) {


private String export(LayoutSortedDiagram layout, ExportType exportType) {
switch (exportType) {
case ASCII:
return exportToAscii(layout);
case BPMN:
return exportToBpmn(layout);
case SVG:
return exportToSvg(layout);
default:
throw new IllegalStateException("Unexpected Export Type: " + exportType);
}
return switch (exportType) {
case ASCII -> exportToAscii(layout);
case BPMN -> exportToBpmn(layout);
case SVG -> exportToSvg(layout);
default -> throw new IllegalStateException("Unexpected Export Type: " + exportType);
};
}

@RequiredArgsConstructor
@Getter
// TODO switch to record
public static class LayoutSortedDiagram {

private final TDefinitions originalDefinitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static io.process.analytics.tools.bpmn.generator.model.Position.position;

import java.util.List;
import java.util.stream.Collectors;

import io.process.analytics.tools.bpmn.generator.model.Edge;
import io.process.analytics.tools.bpmn.generator.model.Grid;
Expand All @@ -22,6 +21,7 @@ public Grid layout(Diagram diagram) {
for (Shape shape : diagram.getShapes()) {
Position positionOfCurrentShape = positionShape(diagram, grid, shape);
putOnGrid(grid, positionOfCurrentShape);
// TODO check usage of supplier, intellij says it is deprecated
log.debug("Adding {}:\n{}", shape::getName, () -> toAscii(grid));
addRowsWhenShapeIsASplit(diagram, grid, shape, positionOfCurrentShape);
}
Expand Down Expand Up @@ -76,8 +76,8 @@ private Position positionShape(Diagram diagram, Grid grid, Shape shape) {
private void compactGrid(Grid grid) {
int i = 0;
while (i < grid.getLastRowIndex()) {
List<Integer> currentRow = grid.getRow(i).stream().map(Position::getX).collect(Collectors.toList());
List<Integer> nextRow = grid.getRow(i + 1).stream().map(Position::getX).collect(Collectors.toList());
List<Integer> currentRow = grid.getRow(i).stream().map(Position::getX).toList();
List<Integer> nextRow = grid.getRow(i + 1).stream().map(Position::getX).toList();

boolean currentRowCanBeMovedBelow = true;
for (Integer shapeIndexInCurrentRow : currentRow) {
Expand Down Expand Up @@ -109,7 +109,7 @@ private Position addStartShape(Grid grid, Shape shape) {
private Position addSplit(Grid grid, Shape shape, String previousShapeID, List<Edge> outgoingEdgesOfPreviousShape) {
Position previousShapePosition = grid.getPosition(previousShapeID);
int numberOfShapesInTheSplit = outgoingEdgesOfPreviousShape.size();
int indexOfCurrentShape = outgoingEdgesOfPreviousShape.stream().map(Edge::getTo).collect(Collectors.toList()).indexOf(shape.getId());
int indexOfCurrentShape = outgoingEdgesOfPreviousShape.stream().map(Edge::getTo).toList().indexOf(shape.getId());
//put element right to the split vertically distributed according to the index
int relativeYPosition;
if (numberOfShapesInTheSplit % 2 == 0 && indexOfCurrentShape >= numberOfShapesInTheSplit / 2) {
Expand All @@ -124,7 +124,7 @@ private Position addSplit(Grid grid, Shape shape, String previousShapeID, List<E
private Position addJoin(Grid grid, Shape shape, List<Edge> incomingEdges) {
//first implementation: middle of elements it joins
// later we should also try yo find the split to align it to that if possible
List<Position> positions = incomingEdges.stream().map(Edge::getFrom).map(grid::getPosition).collect(Collectors.toList());
List<Position> positions = incomingEdges.stream().map(Edge::getFrom).map(grid::getPosition).toList();
int xMax = positions.stream().map(Position::getX).reduce(0, Math::max);
int yMax = positions.stream().map(Position::getY).reduce(0, Math::max);
int yMin = positions.stream().map(Position::getY).reduce(Integer.MAX_VALUE, Math::min);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
public class ShapeSorter {


/**
* sort nodes of a diagram in topological order
*
Expand Down Expand Up @@ -78,12 +77,9 @@ private boolean isAJoinInOriginalDiagram(Diagram diagram, Shape currentElement)
}

private Diagram doSort(Diagram diagram) {
List<Shape> shapeToSort = new ArrayList<>();
List<Edge> remainingEdges = new ArrayList<>();
List<Edge> finalEdges = new ArrayList<>();
shapeToSort.addAll(diagram.getShapes());
remainingEdges.addAll(diagram.getEdges());
finalEdges.addAll(diagram.getEdges());
List<Shape> shapeToSort = new ArrayList<>(diagram.getShapes());
List<Edge> remainingEdges = new ArrayList<>(diagram.getEdges());
List<Edge> finalEdges = new ArrayList<>(diagram.getEdges());
List<Join> joins = findAllJoins(shapeToSort, remainingEdges);

Diagram.DiagramBuilder sortedDiagram = Diagram.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,7 @@ private List<TFlowNode> getFlowNodeElements(String nodes) {
continue;
}
String[] node = line.split(",");
String type = removeEnclosingDoubleQuote(node[3]);
TFlowNode flowNode;
switch (type) {
case "start_event":
flowNode = new TStartEvent();
break;
case "end_event":
flowNode = new TEndEvent();
break;
case "gateway":
flowNode = new TParallelGateway();
break;
case "parallel_gateway":
flowNode = new TParallelGateway();
break;
case "exclusive_gateway":
flowNode = new TExclusiveGateway();
break;
case "inclusive_gateway":
flowNode = new TInclusiveGateway();
break;
case "user_task":
flowNode = new TUserTask();
break;
case "service_task":
flowNode = new TServiceTask();
break;
case "task":
default:
flowNode = new TTask();
}
TFlowNode flowNode = gettFlowNode(node);
flowNode.setName(removeEnclosingDoubleQuote(node[2]));

String originalId = node[1];
Expand All @@ -107,6 +77,21 @@ private List<TFlowNode> getFlowNodeElements(String nodes) {
return flowElements;
}

private static TFlowNode gettFlowNode(String[] node) {
String type = removeEnclosingDoubleQuote(node[3]);
TFlowNode flowNode = switch (type) {
case "start_event" -> new TStartEvent();
case "end_event" -> new TEndEvent();
case "gateway", "parallel_gateway" -> new TParallelGateway();
case "exclusive_gateway" -> new TExclusiveGateway();
case "inclusive_gateway" -> new TInclusiveGateway();
case "user_task" -> new TUserTask();
case "service_task" -> new TServiceTask();
default -> new TTask();
};
return flowNode;
}

private void assignIncomingAndOutgoingReferences(List<TFlowNode> flowNodeElements) {
for (TFlowNode flowNode : flowNodeElements) {
EdgeRelation edgeRelation = this.shapeRelations.get(flowNode.getId());
Expand Down Expand Up @@ -191,7 +176,7 @@ private static boolean isNumeric(String s) {
private static class EdgeRelation {

public final List<String> incoming = new ArrayList<>();
public final List<String> outgoing = new ArrayList<>();;
public final List<String> outgoing = new ArrayList<>();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.process.analytics.tools.bpmn.generator.internal;

import static io.process.analytics.tools.bpmn.generator.internal.FileUtils.createParents;
import static io.process.analytics.tools.bpmn.generator.internal.FileUtils.fileContent;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* Helper to access to the BPMN semantic part
*/
@RequiredArgsConstructor
// TODO switch to record
// TODO lombok getter on class
public class Semantic {

@NonNull
Expand All @@ -42,18 +44,12 @@ public static String getId(Object object) {
return ((TBaseElement) object).getId();
}

public List<TParticipant> getParticipants() {
return getCollaboration()
.map(TCollaboration::getParticipant)
.orElseGet(Collections::emptyList);
}

public Optional<TCollaboration> getCollaboration() {
List<TCollaboration> collaborations = definitions.getRootElement().stream()
.map(JAXBElement::getValue)
.filter(TCollaboration.class::isInstance)
.map(TCollaboration.class::cast)
.collect(Collectors.toList());
.toList();

// TODO check at most 1 otherwise error
// TODO refactor into a more functional way
Expand Down Expand Up @@ -106,9 +102,7 @@ public void add(TProcess process) {

public static void addFlowNodes(TProcess process, Collection<TFlowNode> flowElements) {
flowElements.stream()
.map(f -> {
return new JAXBElement<>(bpmnElementQName(f), TFlowNode.class, null, f);
})
.map(f -> new JAXBElement<>(bpmnElementQName(f), TFlowNode.class, null, f))
.forEach(f -> process.getFlowElement().add(f));
}

Expand All @@ -123,7 +117,7 @@ private static QName bpmnElementQName(String bpmnElement) {
}

//TODO add other type of flow node elements
private static final Map<Class<? extends TFlowNode>, String> bpmnElementBindings = new HashMap<Class<? extends TFlowNode>, String>() {{
private static final Map<Class<? extends TFlowNode>, String> bpmnElementBindings = new HashMap<>() {{
put(TParallelGateway.class, "parallelGateway");
put(TInclusiveGateway.class, "inclusiveGateway");
put(TExclusiveGateway.class, "exclusiveGateway");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.process.analytics.tools.bpmn.generator.internal;

import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;

Expand Down Expand Up @@ -56,6 +55,7 @@ private Marshaller createMarshaller() throws JAXBException {
} catch(PropertyException e) {
// In case another JAXB implementation is used
// do not stop processing, namespace prefixes will be generated automatically in that case
// TODO switch to logger
e.printStackTrace();
}
return marshaller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package io.process.analytics.tools.bpmn.generator.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
*
* Represent a grid with coordinate as follow
* Represent a grid with coordinate as follows
*
* <pre>
* + ➞ x
* ↓
* y
* </pre>
*/
// TODO use lombok getter?
public class Grid {

private final List<Position> positions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@Data
@Builder(toBuilder = true)
@RequiredArgsConstructor
// TODO switch to record
public class Shape {

private final String id; // the bpmnElement id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
package io.process.analytics.tools.bpmn.generator.model;

public enum ShapeType {
ACTIVITY, EVENT, GATEWAY;
ACTIVITY, EVENT, GATEWAY
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
// TODO switch to record
public class DisplayDimension {

public final int x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*/
package io.process.analytics.tools.bpmn.generator.model.display;

import io.process.analytics.tools.bpmn.generator.model.display.DisplayPoint;
import lombok.Builder;
import lombok.RequiredArgsConstructor;

import java.util.List;

@RequiredArgsConstructor
@Builder
// TODO switch to record
public class DisplayEdge {

public final String bpmnElementId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

@RequiredArgsConstructor
@Builder
// TODO switch to record
public class DisplayFlowNode {

public final String bpmnElementId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
// TODO switch to record
public class DisplayLabel {

public final String text; // for non BPMN exporters only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@RequiredArgsConstructor
@Builder
// TODO switch to record
public class DisplayModel {
public final int width;
public final int height;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@RequiredArgsConstructor
@ToString
// TODO switch to record
public class DisplayPoint {

public final int x;
Expand Down