use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class BaseProcessInstanceResource method addVariables.
protected void addVariables(ProcessInstanceQuery processInstanceQuery, 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) {
processInstanceQuery.variableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueEqualsIgnoreCase(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:
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported when ignoring casing, but was: " + actualValue.getClass().getName());
}
break;
case LIKE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueLike(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported for like, but was: " + actualValue.getClass().getName());
}
break;
case LIKE_IGNORE_CASE:
if (actualValue instanceof String) {
processInstanceQuery.variableValueLikeIgnoreCase(variable.getName(), (String) actualValue);
} else {
throw new ActivitiIllegalArgumentException("Only string variable values are supported for like ignore case, but was: " + actualValue.getClass().getName());
}
break;
case GREATER_THAN:
processInstanceQuery.variableValueGreaterThan(variable.getName(), actualValue);
break;
case GREATER_THAN_OR_EQUALS:
processInstanceQuery.variableValueGreaterThanOrEqual(variable.getName(), actualValue);
break;
case LESS_THAN:
processInstanceQuery.variableValueLessThan(variable.getName(), actualValue);
break;
case LESS_THAN_OR_EQUALS:
processInstanceQuery.variableValueLessThanOrEqual(variable.getName(), actualValue);
break;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskIdentityLinkFamilyResource method getIdentityLinksForFamily.
@RequestMapping(value = "/runtime/tasks/{taskId}/identitylinks/{family}", method = RequestMethod.GET, produces = "application/json")
public List<RestIdentityLink> getIdentityLinksForFamily(@PathVariable("taskId") String taskId, @PathVariable("family") String family, HttpServletRequest request) {
Task task = getTaskFromRequest(taskId);
if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
}
boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();
List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
for (IdentityLink link : allLinks) {
boolean match = false;
if (isUser) {
match = link.getUserId() != null;
} else {
match = link.getGroupId() != null;
}
if (match) {
results.add(restResponseFactory.createRestIdentityLink(link));
}
}
return results;
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskResource method completeTask.
protected void completeTask(Task task, TaskActionRequest actionRequest) {
if (actionRequest.getVariables() != null) {
Map<String, Object> variablesToSet = new HashMap<String, Object>();
for (RestVariable var : actionRequest.getVariables()) {
if (var.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
Object actualVariableValue = restResponseFactory.getVariableValue(var);
variablesToSet.put(var.getName(), actualVariableValue);
}
taskService.complete(task.getId(), variablesToSet);
} else {
taskService.complete(task.getId());
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskVariableBaseResource method setSimpleVariable.
protected RestVariable setSimpleVariable(RestVariable restVariable, Task task, boolean isNew) {
if (restVariable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required");
}
// Figure out scope, revert to local is omitted
RestVariableScope scope = restVariable.getVariableScope();
if (scope == null) {
scope = RestVariableScope.LOCAL;
}
Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);
setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);
return restResponseFactory.createRestVariable(restVariable.getName(), actualVariableValue, scope, task.getId(), RestResponseFactory.VARIABLE_TASK, false);
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskVariableBaseResource method setBinaryVariable.
protected RestVariable setBinaryVariable(MultipartHttpServletRequest request, Task task, boolean isNew) {
// Validate input and set defaults
if (request.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("No file content was found in request body.");
}
// Get first file in the map, ignore possible other files
MultipartFile file = request.getFile(request.getFileMap().keySet().iterator().next());
if (file == null) {
throw new ActivitiIllegalArgumentException("No file content was found in request body.");
}
String variableScope = null;
String variableName = null;
String variableType = null;
Map<String, String[]> paramMap = request.getParameterMap();
for (String parameterName : paramMap.keySet()) {
if (paramMap.get(parameterName).length > 0) {
if (parameterName.equalsIgnoreCase("scope")) {
variableScope = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("name")) {
variableName = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("type")) {
variableType = paramMap.get(parameterName)[0];
}
}
}
try {
if (variableName == null) {
throw new ActivitiIllegalArgumentException("No variable name was found in request body.");
}
if (variableType != null) {
if (!RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variableType) && !RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variableType)) {
throw new ActivitiIllegalArgumentException("Only 'binary' and 'serializable' are supported as variable type.");
}
} else {
variableType = RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE;
}
RestVariableScope scope = RestVariableScope.LOCAL;
if (variableScope != null) {
scope = RestVariable.getScopeFromString(variableScope);
}
if (variableType.equals(RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE)) {
// Use raw bytes as variable value
byte[] variableBytes = IOUtils.toByteArray(file.getInputStream());
setVariable(task, variableName, variableBytes, scope, isNew);
} else if (isSerializableVariableAllowed) {
// Try deserializing the object
ObjectInputStream stream = new ObjectInputStream(file.getInputStream());
Object value = stream.readObject();
setVariable(task, variableName, value, scope, isNew);
stream.close();
} else {
throw new ActivitiContentNotSupportedException("Serialized objects are not allowed");
}
return restResponseFactory.createBinaryRestVariable(variableName, scope, variableType, task.getId(), null, null);
} catch (IOException ioe) {
throw new ActivitiIllegalArgumentException("Error getting binary variable", ioe);
} catch (ClassNotFoundException ioe) {
throw new ActivitiContentNotSupportedException("The provided body contains a serialized object for which the class is nog found: " + ioe.getMessage());
}
}
Aggregations