use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ExecutionBaseResource method addVariables.
protected void addVariables(ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
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) {
if (process) {
processInstanceQuery.processVariableValueEquals(actualValue);
} else {
processInstanceQuery.variableValueEquals(actualValue);
}
} else {
if (process) {
processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
} else {
processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
}
}
break;
case EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
if (process) {
processInstanceQuery.processVariableValueEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
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:
if (process) {
processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
} else {
processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
}
break;
case NOT_EQUALS_IGNORE_CASE:
if (actualValue instanceof String) {
if (process) {
processInstanceQuery.processVariableValueNotEqualsIgnoreCase(variable.getName(), (String) actualValue);
} else {
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;
default:
throw new ActivitiIllegalArgumentException("Unsupported variable query operation: " + variable.getVariableOperation());
}
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ProcessInstanceCollectionResource method createProcessInstance.
@RequestMapping(value = "/runtime/process-instances", method = RequestMethod.POST, produces = "application/json")
public ProcessInstanceResponse createProcessInstance(@RequestBody ProcessInstanceCreateRequest request, HttpServletRequest httpRequest, HttpServletResponse response) {
if (request.getProcessDefinitionId() == null && request.getProcessDefinitionKey() == null && request.getMessage() == null) {
throw new ActivitiIllegalArgumentException("Either processDefinitionId, processDefinitionKey or message is required.");
}
int paramsSet = ((request.getProcessDefinitionId() != null) ? 1 : 0) + ((request.getProcessDefinitionKey() != null) ? 1 : 0) + ((request.getMessage() != null) ? 1 : 0);
if (paramsSet > 1) {
throw new ActivitiIllegalArgumentException("Only one of processDefinitionId, processDefinitionKey or message should be set.");
}
if (request.isCustomTenantSet()) {
// Tenant-id can only be used with either key or message
if (request.getProcessDefinitionId() != null) {
throw new ActivitiIllegalArgumentException("TenantId can only be used with either processDefinitionKey or message.");
}
}
Map<String, Object> startVariables = null;
if (request.getVariables() != null) {
startVariables = new HashMap<String, Object>();
for (RestVariable variable : request.getVariables()) {
if (variable.getName() == null) {
throw new ActivitiIllegalArgumentException("Variable name is required.");
}
startVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
}
}
// Actually start the instance based on key or id
try {
ProcessInstance instance = null;
if (request.getProcessDefinitionId() != null) {
instance = runtimeService.startProcessInstanceById(request.getProcessDefinitionId(), request.getBusinessKey(), startVariables);
} else if (request.getProcessDefinitionKey() != null) {
if (request.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByKeyAndTenantId(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables, request.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByKey(request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables);
}
} else {
if (request.isCustomTenantSet()) {
instance = runtimeService.startProcessInstanceByMessageAndTenantId(request.getMessage(), request.getBusinessKey(), startVariables, request.getTenantId());
} else {
instance = runtimeService.startProcessInstanceByMessage(request.getMessage(), request.getBusinessKey(), startVariables);
}
}
response.setStatus(HttpStatus.CREATED.value());
//Added by Ryan Johnston
if (request.getReturnVariables()) {
Map<String, Object> runtimeVariableMap = null;
List<HistoricVariableInstance> historicVariableList = null;
if (instance.isEnded()) {
historicVariableList = historyService.createHistoricVariableInstanceQuery().processInstanceId(instance.getId()).list();
} else {
runtimeVariableMap = runtimeService.getVariables(instance.getId());
}
return restResponseFactory.createProcessInstanceResponse(instance, true, runtimeVariableMap, historicVariableList);
} else {
return restResponseFactory.createProcessInstanceResponse(instance);
}
//End Added by Ryan Johnston
//Removed by Ryan Johnston (obsolete given the above).
//return factory.createProcessInstanceResponse(this, instance);
} catch (ActivitiObjectNotFoundException aonfe) {
throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ProcessInstanceIdentityLinkCollectionResource method createIdentityLink.
@RequestMapping(value = "/runtime/process-instances/{processInstanceId}/identitylinks", method = RequestMethod.POST, produces = "application/json")
public RestIdentityLink createIdentityLink(@PathVariable String processInstanceId, @RequestBody RestIdentityLink identityLink, HttpServletRequest request, HttpServletResponse response) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
if (identityLink.getGroup() != null) {
throw new ActivitiIllegalArgumentException("Only user identity links are supported on a process instance.");
}
if (identityLink.getUser() == null) {
throw new ActivitiIllegalArgumentException("The user is required.");
}
if (identityLink.getType() == null) {
throw new ActivitiIllegalArgumentException("The identity link type is required.");
}
runtimeService.addUserIdentityLink(processInstance.getId(), identityLink.getUser(), identityLink.getType());
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, processInstance.getId());
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createAttachment.
@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.POST, produces = "application/json")
public AttachmentResponse createAttachment(@PathVariable String taskId, HttpServletRequest request, HttpServletResponse response) {
AttachmentResponse result = null;
Task task = getTaskFromRequest(taskId);
if (request instanceof MultipartHttpServletRequest) {
result = createBinaryAttachment((MultipartHttpServletRequest) request, task, response);
} else {
AttachmentRequest attachmentRequest = null;
try {
attachmentRequest = objectMapper.readValue(request.getInputStream(), AttachmentRequest.class);
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Failed to serialize to a AttachmentRequest instance", e);
}
if (attachmentRequest == null) {
throw new ActivitiIllegalArgumentException("AttachmentRequest properties not found in request");
}
result = createSimpleAttachment(attachmentRequest, task);
}
response.setStatus(HttpStatus.CREATED.value());
return result;
}
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);
}
}
Aggregations