cancel
Showing results for 
Search instead for 
Did you mean: 

Which code lines of Activiti Explorer to edit model?

holysoul
Champ in-the-making
Champ in-the-making
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
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
Your error indicates your json is wrong.

Could you post your json that you used as input?

holysoul
Champ in-the-making
Champ in-the-making
Thank jbarrez.
It's very strange, because I use demo file of Activiti explorer. I have just attached it to  my post.
It runs really well with Activiti explorer app.
However when I want to edit using my app, it has errors. My web is okay with create,deploy or export model.

jbarrez
Star Contributor
Star Contributor
It seems you are trying to parse Modeler json format with the simple workflow API.
The simple workflow API looks completely different from that one and so it's logical it doesn't work.

holysoul
Champ in-the-making
Champ in-the-making
After days, I still have no clue at all Smiley Sad.
Here are my package used for method above:
<code>
import org.activiti.workflow.simple.converter.WorkflowDefinitionConversion;
import org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory;
import org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter;
import org.activiti.workflow.simple.definition.WorkflowDefinition;
</code>

jbarrez
Star Contributor
Star Contributor
That's all very dandy and fine … but you are not reading what I posted.

The json file you try to parse with those classes is the wrong json file. You are passing the modeler json. That is *completely* different from the json used in this API.

holysoul
Champ in-the-making
Champ in-the-making
Hi jbarrez and thanks again.
I have already checked my code and found mistakes. I really did not pass the right format json file. So to edit model, I examine Explorer and found an simple way.