SHA-1598: Added support to Get Task Instances API to filter result, based on the given property.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130404 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-09-07 13:06:32 +00:00
parent 59eed12c13
commit f46962577f
3 changed files with 190 additions and 67 deletions

View File

@@ -1,30 +1,31 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.web.scripts.workflow;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -41,6 +42,8 @@ import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery.OrderBy;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ModelUtil;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
@@ -63,6 +66,7 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
public static final String PARAM_DUE_AFTER = "dueAfter";
public static final String PARAM_PROPERTIES = "properties";
public static final String PARAM_POOLED_TASKS = "pooledTasks";
public static final String PARAM_PROPERTY = "property";
public static final String VAR_WORKFLOW_INSTANCE_ID = "workflow_instance_id";
private WorkflowTaskDueAscComparator taskComparator = new WorkflowTaskDueAscComparator();
@@ -96,6 +100,7 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
// get filter param values
filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));
filters.put(PARAM_PROPERTY, req.getParameter(PARAM_PROPERTY));
processDateFilter(req, PARAM_DUE_BEFORE, filters);
processDateFilter(req, PARAM_DUE_AFTER, filters);
@@ -104,7 +109,7 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
{
filters.put(PARAM_EXCLUDE, new ExcludeFilter(excludeParam));
}
List<WorkflowTask> allTasks;
if (workflowInstanceId != null)
@@ -179,20 +184,18 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
ArrayList<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
// Filter results
WorkflowTask task = null;
for(int i=0; i<allTasks.size(); i++)
for (WorkflowTask task : allTasks)
{
task = allTasks.get(i);
if (matches(task, filters))
if (matches(task, filters))
{
// Total-count needs to be based on matching tasks only, so we can't just use allTasks.size() for this
totalCount++;
if(totalCount > skipCount && (maxItems < 0 || maxItems > results.size()))
{
// Only build the actual detail if it's in the range of items we need. This will
// drastically improve performance over paging after building the model
results.add(modelBuilder.buildSimple(task, properties));
}
// Total-count needs to be based on matching tasks only, so we can't just use allTasks.size() for this
totalCount++;
if(totalCount > skipCount && (maxItems < 0 || maxItems > results.size()))
{
// Only build the actual detail if it's in the range of items we need. This will
// drastically improve performance over paging after building the model
results.add(modelBuilder.buildSimple(task, properties));
}
}
}
@@ -341,12 +344,35 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
break;
}
}
else if(key.equals(PARAM_PROPERTY))
{
String[] propertyValuePair = filterValue.toString().split("/");
if (propertyValuePair.length != 2)
{
break;
}
QName propertyQName;
try
{
propertyQName = QName.createQName(propertyValuePair[0], namespaceService);
}
catch (NamespaceException ne)
{
break;
}
Serializable value = task.getProperties().get(propertyQName);
if (value != null && !value.equals(propertyValuePair[1]))
{
result = false;
break;
}
}
}
}
return result;
}
/**
* Comparator to sort workflow tasks by due date in ascending order.
*/