use of org.flowable.engine.common.api.FlowableException in project plumdo-work by wengwh.
the class ProcessDefinitionXmlResource method getProcessDefinitionXml.
@RequestMapping(value = "/process-definition/{processDefinitionId}/xml", method = RequestMethod.GET, name = "流程定义XML")
public ResponseEntity<byte[]> getProcessDefinitionXml(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
String deploymentId = processDefinition.getDeploymentId();
String resourceId = processDefinition.getResourceName();
if (deploymentId == null) {
throw new FlowableIllegalArgumentException("No deployment id provided");
}
if (resourceId == null) {
throw new FlowableIllegalArgumentException("No resource id provided");
}
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment == null) {
throw new FlowableObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
}
List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
if (resourceList.contains(resourceId)) {
final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_XML);
try {
return new ResponseEntity<byte[]>(IOUtils.toByteArray(resourceStream), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
throw new FlowableException("Error converting resource stream", e);
}
} else {
throw new FlowableObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
}
}
use of org.flowable.engine.common.api.FlowableException in project plumdo-work by wengwh.
the class ModelEditorResource method saveModel.
@RequestMapping(value = "/models/{modelId}/editor", method = { RequestMethod.POST }, name = "模型设计器保存模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public void saveModel(@PathVariable String modelId, @RequestBody ModelEditorJsonRequest values) {
try {
Model model = getModelFromRequest(modelId);
ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
modelJson.put(MODEL_NAME, values.getName());
modelJson.put(MODEL_DESCRIPTION, values.getDescription());
model.setMetaInfo(modelJson.toString());
model.setName(values.getName());
if (model.getDeploymentId() != null) {
model.setDeploymentId(null);
}
if (values.isAddVersion()) {
model.setVersion(model.getVersion() + 1);
}
repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), values.getJson_xml().getBytes("utf-8"));
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(values.getJson_xml().getBytes("utf-8"));
BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", Collections.<String>emptyList(), Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(), processEngineConfiguration.getAnnotationFontName(), processEngineConfiguration.getClassLoader(), 1.0);
repositoryService.addModelEditorSourceExtra(model.getId(), IOUtils.toByteArray(resource));
} catch (Exception e) {
LOGGER.error("Error saving model", e);
throw new FlowableException("Error saving model", e);
}
}
use of org.flowable.engine.common.api.FlowableException in project plumdo-work by wengwh.
the class ProcessDefinitionGetModelResource method processDefinitionGetModel.
@RequestMapping(value = "/process-definition/{processDefinitionId}/getModel", method = RequestMethod.GET, produces = "application/json", name = "流程定义获取对应模型")
public ModelResponse processDefinitionGetModel(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
try {
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();
if (deployment == null) {
throw new FlowableObjectNotFoundException("Could not find a process deployment with id '" + processDefinition.getDeploymentId() + "'.", Deployment.class);
}
Model modelData = null;
if (deployment.getCategory() != null) {
modelData = repositoryService.getModel(deployment.getCategory());
}
// 如果不存在,创建对应模型
if (modelData == null) {
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);
modelData = repositoryService.newModel();
modelData.setKey(processDefinition.getKey());
modelData.setName(processDefinition.getName());
modelData.setCategory(processDefinition.getCategory());
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"));
repositoryService.addModelEditorSourceExtra(modelData.getId(), IOUtils.toByteArray(managementService.executeCommand(new GetDeploymentProcessDiagramCmd(processDefinitionId))));
repositoryService.setDeploymentCategory(processDefinition.getDeploymentId(), modelData.getId());
}
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
throw new FlowableException("Error process-definition get model", e);
}
}
use of org.flowable.engine.common.api.FlowableException in project plumdo-work by wengwh.
the class ProcessDefinitionToModelResource method processDefinitionToModel.
@RequestMapping(value = "/process-definition/{processDefinitionId}/toModel", method = RequestMethod.PUT, produces = "application/json", name = "流程定义转换模型")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public ModelResponse processDefinitionToModel(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
try {
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.getName());
modelData.setCategory(processDefinition.getCategory());
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"));
repositoryService.addModelEditorSourceExtra(modelData.getId(), IOUtils.toByteArray(repositoryService.getProcessDiagram(processDefinition.getId())));
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
throw new FlowableException("Error converting process-definition to model", e);
}
}
use of org.flowable.engine.common.api.FlowableException in project plumdo-work by wengwh.
the class ModelCopyResource method copyModel.
@RequestMapping(value = "/model/{modelId}/copy", method = RequestMethod.POST, produces = "application/json", name = "模型复制")
@ResponseStatus(value = HttpStatus.OK)
@Transactional(propagation = Propagation.REQUIRED)
public ModelResponse copyModel(@PathVariable String modelId, @RequestBody(required = false) ModelRequest modelRequest) {
Model model = getModelFromRequest(modelId);
try {
Model modelData = repositoryService.newModel();
if (modelRequest != null && modelRequest.isKeyChanged()) {
modelData.setKey(modelRequest.getKey());
} else {
modelData.setKey(model.getKey());
}
if (modelRequest != null && modelRequest.isNameChanged()) {
modelData.setName(modelRequest.getName());
} else {
modelData.setName(model.getName());
}
if (modelRequest != null && modelRequest.isCategoryChanged()) {
modelData.setCategory(modelRequest.getCategory());
} else {
modelData.setCategory(model.getCategory());
}
if (modelRequest != null && modelRequest.isMetaInfoChanged()) {
modelData.setMetaInfo(modelRequest.getMetaInfo());
} else {
modelData.setMetaInfo(model.getMetaInfo());
}
if (modelRequest != null && modelRequest.isVersionChanged()) {
modelData.setVersion(modelRequest.getVersion());
} else {
modelData.setVersion(model.getVersion());
}
if (modelRequest != null && modelRequest.isTenantIdChanged()) {
modelData.setTenantId(modelRequest.getTenantId());
} else {
modelData.setTenantId(model.getTenantId());
}
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), repositoryService.getModelEditorSource(modelId));
repositoryService.addModelEditorSourceExtra(modelData.getId(), repositoryService.getModelEditorSourceExtra(modelId));
return restResponseFactory.createModelResponse(modelData);
} catch (Exception e) {
throw new FlowableException("Error copy model", e);
}
}
Aggregations