use of org.alfresco.rest.framework.resource.parameters.SortColumn in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractor method getRecognizedParams.
/**
* Finds the formal set of params that any rest service could potentially have passed in as request params
*
* @param req WebScriptRequest
* @return RecognizedParams a POJO containing the params for use with the Params objects
*/
default Params.RecognizedParams getRecognizedParams(WebScriptRequest req) {
Paging paging = findPaging(req);
List<SortColumn> sorting = getSort(req.getParameter(PARAM_ORDERBY));
Map<String, BeanPropertiesFilter> relationFilter = getRelationFilter(req.getParameter(PARAM_RELATIONS));
Query whereQuery = getWhereClause(req.getParameter(PARAM_WHERE));
Map<String, String[]> requestParams = getRequestParameters(req);
boolean includeSource = Boolean.valueOf(req.getParameter(PARAM_INCLUDE_SOURCE_ENTITY));
List<String> includedFields = getIncludeClause(req.getParameter(PARAM_INCLUDE));
List<String> selectFields = getSelectClause(req.getParameter(PARAM_SELECT));
String fields = req.getParameter(PARAM_FILTER_FIELDS);
String properties = req.getParameter(PARAM_FILTER_PROPERTIES);
if ((fields != null) && (properties != null)) {
if (rpeLogger().isWarnEnabled()) {
rpeLogger().warn("Taking 'fields' param [" + fields + "] and ignoring deprecated 'properties' param [" + properties + "]");
}
}
BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), includedFields);
return new Params.RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting, includeSource);
}
use of org.alfresco.rest.framework.resource.parameters.SortColumn 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.resource.parameters.SortColumn 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