use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.
the class AbstractPaginateList method paginateList.
@SuppressWarnings("rawtypes")
public DataResponse paginateList(Map<String, String> requestParams, PaginateRequest paginateRequest, Query query, String defaultSort, Map<String, QueryProperty> properties) {
if (paginateRequest == null) {
paginateRequest = new PaginateRequest();
}
// URL if possible
if (paginateRequest.getPageNum() == null) {
paginateRequest.setPageNum(RequestUtil.getInteger(requestParams, "pageNum", 1));
}
if (paginateRequest.getPageSize() == null) {
paginateRequest.setPageSize(RequestUtil.getInteger(requestParams, "pageSize", 10));
}
if (paginateRequest.getSortOrder() == null) {
paginateRequest.setSortOrder(requestParams.get("sortOrder"));
}
if (paginateRequest.getSortName() == null) {
paginateRequest.setSortName(requestParams.get("sortName"));
}
// Use defaults for paging, if not set in the PaginationRequest, nor in
// the URL
Integer pageNum = paginateRequest.getPageNum();
if (pageNum == null || pageNum <= 0) {
pageNum = 1;
}
Integer pageSize = paginateRequest.getPageSize();
if (pageSize == null || (pageSize != -1 && pageSize < 0)) {
pageSize = 10;
}
String sort = paginateRequest.getSortName();
if (sort == null) {
sort = defaultSort;
}
String order = paginateRequest.getSortOrder();
if (order == null) {
order = "asc";
}
// Sort order
if (sort != null && !properties.isEmpty()) {
QueryProperty qp = properties.get(sort);
if (qp == null) {
throw new FlowableIllegalArgumentException("Value for param 'sort' is not valid, '" + sort + "' is not a valid property");
}
((AbstractQuery) query).orderBy(qp);
if (order.equals("asc")) {
query.asc();
} else if (order.equals("desc")) {
query.desc();
} else {
throw new FlowableIllegalArgumentException("Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
}
}
// Get result and set pagination parameters
List list = null;
// size等于-1不做分页
if (pageSize == -1) {
list = processList(query.list());
} else {
list = processList(query.listPage((pageNum - 1) * pageSize, pageSize));
}
DataResponse response = new DataResponse();
response.setData(list);
response.setDataTotal(query.count());
response.setPageSize(pageSize);
response.setPageNum(pageNum);
response.setStartNum((pageNum - 1) * pageSize + 1);
if (response.getDataTotal() > pageNum * pageSize) {
response.setEndNum(pageNum * pageSize);
} else {
response.setEndNum(response.getDataTotal());
}
if (response.getDataTotal() % pageSize == 0) {
response.setPageTotal((int) (response.getDataTotal() / pageSize));
} else {
response.setPageTotal((int) (response.getDataTotal() / pageSize) + 1);
}
return response;
}
use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.
the class ProcessDefinitionResource method createProcessDefinition.
@RequestMapping(value = "/process-definition", method = RequestMethod.POST, produces = "application/json", name = "流程定义创建")
@ResponseStatus(value = HttpStatus.CREATED)
public ProcessDefinitionResponse createProcessDefinition(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request) {
if (request instanceof MultipartHttpServletRequest == false) {
throw new FlowableIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new FlowableIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
try {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
String fileName = file.getOriginalFilename();
if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
fileName = file.getName();
}
if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
deploymentBuilder.addInputStream(fileName, file.getInputStream());
} else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
} else {
throw new FlowableIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
}
deploymentBuilder.name(fileName);
if (tenantId != null) {
deploymentBuilder.tenantId(tenantId);
}
String deploymentId = deploymentBuilder.deploy().getId();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
return restResponseFactory.createProcessDefinitionResponse(processDefinition);
} catch (Exception e) {
if (e instanceof FlowableException) {
throw (FlowableException) e;
}
throw new FlowableException(e.getMessage(), e);
}
}
use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.
the class ListRestVariableConverter method getVariableValue.
@SuppressWarnings({ "rawtypes" })
@Override
public Object getVariableValue(RestVariable result) {
if (result.getValue() != null) {
ObjectMapper mapper = new ObjectMapper();
List list = null;
try {
list = mapper.readValue(String.valueOf(result.getValue()), List.class);
} catch (Exception e) {
throw new FlowableIllegalArgumentException("Converter to list error", e);
}
return list;
}
return null;
}
use of org.flowable.engine.common.api.FlowableIllegalArgumentException in project plumdo-work by wengwh.
the class ProcessDefinitionImageResource method getProcessDefinitionImage.
@RequestMapping(value = "/process-definition/{processDefinitionId}/image", method = RequestMethod.GET, name = "流程定义流程图")
public ResponseEntity<byte[]> getProcessDefinitionImage(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
InputStream imageStream = repositoryService.getProcessDiagram(processDefinition.getId());
if (imageStream != null) {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.IMAGE_PNG);
try {
return new ResponseEntity<byte[]>(IOUtils.toByteArray(imageStream), responseHeaders, HttpStatus.OK);
} catch (Exception e) {
throw new FlowableException("Error reading image stream", e);
}
} else {
throw new FlowableIllegalArgumentException("Process definition with id '" + processDefinition.getId() + "' has no image.");
}
}
use of org.flowable.engine.common.api.FlowableIllegalArgumentException 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);
}
}
Aggregations