Package org.activiti.engine.repository

Examples of org.activiti.engine.repository.Model


    @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);
View Full Code Here


            @FormParam("svg_xml") String svgXml,
            @FormParam("type") String type, @FormParam("views") String views)
            throws Exception {
        RepositoryService repositoryService = processEngine
                .getRepositoryService();
        Model model = repositoryService.getModel(id);
        model.setName(name);
        // model.setMetaInfo(root.toString());
        System.out.println("jsonXml : " + jsonXml);
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSource(model.getId(),
                jsonXml.getBytes("utf-8"));

        Map map = new HashMap();

        return map;
View Full Code Here

    @RequestMapping("modeler-open")
    public String open(@RequestParam(value = "id", required = false) String id)
            throws Exception {
        RepositoryService repositoryService = processEngine
                .getRepositoryService();
        Model model = repositoryService.getModel(id);

        if (model == null) {
            model = repositoryService.newModel();
            repositoryService.saveModel(model);
            id = model.getId();
        }

        return "redirect:/widgets/modeler/editor.html?id=" + id;
    }
View Full Code Here

    @RequestMapping("modeler-deploy")
    public String deploy(@RequestParam("id") String id) throws Exception {
        RepositoryService repositoryService = processEngine
                .getRepositoryService();
        Model modelData = repositoryService.getModel(id);
        JsonNode modelNode = (JsonNode) new ObjectMapper()
                .readTree(repositoryService.getModelEditorSource(modelData
                        .getId()));
        byte[] bpmnBytes = null;

        BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        bpmnBytes = new BpmnXMLConverter().convertToXML(model);

        String processName = modelData.getName() + ".bpmn20.xml";
        Deployment deployment = repositoryService.createDeployment()
                .name(modelData.getName())
                .addString(processName, new String(bpmnBytes, "UTF-8"))
                .deploy();
        modelData.setDeploymentId(deployment.getId());
        repositoryService.saveModel(modelData);

        List<ProcessDefinition> processDefinitions = repositoryService
                .createProcessDefinitionQuery()
                .deploymentId(deployment.getId()).list();
View Full Code Here

        if (StringUtils.isEmpty((String) nameTextField.getValue())) {
          form.setComponentError(new UserError("The name field is required."));
          return;
        }
       
        Model newModelData = repositoryService.newModel();
       
        ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
        modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
        String description = null;
        if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
          description = (String) descriptionTextArea.getValue();
        } else {
          description = "";
        }
        modelObjectNode.put(MODEL_DESCRIPTION, description);
        newModelData.setMetaInfo(modelObjectNode.toString());
        newModelData.setName((String) nameTextField.getValue());
       
        repositoryService.saveModel(newModelData);
       
        repositoryService.addModelEditorSource(newModelData.getId(), repositoryService.getModelEditorSource(modelData.getId()));
        repositoryService.addModelEditorSourceExtra(newModelData.getId(), repositoryService.getModelEditorSourceExtra(modelData.getId()));
       
        close();
        ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(newModelData.getId());
      }
    });
   
    // Alignment
    HorizontalLayout buttonLayout = new HorizontalLayout();
View Full Code Here

          editorNode.put("id", "canvas");
          editorNode.put("resourceId", "canvas");
          ObjectNode stencilSetNode = objectMapper.createObjectNode();
          stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
          editorNode.put("stencilset", stencilSetNode);
          Model modelData = repositoryService.newModel();
         
          ObjectNode modelObjectNode = objectMapper.createObjectNode();
          modelObjectNode.put(MODEL_NAME, (String) nameTextField.getValue());
          modelObjectNode.put(MODEL_REVISION, 1);
          String description = null;
          if (StringUtils.isNotEmpty((String) descriptionTextArea.getValue())) {
            description = (String) descriptionTextArea.getValue();
          } else {
            description = "";
          }
          modelObjectNode.put(MODEL_DESCRIPTION, description);
          modelData.setMetaInfo(modelObjectNode.toString());
          modelData.setName((String) nameTextField.getValue());
         
          repositoryService.saveModel(modelData);
         
          repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
         
          close();
          ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
          ExplorerApp.get().getMainWindow().open(new ExternalResource(
              ExplorerApp.get().getURL().toString() + "service/editor?id=" + modelData.getId()));
         
        } catch(Exception e) {
          notificationManager.showErrorNotification("error", e);
        }
      }
