Java Code Examples for org.activiti.engine.repository.Model#setDeploymentId()
The following examples show how to use
org.activiti.engine.repository.Model#setDeploymentId() .
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 |
public void testByDeploymentId() { Deployment deployment = repositoryService.createDeployment().addString("test", "test").deploy(); assertEquals(0, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(0, repositoryService.createModelQuery().deployed().count()); assertEquals(1, repositoryService.createModelQuery().notDeployed().count()); Model model = repositoryService.createModelQuery().singleResult(); model.setDeploymentId(deployment.getId()); repositoryService.saveModel(model); assertEquals(1, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(1, repositoryService.createModelQuery().deployed().count()); assertEquals(0, repositoryService.createModelQuery().notDeployed().count()); // Cleanup repositoryService.deleteDeployment(deployment.getId(), true); // After cleanup the model should still exist assertEquals(0, repositoryService.createDeploymentQuery().count()); assertEquals(0, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(1, repositoryService.createModelQuery().notDeployed().count()); assertEquals(1, repositoryService.createModelQuery().count()); }
Example 2
Source File: ModelCollectionResource.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@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 |
public void testByDeploymentId() { Deployment deployment = repositoryService.createDeployment().addString("test", "test") .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); assertEquals(0, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(0, repositoryService.createModelQuery().deployed().count()); assertEquals(1, repositoryService.createModelQuery().notDeployed().count()); Model model = repositoryService.createModelQuery().singleResult(); model.setDeploymentId(deployment.getId()); repositoryService.saveModel(model); assertEquals(1, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(1, repositoryService.createModelQuery().deployed().count()); assertEquals(0, repositoryService.createModelQuery().notDeployed().count()); // Cleanup repositoryService.deleteDeployment(deployment.getId(), true); // After cleanup the model should still exist assertEquals(0, repositoryService.createDeploymentQuery().count()); assertEquals(0, repositoryService.createModelQuery().deploymentId(deployment.getId()).count()); assertEquals(1, repositoryService.createModelQuery().notDeployed().count()); assertEquals(1, repositoryService.createModelQuery().count()); }
Example 4
Source File: ModelUtils.java From openwebflow with BSD 2-Clause "Simplified" License | 6 votes |
public static Deployment deployModel(RepositoryService repositoryService, String modelId) throws IOException { Model modelData = repositoryService.getModel(modelId); //EditorSource就是XML格式的 byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment().name(modelData.getName()) .addString(processName, new String(bpmnBytes, "utf-8")).deploy(); //设置部署ID modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); return deployment; }
Example 5
Source File: ModelResource.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@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: ModelerController.java From lemon with Apache License 2.0 | 5 votes |
@RequestMapping("xml2json") public String xml2json( @RequestParam("processDefinitionId") String processDefinitionId) throws Exception { RepositoryService repositoryService = processEngine .getRepositoryService(); ProcessDefinition processDefinition = repositoryService .getProcessDefinition(processDefinitionId); Model model = repositoryService.newModel(); model.setName(processDefinition.getName()); model.setDeploymentId(processDefinition.getDeploymentId()); repositoryService.saveModel(model); BpmnModel bpmnModel = repositoryService .getBpmnModel(processDefinitionId); ObjectNode objectNode = new BpmnJsonConverter() .convertToJson(bpmnModel); String json = objectNode.toString(); repositoryService.addModelEditorSource(model.getId(), json.getBytes("utf-8")); return "redirect:/modeler/modeler-list.do"; }
Example 7
Source File: ModelResourceTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@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 8
Source File: ModelResourceTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@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 9
Source File: ModelerController.java From lemon with Apache License 2.0 | 4 votes |
@RequestMapping("modeler-deploy") public String deploy(@RequestParam("id") String id, org.springframework.ui.Model theModel) throws Exception { String tenantId = tenantHolder.getTenantId(); RepositoryService repositoryService = processEngine .getRepositoryService(); Model modelData = repositoryService.getModel(id); byte[] bytes = repositoryService .getModelEditorSource(modelData.getId()); if (bytes == null) { theModel.addAttribute("message", "模型数据为空,请先设计流程并成功保存,再进行发布。"); return "modeler/failure"; } JsonNode modelNode = (JsonNode) new ObjectMapper().readTree(bytes); byte[] bpmnBytes = null; BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); bpmnBytes = new BpmnXMLConverter().convertToXML(model); String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment() .name(modelData.getName()) .addString(processName, new String(bpmnBytes, "UTF-8")) .tenantId(tenantId).deploy(); modelData.setDeploymentId(deployment.getId()); repositoryService.saveModel(modelData); List<ProcessDefinition> processDefinitions = repositoryService .createProcessDefinitionQuery() .deploymentId(deployment.getId()).list(); for (ProcessDefinition processDefinition : processDefinitions) { processEngine.getManagementService().executeCommand( new SyncProcessCmd(processDefinition.getId())); } return "redirect:/modeler/modeler-list.do"; }