Package org.activiti.engine.repository

Examples of org.activiti.engine.repository.Model


      model2 = new ModelEntity();
      model2.setKey("key2");
      model2.setVersion(2);
      repositoryService.saveModel(model2);
     
      Model model = repositoryService.createModelQuery().modelKey("key1").latestVersion().singleResult();
      Assert.assertNotNull(model);
    } finally {
      try {
        if(model1 != null) {
          repositoryService.deleteModel(model1.getId());
View Full Code Here


        .paginateList(allRequestParams, modelQuery, "id", allowedSortProperties);
  }
 
  @RequestMapping(value="/repository/models", method = RequestMethod.POST, produces = "application/json")
  public ModelResponse createModel(@RequestBody ModelRequest modelRequest, HttpServletRequest request, HttpServletResponse response) {
    Model model = repositoryService.newModel();
    model.setCategory(modelRequest.getCategory());
    model.setDeploymentId(modelRequest.getDeploymentId());
    model.setKey(modelRequest.getKey());
    model.setMetaInfo(modelRequest.getMetaInfo());
    model.setName(modelRequest.getName());
    model.setVersion(modelRequest.getVersion());
    model.setTenantId(modelRequest.getTenantId());

    repositoryService.saveModel(model);
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createModelResponse(model, request.getRequestURL().toString().replace("/repository/models", ""));
  }
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

   
    repositoryService.deleteModel(model.getId());
  }
 
  public void testNewModelWithSource() throws Exception {
    Model model = repositoryService.newModel();
    model.setName("Test model");
    byte[] testSource = "modelsource".getBytes("utf-8");
    repositoryService.saveModel(model);
   
    assertNotNull(model.getId());
    repositoryService.addModelEditorSource(model.getId(), testSource);
   
    model = repositoryService.getModel(model.getId());
    assertNotNull(model);
    assertEquals("Test model", model.getName());
   
    byte[] editorSourceBytes = repositoryService.getModelEditorSource(model.getId());
    assertEquals("modelsource", new String(editorSourceBytes, "utf-8"));
   
    repositoryService.deleteModel(model.getId());
  }
View Full Code Here

   
    repositoryService.deleteModel(model.getId());
  }
 
  public void testUpdateModelPersistence() throws Exception {
    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);
   
    model.setName("New name");
    model.setCategory("New category");
    model.setMetaInfo("test");
    model.setVersion(2);
    repositoryService.saveModel(model);
   
    assertNotNull(model.getId());
    repositoryService.addModelEditorSource(model.getId(), "new".getBytes("utf-8"));
    repositoryService.addModelEditorSourceExtra(model.getId(), "new".getBytes("utf-8"));
   
    model = repositoryService.getModel(model.getId());
   
    assertEquals("New name", model.getName());
    assertEquals("New category", model.getCategory());
    assertEquals("test", model.getMetaInfo());
    assertNotNull(model.getCreateTime());
    assertEquals(Integer.valueOf(2), model.getVersion());
    assertEquals("new", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
    assertEquals("new", new String(repositoryService.getModelEditorSourceExtra(model.getId()), "utf-8"));
   
    repositoryService.deleteModel(model.getId());
  }
View Full Code Here

 
  /**
   * Test create, update and delete events of model entities.
   */
  public void testModelEvents() throws Exception {
    Model model = null;
    try {
      model = repositoryService.newModel();
      model.setName("My model");
      model.setKey("key");
      repositoryService.saveModel(model);
     
      // Check create event
      assertEquals(2, listener.getEventsReceived().size());
      assertEquals(ActivitiEventType.ENTITY_CREATED, listener.getEventsReceived().get(0).getType());
      assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
     
      assertEquals(ActivitiEventType.ENTITY_INITIALIZED, listener.getEventsReceived().get(1).getType());
      assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(1)).getEntity()).getId());
      listener.clearEventsReceived();
     
     
      // Update model
      model = repositoryService.getModel(model.getId());
      model.setName("Updated");
      repositoryService.saveModel(model);
      assertEquals(1, listener.getEventsReceived().size());
      assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
      assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
      listener.clearEventsReceived();
     
      // Test additional update-methods (source and extra-source)
      repositoryService.addModelEditorSource(model.getId(), "test".getBytes());
      repositoryService.addModelEditorSourceExtra(model.getId(), "test extra".getBytes());
      assertEquals(2, listener.getEventsReceived().size());
      assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(0).getType());
      assertEquals(ActivitiEventType.ENTITY_UPDATED, listener.getEventsReceived().get(1).getType());
      listener.clearEventsReceived();
     
      // Delete model events
      repositoryService.deleteModel(model.getId());
      assertEquals(1, listener.getEventsReceived().size());
      assertEquals(ActivitiEventType.ENTITY_DELETED, listener.getEventsReceived().get(0).getType());
      assertEquals(model.getId(), ((Model) ((ActivitiEntityEvent) listener.getEventsReceived().get(0)).getEntity()).getId());
      listener.clearEventsReceived();
     
    } finally {
      if(model != null && repositoryService.getModel(model.getId()) != null) {
        repositoryService.deleteModel(model.getId());
      }
    }
  }
View Full Code Here

    closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
  }
 
  public void testSetModelEditorSource() throws Exception {
   
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
      httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream",
          new ByteArrayInputStream("This is the new editor source".getBytes()), null));
      closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
     
      assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId())));
 
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

    }
  }
 
  public void testSetModelEditorSourceExtra() throws Exception {
   
    Model model = null;
    try {
     
      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);
     
      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
      httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream",
          new ByteArrayInputStream("This is the new extra editor source".getBytes()), null));
      closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));
     
      assertEquals("This is the new extra editor source", new String(repositoryService.getModelEditorSourceExtra(model.getId())));
     
    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch(Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
View Full Code Here

public class ModelCollectionResourceTest extends BaseSpringRestTestCase {

  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testGetModels() throws Exception {
    // Create 2 models
    Model model1 = null;
    Model model2 = null;
   
    try {
      model1 = repositoryService.newModel();
      model1.setCategory("Model category");
      model1.setKey("Model key");
      model1.setMetaInfo("Model metainfo");
      model1.setName("Model name");
      model1.setVersion(2);
      model1.setDeploymentId(deploymentId);
      repositoryService.saveModel(model1);
     
      model2 = repositoryService.newModel();
      model2.setCategory("Another category");
      model2.setKey("Another key");
      model2.setMetaInfo("Another metainfo");
      model2.setName("Another name");
      model2.setVersion(3);
      repositoryService.saveModel(model2);
     
      // Try filter-less, should return all models
      String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION);
      assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());
     
      // Filter based on id
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?id=" + model1.getId();
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on category
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?category=" + encode("Another category");
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter based on category like
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryLike=" + encode("Mode%");
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on category not equals
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?categoryNotEquals=" + encode("Another category");
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on name
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?name=" + encode("Another name");
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter based on name like
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?nameLike=" + encode("%del name");
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on key
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key");
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on version
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?version=3";
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter based on deploymentId
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deploymentId=" + deploymentId;
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on deployed=true
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=true";
      assertResultsPresentInDataResponse(url, model1.getId());
     
      // Filter based on deployed=false
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?deployed=false";
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter based on latestVersion
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?key=" + encode("Model key") + "&latestVersion=true";
      // Make sure both models have same key
      model2 = repositoryService.createModelQuery().modelId(model2.getId()).singleResult();
      model2.setKey("Model key");
      repositoryService.saveModel(model2);
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter without tenant ID, before tenant update
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
      assertResultsPresentInDataResponse(url, model1.getId(), model2.getId());

      // Set tenant ID
      model1 = repositoryService.getModel(model1.getId());
      model1.setTenantId("myTenant");
      repositoryService.saveModel(model1);
     
      // Filter without tenant ID, after tenant update
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?withoutTenantId=true";
      assertResultsPresentInDataResponse(url, model2.getId());
     
      // Filter based on tenantId
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=myTenant";
      assertResultsPresentInDataResponse(url, model1.getId());
     
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantId=anotherTenant";
      assertResultsPresentInDataResponse(url);
     
      // Filter based on tenantId like
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=" + encode("%enant");
      assertResultsPresentInDataResponse(url, model1.getId());
     
      url = RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION) + "?tenantIdLike=anotherTenant";
      assertResultsPresentInDataResponse(url);
     
     
     
    } finally {
      if(model1 != null) {
        try {
          repositoryService.deleteModel(model1.getId());
        } catch(Throwable ignore) { }
      }
      if(model2 != null) {
        try {
          repositoryService.deleteModel(model2.getId());
        } catch(Throwable ignore) { }
      }
    }
  }
View Full Code Here

    }
  }
 
  @Deployment(resources={"org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"})
  public void testCreateModel() throws Exception {
    Model model = null;
    try {
     
      Calendar createTime = Calendar.getInstance();
      createTime.set(Calendar.MILLISECOND, 0);
      processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());
     
      // Create create request
      ObjectNode requestNode = objectMapper.createObjectNode();
      requestNode.put("name", "Model name");
      requestNode.put("category", "Model category");
      requestNode.put("key", "Model key");
      requestNode.put("metaInfo", "Model metainfo");
      requestNode.put("deploymentId", deploymentId);
      requestNode.put("version", 2);
      requestNode.put("tenantId", "myTenant");
     
      HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX +
          RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_COLLECTION));
      httpPost.setEntity(new StringEntity(requestNode.toString()));
      CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
      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("myTenant", responseNode.get("tenantId").textValue());
     
      assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
      assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());
     
      assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, responseNode.get("id").textValue())));
      assertTrue(responseNode.get("deploymentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
     
      model = repositoryService.createModelQuery().modelId(responseNode.get("id").textValue()).singleResult();
      assertNotNull(model);
      assertEquals("Model category", model.getCategory());
      assertEquals("Model name", model.getName());
      assertEquals("Model key", model.getKey());
      assertEquals(deploymentId, model.getDeploymentId());
      assertEquals("Model metainfo", model.getMetaInfo());
      assertEquals("myTenant", model.getTenantId());
      assertEquals(2, model.getVersion().intValue());
     
    } finally {
      if(model != null) {
        try {
          repositoryService.deleteModel(model.getId());
        } catch(Throwable ignore) { }
      }
    }
  }
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.