View Full Code Here

                  i18nManager.getMessage(Messages.MODEL_IMPORT_INVALID_BPMNDI_EXPLANATION));
            } else {
         
              BpmnJsonConverter converter = new BpmnJsonConverter();
              ObjectNode modelNode = converter.convertToJson(bpmnModel);
              Model modelData = repositoryService.newModel();
             
              ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
              modelObjectNode.put(MODEL_NAME, processDefinition.getName());
              modelObjectNode.put(MODEL_REVISION, 1);
              modelObjectNode.put(MODEL_DESCRIPTION, processDefinition.getDescription());
              modelData.setMetaInfo(modelObjectNode.toString());
             
              repositoryService.saveModel(modelData);
             
              repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
             
              close();
              ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());
              ExplorerApp.get().getMainWindow().open(new ExternalResource(
                  ExplorerApp.get().getURL().toString() + "service/editor?id=" + modelData.getId()));
            }
          }
         
        } catch(Exception e) {
          notificationManager.showErrorNotification("error", e);
View Full Code Here

  protected void createModelData(String name, String description, String jsonFile) {
    List<Model> modelList = repositoryService.createModelQuery().modelName("Demo model").list();
   
    if (modelList == null || modelList.size() == 0) {
   
      Model model = repositoryService.newModel();
      model.setName(name);
     
      ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
      modelObjectNode.put(MODEL_NAME, name);
      modelObjectNode.put(MODEL_DESCRIPTION, description);
      model.setMetaInfo(modelObjectNode.toString());
     
      repositoryService.saveModel(model);
     
      try {
        InputStream svgStream = this.getClass().getClassLoader().getResourceAsStream("org/activiti/explorer/demo/model/test.svg");
        repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(svgStream));
      } catch(Exception e) {
        LOGGER.log(Level.WARNING, "Failed to read SVG", e);
      }
     
      try {
        InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
        repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
      } catch(Exception e) {
        LOGGER.log(Level.WARNING, "Failed to read editor JSON", e);
      }
    }
  }
View Full Code Here

 
  @RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json")
  public ObjectNode getEditorJson(@PathVariable String modelId) {
    ObjectNode modelNode = null;
   
    Model model = repositoryService.getModel(modelId);
     
    if (model != null) {
      try {
        if (StringUtils.isNotEmpty(model.getMetaInfo())) {
          modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
        } else {
          modelNode = objectMapper.createObjectNode();
          modelNode.put(MODEL_NAME, model.getName());
        }
        modelNode.put(MODEL_ID, model.getId());
        ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(
            new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
        modelNode.put("model", editorJsonNode);
       
      } catch (Exception e) {
        LOGGER.error("Error creating model JSON", e);
        throw new ActivitiException("Error creating model JSON", e);
View Full Code Here

 
  @RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT)
  public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
    try {
     
      Model model = repositoryService.getModel(modelId);
     
      ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
     
      modelJson.put(MODEL_NAME, values.getFirst("name"));
      modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
      model.setMetaInfo(modelJson.toString());
      model.setName(values.getFirst("name"));
     
      repositoryService.saveModel(model);
     
      repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));
     
      InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
      TranscoderInput input = new TranscoderInput(svgStream);
     
      PNGTranscoder transcoder = new PNGTranscoder();
      // Setup output
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();
      TranscoderOutput output = new TranscoderOutput(outStream);
     
      // Do the transformation
      transcoder.transcode(input, output);
      final byte[] result = outStream.toByteArray();
      repositoryService.addModelEditorSourceExtra(model.getId(), result);
      outStream.close();
     
    } catch (Exception e) {
      LOGGER.error("Error saving model", e);
      throw new ActivitiException("Error saving model", e);
View Full Code Here

TOP

Related Classes of org.activiti.engine.repository.Model

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.