org.ikasan.designer.event.CanvasEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ikasan-designer Show documentation
Show all versions of ikasan-designer Show documentation
Integration of vis.js library for Ikasan platform
package org.ikasan.designer.event;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.ikasan.designer.model.Connection;
import org.ikasan.designer.model.Image;
import org.ikasan.designer.model.Rectangle;
import java.io.IOException;
import java.util.*;
public class CanvasEvent {
ObjectMapper objectMapper = new ObjectMapper();
protected String canvasJson;
protected Map schedulerJobs;
protected List orBoundaries;
protected List andBoundaries;
protected List connections;
public CanvasEvent(String canvasJson) {
this.canvasJson = canvasJson;
this.schedulerJobs = new HashMap<>();
this.orBoundaries = new ArrayList<>();
this.andBoundaries = new ArrayList<>();
this.connections = new ArrayList<>();
init();
}
private void init() {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
List values = objectMapper.readValue(this.canvasJson, List.class);
for (LinkedHashMap value : values) {
if (value.get("type").equals("draw2d.shape.basic.Image")) {
Image image = objectMapper.readValue(objectMapper.writeValueAsBytes(value), Image.class);
this.schedulerJobs.put(image.getId(), image);
}
else if (value.get("type").equals("draw2d.shape.basic.Rectangle") && value.get("id").toString().startsWith("AND")) {
Rectangle rectangle = objectMapper.readValue(objectMapper.writeValueAsBytes(value), Rectangle.class);
this.andBoundaries.add(rectangle);
}
else if (value.get("type").equals("draw2d.shape.basic.Rectangle") && value.get("id").toString().startsWith("OR")) {
Rectangle rectangle = objectMapper.readValue(objectMapper.writeValueAsBytes(value), Rectangle.class);
this.orBoundaries.add(rectangle);
}
else if (value.get("type").equals("draw2d.Connection")) {
Connection connection = objectMapper.readValue(objectMapper.writeValueAsBytes(value), Connection.class);
this.connections.add(connection);
}
}
}
catch (JsonProcessingException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public Map getSchedulerJobs() {
return schedulerJobs;
}
public List getOrBoundaries() {
return orBoundaries;
}
public List getAndBoundaries() {
return andBoundaries;
}
public List getConnections() {
return connections;
}
}