Package org.activiti.engine.repository

Examples of org.activiti.engine.repository.Model


    final ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
    ProcessEngineConfiguration processEngineConfiguration = defaultProcessEngine.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
   
    Model model = null;
    if (modelId == null) { // new process
      model = repositoryService.newModel();
    } else { // update existing process
      model = repositoryService.getModel(modelId);
    }

    model.setName(workflowDefinition.getName());
    model.setCategory(SimpleTableEditorConstants.TABLE_EDITOR_CATEGORY);
    repositoryService.saveModel(model);

    // Store model entity
    WorkflowDefinitionConversion conversion =
            ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
   
    try {
      // Write JSON to byte-array and set as editor-source
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ExplorerApp.get().getSimpleWorkflowJsonConverter().writeWorkflowDefinition(workflowDefinition, new OutputStreamWriter(baos));
      repositoryService.addModelEditorSource(model.getId(), baos.toByteArray());
     
      // Store process image
      // TODO: we should really allow the service to take an inputstream as input. Now we load it into memory ...
      repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(
          diagramGenerator.generateDiagram(conversion.getBpmnModel(), "png", processEngineConfiguration.getActivityFontName(),
              processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getClassLoader())));
    } catch (IOException e) {
      logger.warn("Could not generate process image. Image is not stored and will not be shown.", e);
    }
   
    ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(model.getId());
  }
View Full Code Here


    return editorSource;
  }
 
  @RequestMapping(value="/repository/models/{modelId}/source", method = RequestMethod.PUT)
  protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
     
      if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
      }
View Full Code Here

    }

    protected Model getModel(final ProcessDefinition procDef) {
        try {
            Model model = repositoryService.createModelQuery().deploymentId(procDef.getDeploymentId()).singleResult();
            if (model == null) {
                throw new NotFoundException("Could not find Model for deployment " + procDef.getDeploymentId());
            }
            return model;
        } catch (Exception e) {
View Full Code Here

            IOUtils.closeQuietly(procDefIS);
        }
    }

    protected void exportProcessModel(final OutputStream os) {
        Model model = getModel(getProcessDefinition());

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            ObjectNode modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
            modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId());
            modelNode.replace(MODEL_DATA_JSON_MODEL,
                    objectMapper.readTree(repositoryService.getModelEditorSource(model.getId())));

            os.write(modelNode.toString().getBytes());
        } catch (IOException e) {
            LOG.error("While exporting workflow definition {}", model.getKey(), e);
        }
    }
View Full Code Here

    @Override
    public void importDefinition(final WorkflowDefinitionFormat format, final String definition)
            throws WorkflowException {

        Model model = getModel(getProcessDefinition());
        switch (format) {
            case JSON:
                JsonNode definitionNode;
                try {
                    definitionNode = new ObjectMapper().readTree(definition);
View Full Code Here

                        new ByteArrayInputStream(IOUtils.toByteArray(wfIn))).deploy();

                ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey(
                        ActivitiUserWorkflowAdapter.WF_PROCESS_ID).latestVersion().singleResult();

                Model model = repositoryService.newModel();
                ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
                modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, procDef.getName());
                modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
                modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, procDef.getDescription());
                model.setMetaInfo(modelObjectNode.toString());
                model.setName(procDef.getName());
                model.setDeploymentId(procDef.getDeploymentId());
                activitiJSONUtils.fromJSON(procDef, model);

                LOG.debug("Activiti Workflow definition loaded");
            } catch (IOException e) {
                LOG.error("While loading " + ActivitiUserWorkflowAdapter.WF_PROCESS_RESOURCE, e);
View Full Code Here

                LOG.info("Importing default workflow for Syncope 1.2.X");

                importUtils.fromXML(userWorkflowBytes);

                // add activiti model to database
                final Model model = repositoryService.newModel();

                final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().
                        processDefinitionKey(ActivitiUserWorkflowAdapter.WF_PROCESS_ID).latestVersion().singleResult();

                model.setDeploymentId(processDefinition.getDeploymentId());
                model.setName("User Workflow");
                model.setVersion(1);
                model.setMetaInfo("{\"name\":\"User Workflow\",\"revision\":2,\"description\":null}");
                repositoryService.saveModel(model);

                repositoryService.addModelEditorSource(repositoryService.createModelQuery().deploymentId(
                        processDefinition.getDeploymentId()).singleResult().getId(), userWorkflowBytes);
View Full Code Here

    ObjectNode modelNode = null;
    String modelId = (String) getRequest().getAttributes().get("modelId");
   
    if(NumberUtils.isNumber(modelId)) {
      RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
      Model model = repositoryService.getModel(modelId);
     
      if (model != null) {
        try {
          modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
          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.log(Level.SEVERE, "Error creating model JSON", e);
          setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

      JsonToBpmnExport converter = new JsonToBpmnExport(modelNode);
      byte[] bpmnBytes = converter.convert();
      System.out.println("bpmn " + new String(bpmnBytes));*/
     
      RepositoryService repositoryService = ProcessEngines.getDefaultProcessEngine().getRepositoryService();
      Model model = repositoryService.getModel(modelId);
     
      ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
     
      modelJson.put(MODEL_NAME, modelForm.getFirstValue("name"));
      modelJson.put(MODEL_DESCRIPTION, modelForm.getFirstValue("description"));
      model.setMetaInfo(modelJson.toString());
      model.setName(modelForm.getFirstValue("name"));
     
      repositoryService.saveModel(model);
     
      repositoryService.addModelEditorSource(model.getId(), modelForm.getFirstValue("json_xml").getBytes("utf-8"));
      repositoryService.addModelEditorSourceExtra(model.getId(), modelForm.getFirstValue("svg_xml").getBytes("utf-8"));
     
    } catch(Exception e) {
      LOGGER.log(Level.SEVERE, "Error saving model", e);
      setStatus(Status.SERVER_ERROR_INTERNAL);
    }
View Full Code Here

      assertTextPresent("resourceName is null", ae.getMessage());
    }
  }

  public void testNewModelPersistence() {
    Model model = repositoryService.newModel();
    assertNotNull(model);
   
    model.setName("Test model");
    model.setCategory("test");
    model.setMetaInfo("meta");
    repositoryService.saveModel(model);
   
    assertNotNull(model.getId());
    model = repositoryService.getModel(model.getId());
    assertNotNull(model);
    assertEquals("Test model", model.getName());
    assertEquals("test", model.getCategory());
    assertEquals("meta", model.getMetaInfo());
    assertNotNull(model.getCreateTime());
    assertEquals(Integer.valueOf(1), model.getVersion());
   
    repositoryService.deleteModel(model.getId());
  }
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.