use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method create.
@Override
public ProcessInfo create(ProcessInfo process) {
if (process == null) {
throw new InvalidArgumentException("post body expected when starting a new process instance");
}
boolean definitionExistingChecked = false;
RuntimeService runtimeService = activitiProcessEngine.getRuntimeService();
String processDefinitionId = null;
if (process.getProcessDefinitionId() != null) {
processDefinitionId = process.getProcessDefinitionId();
} else if (process.getProcessDefinitionKey() != null) {
ProcessDefinition definition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(getProcessDefinitionKey(process.getProcessDefinitionKey())).latestVersion().singleResult();
if (definition == null) {
throw new InvalidArgumentException("No workflow definition could be found with key '" + process.getProcessDefinitionKey() + "'.");
}
processDefinitionId = definition.getId();
definitionExistingChecked = true;
} else {
throw new InvalidArgumentException("Either processDefinitionId or processDefinitionKey is required");
}
if (definitionExistingChecked == false) {
// Check if the required definition actually exists
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(processDefinitionId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
if (query.count() == 0) {
throw new InvalidArgumentException("No workflow definition could be found with id '" + processDefinitionId + "'.");
}
}
Map<QName, Serializable> startParams = new HashMap<QName, Serializable>();
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
if (startFormData != null) {
if (CollectionUtils.isEmpty(process.getVariables()) == false) {
TypeDefinition startTaskType = getWorkflowFactory().getTaskFullTypeDefinition(startFormData.getFormKey(), true);
// Lookup type definition for the startTask
Map<QName, PropertyDefinition> taskProperties = startTaskType.getProperties();
Map<String, QName> propNameMap = new HashMap<String, QName>();
for (QName key : taskProperties.keySet()) {
propNameMap.put(key.getPrefixString().replace(':', '_'), key);
}
Map<QName, AssociationDefinition> taskAssociations = startTaskType.getAssociations();
for (QName key : taskAssociations.keySet()) {
propNameMap.put(key.getPrefixString().replace(':', '_'), key);
}
for (String variableName : process.getVariables().keySet()) {
if (propNameMap.containsKey(variableName)) {
Object variableValue = process.getVariables().get(variableName);
if (taskAssociations.containsKey(propNameMap.get(variableName))) {
AssociationDefinition associationDef = taskAssociations.get(propNameMap.get(variableName));
variableValue = convertAssociationDefinitionValue(associationDef, variableName, variableValue);
} else if (taskProperties.containsKey(propNameMap.get(variableName))) {
PropertyDefinition propDef = taskProperties.get(propNameMap.get(variableName));
DataTypeDefinition propDataType = propDef.getDataType();
if ("java.util.Date".equalsIgnoreCase(propDataType.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
variableValue = ISO8601DateFormat.parse((String) variableValue);
}
}
if (variableValue instanceof Serializable) {
startParams.put(propNameMap.get(variableName), (Serializable) variableValue);
}
}
}
}
}
String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser();
Authentication.setAuthenticatedUserId(currentUserName);
NodeRef workflowPackageNodeRef = null;
try {
workflowPackageNodeRef = workflowPackageComponent.createPackage(null);
startParams.put(WorkflowModel.ASSOC_PACKAGE, workflowPackageNodeRef);
} catch (Exception e) {
throw new ApiException("couldn't create workflow package: " + e.getMessage(), e);
}
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(process.getItems())) {
try {
for (String item : process.getItems()) {
NodeRef itemNodeRef = getNodeRef(item);
QName workflowPackageItemId = QName.createQName("wpi", itemNodeRef.toString());
nodeService.addChild(workflowPackageNodeRef, itemNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, workflowPackageItemId);
}
} catch (Exception e) {
throw new ApiException("Error while adding items to package: " + e.getMessage(), e);
}
}
// Set start task properties. This should be done before instance is started, since it's id will be used
Map<String, Object> variables = getPropertyConverter().getStartVariables(processDefinitionId, startParams);
variables.put(WorkflowConstants.PROP_CANCELLED, Boolean.FALSE);
// Add company home
Object companyHome = getNodeConverter().convertNode(repositoryHelper.getCompanyHome());
variables.put(WorkflowConstants.PROP_COMPANY_HOME, companyHome);
// Add the initiator
NodeRef initiator = getPersonNodeRef(currentUserName);
if (initiator != null) {
variables.put(WorkflowConstants.PROP_INITIATOR, nodeConverter.convertNode(initiator));
// Also add the initiator home reference, if one exists
NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
if (initiatorHome != null) {
variables.put(WorkflowConstants.PROP_INITIATOR_HOME, nodeConverter.convertNode(initiatorHome));
}
}
if (tenantService.isEnabled()) {
// Specify which tenant domain the workflow was started in.
variables.put(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
// Start the process-instance
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, process.getBusinessKey(), variables);
if (processInstance.isEnded() == false) {
runtimeService.setVariable(processInstance.getProcessInstanceId(), ActivitiConstants.PROP_START_TASK_END_DATE, new Date());
}
HistoricProcessInstance historicProcessInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
return createProcessInfo(historicProcessInstance);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class TasksImpl method convertToTypedVariable.
protected TaskVariable convertToTypedVariable(TaskVariable taskVariable, org.activiti.engine.task.Task taskInstance) {
if (taskVariable.getName() == null) {
throw new InvalidArgumentException("Variable name is required.");
}
if (taskVariable.getVariableScope() == null || (taskVariable.getVariableScope() != VariableScope.GLOBAL && taskVariable.getVariableScope() != VariableScope.LOCAL)) {
throw new InvalidArgumentException("Variable scope is required and can only be 'local' or 'global'.");
}
DataTypeDefinition dataTypeDefinition = null;
TypeDefinitionContext context = null;
if (taskVariable.getVariableScope() == VariableScope.GLOBAL) {
// Get start-task definition for explicit typing of variables submitted at the start
String formKey = null;
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(taskInstance.getProcessDefinitionId());
if (startFormData != null) {
formKey = startFormData.getFormKey();
}
TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
context = new TypeDefinitionContext(startTaskTypeDefinition, getQNameConverter());
if (context.getPropertyDefinition(taskVariable.getName()) != null) {
dataTypeDefinition = context.getPropertyDefinition(taskVariable.getName()).getDataType();
if (taskVariable.getType() != null && dataTypeDefinition.getName().toPrefixString(namespaceService).equals(taskVariable.getType()) == false) {
throw new InvalidArgumentException("type of variable " + taskVariable.getName() + " should be " + dataTypeDefinition.getName().toPrefixString(namespaceService));
}
} else if (context.getAssociationDefinition(taskVariable.getName()) != null) {
dataTypeDefinition = dictionaryService.getDataType(DataTypeDefinition.NODE_REF);
}
} else {
// Revert to either the content-model type or the raw type provided by the request
try {
String formKey = activitiProcessEngine.getFormService().getTaskFormKey(taskInstance.getProcessDefinitionId(), taskInstance.getTaskDefinitionKey());
TypeDefinition typeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, false);
context = new TypeDefinitionContext(typeDefinition, getQNameConverter());
if (context.getPropertyDefinition(taskVariable.getName()) != null) {
dataTypeDefinition = context.getPropertyDefinition(taskVariable.getName()).getDataType();
if (taskVariable.getType() != null && dataTypeDefinition.getName().toPrefixString(namespaceService).equals(taskVariable.getType()) == false) {
throw new InvalidArgumentException("type of variable " + taskVariable.getName() + " should be " + dataTypeDefinition.getName().toPrefixString(namespaceService));
}
} else if (context.getAssociationDefinition(taskVariable.getName()) != null) {
dataTypeDefinition = dictionaryService.getDataType(DataTypeDefinition.NODE_REF);
}
} catch (InvalidQNameException ignore) {
// In case the property is not part of the model, it's possible that the property-name is not a valid.
// This can be ignored safeley as it falls back to the raw type
}
}
if (dataTypeDefinition == null && taskVariable.getType() != null) {
try {
QName dataType = QName.createQName(taskVariable.getType(), namespaceService);
dataTypeDefinition = dictionaryService.getDataType(dataType);
} catch (InvalidQNameException iqne) {
throw new InvalidArgumentException("Unsupported type of variable: '" + taskVariable.getType() + "'.");
}
} else if (dataTypeDefinition == null) {
// Final fallback to raw value when no type has been passed and not present in model
dataTypeDefinition = dictionaryService.getDataType(restVariableHelper.extractTypeFromValue(taskVariable.getValue()));
}
if (dataTypeDefinition == null) {
throw new InvalidArgumentException("Unsupported type of variable: '" + taskVariable.getType() + "'.");
}
Object actualValue = null;
if ("java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse((String) taskVariable.getValue());
} else {
if (context != null && context.getAssociationDefinition(taskVariable.getName()) != null) {
actualValue = convertAssociationDefinitionValue(context.getAssociationDefinition(taskVariable.getName()), taskVariable.getName(), taskVariable.getValue());
} else {
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, taskVariable.getValue());
}
}
taskVariable.setValue(actualValue);
// Set type so it's returned in case it was left empty
taskVariable.setType(dataTypeDefinition.getName().toPrefixString(namespaceService));
return taskVariable;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class TasksImpl method convertAssociationDefinitionValue.
protected Object convertAssociationDefinitionValue(AssociationDefinition associationDef, String variableName, Object variableValue) {
if (variableValue != null && ContentModel.TYPE_PERSON.equals(associationDef.getTargetClass().getName())) {
if (associationDef.isTargetMany()) {
if (variableValue instanceof List<?>) {
List<NodeRef> personList = new ArrayList<NodeRef>();
List<?> values = (List<?>) variableValue;
for (Object value : values) {
NodeRef personRef = getPersonNodeRef(value.toString());
if (personRef == null) {
throw new InvalidArgumentException(value.toString() + " is not a valid person user id");
}
personList.add(personRef);
}
variableValue = personList;
} else {
throw new InvalidArgumentException(variableName + " should have an array value");
}
} else {
NodeRef personRef = getPersonNodeRef(variableValue.toString());
if (personRef == null) {
throw new InvalidArgumentException(variableValue.toString() + " is not a valid person user id");
}
variableValue = personRef;
}
} else if (variableValue != null && ContentModel.TYPE_AUTHORITY_CONTAINER.equals(associationDef.getTargetClass().getName())) {
if (associationDef.isTargetMany()) {
if (variableValue instanceof List<?>) {
List<NodeRef> authorityList = new ArrayList<NodeRef>();
List<?> values = (List<?>) variableValue;
for (Object value : values) {
NodeRef authorityRef = authorityService.getAuthorityNodeRef(value.toString());
if (authorityRef == null) {
throw new InvalidArgumentException(value.toString() + " is not a valid authority id");
}
authorityList.add(authorityRef);
}
variableValue = authorityList;
} else {
throw new InvalidArgumentException(variableName + " should have an array value");
}
} else {
NodeRef authorityRef = authorityService.getAuthorityNodeRef(variableValue.toString());
if (authorityRef == null) {
throw new InvalidArgumentException(variableValue.toString() + " is not a valid authority id");
}
variableValue = authorityRef;
}
}
return variableValue;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class TasksImpl method getTasks.
@Override
public CollectionWithPagingInfo<Task> getTasks(Parameters parameters) {
Paging paging = parameters.getPaging();
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(TASK_COLLECTION_EQUALS_QUERY_PROPERTIES, TASK_COLLECTION_MATCHES_QUERY_PROPERTIES);
propertyWalker.setSupportedGreaterThanParameters(TASK_COLLECTION_GREATERTHAN_QUERY_PROPERTIES);
propertyWalker.setSupportedGreaterThanOrEqualParameters(TASK_COLLECTION_GREATERTHANOREQUAL_QUERY_PROPERTIES);
propertyWalker.setSupportedLessThanParameters(TASK_COLLECTION_LESSTHAN_QUERY_PROPERTIES);
propertyWalker.setSupportedLessThanOrEqualParameters(TASK_COLLECTION_LESSTHANOREQUAL_QUERY_PROPERTIES);
propertyWalker.enableVariablesSupport(namespaceService, dictionaryService);
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
}
String status = propertyWalker.getProperty("status", WhereClauseParser.EQUALS);
String assignee = propertyWalker.getProperty("assignee", WhereClauseParser.EQUALS);
String assigneeLike = propertyWalker.getProperty("assignee", WhereClauseParser.MATCHES);
String owner = propertyWalker.getProperty("owner", WhereClauseParser.EQUALS);
String ownerLike = propertyWalker.getProperty("owner", WhereClauseParser.MATCHES);
String candidateUser = propertyWalker.getProperty("candidateUser", WhereClauseParser.EQUALS);
String candidateGroup = propertyWalker.getProperty("candidateGroup", WhereClauseParser.EQUALS);
String name = propertyWalker.getProperty("name", WhereClauseParser.EQUALS);
String nameLike = propertyWalker.getProperty("name", WhereClauseParser.MATCHES);
String description = propertyWalker.getProperty("description", WhereClauseParser.EQUALS);
String descriptionLike = propertyWalker.getProperty("description", WhereClauseParser.MATCHES);
Integer priority = propertyWalker.getProperty("priority", WhereClauseParser.EQUALS, Integer.class);
Integer priorityGreaterThanOrEquals = propertyWalker.getProperty("priority", WhereClauseParser.GREATERTHANOREQUALS, Integer.class);
Integer priorityLessThanOrEquals = propertyWalker.getProperty("priority", WhereClauseParser.LESSTHANOREQUALS, Integer.class);
String processInstanceId = propertyWalker.getProperty("processId", WhereClauseParser.EQUALS);
String processInstanceBusinessKey = propertyWalker.getProperty("processBusinessKey", WhereClauseParser.EQUALS);
String processInstanceBusinessKeyLike = propertyWalker.getProperty("processBusinessKey", WhereClauseParser.MATCHES);
String activityDefinitionId = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.EQUALS);
String activityDefinitionIdLike = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.MATCHES);
String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
String processDefinitionKeyLike = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.MATCHES);
String processDefinitionName = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.EQUALS);
String processDefinitionNameLike = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.MATCHES);
Date startedAt = propertyWalker.getProperty("startedAt", WhereClauseParser.EQUALS, Date.class);
Date startedAtGreaterThan = propertyWalker.getProperty("startedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
Date endedAt = propertyWalker.getProperty("endedAt", WhereClauseParser.EQUALS, Date.class);
Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
Date dueAt = propertyWalker.getProperty("dueAt", WhereClauseParser.EQUALS, Date.class);
Date dueAtGreaterThan = propertyWalker.getProperty("dueAt", WhereClauseParser.GREATERTHAN, Date.class);
Date dueAtLessThan = propertyWalker.getProperty("dueAt", WhereClauseParser.LESSTHAN, Date.class);
Boolean includeProcessVariables = propertyWalker.getProperty("includeProcessVariables", WhereClauseParser.EQUALS, Boolean.class);
Boolean includeTaskVariables = propertyWalker.getProperty("includeTaskVariables", WhereClauseParser.EQUALS, Boolean.class);
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one order by parameter is supported");
}
sortColumn = sortList.get(0);
}
List<Task> page = null;
int totalCount = 0;
if (status == null || STATUS_ACTIVE.equals(status)) {
TaskQuery query = activitiProcessEngine.getTaskService().createTaskQuery();
if (assignee != null)
query.taskAssignee(assignee);
if (assigneeLike != null)
query.taskAssigneeLike(assigneeLike);
if (owner != null)
query.taskOwner(owner);
if (ownerLike != null)
query.taskOwner(ownerLike);
if (candidateUser != null) {
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, candidateUser, false);
if (parents != null) {
List<String> authorities = new ArrayList<String>();
authorities.addAll(parents);
// there's a limitation in at least Oracle for using an IN statement with more than 1000 items
if (parents.size() > 1000) {
authorities = authorities.subList(0, 1000);
}
if (authorities.size() > 0) {
query.taskCandidateGroupIn(authorities);
} else {
query.taskCandidateUser(candidateUser);
}
}
}
if (candidateGroup != null)
query.taskCandidateGroup(candidateGroup);
if (name != null)
query.taskName(name);
if (nameLike != null)
query.taskNameLike(nameLike);
if (description != null)
query.taskDescription(description);
if (descriptionLike != null)
query.taskDescriptionLike(descriptionLike);
if (priority != null)
query.taskPriority(priority);
if (priorityGreaterThanOrEquals != null)
query.taskMinPriority(priorityGreaterThanOrEquals);
if (priorityLessThanOrEquals != null)
query.taskMaxPriority(priorityLessThanOrEquals);
if (processInstanceId != null)
query.processInstanceId(processInstanceId);
if (processInstanceBusinessKey != null)
query.processInstanceBusinessKey(processInstanceBusinessKey);
if (processInstanceBusinessKeyLike != null)
query.processInstanceBusinessKeyLike(processInstanceBusinessKeyLike);
if (activityDefinitionId != null)
query.taskDefinitionKey(activityDefinitionId);
if (activityDefinitionIdLike != null)
query.taskDefinitionKey(activityDefinitionIdLike);
if (processDefinitionId != null)
query.processDefinitionId(processDefinitionId);
if (processDefinitionKey != null)
query.processDefinitionKey(processDefinitionKey);
if (processDefinitionKeyLike != null)
query.processDefinitionKeyLike(processDefinitionKeyLike);
if (processDefinitionName != null)
query.processDefinitionName(processDefinitionName);
if (processDefinitionNameLike != null)
query.processDefinitionNameLike(processDefinitionNameLike);
if (dueAt != null)
query.dueDate(dueAt);
if (dueAtGreaterThan != null)
query.dueAfter(dueAtGreaterThan);
if (dueAtLessThan != null)
query.dueBefore(dueAtLessThan);
if (startedAt != null)
query.taskCreatedOn(startedAt);
if (startedAtGreaterThan != null)
query.taskCreatedAfter(startedAtGreaterThan);
if (startedAtLessThan != null)
query.taskCreatedBefore(startedAtLessThan);
if (includeProcessVariables != null && includeProcessVariables) {
query.includeProcessVariables();
}
if (includeTaskVariables != null && includeTaskVariables) {
query.includeTaskLocalVariables();
}
// use the limit set in alfresco-global.properties
query.limitTaskVariables(taskVariablesLimit);
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
setQueryUsingVariables(query, variableProperties);
// Add tenant-filtering
if (tenantService.isEnabled()) {
query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
// Add involvement filtering if user is not admin
if (processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser()) && candidateUser == null && candidateGroup == null) {
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
}
setSorting(query, sortColumn);
List<org.activiti.engine.task.Task> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
totalCount = (int) query.count();
page = new ArrayList<Task>(tasks.size());
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
for (org.activiti.engine.task.Task taskInstance : tasks) {
Task task = new Task(taskInstance);
task.setFormResourceKey(getFormResourceKey(taskInstance));
if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables)) {
addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(), taskInstance.getTaskLocalVariables(), definitionTypeMap);
}
page.add(task);
}
} else if (STATUS_COMPLETED.equals(status) || STATUS_ANY.equals(status)) {
// Candidate user and group is only supported with STATUS_ACTIVE
if (candidateUser != null) {
throw new InvalidArgumentException("Filtering on candidateUser is only allowed in combination with status-parameter 'active'");
}
if (candidateGroup != null) {
throw new InvalidArgumentException("Filtering on candidateGroup is only allowed in combination with status-parameter 'active'");
}
HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery();
if (STATUS_COMPLETED.equals(status))
query.finished();
if (assignee != null)
query.taskAssignee(assignee);
if (assigneeLike != null)
query.taskAssigneeLike(assigneeLike);
if (owner != null)
query.taskOwner(owner);
if (ownerLike != null)
query.taskOwnerLike(ownerLike);
if (name != null)
query.taskName(name);
if (nameLike != null)
query.taskNameLike(nameLike);
if (description != null)
query.taskDescription(description);
if (descriptionLike != null)
query.taskDescriptionLike(descriptionLike);
if (priority != null)
query.taskPriority(priority);
if (priorityGreaterThanOrEquals != null)
query.taskMinPriority(priorityGreaterThanOrEquals);
if (priorityLessThanOrEquals != null)
query.taskMaxPriority(priorityLessThanOrEquals);
if (processInstanceId != null)
query.processInstanceId(processInstanceId);
if (processInstanceBusinessKey != null)
query.processInstanceBusinessKey(processInstanceBusinessKey);
if (processInstanceBusinessKeyLike != null)
query.processInstanceBusinessKeyLike(processInstanceBusinessKeyLike);
if (activityDefinitionId != null)
query.taskDefinitionKey(activityDefinitionId);
if (activityDefinitionIdLike != null)
query.taskDefinitionKey(activityDefinitionIdLike);
if (processDefinitionId != null)
query.processDefinitionId(processDefinitionId);
if (processDefinitionKey != null)
query.processDefinitionKey(processDefinitionKey);
if (processDefinitionKeyLike != null)
query.processDefinitionKeyLike(processDefinitionKeyLike);
if (processDefinitionName != null)
query.processDefinitionName(processDefinitionName);
if (processDefinitionNameLike != null)
query.processDefinitionNameLike(processDefinitionNameLike);
if (dueAt != null)
query.taskDueDate(dueAt);
if (dueAtGreaterThan != null)
query.taskDueAfter(dueAtGreaterThan);
if (dueAtLessThan != null)
query.taskDueBefore(dueAtLessThan);
if (startedAt != null)
query.taskCreatedOn(startedAt);
if (startedAtGreaterThan != null)
query.taskCreatedAfter(startedAtGreaterThan);
if (startedAtLessThan != null)
query.taskCreatedBefore(startedAtLessThan);
if (endedAt != null)
query.taskCompletedOn(endedAt);
if (endedAtGreaterThan != null)
query.taskCompletedAfter(endedAtGreaterThan);
if (endedAtLessThan != null)
query.taskCompletedBefore(endedAtLessThan);
if (includeProcessVariables != null && includeProcessVariables) {
query.includeProcessVariables();
}
if (includeTaskVariables != null && includeTaskVariables) {
query.includeTaskLocalVariables();
}
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
setQueryUsingVariables(query, variableProperties);
// Add tenant filtering
if (tenantService.isEnabled()) {
query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
// Add involvement filtering if user is not admin
if (processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
}
setSorting(query, sortColumn);
List<HistoricTaskInstance> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
totalCount = (int) query.count();
page = new ArrayList<Task>(tasks.size());
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
for (HistoricTaskInstance taskInstance : tasks) {
Task task = new Task(taskInstance);
if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables)) {
addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(), taskInstance.getTaskLocalVariables(), definitionTypeMap);
}
page.add(task);
}
} else {
throw new InvalidArgumentException("Invalid status parameter: " + status);
}
return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class TasksImpl method getTasks.
@Override
public CollectionWithPagingInfo<Task> getTasks(String processId, Parameters parameters) {
Paging paging = parameters.getPaging();
String status = parameters.getParameter("status");
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one order by parameter is supported");
}
sortColumn = sortList.get(0);
}
validateIfUserAllowedToWorkWithProcess(processId);
List<Task> page = null;
int totalCount = 0;
if (status == null || STATUS_ACTIVE.equals(status)) {
TaskQuery query = activitiProcessEngine.getTaskService().createTaskQuery();
query.processInstanceId(processId);
setSorting(query, sortColumn);
List<org.activiti.engine.task.Task> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
totalCount = (int) query.count();
page = new ArrayList<Task>(tasks.size());
for (org.activiti.engine.task.Task taskInstance : tasks) {
Task task = new Task(taskInstance);
task.setFormResourceKey(getFormResourceKey(taskInstance));
page.add(task);
}
} else if (STATUS_COMPLETED.equals(status) || STATUS_ANY.equals(status)) {
HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery();
if (STATUS_COMPLETED.equals(status))
query.finished();
query.processInstanceId(processId);
// Add tenant filtering
if (tenantService.isEnabled()) {
query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
setSorting(query, sortColumn);
List<HistoricTaskInstance> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
totalCount = (int) query.count();
page = new ArrayList<Task>(tasks.size());
for (HistoricTaskInstance taskInstance : tasks) {
Task task = new Task(taskInstance);
page.add(task);
}
} else {
throw new InvalidArgumentException("Invalid status parameter: " + status);
}
return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
Aggregations