Search in sources :

Example 61 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class DeploymentService method getDeploymentResourceData.

private byte[] getDeploymentResourceData(String deploymentId, String resourceId) {
    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("No deployment id provided");
    }
    if (resourceId == null) {
        throw new ActivitiIllegalArgumentException("No resource id provided");
    }
    RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
    // 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);
        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) RepositoryService(org.activiti.engine.RepositoryService)

Example 62 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class ProcessInstanceService method getVariableDataByteArray.

protected byte[] getVariableDataByteArray(Execution execution, String variableName, String scope, Response.ResponseBuilder responseBuilder) {
    try {
        byte[] result;
        RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            responseBuilder.type(MediaType.APPLICATION_OCTET_STREAM);
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            responseBuilder.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return result;
    } catch (IOException ioe) {
        throw new ActivitiException("Error getting variable " + variableName, ioe);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 63 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class UserSubstitutionService method updateSubstituteInfo.

/**
 * Update the substitute info of the given user in the request path. Use the same format used in POST method.
 * @param user - user that need to update his substitute info
 * @param request - substitute info that need to be updated
 * @return
 * @throws URISyntaxException
 */
@PUT
@Path("/{user}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateSubstituteInfo(@PathParam("user") String user, SubstitutionRequest request) throws URISyntaxException {
    try {
        if (!subsFeatureEnabled) {
            return Response.status(405).build();
        }
        request.setAssignee(user);
        String assignee = getRequestedAssignee(user);
        String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
        Date endTime = null;
        Date startTime = new Date();
        DateTime requestStartTime = null;
        if (request.getStartTime() != null) {
            requestStartTime = new DateTime(request.getStartTime());
            startTime = new Date(requestStartTime.getMillis());
        }
        if (request.getEndTime() != null) {
            endTime = validateEndTime(request.getEndTime(), requestStartTime);
        }
        if (!UserSubstitutionUtils.validateTasksList(request.getTaskList(), assignee)) {
            throw new ActivitiIllegalArgumentException("Invalid task list provided, for substitution.");
        }
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserSubstitutionUtils.handleUpdateSubstitute(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
        return Response.ok().build();
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store", e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) DateTime(org.joda.time.DateTime)

Example 64 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class UserSubstitutionService method querySubstitutes.

/**
 * Query the substitution records based on substitute, assignee and enabled or disabled.
 * Pagination parameters, start, size, sort, order are allowed.
 * @return paginated list of substitution info records
 */
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response querySubstitutes() {
    if (!subsFeatureEnabled) {
        return Response.status(405).build();
    }
    Map<String, String> queryMap = new HashedMap();
    for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
        String value = uriInfo.getQueryParameters().getFirst(entry.getKey());
        if (value != null) {
            queryMap.put(entry.getValue(), value);
        }
    }
    // validate the parameters
    try {
        // replace with tenant aware user names
        String tenantAwareUser = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.USER));
        queryMap.put(SubstitutionQueryProperties.USER, tenantAwareUser);
        String tenantAwareSub = getTenantAwareUser(queryMap.get(SubstitutionQueryProperties.SUBSTITUTE));
        queryMap.put(SubstitutionQueryProperties.SUBSTITUTE, tenantAwareSub);
        if (!isUserAuthorizedForSubstitute(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername())) {
            String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
            if (!((queryMap.get(SubstitutionQueryProperties.USER) != null && queryMap.get(SubstitutionQueryProperties.USER).equals(loggedInUser)) || (queryMap.get(SubstitutionQueryProperties.SUBSTITUTE) != null && queryMap.get(SubstitutionQueryProperties.SUBSTITUTE).equals(loggedInUser)))) {
                throw new BPMNForbiddenException("Not allowed to view others substitution details. No sufficient permission");
            }
        }
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store for input validations", e);
    }
    // validate pagination parameters
    validatePaginationParams(queryMap);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<SubstitutesDataModel> dataModelList = UserSubstitutionUtils.querySubstitutions(queryMap, tenantId);
    int totalResultCount = UserSubstitutionUtils.getQueryResultCount(queryMap, tenantId);
    SubstituteInfoCollectionResponse collectionResponse = new SubstituteInfoCollectionResponse();
    collectionResponse.setTotal(totalResultCount);
    List<SubstituteInfoResponse> responseList = new ArrayList<>();
    for (SubstitutesDataModel subsData : dataModelList) {
        SubstituteInfoResponse response = new SubstituteInfoResponse();
        response.setEnabled(subsData.isEnabled());
        response.setEndTime(subsData.getSubstitutionEnd());
        response.setStartTime(subsData.getSubstitutionStart());
        response.setSubstitute(subsData.getSubstitute());
        response.setAssignee(subsData.getUser());
        responseList.add(response);
    }
    collectionResponse.setSubstituteInfoList(responseList);
    collectionResponse.setSize(responseList.size());
    String sortType = getSortType(queryMap.get(SubstitutionQueryProperties.SORT));
    collectionResponse.setSort(sortType);
    collectionResponse.setStart(Integer.parseInt(queryMap.get(SubstitutionQueryProperties.START)));
    collectionResponse.setOrder(queryMap.get(SubstitutionQueryProperties.ORDER));
    return Response.ok(collectionResponse).build();
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) BPMNForbiddenException(org.wso2.carbon.bpmn.rest.common.exception.BPMNForbiddenException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) HashedMap(org.apache.commons.collections.map.HashedMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 65 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class UserSubstitutionService method changeSubstitute.

/**
 * Change the substitute of the {user}. Use following request body format.
 * {"substitute":"user"}
 * @param user
 * @param request
 * @return
 * @throws URISyntaxException
 */
@PUT
@Path("/{user}/substitute")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response changeSubstitute(@PathParam("user") String user, SubstituteRequest request) throws URISyntaxException {
    try {
        if (!subsFeatureEnabled) {
            return Response.status(405).build();
        }
        String assignee = getRequestedAssignee(user);
        String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        UserSubstitutionUtils.handleChangeSubstitute(assignee, substitute, tenantId);
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store", e);
    }
    return Response.ok().build();
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10