Search in sources :

Example 1 with FlowableIllegalArgumentException

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;
}
Also used : FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) QueryProperty(org.flowable.engine.common.api.query.QueryProperty) AbstractQuery(org.flowable.engine.impl.AbstractQuery) List(java.util.List)

Example 2 with FlowableIllegalArgumentException

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);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) FlowableException(org.flowable.engine.common.api.FlowableException) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) DeploymentBuilder(org.flowable.engine.repository.DeploymentBuilder) FlowableForbiddenException(com.plumdo.flow.exception.FlowableForbiddenException) FlowableException(org.flowable.engine.common.api.FlowableException) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with FlowableIllegalArgumentException

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;
}
Also used : FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException)

Example 4 with FlowableIllegalArgumentException

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.");
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FlowableException(org.flowable.engine.common.api.FlowableException) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableException(org.flowable.engine.common.api.FlowableException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with FlowableIllegalArgumentException

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) FlowableException(org.flowable.engine.common.api.FlowableException) InputStream(java.io.InputStream) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) Deployment(org.flowable.engine.repository.Deployment) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowableIllegalArgumentException(org.flowable.engine.common.api.FlowableIllegalArgumentException) FlowableObjectNotFoundException(org.flowable.engine.common.api.FlowableObjectNotFoundException) FlowableException(org.flowable.engine.common.api.FlowableException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FlowableIllegalArgumentException (org.flowable.engine.common.api.FlowableIllegalArgumentException)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)4 InputStream (java.io.InputStream)3 FlowableException (org.flowable.engine.common.api.FlowableException)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 RestVariable (com.plumdo.flow.rest.variable.RestVariable)2 List (java.util.List)2 FlowableObjectNotFoundException (org.flowable.engine.common.api.FlowableObjectNotFoundException)2 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)2 Task (org.flowable.engine.task.Task)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FlowableForbiddenException (com.plumdo.flow.exception.FlowableForbiddenException)1 MultiKey (com.plumdo.flow.rest.task.MultiKey)1 TaskCompleteResponse (com.plumdo.flow.rest.task.TaskCompleteResponse)1 BooleanRestVariableConverter (com.plumdo.flow.rest.variable.BooleanRestVariableConverter)1 DateRestVariableConverter (com.plumdo.flow.rest.variable.DateRestVariableConverter)1