mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
ACE-4578 Workflow ProcessDefinitions Public Api doesn't use orderBy, fixed and added tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@116443 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -47,6 +47,7 @@ import org.alfresco.rest.framework.resource.content.FileBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.resource.parameters.SortColumn;
|
||||
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||
import org.alfresco.rest.workflow.api.ProcessDefinitions;
|
||||
import org.alfresco.rest.workflow.api.model.FormModelElement;
|
||||
@@ -163,58 +164,47 @@ public class ProcessDefinitionsImpl extends WorkflowRestImpl implements ProcessD
|
||||
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
|
||||
}
|
||||
|
||||
String sortParam = parameters.getParameter("sort");
|
||||
if (sortParam != null)
|
||||
List<SortColumn> sortList = parameters.getSorting();
|
||||
SortColumn sortColumn = null;
|
||||
if (sortList != null && sortList.size() > 0)
|
||||
{
|
||||
if (PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES.contains(sortParam))
|
||||
{
|
||||
if ("id".equalsIgnoreCase(sortParam))
|
||||
if (sortList.size() != 1)
|
||||
{
|
||||
throw new InvalidArgumentException("Only one orderBy parameter is supported");
|
||||
}
|
||||
sortColumn = sortList.get(0);
|
||||
|
||||
switch (sortColumn.column) {
|
||||
case "id":
|
||||
query.orderByProcessDefinitionId();
|
||||
}
|
||||
else if ("deploymentId".equalsIgnoreCase(sortParam))
|
||||
{
|
||||
break;
|
||||
case "deploymentId":
|
||||
query.orderByDeploymentId();
|
||||
}
|
||||
else if ("key".equalsIgnoreCase(sortParam))
|
||||
{
|
||||
break;
|
||||
case "key":
|
||||
query.orderByProcessDefinitionKey();
|
||||
}
|
||||
else if ("category".equalsIgnoreCase(sortParam))
|
||||
{
|
||||
break;
|
||||
case "category":
|
||||
query.orderByProcessDefinitionCategory();
|
||||
}
|
||||
else if ("version".equalsIgnoreCase(sortParam))
|
||||
{
|
||||
break;
|
||||
case "version":
|
||||
query.orderByProcessDefinitionVersion();
|
||||
}
|
||||
else if ("name".equalsIgnoreCase(sortParam))
|
||||
{
|
||||
break;
|
||||
case "name":
|
||||
query.orderByProcessDefinitionName();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException("sort " + sortParam +
|
||||
" is not supported, supported items are " + PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES.toArray());
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException("OrderBy " + sortColumn.column +
|
||||
" is not supported, supported items are " + PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES);
|
||||
}
|
||||
|
||||
String sortOrderParam = parameters.getParameter("sortOrder");
|
||||
if (sortOrderParam != null)
|
||||
{
|
||||
if ("asc".equalsIgnoreCase(sortOrderParam))
|
||||
if (sortColumn.asc)
|
||||
{
|
||||
query.asc();
|
||||
}
|
||||
else if ("desc".equalsIgnoreCase(sortOrderParam))
|
||||
{
|
||||
query.desc();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException("sort order " + sortOrderParam +
|
||||
" is not supported, supported items are asc and desc");
|
||||
}
|
||||
query.desc();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -142,6 +144,135 @@ public class ProcessDefinitionWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
assertEquals(false, paginationJSON.get("hasMoreItems"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessDefinitionsSorting() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
|
||||
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService()
|
||||
.createProcessDefinitionQuery()
|
||||
.processDefinitionKey(adhocKey)
|
||||
.singleResult();
|
||||
|
||||
assertNotNull(activitiDefinition);
|
||||
|
||||
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
|
||||
|
||||
List<ProcessDefinition> processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name");
|
||||
assertEquals(5, processDefinitions.size());
|
||||
List<String> expectedNames = Arrays.asList("Adhoc Activiti Process",
|
||||
"Parallel Group Review And Approve Activiti Process",
|
||||
"Parallel Review And Approve Activiti Process",
|
||||
"Pooled Review And Approve Activiti Process",
|
||||
"Review And Approve Activiti Process");
|
||||
|
||||
List<String> names = collect(processDefinitions, new Collector()
|
||||
{
|
||||
@Override
|
||||
public String collect(ProcessDefinition definition)
|
||||
{
|
||||
return definition.getName();
|
||||
}
|
||||
});
|
||||
assertEquals(expectedNames, names);
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "name DESC");
|
||||
assertEquals(5, processDefinitions.size());
|
||||
names = collect(processDefinitions, new Collector()
|
||||
{
|
||||
@Override
|
||||
public String collect(ProcessDefinition definition)
|
||||
{
|
||||
return definition.getName();
|
||||
}
|
||||
});
|
||||
Collections.reverse(expectedNames);
|
||||
assertEquals(expectedNames, names);
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "version DESC");
|
||||
assertEquals(5, processDefinitions.size()); //all the same version so no sorting
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "id ASC");
|
||||
assertEquals(5, processDefinitions.size());
|
||||
List<String> ids = collect(processDefinitions, new Collector()
|
||||
{
|
||||
@Override
|
||||
public String collect(ProcessDefinition definition)
|
||||
{
|
||||
return definition.getId();
|
||||
}
|
||||
});
|
||||
List<String> sortedIds = new ArrayList<>(ids);
|
||||
Collections.sort(sortedIds);
|
||||
assertEquals(sortedIds, ids);
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "category ASC");
|
||||
assertEquals(5, processDefinitions.size()); //all the same
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "key DESC");
|
||||
assertEquals(5, processDefinitions.size());
|
||||
List<String> keys = collect(processDefinitions, new Collector()
|
||||
{
|
||||
@Override
|
||||
public String collect(ProcessDefinition definition)
|
||||
{
|
||||
return definition.getKey();
|
||||
}
|
||||
});
|
||||
List<String> sortedKeys = new ArrayList<>(keys);
|
||||
Collections.sort(sortedKeys); //order
|
||||
Collections.reverse(sortedKeys); //reverse order
|
||||
assertEquals(sortedKeys, keys);
|
||||
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC");
|
||||
assertEquals(5, processDefinitions.size());
|
||||
List<String> deploymentIds = collect(processDefinitions, new Collector()
|
||||
{
|
||||
@Override
|
||||
public String collect(ProcessDefinition definition)
|
||||
{
|
||||
return definition.getDeploymentId();
|
||||
}
|
||||
});
|
||||
List<String> sortedDeploymentIds = new ArrayList<>(deploymentIds);
|
||||
Collections.sort(sortedDeploymentIds);
|
||||
assertEquals(sortedDeploymentIds, deploymentIds);
|
||||
|
||||
try
|
||||
{
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "sausage ASC");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(400, e.getHttpResponse().getStatusCode());
|
||||
assertTrue(e.getMessage().contains("OrderBy sausage is not supported, supported items are"));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
processDefinitions = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')", "deploymentId ASC, key");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(400, e.getHttpResponse().getStatusCode());
|
||||
assertTrue(e.getHttpResponse().getResponse().contains("Only one orderBy parameter is supported"));
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> collect(List<ProcessDefinition> processDefinitions, Collector collector)
|
||||
{
|
||||
List<String> collected = new ArrayList<>();
|
||||
for (ProcessDefinition definition:processDefinitions)
|
||||
{
|
||||
collected.add(collector.collect(definition));
|
||||
}
|
||||
|
||||
return collected;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessDefinitionsWhereClause() throws Exception
|
||||
{
|
||||
@@ -643,4 +774,24 @@ public class ProcessDefinitionWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(params);
|
||||
return getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
|
||||
}
|
||||
|
||||
protected List<ProcessDefinition> getProcessDefinitions(ProcessDefinitionsClient processDefinitionsClient, String whereClause, String sort) throws PublicApiException
|
||||
{
|
||||
Map<String, String> params = null;
|
||||
if(whereClause != null)
|
||||
{
|
||||
params = Collections.singletonMap("where", whereClause);
|
||||
}
|
||||
if(sort != null)
|
||||
{
|
||||
params = Collections.singletonMap("orderBy", sort);
|
||||
}
|
||||
|
||||
return processDefinitionsClient.getProcessDefinitions(params).getList();
|
||||
}
|
||||
|
||||
interface Collector
|
||||
{
|
||||
public String collect (ProcessDefinition processDefinitions);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user