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);
}
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations