use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getProcessDefinitions.
@Override
public CollectionWithPagingInfo<ProcessDefinition> getProcessDefinitions(Parameters parameters) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionCategoryNotEquals(WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL);
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_DEFINITION_COLLECTION_EQUALS_QUERY_PROPERTIES, PROCESS_DEFINITION_COLLECTION_MATCHES_QUERY_PROPERTIES);
boolean keyQueryIncluded = false;
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
// Property equals
String categoryProperty = propertyWalker.getProperty("category", WhereClauseParser.EQUALS);
if (categoryProperty != null) {
query.processDefinitionCategory(categoryProperty);
}
String keyProperty = propertyWalker.getProperty("key", WhereClauseParser.EQUALS);
if (keyProperty != null) {
query.processDefinitionKey(getProcessDefinitionKey(keyProperty));
keyQueryIncluded = true;
}
String nameProperty = propertyWalker.getProperty("name", WhereClauseParser.EQUALS);
if (nameProperty != null) {
query.processDefinitionName(nameProperty);
}
Integer versionProperty = propertyWalker.getProperty("version", WhereClauseParser.EQUALS, Integer.class);
if (versionProperty != null) {
query.processDefinitionVersion(versionProperty);
}
String deploymentProperty = propertyWalker.getProperty("deploymentId", WhereClauseParser.EQUALS);
if (deploymentProperty != null) {
query.deploymentId(deploymentProperty);
}
// Property matches
String categoryMatchesProperty = propertyWalker.getProperty("category", WhereClauseParser.MATCHES);
if (categoryMatchesProperty != null) {
query.processDefinitionCategoryLike(categoryMatchesProperty);
}
String keyMatchesProperty = propertyWalker.getProperty("key", WhereClauseParser.MATCHES);
if (keyMatchesProperty != null) {
query.processDefinitionKeyLike(getProcessDefinitionKey(keyMatchesProperty));
keyQueryIncluded = true;
}
String nameLikeProperty = propertyWalker.getProperty("name", WhereClauseParser.MATCHES);
if (nameLikeProperty != null) {
query.processDefinitionNameLike(nameLikeProperty);
}
}
// Filter based on tenant, if required
if (keyQueryIncluded == false && tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one orderBy parameter is supported");
}
sortColumn = sortList.get(0);
switch(sortColumn.column) {
case "id":
query.orderByProcessDefinitionId();
break;
case "deploymentId":
query.orderByDeploymentId();
break;
case "key":
query.orderByProcessDefinitionKey();
break;
case "category":
query.orderByProcessDefinitionCategory();
break;
case "version":
query.orderByProcessDefinitionVersion();
break;
case "name":
query.orderByProcessDefinitionName();
break;
default:
throw new InvalidArgumentException("OrderBy " + sortColumn.column + " is not supported, supported items are " + PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES);
}
if (sortColumn.asc) {
query.asc();
} else {
query.desc();
}
} else {
query.orderByProcessDefinitionId().asc();
}
List<org.activiti.engine.repository.ProcessDefinition> processDefinitions = query.listPage(parameters.getPaging().getSkipCount(), parameters.getPaging().getMaxItems());
int totalCount = (int) query.count();
List<ProcessDefinition> page = new ArrayList<ProcessDefinition>(processDefinitions.size());
for (org.activiti.engine.repository.ProcessDefinition processDefinition : processDefinitions) {
page.add(createProcessDefinitionRest((ProcessDefinitionEntity) processDefinition));
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), page, (page.size() + parameters.getPaging().getSkipCount()) < totalCount, totalCount);
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method createProcessDefinitionRest.
protected ProcessDefinition createProcessDefinitionRest(ProcessDefinitionEntity processDefinition) {
ProcessDefinition processDefinitionRest = new ProcessDefinition(processDefinition);
String localKey = getLocalProcessDefinitionKey(processDefinition.getKey());
processDefinitionRest.setKey(localKey);
String displayId = localKey + ".workflow";
processDefinitionRest.setTitle(getLabel(displayId, "title"));
processDefinitionRest.setDescription(getLabel(displayId, "description"));
processDefinitionRest.setGraphicNotationDefined(processDefinition.isGraphicalNotationDefined());
if (processDefinition.hasStartFormKey()) {
try {
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinition.getId());
if (startFormData != null) {
processDefinitionRest.setStartFormResourceKey(startFormData.getFormKey());
}
} catch (Exception e) {
throw new ApiException("Error while retrieving start form key");
}
}
return processDefinitionRest;
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsWhereClause.
@Test
public void testGetProcessDefinitionsWhereClause() 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();
// Filter on category equals
Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org')");
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on name equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'Adhoc Activiti Process')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on key equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='activitiAdhoc')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on version equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='1')");
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(version='2')");
assertEquals(0, processDefinitionMap.size());
// Filter on deploymentId equals
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='" + activitiDefinition.getDeploymentId() + "')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(deploymentId='unexisting')");
assertEquals(0, processDefinitionMap.size());
// Filter on category matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('%alfresco.o%'))");
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category matches('unexisting'))");
assertEquals(0, processDefinitionMap.size());
// Filter on name matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('Adhoc Activiti %'))");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('unexisting'))");
assertEquals(0, processDefinitionMap.size());
// Filter on key matches
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key matches('activitiAd%'))");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
// Use AND operator
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' AND name = 'Adhoc Activiti Process')");
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(1, processDefinitionMap.size());
// Use OR operator
try {
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(category = 'http://alfresco.org' OR name = 'Adhoc Activiti Process')");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(400, e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsSorting.
@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");
// all the same version so no sorting
assertEquals(5, processDefinitions.size());
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");
// all the same
assertEquals(5, processDefinitions.size());
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);
// order
Collections.sort(sortedKeys);
// reverse order
Collections.reverse(sortedKeys);
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"));
}
}
Aggregations