AnsweredAssumed Answered

Which code lines of Activiti Explorer to edit model?

Question asked by holysoul on Feb 7, 2014
Latest reply on Feb 12, 2014 by holysoul
Hi all.
I now have plan to create new Activiti Explorer separated from Vaadin. Would you show me which code lines to edit model?. I have read source code and extract that method:

   public String editModel(String modelID) {
      // TODO Auto-generated method stub
      RepositoryService repositoryService = ActivitiUtil
            .getRepositoryService();

      Model model = repositoryService.getModel(modelID);
      //
      SimpleWorkflowJsonConverter simpleWorkflowJsonConverter = new SimpleWorkflowJsonConverter();
      WorkflowDefinition workflowDefinition = simpleWorkflowJsonConverter
            .readWorkflowDefinition(repositoryService
                  .getModelEditorSource(model.getId()));
      WorkflowDefinitionConversionFactory workflowDefinitionConversionFactory = new WorkflowDefinitionConversionFactory();
      
      WorkflowDefinitionConversion conversion = workflowDefinitionConversionFactory
            .createWorkflowDefinitionConversion(workflowDefinition);
      conversion.convert();

      model.setCategory(null);

      ObjectMapper objectMapper = new ObjectMapper();
      ObjectNode metaInfoJson = objectMapper.createObjectNode();
      metaInfoJson.put("name", model.getName());
      model.setMetaInfo(metaInfoJson.toString());
      repositoryService.saveModel(model);

      BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
      ObjectNode json = bpmnJsonConverter.convertToJson(conversion
            .getBpmnModel());
      try {
         repositoryService.addModelEditorSource(model.getId(), json
               .toString().getBytes("utf-8"));
      } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      return model.getId();
   }


However, I got this error:
org.activiti.workflow.simple.exception.SimpleWorkflowException: Error while parsing JSON
   at org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter.wrapExceptionRead(SimpleWorkflowJsonConverter.java:107)
   at org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter.readWorkflowDefinition(SimpleWorkflowJsonConverter.java:69)


How do I fix those codes?
Thank you very much

Outcomes