use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createBinaryAttachment.
protected AttachmentResponse createBinaryAttachment(MultipartHttpServletRequest request, Task task, HttpServletResponse response) {
String name = null;
String description = null;
String type = null;
Map<String, String[]> paramMap = request.getParameterMap();
for (String parameterName : paramMap.keySet()) {
if (paramMap.get(parameterName).length > 0) {
if (parameterName.equalsIgnoreCase("name")) {
name = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("description")) {
description = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("type")) {
type = paramMap.get(parameterName)[0];
}
}
}
if (name == null) {
throw new ActivitiIllegalArgumentException("Attachment name is required.");
}
if (request.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
MultipartFile file = request.getFileMap().values().iterator().next();
if (file == null) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
try {
Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name, description, file.getInputStream());
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createAttachmentResponse(createdAttachment);
} catch (Exception e) {
throw new ActivitiException("Error creating attachment response", e);
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskBaseResource method addProcessvariables.
protected void addProcessvariables(TaskQuery taskQuery, List<QueryVariable> variables) {
for (QueryVariable variable : variables) {
if (variable.getVariableOperation() == null) {
throw new ActivitiIllegalArgumentException("Variable operation is missing for variable: " + variable.getName());
}
if (variable.getValue() == null) {
throw new ActivitiIllegalArgumentException("Variable value is missing for variable: " + variable.getName());
}
boolean nameLess = variable.getName() == null;
Object actualValue = restResponseFactory.getVariableValue(variable);
// A value-only query is only possible using equals-operator
if (nameLess && variable.getVariableOperation() != QueryVariableOperation.EQUALS) {
throw new ActivitiIllegalArgumentException("Value-only query (without a variable-name) is only supported when using 'equals' operation.");
}
switch(variable.getVariableOperation()) {
case EQUALS:
if (nameLess) {
taskQuery.processVariableValueEquals(actualValue);
} else {
taskQuery.processVariableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
taskQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case NOT_EQUALS:
taskQuery.processVariableValueNotEquals(variable.getName(), actualValue);
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
taskQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
taskQuery.processVariableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
taskQuery.processVariableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
taskQuery.processVariableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
taskQuery.processVariableValueLessThanOrEqual(variable.getName(), actualValue);
break;
case LIKE:
if (actualValue instanceof String) {
taskQuery.processVariableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported using like, but was: " + actualValue.getClass().getName());
}
break;
case LIKE_IGNORE_CASE:
if (actualValue instanceof String) {
taskQuery.processVariableValueLikeIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported using likeIgnoreCase, but was: " + actualValue.getClass().getName());
}
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class UserTaskActivityBehavior method execute.
public void execute(ActivityExecution execution) throws Exception {
TaskEntity task = TaskEntity.createAndInsert(execution);
task.setExecution(execution);
Expression activeNameExpression = null;
Expression activeDescriptionExpression = null;
Expression activeDueDateExpression = null;
Expression activePriorityExpression = null;
Expression activeCategoryExpression = null;
Expression activeFormKeyExpression = null;
Expression activeSkipExpression = null;
Expression activeAssigneeExpression = null;
Expression activeOwnerExpression = null;
Set<Expression> activeCandidateUserExpressions = null;
Set<Expression> activeCandidateGroupExpressions = null;
if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(userTaskId, execution.getProcessDefinitionId());
activeNameExpression = getActiveValue(taskDefinition.getNameExpression(), DynamicBpmnConstants.USER_TASK_NAME, taskElementProperties);
taskDefinition.setNameExpression(activeNameExpression);
activeDescriptionExpression = getActiveValue(taskDefinition.getDescriptionExpression(), DynamicBpmnConstants.USER_TASK_DESCRIPTION, taskElementProperties);
taskDefinition.setDescriptionExpression(activeDescriptionExpression);
activeDueDateExpression = getActiveValue(taskDefinition.getDueDateExpression(), DynamicBpmnConstants.USER_TASK_DUEDATE, taskElementProperties);
taskDefinition.setDueDateExpression(activeDueDateExpression);
activePriorityExpression = getActiveValue(taskDefinition.getPriorityExpression(), DynamicBpmnConstants.USER_TASK_PRIORITY, taskElementProperties);
taskDefinition.setPriorityExpression(activePriorityExpression);
activeCategoryExpression = getActiveValue(taskDefinition.getCategoryExpression(), DynamicBpmnConstants.USER_TASK_CATEGORY, taskElementProperties);
taskDefinition.setCategoryExpression(activeCategoryExpression);
activeFormKeyExpression = getActiveValue(taskDefinition.getFormKeyExpression(), DynamicBpmnConstants.USER_TASK_FORM_KEY, taskElementProperties);
taskDefinition.setFormKeyExpression(activeFormKeyExpression);
activeSkipExpression = getActiveValue(taskDefinition.getSkipExpression(), DynamicBpmnConstants.TASK_SKIP_EXPRESSION, taskElementProperties);
taskDefinition.setSkipExpression(activeSkipExpression);
activeAssigneeExpression = getActiveValue(taskDefinition.getAssigneeExpression(), DynamicBpmnConstants.USER_TASK_ASSIGNEE, taskElementProperties);
taskDefinition.setAssigneeExpression(activeAssigneeExpression);
activeOwnerExpression = getActiveValue(taskDefinition.getOwnerExpression(), DynamicBpmnConstants.USER_TASK_OWNER, taskElementProperties);
taskDefinition.setOwnerExpression(activeOwnerExpression);
activeCandidateUserExpressions = getActiveValueSet(taskDefinition.getCandidateUserIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_USERS, taskElementProperties);
taskDefinition.setCandidateUserIdExpressions(activeCandidateUserExpressions);
activeCandidateGroupExpressions = getActiveValueSet(taskDefinition.getCandidateGroupIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_GROUPS, taskElementProperties);
taskDefinition.setCandidateGroupIdExpressions(activeCandidateGroupExpressions);
} else {
activeNameExpression = taskDefinition.getNameExpression();
activeDescriptionExpression = taskDefinition.getDescriptionExpression();
activeDueDateExpression = taskDefinition.getDueDateExpression();
activePriorityExpression = taskDefinition.getPriorityExpression();
activeCategoryExpression = taskDefinition.getCategoryExpression();
activeFormKeyExpression = taskDefinition.getFormKeyExpression();
activeSkipExpression = taskDefinition.getSkipExpression();
activeAssigneeExpression = taskDefinition.getAssigneeExpression();
activeOwnerExpression = taskDefinition.getOwnerExpression();
activeCandidateUserExpressions = taskDefinition.getCandidateUserIdExpressions();
activeCandidateGroupExpressions = taskDefinition.getCandidateGroupIdExpressions();
}
task.setTaskDefinition(taskDefinition);
if (activeNameExpression != null) {
String name = null;
try {
name = (String) activeNameExpression.getValue(execution);
} catch (ActivitiException e) {
name = activeNameExpression.getExpressionText();
LOGGER.warn("property not found in task name expression " + e.getMessage());
}
task.setName(name);
}
if (activeDescriptionExpression != null) {
String description = null;
try {
description = (String) activeDescriptionExpression.getValue(execution);
} catch (ActivitiException e) {
description = activeDescriptionExpression.getExpressionText();
LOGGER.warn("property not found in task description expression " + e.getMessage());
}
task.setDescription(description);
}
if (activeDueDateExpression != null) {
Object dueDate = activeDueDateExpression.getValue(execution);
if (dueDate != null) {
if (dueDate instanceof Date) {
task.setDueDate((Date) dueDate);
} else if (dueDate instanceof String) {
BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(taskDefinition.getBusinessCalendarNameExpression().getValue(execution).toString());
task.setDueDate(businessCalendar.resolveDuedate((String) dueDate));
} else {
throw new ActivitiIllegalArgumentException("Due date expression does not resolve to a Date or Date string: " + activeDueDateExpression.getExpressionText());
}
}
}
if (activePriorityExpression != null) {
final Object priority = activePriorityExpression.getValue(execution);
if (priority != null) {
if (priority instanceof String) {
try {
task.setPriority(Integer.valueOf((String) priority));
} catch (NumberFormatException e) {
throw new ActivitiIllegalArgumentException("Priority does not resolve to a number: " + priority, e);
}
} else if (priority instanceof Number) {
task.setPriority(((Number) priority).intValue());
} else {
throw new ActivitiIllegalArgumentException("Priority expression does not resolve to a number: " + activePriorityExpression.getExpressionText());
}
}
}
if (activeCategoryExpression != null) {
final Object category = activeCategoryExpression.getValue(execution);
if (category != null) {
if (category instanceof String) {
task.setCategory((String) category);
} else {
throw new ActivitiIllegalArgumentException("Category expression does not resolve to a string: " + activeCategoryExpression.getExpressionText());
}
}
}
if (activeFormKeyExpression != null) {
final Object formKey = activeFormKeyExpression.getValue(execution);
if (formKey != null) {
if (formKey instanceof String) {
task.setFormKey((String) formKey);
} else {
throw new ActivitiIllegalArgumentException("FormKey expression does not resolve to a string: " + activeFormKeyExpression.getExpressionText());
}
}
}
boolean skipUserTask = SkipExpressionUtil.isSkipExpressionEnabled(execution, activeSkipExpression) && SkipExpressionUtil.shouldSkipFlowElement(execution, activeSkipExpression);
if (!skipUserTask) {
handleAssignments(activeAssigneeExpression, activeOwnerExpression, activeCandidateUserExpressions, activeCandidateGroupExpressions, task, execution);
}
task.fireEvent(TaskListener.EVENTNAME_CREATE);
// All properties set, now firing 'create' events
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_CREATED, task));
}
if (skipUserTask) {
task.complete(null, false);
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project carbon-business-process by wso2.
the class RestResponseFactory method getVariableValue.
public Object getVariableValue(QueryVariable restVariable) {
Object value;
if (restVariable.getType() != null) {
// Try locating a converter if the type has been specified
RestVariableConverter converter = null;
for (RestVariableConverter conv : variableConverters) {
if (conv.getRestTypeName().equals(restVariable.getType())) {
converter = conv;
break;
}
}
if (converter == null) {
throw new ActivitiIllegalArgumentException("Variable '" + restVariable.getName() + "' has unsupported type: '" + restVariable.getType() + "'.");
}
RestVariable temp = new RestVariable();
temp.setValue(restVariable.getValue());
temp.setType(restVariable.getType());
temp.setName(restVariable.getName());
value = converter.getVariableValue(temp);
} else {
// Revert to type determined by REST-to-Java mapping when no explicit type has been provided
value = restVariable.getValue();
}
return value;
}
use of org.activiti.engine.ActivitiIllegalArgumentException 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);
}
}
Aggregations