Java Code Examples for org.activiti.engine.repository.Model#setVersion()

The following examples show how to use org.activiti.engine.repository.Model#setVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testByLatestVersion() {
  ModelQuery query = repositoryService.createModelQuery().latestVersion().modelKey("someKey");
  Model model = query.singleResult();
  assertNotNull(model);

  // Add a new version of the model
  Model newVersion = repositoryService.newModel();
  newVersion.setName("my model");
  newVersion.setKey("someKey");
  newVersion.setCategory("test");
  newVersion.setVersion(model.getVersion() + 1);
  repositoryService.saveModel(newVersion);

  // Verify query
  model = query.singleResult();
  assertNotNull(model);
  assertTrue(model.getVersion() == 2);

  // Cleanup
  repositoryService.deleteModel(model.getId());
}
 
Example 2
Source File: ModelCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create a model", tags = {"Models"}, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the model was created.")
})
@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);
}
 
Example 3
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testByLatestVersion() {
  ModelQuery query = repositoryService.createModelQuery().latestVersion().modelKey("someKey");
  Model model = query.singleResult();
  assertNotNull(model);
  
  // Add a new version of the model
  Model newVersion = repositoryService.newModel();
  newVersion.setName("my model");
  newVersion.setKey("someKey");
  newVersion.setCategory("test");
  newVersion.setVersion(model.getVersion() + 1);
  repositoryService.saveModel(newVersion);
  
  // Verify query
  model = query.singleResult();
  assertNotNull(model);
  assertTrue(model.getVersion() == 2);
  
  // Cleanup
  repositoryService.deleteModel(model.getId());
}
 
Example 4
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 5
Source File: ModelResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a model", tags = {"Models"},
    notes ="All request values are optional. "
        + "For example, you can only include the name attribute in the request body JSON-object, only updating the name of the model, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the model-value will be updated to null. "
        + "Example: ```JSON \n{\"metaInfo\" : null}``` will clear the metaInfo of the model).")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the model was found and updated."),
    @ApiResponse(code = 404, message = "Indicates the requested model was not found.")
})
@RequestMapping(value = "/repository/models/{modelId}", method = RequestMethod.PUT, produces = "application/json")
public ModelResponse updateModel(@ApiParam(name = "modelId") @PathVariable String modelId, @RequestBody ModelRequest modelRequest, HttpServletRequest request) {
  Model model = getModelFromRequest(modelId);

  if (modelRequest.isCategoryChanged()) {
    model.setCategory(modelRequest.getCategory());
  }
  if (modelRequest.isDeploymentChanged()) {
    model.setDeploymentId(modelRequest.getDeploymentId());
  }
  if (modelRequest.isKeyChanged()) {
    model.setKey(modelRequest.getKey());
  }
  if (modelRequest.isMetaInfoChanged()) {
    model.setMetaInfo(modelRequest.getMetaInfo());
  }
  if (modelRequest.isNameChanged()) {
    model.setName(modelRequest.getName());
  }
  if (modelRequest.isVersionChanged()) {
    model.setVersion(modelRequest.getVersion());
  }
  if (modelRequest.isTenantIdChanged()) {
    model.setTenantId(modelRequest.getTenantId());
  }

  repositoryService.saveModel(model);
  return restResponseFactory.createModelResponse(model);
}
 
Example 6
Source File: ModelResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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
      }
    }
  }
}
 
Example 7
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 8
Source File: ModelResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@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
    }
  }
}
 
Example 9
Source File: ModelResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModel() throws Exception {

  Model model = null;
  try {
    Calendar createTime = Calendar.getInstance();
    createTime.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(createTime.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);

    Calendar updateTime = Calendar.getInstance();
    updateTime.set(Calendar.MILLISECOND, 0);
    updateTime.add(Calendar.HOUR, 1);
    processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());

    // Create update request
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", "Updated name");
    requestNode.put("category", "Updated category");
    requestNode.put("key", "Updated key");
    requestNode.put("metaInfo", "Updated metainfo");
    requestNode.put("deploymentId", deploymentId);
    requestNode.put("version", 3);
    requestNode.put("tenantId", "myTenant");

    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("Updated name", responseNode.get("name").textValue());
    assertEquals("Updated key", responseNode.get("key").textValue());
    assertEquals("Updated category", responseNode.get("category").textValue());
    assertEquals(3, responseNode.get("version").intValue());
    assertEquals("Updated 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(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
    assertEquals(updateTime.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
    }
  }
}
 
Example 10
Source File: ModelResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testUpdateModelOverrideWithNull() throws Exception {
  Model model = null;
  try {
    Calendar createTime = Calendar.getInstance();
    createTime.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(createTime.getTime());

    model = repositoryService.newModel();
    model.setCategory("Model category");
    model.setKey("Model key");
    model.setMetaInfo("Model metainfo");
    model.setName("Model name");
    model.setTenantId("myTenant");
    model.setVersion(2);
    repositoryService.saveModel(model);

    Calendar updateTime = Calendar.getInstance();
    updateTime.set(Calendar.MILLISECOND, 0);
    processEngineConfiguration.getClock().setCurrentTime(updateTime.getTime());

    // Create update request
    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("name", (String) null);
    requestNode.put("category", (String) null);
    requestNode.put("key", (String) null);
    requestNode.put("metaInfo", (String) null);
    requestNode.put("deploymentId", (String) null);
    requestNode.put("version", (String) null);
    requestNode.put("tenantId", (String) null);

    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);
    assertNull(responseNode.get("name").textValue());
    assertNull(responseNode.get("key").textValue());
    assertNull(responseNode.get("category").textValue());
    assertNull(responseNode.get("version").textValue());
    assertNull(responseNode.get("metaInfo").textValue());
    assertNull(responseNode.get("deploymentId").textValue());
    assertNull(responseNode.get("tenantId").textValue());
    assertEquals(model.getId(), responseNode.get("id").textValue());

    assertEquals(createTime.getTime().getTime(), getDateFromISOString(responseNode.get("createTime").textValue()).getTime());
    assertEquals(updateTime.getTime().getTime(), getDateFromISOString(responseNode.get("lastUpdateTime").textValue()).getTime());

    assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL, model.getId())));

    model = repositoryService.getModel(model.getId());
    assertNull(model.getName());
    assertNull(model.getKey());
    assertNull(model.getCategory());
    assertNull(model.getMetaInfo());
    assertNull(model.getDeploymentId());
    assertEquals("", model.getTenantId());

  } finally {
    try {
      repositoryService.deleteModel(model.getId());
    } catch (Throwable ignore) {
      // Ignore, model might not be created
    }
  }
}
 
Example 11
Source File: ModelResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@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
    }
  }
}