@Path("open")
@Produces(MediaType.APPLICATION_JSON)
public Object open(@QueryParam("id") String modelId) throws Exception {
RepositoryService repositoryService = processEngine
.getRepositoryService();
Model model = repositoryService.getModel(modelId);
if (model == null) {
logger.info("model({}) is null", modelId);
model = repositoryService.newModel();
repositoryService.saveModel(model);
}
Map root = new HashMap();
root.put("modelId", model.getId());
root.put("name", "name");
root.put("revision", 1);
root.put("description", "description");
byte[] bytes = repositoryService.getModelEditorSource(model.getId());
if (bytes != null) {
String modelEditorSource = new String(bytes, "utf-8");
logger.info("modelEditorSource : {}", modelEditorSource);
Map modelNode = jsonMapper.fromJson(modelEditorSource, Map.class);
root.put("model", modelNode);
} else {
Map modelNode = new HashMap();
modelNode.put("id", "canvas");
modelNode.put("resourceId", "canvas");
Map stencilSetNode = new HashMap();
stencilSetNode.put("namespace",
"http://b3mn.org/stencilset/bpmn2.0#");
modelNode.put("stencilset", stencilSetNode);
model.setMetaInfo(jsonMapper.toJson(root));
model.setName("name");
model.setKey("key");
root.put("model", modelNode);
}
logger.info("model : {}", root);