Search in sources :

Example 31 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class UserPictureResource method updateUserPicture.

@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.PUT)
public void updateUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
    }
    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
    try {
        String mimeType = file.getContentType();
        int size = ((Long) file.getSize()).intValue();
        // Copy file-body in a bytearray as the engine requires this
        ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(size);
        IOUtils.copy(file.getInputStream(), bytesOutput);
        Picture newPicture = new Picture(bytesOutput.toByteArray(), mimeType);
        identityService.setUserPicture(user.getId(), newPicture);
        response.setStatus(HttpStatus.NO_CONTENT.value());
    } catch (Exception e) {
        throw new ActivitiException("Error while reading uploaded file: " + e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) User(org.activiti.engine.identity.User) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Picture(org.activiti.engine.identity.Picture) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class TableDataResource method getTableData.

@RequestMapping(value = "/management/tables/{tableName}/data", method = RequestMethod.GET, produces = "application/json")
public DataResponse getTableData(@PathVariable String tableName, @RequestParam Map<String, String> allRequestParams) {
    // Check if table exists before continuing
    if (managementService.getTableMetaData(tableName) == null) {
        throw new ActivitiObjectNotFoundException("Could not find a table with name '" + tableName + "'.", String.class);
    }
    String orderAsc = allRequestParams.get("orderAscendingColumn");
    String orderDesc = allRequestParams.get("orderDescendingColumn");
    if (orderAsc != null && orderDesc != null) {
        throw new ActivitiIllegalArgumentException("Only one of 'orderAscendingColumn' or 'orderDescendingColumn' can be supplied.");
    }
    Integer start = null;
    if (allRequestParams.containsKey("start")) {
        start = Integer.valueOf(allRequestParams.get("start"));
    }
    if (start == null) {
        start = 0;
    }
    Integer size = null;
    if (allRequestParams.containsKey("size")) {
        size = Integer.valueOf(allRequestParams.get("size"));
    }
    if (size == null) {
        size = DEFAULT_RESULT_SIZE;
    }
    DataResponse response = new DataResponse();
    TablePageQuery tablePageQuery = managementService.createTablePageQuery().tableName(tableName);
    if (orderAsc != null) {
        tablePageQuery.orderAsc(orderAsc);
        response.setOrder("asc");
        response.setSort(orderAsc);
    }
    if (orderDesc != null) {
        tablePageQuery.orderDesc(orderDesc);
        response.setOrder("desc");
        response.setSort(orderDesc);
    }
    TablePage listPage = tablePageQuery.listPage(start, size);
    response.setSize(((Long) listPage.getSize()).intValue());
    response.setStart(((Long) listPage.getFirstResult()).intValue());
    response.setTotal(listPage.getTotal());
    response.setData(listPage.getRows());
    return response;
}
Also used : TablePage(org.activiti.engine.management.TablePage) DataResponse(org.activiti.rest.common.api.DataResponse) TablePageQuery(org.activiti.engine.management.TablePageQuery) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class BaseDeploymentResourceDataResource method getDeploymentResourceData.

protected byte[] getDeploymentResourceData(String deploymentId, String resourceId, HttpServletResponse response) {
    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("No deployment id provided");
    }
    if (resourceId == null) {
        throw new ActivitiIllegalArgumentException("No resource id provided");
    }
    // Check if deployment exists
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("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);
        String contentType = contentTypeResolver.resolveContentType(resourceId);
        response.setContentType(contentType);
        try {
            return IOUtils.toByteArray(resourceStream);
        } catch (Exception e) {
            throw new ActivitiException("Error converting resource stream", e);
        }
    } else {
        // Resource not found in deployment
        throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InputStream(java.io.InputStream) Deployment(org.activiti.engine.repository.Deployment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 34 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class DeploymentCollectionResource method uploadDeployment.

@RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json")
public DeploymentResponse uploadDeployment(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("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 ActivitiIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
        }
        deploymentBuilder.name(fileName);
        if (tenantId != null) {
            deploymentBuilder.tenantId(tenantId);
        }
        Deployment deployment = deploymentBuilder.deploy();
        response.setStatus(HttpStatus.CREATED.value());
        return restResponseFactory.createDeploymentResponse(deployment);
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        }
        throw new ActivitiException(e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.repository.Deployment) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with ActivitiIllegalArgumentException

use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.

the class ModelSourceExtraResource method setModelSource.

@RequestMapping(value = "/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
    Model model = getModelFromRequest(modelId);
    if (model != null) {
        try {
            if (request instanceof MultipartHttpServletRequest == false) {
                throw new ActivitiIllegalArgumentException("Multipart request is required");
            }
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            if (multipartRequest.getFileMap().size() == 0) {
                throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
            }
            MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
            repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
            response.setStatus(HttpStatus.NO_CONTENT.value());
        } catch (Exception e) {
            throw new ActivitiException("Error adding model editor source extra", e);
        }
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Model(org.activiti.engine.repository.Model) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)180 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)47 ActivitiException (org.activiti.engine.ActivitiException)43 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)23 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)19 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)12 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)11 VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)10 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)10 Path (javax.ws.rs.Path)9 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)9 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)9 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)9 IOException (java.io.IOException)8 Date (java.util.Date)8 Produces (javax.ws.rs.Produces)8