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

The following examples show how to use org.activiti.engine.repository.Model#setMetaInfo() . 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: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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());
}
 
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: ModelUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Model createNewModel(RepositoryService repositoryService, String name, String description)
		throws IOException
{
	ObjectMapper objectMapper = new ObjectMapper();
	Model modelData = repositoryService.newModel();

	ObjectNode modelObjectNode = objectMapper.createObjectNode();
	modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
	modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);

	modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
	modelData.setMetaInfo(modelObjectNode.toString());
	modelData.setName(name);

	repositoryService.saveModel(modelData);
	repositoryService.addModelEditorSource(modelData.getId(), EMPTY_MODEL_XML.getBytes("utf-8"));
	return modelData;
}
 
Example 4
Source File: FlowableModelManagerController.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@PostMapping
@ResponseStatus(value = HttpStatus.CREATED)
@ApiOperation("创建模型")
public ResponseMessage<Model> createModel(@RequestBody ModelCreateRequest model) throws Exception {
    JSONObject stencilset = new JSONObject();
    stencilset.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    JSONObject editorNode = new JSONObject();
    editorNode.put("id", "canvas");
    editorNode.put("resourceId", "canvas");
    editorNode.put("stencilset", stencilset);
    JSONObject modelObjectNode = new JSONObject();
    modelObjectNode.put(MODEL_REVISION, 1);
    modelObjectNode.put(MODEL_DESCRIPTION, model.getDescription());
    modelObjectNode.put(MODEL_KEY, model.getKey());
    modelObjectNode.put(MODEL_NAME, model.getName());

    Model modelData = repositoryService.newModel();
    modelData.setMetaInfo(modelObjectNode.toJSONString());
    modelData.setName(model.getName());
    modelData.setKey(model.getKey());
    repositoryService.saveModel(modelData);
    repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
    return ResponseMessage.ok(modelData).status(201);
}
 
Example 5
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 6
Source File: ModelTest.java    From opscenter with Apache License 2.0 5 votes vote down vote up
@RequestMapping("create")
public void createModel(HttpServletRequest request, HttpServletResponse response){
    try{
        String modelName = "modelName";
        String modelKey = "modelKey";
        String description = "description";

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RepositoryService repositoryService = processEngine.getRepositoryService();

        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode editorNode = objectMapper.createObjectNode();
        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(ModelDataJsonConstants.MODEL_NAME, modelName);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
        modelData.setMetaInfo(modelObjectNode.toString());
        modelData.setName(modelName);
        modelData.setKey(modelKey);

        //保存模型
        repositoryService.saveModel(modelData);
        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
        response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());
    }catch (Exception e){
    }
}
 
Example 7
Source File: DeploymentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 转换流程定义为模型
 * @param processDefinitionId
 * @return
 * @throws UnsupportedEncodingException
 * @throws XMLStreamException
 */
@RequestMapping(value = "/process/convert-to-model/{processDefinitionId}")
public String convertToModel(@PathVariable("processDefinitionId") String processDefinitionId)
        throws UnsupportedEncodingException, XMLStreamException {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).singleResult();
    InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
            processDefinition.getResourceName());
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

    BpmnJsonConverter converter = new BpmnJsonConverter();
    ObjectNode modelNode = converter.convertToJson(bpmnModel);
    Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName());
    modelData.setCategory(processDefinition.getDeploymentId());

    ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
    modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);

    repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));

    return "redirect:/chapter20/model/list";
}
 
Example 8
Source File: ModelController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 创建模型
 */
@RequestMapping(value = "create")
public void create(@RequestParam("name") String name, @RequestParam("key") String key,
                   @RequestParam(value = "description", required = false) String description,
                   HttpServletRequest request, HttpServletResponse response) {
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode editorNode = objectMapper.createObjectNode();
        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);

        ObjectNode modelObjectNode = objectMapper.createObjectNode();
        modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
        description = StringUtils.defaultString(description);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);

        Model newModel = repositoryService.newModel();
        newModel.setMetaInfo(modelObjectNode.toString());
        newModel.setName(name);
        newModel.setKey(StringUtils.defaultString(key));

        repositoryService.saveModel(newModel);
        repositoryService.addModelEditorSource(newModel.getId(), editorNode.toString().getBytes("utf-8"));

        response.sendRedirect(request.getContextPath() + "/mservice/editor?id=" + newModel.getId());
    } catch (Exception e) {
        logger.error("创建模型失败:", e);
    }
}
 
Example 9
Source File: ModelUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void importModel(RepositoryService repositoryService, File modelFile) throws IOException,
		XMLStreamException
{
	InputStreamReader reader = new InputStreamReader(new FileInputStream(modelFile), "utf-8");
	String fileContent = IOUtils.readStringAndClose(reader, (int) modelFile.length());

	BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(new StringStreamSourceEx(fileContent), false,
		false);

	String processName = bpmnModel.getMainProcess().getName();
	if (processName == null || processName.isEmpty())
	{
		processName = bpmnModel.getMainProcess().getId();
	}

	Model modelData = repositoryService.newModel();
	ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
	modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName);
	modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
	modelData.setMetaInfo(modelObjectNode.toString());
	modelData.setName(processName);
	modelData.setKey(modelFile.getName());

	repositoryService.saveModel(modelData);

	repositoryService.addModelEditorSource(modelData.getId(), fileContent.getBytes("utf-8"));
	Logger.getLogger(ModelUtils.class)
			.info(String.format("importing model file: %s", modelFile.getCanonicalPath()));
}
 
Example 10
Source File: FlowableModelManagerController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@PutMapping(value = "/{modelId}")
@ResponseStatus(value = HttpStatus.OK)
@Authorize(action = Permission.ACTION_UPDATE)
public void saveModel(@PathVariable String modelId,
                      @RequestParam Map<String, String> values) throws TranscoderException, IOException {
    Model model = repositoryService.getModel(modelId);
    JSONObject modelJson = JSON.parseObject(model.getMetaInfo());

    modelJson.put(MODEL_NAME, values.get("name"));
    modelJson.put(MODEL_DESCRIPTION, values.get("description"));

    model.setMetaInfo(modelJson.toString());
    model.setName(values.get("name"));

    repositoryService.saveModel(model);

    repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8"));

    InputStream svgStream = new ByteArrayInputStream(values.get("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();
}
 
Example 11
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 12
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 13
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 14
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 15
Source File: ModelSaveRestResource.java    From opscenter with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)
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);
  }
}
 
Example 16
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
    }
  }
}
 
Example 17
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 18
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 19
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
    }
  }
}