use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionParser method parseEntry.
@Override
public ProcessDefinition parseEntry(JSONObject entry) {
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setId((String) entry.get("id"));
processDefinition.setKey((String) entry.get("key"));
processDefinition.setVersion(((Number) entry.get("version")).intValue());
processDefinition.setName((String) entry.get("name"));
processDefinition.setDeploymentId((String) entry.get("deploymentId"));
processDefinition.setTitle((String) entry.get("title"));
processDefinition.setDescription((String) entry.get("description"));
processDefinition.setCategory((String) entry.get("category"));
processDefinition.setStartFormResourceKey((String) entry.get("startFormResourceKey"));
processDefinition.setGraphicNotationDefined((Boolean) entry.get("graphicNotationDefined"));
return processDefinition;
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionById.
@Test
public void testGetProcessDefinitionById() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
// Get a single process definitions
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
// get process definition with admin
publicApiClient.setRequestContext(adminContext);
adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testAuthenticationAndAuthorization.
@Test
public void testAuthenticationAndAuthorization() throws Exception {
// Fetching process definitions as admin should be possible
RequestContext requestContext = initApiClientWithTestUser();
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
// Fetching process definitions as admin from another tenant shouldn't be possible
TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
publicApiClient.setRequestContext(otherContext);
processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
// the response should contain process definitions from the new tenant
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
// Fetching a specific process definitions as admin should be possible
publicApiClient.setRequestContext(requestContext);
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
// Get a single process definitions
ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
assertNotNull(adhocDefinition);
// Check fields of a resulting process-definition
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
assertEquals("activitiAdhoc", adhocDefinition.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
// Fetching a specific process definitions as admin from another tenant should not be possible
publicApiClient.setRequestContext(otherContext);
try {
adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
// Fetching the start form model of a process definition as admin should be possible
publicApiClient.setRequestContext(requestContext);
JSONObject model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
assertNotNull(model);
JSONArray entries = (JSONArray) model.get("entries");
assertNotNull(entries);
// Add all entries to a map, to make lookup easier
Map<String, JSONObject> modelFieldsByName = new HashMap<String, JSONObject>();
JSONObject entry = null;
for (int i = 0; i < entries.size(); i++) {
entry = (JSONObject) entries.get(i);
assertNotNull(entry);
entry = (JSONObject) entry.get("entry");
assertNotNull(entry);
modelFieldsByName.put((String) entry.get("name"), entry);
}
// Check well-known properties and their types
// Validate bpm:description
JSONObject modelEntry = modelFieldsByName.get("bpm_workflowDescription");
assertNotNull(modelEntry);
assertEquals("Description", modelEntry.get("title"));
assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowDescription", modelEntry.get("qualifiedName"));
assertEquals("d:text", modelEntry.get("dataType"));
assertFalse((Boolean) modelEntry.get("required"));
// Fetching a specific process definitions as admin from another tenant should not be possible
publicApiClient.setRequestContext(otherContext);
try {
model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
fail("not found expected");
} catch (PublicApiException e) {
assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
}
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitions.
@Test
public void testGetProcessDefinitions() throws Exception {
RequestContext requestContext = initApiClientWithTestUser();
// Get all process definitions
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
assertTrue(processDefinitionMap.containsKey("activitiReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
assertEquals(5, processDefinitionMap.size());
// Check fields of a resulting process-definition
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
assertNotNull(activitiDefinition);
ProcessDefinition adhocDefinitionRest = processDefinitionMap.get("activitiAdhoc");
assertEquals(activitiDefinition.getId(), adhocDefinitionRest.getId());
assertEquals("activitiAdhoc", adhocDefinitionRest.getKey());
assertEquals(activitiDefinition.getDeploymentId(), adhocDefinitionRest.getDeploymentId());
assertEquals(activitiDefinition.getCategory(), adhocDefinitionRest.getCategory());
assertEquals(activitiDefinition.getName(), adhocDefinitionRest.getName());
assertEquals(activitiDefinition.getVersion(), adhocDefinitionRest.getVersion());
assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinitionRest.isGraphicNotationDefined());
assertEquals("wf:submitAdhocTask", adhocDefinitionRest.getStartFormResourceKey());
assertEquals("New Task", adhocDefinitionRest.getTitle());
assertEquals("Assign a new task to yourself or a colleague", adhocDefinitionRest.getDescription());
Map<String, String> params = new HashMap<String, String>();
params.put("maxItems", "2");
JSONObject definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
JSONObject paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "2");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(2l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(true, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "2");
params.put("maxItems", "5");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(3l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(2l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
params = new HashMap<String, String>();
params.put("skipCount", "0");
params.put("maxItems", "7");
definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
assertNotNull(definitionListObject);
paginationJSON = (JSONObject) definitionListObject.get("pagination");
assertEquals(5l, paginationJSON.get("count"));
assertEquals(5l, paginationJSON.get("totalItems"));
assertEquals(0l, paginationJSON.get("skipCount"));
assertEquals(false, paginationJSON.get("hasMoreItems"));
}
use of org.alfresco.rest.workflow.api.model.ProcessDefinition in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getProcessDefinition.
@Override
public ProcessDefinition getProcessDefinition(String definitionId) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(definitionId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
if (processDefinition == null) {
throw new EntityNotFoundException(definitionId);
}
ProcessDefinition deploymentRest = createProcessDefinitionRest((ProcessDefinitionEntity) processDefinition);
return deploymentRest;
}
Aggregations