Package org.activiti.engine.repository

Examples of org.activiti.engine.repository.Model


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


  public void testModelTenancy() {

    // Create a few models with tenant
    int nrOfModelsWithTenant = 3;
    for (int i = 0; i < nrOfModelsWithTenant; i++) {
      Model model = repositoryService.newModel();
      model.setName(i + "");
      model.setTenantId(TEST_TENANT_ID);
      repositoryService.saveModel(model);
    }

    // Create a few models without tenant
    int nrOfModelsWithoutTenant = 5;
    for (int i = 0; i < nrOfModelsWithoutTenant; i++) {
      Model model = repositoryService.newModel();
      model.setName(i + "");
      repositoryService.saveModel(model);
    }
   
    // Check query
    assertEquals(nrOfModelsWithoutTenant + nrOfModelsWithTenant, repositoryService.createModelQuery().list().size());
    assertEquals(nrOfModelsWithoutTenant, repositoryService.createModelQuery().modelWithoutTenantId().list().size());
    assertEquals(nrOfModelsWithTenant, repositoryService.createModelQuery().modelTenantId(TEST_TENANT_ID).list().size());
    assertEquals(nrOfModelsWithTenant, repositoryService.createModelQuery().modelTenantIdLike("my%").list().size());
    assertEquals(0, repositoryService.createModelQuery().modelTenantId("a%").list().size());

    // Clean up
    for (Model model : repositoryService.createModelQuery().list()) {
      repositoryService.deleteModel(model.getId());
    }
   
  }
View Full Code Here

  }
 
  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testUpdateModelNoFields() throws Exception {
   
    Model model = null;
    try {
      Calendar now = Calendar.getInstance();
      now.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(now.getTime());
     
      model = repositoryService.newModel();
      model.setCategory("Model category");
      model.setKey("Model key");
      model.setMetaInfo("Model metainfo");
      model.setName("Model name");
      model.setVersion(2);
      model.setDeploymentId(deploymentId);
      repositoryService.saveModel(model);
     
      // Use empty request-node, nothing should be changed after update
      ObjectNode requestNode = objectMapper.createObjectNode();
     
      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
      httpPut.setEntity(new StringEntity(requestNode.toString()));
      CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertNotNull(responseNode);
      assertEquals("Model name", responseNode.get("name").textValue());
      assertEquals("Model key", responseNode.get("key").textValue());
      assertEquals("Model category", responseNode.get("category").textValue());
      assertEquals(2, responseNode.get("version").intValue());
      assertEquals("Model metainfo", responseNode.get("metaInfo").textValue());
      assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
      assertEquals(model.getId(), responseNode.get("id").textValue());
     
      assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
      assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
     
      assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
      assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
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());
            URL explorerURL = ExplorerApp.get().getURL();
            URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(),
                    explorerURL.getPath().replace("/ui", "") + "service/editor?id=" + modelData.getId());
            ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
           
          } 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());
              modelData.setName(processDefinition.getName());
             
              repositoryService.saveModel(modelData);
             
              repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));
             
              close();
              ExplorerApp.get().getViewManager().showEditorProcessDefinitionPage(modelData.getId());

            URL explorerURL = ExplorerApp.get().getURL();
            URL url = new URL(explorerURL.getProtocol(), explorerURL.getHost(), explorerURL.getPort(),
                explorerURL.getPath().replace("/ui", "") + "service/editor?id=" + modelData.getId());
              ExplorerApp.get().getMainWindow().open(new ExternalResource(url));
            }
          }
         
        } catch(Exception 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.isEmpty()) {
   
      Model model = repositoryService.newModel();
      model.setName(name);
     
      ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
      modelObjectNode.put("name", name);
      modelObjectNode.put("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.warn("Failed to read SVG", e);
      }
     
      try {
        InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
        repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
      } catch(Exception e) {
        LOGGER.warn("Failed to read editor JSON", e);
      }
    }
  }
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

  protected void createModelData(String name, String description, String jsonFile) {
    List<Model> modelList = repositoryService.createModelQuery().modelName("Demo model").list();
   
    if (modelList == null || modelList.isEmpty()) {
   
      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.warn("Failed to read SVG", e);
      }
     
      try {
        InputStream editorJsonStream = this.getClass().getClassLoader().getResourceAsStream(jsonFile);
        repositoryService.addModelEditorSource(model.getId(), IOUtils.toByteArray(editorJsonStream));
      } catch(Exception e) {
        LOGGER.warn("Failed to read editor JSON", e);
      }
    }
  }
View Full Code Here

public class ModelResourceTest extends BaseSpringRestTestCase {

  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testGetModel() throws Exception {
   
    Model model = null;
    try {
      Calendar now = Calendar.getInstance();
      now.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(now.getTime());
     
      model = repositoryService.newModel();
      model.setCategory("Model category");
      model.setKey("Model key");
      model.setMetaInfo("Model metainfo");
      model.setName("Model name");
      model.setVersion(2);
      model.setDeploymentId(deploymentId);
      model.setTenantId("myTenant");
      repositoryService.saveModel(model);
     
      repositoryService.addModelEditorSource(model.getId(), "This is the editor source".getBytes());
      repositoryService.addModelEditorSourceExtra(model.getId(), "This is the extra editor source".getBytes());
     
      HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
      CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
     
      JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
      closeResponse(response);
      assertNotNull(responseNode);
      assertEquals("Model name", responseNode.get("name").textValue());
      assertEquals("Model key", responseNode.get("key").textValue());
      assertEquals("Model category", responseNode.get("category").textValue());
      assertEquals(2, responseNode.get("version").intValue());
      assertEquals("Model metainfo", responseNode.get("metaInfo").textValue());
      assertEquals(deploymentId, responseNode.get("deploymentId").textValue());
      assertEquals(model.getId(), responseNode.get("id").textValue());
      assertEquals("myTenant", responseNode.get("tenantId").textValue());
     
      assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
      assertEquals(now.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
     
      assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));
      assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
     
      assertTrue(responseNode.get("sourceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId())));
      assertTrue(responseNode.get("sourceExtraUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId())));
     
    } finally
    {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

        RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, "unexisting"));
    closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
  }
 
  public void testDeleteModel() throws Exception {
    Model model = null;
    try {
      Calendar now = Calendar.getInstance();
      now.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(now.getTime());
     
      model = repositoryService.newModel();
      model.setCategory("Model category");
      model.setKey("Model key");
      model.setMetaInfo("Model metainfo");
      model.setName("Model name");
      model.setVersion(2);
      repositoryService.saveModel(model);
     
      HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId()));
      closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
     
      // Check if the model is really gone
      assertNull(repositoryService.createModelQuery().modelId(model.getId()).singleResult());
     
      model = null;
    } finally
    {
      if(model != null) {
        try {
          repositoryService.deleteModel(model.getId());
        } catch(Throwable ignore) {
          // Ignore, model might not be created
        }
      }
    }
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.