mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
|
||||
public class ClientDeployment
|
||||
{
|
||||
String name;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import org.alfresco.rest.workflow.api.model.Deployment;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class DeploymentParser extends ListParser<Deployment>
|
||||
{
|
||||
public static DeploymentParser INSTANCE = new DeploymentParser();
|
||||
|
||||
@Override
|
||||
public Deployment parseEntry(JSONObject entry)
|
||||
{
|
||||
Deployment deployment = new Deployment();
|
||||
deployment.setId((String) entry.get("id"));
|
||||
deployment.setName((String) entry.get("name"));
|
||||
deployment.setDeployedAt(WorkflowApiClient.parseDate(entry, "deployedAt"));
|
||||
return deployment;
|
||||
}
|
||||
}
|
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.workflow.api.model.Deployment;
|
||||
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Rest api tests using http client to communicate with the rest apis in the repository.
|
||||
*
|
||||
* Note: currently certain tests work only with lucene search subsystem e.g. tags.
|
||||
*
|
||||
* @author steveglover
|
||||
*
|
||||
*/
|
||||
public class DeploymentWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
{
|
||||
protected static HashSet<String> alfrescoPublicDeploymentNames = new HashSet<String>(Arrays.asList(new String[]{
|
||||
"review-pooled.bpmn20.xml",
|
||||
"review.bpmn20.xml",
|
||||
"parallel-review-group.bpmn20.xml",
|
||||
"parallel-review.bpmn20.xml",
|
||||
"adhoc.bpmn20.xml"}));
|
||||
|
||||
protected static HashSet<String> alfrescoPublicProcessDefinitionKeys = new HashSet<String>(Arrays.asList(new String[]{
|
||||
"activitiReviewPooled",
|
||||
"activitiReview",
|
||||
"activitiParallelGroupReview",
|
||||
"activitiParallelReview",
|
||||
"activitiAdhoc"}));
|
||||
|
||||
@Test
|
||||
public void testGetDeploymentsWithNonAdminUser() throws Exception
|
||||
{
|
||||
// deployments-get#1
|
||||
initApiClientWithTestUser();
|
||||
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
|
||||
|
||||
try {
|
||||
deploymentsClient.getDeployments();
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.FORBIDDEN.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("Permission was denied", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetDeployments() throws Exception
|
||||
{
|
||||
// testGetDeployments#1: Getting deployments with admin-user
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
|
||||
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
|
||||
|
||||
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
|
||||
|
||||
ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
|
||||
Map<String, Deployment> deploymentMap = new HashMap<String, Deployment>();
|
||||
for (Deployment deployment : deploymentResponse.getList())
|
||||
{
|
||||
deploymentMap.put(deployment.getName(), deployment);
|
||||
}
|
||||
assertEquals(5, deploymentResponse.getList().size());
|
||||
|
||||
assertTrue(deploymentMap.containsKey("review-pooled.bpmn20.xml"));
|
||||
assertTrue(deploymentMap.containsKey("review.bpmn20.xml"));
|
||||
assertTrue(deploymentMap.containsKey("parallel-review-group.bpmn20.xml"));
|
||||
assertTrue(deploymentMap.containsKey("parallel-review.bpmn20.xml"));
|
||||
assertTrue(deploymentMap.containsKey("adhoc.bpmn20.xml"));
|
||||
|
||||
// testGetDeployments#2: Check all deployment fields in resulting deployment
|
||||
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService()
|
||||
.createDeploymentQuery()
|
||||
.deploymentName("adhoc.bpmn20.xml")
|
||||
.processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc")
|
||||
.singleResult();
|
||||
|
||||
assertNotNull(activitiDeployment);
|
||||
Deployment adhocDeployment = deploymentMap.get("adhoc.bpmn20.xml");
|
||||
|
||||
assertEquals(activitiDeployment.getId(), adhocDeployment.getId());
|
||||
assertEquals(activitiDeployment.getCategory(), adhocDeployment.getCategory());
|
||||
assertEquals(activitiDeployment.getName(), adhocDeployment.getName());
|
||||
assertEquals(activitiDeployment.getDeploymentTime(), adhocDeployment.getDeployedAt());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testGetDeploymentsEmpty() throws Exception
|
||||
// {
|
||||
// // Create a new test-network, not added to the test-fixture to prevent being used
|
||||
// // in other tests
|
||||
// String networkName = AbstractTestFixture.TEST_DOMAIN_PREFIX + UUID.randomUUID();
|
||||
// TestNetwork testNetwork = repoService.createNetworkWithAlias(networkName, true);
|
||||
// testNetwork.create();
|
||||
//
|
||||
// // Delete all deployments in the network
|
||||
// List<org.activiti.engine.repository.Deployment> deployments = activitiProcessEngine.getRepositoryService()
|
||||
// .createDeploymentQuery()
|
||||
// .processDefinitionKeyLike("@" + networkName + "@")
|
||||
// .list();
|
||||
//
|
||||
// for(org.activiti.engine.repository.Deployment deployment : deployments) {
|
||||
// activitiProcessEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
|
||||
// }
|
||||
//
|
||||
// // Fetch deployments using tenant-admin
|
||||
// String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + networkName;
|
||||
// publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
|
||||
//
|
||||
// DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
|
||||
//
|
||||
// ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
|
||||
// assertEquals(0, deploymentResponse.getList().size());
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testGetDeploymentById() throws Exception
|
||||
{
|
||||
// Use admin-user for tenant
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
|
||||
publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
|
||||
|
||||
// Fetch the actual deployment from activiti
|
||||
org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService()
|
||||
.createDeploymentQuery()
|
||||
.deploymentName("adhoc.bpmn20.xml")
|
||||
.processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc")
|
||||
.singleResult();
|
||||
|
||||
assertNotNull(activitiDeployment);
|
||||
|
||||
// Do the actual API-call
|
||||
DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
|
||||
Deployment deployment = deploymentsClient.findDeploymentById(activitiDeployment.getId());
|
||||
|
||||
assertNotNull(deployment);
|
||||
|
||||
assertEquals(activitiDeployment.getId(), deployment.getId());
|
||||
assertEquals(activitiDeployment.getCategory(), deployment.getCategory());
|
||||
assertEquals(activitiDeployment.getName(), deployment.getName());
|
||||
assertEquals(activitiDeployment.getDeploymentTime(), deployment.getDeployedAt());
|
||||
}
|
||||
|
||||
protected String createProcessDefinitionKey(String key, RequestContext requestContext) {
|
||||
return "@" + requestContext.getNetworkId() + "@" + key;
|
||||
}
|
||||
}
|
@@ -0,0 +1,232 @@
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.repository.DeploymentBuilder;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
|
||||
import org.alfresco.rest.api.tests.EnterpriseTestApi;
|
||||
import org.alfresco.rest.api.tests.RepoService.SiteInformation;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestSite;
|
||||
import org.alfresco.rest.api.tests.TestFixture;
|
||||
import org.alfresco.rest.api.tests.client.AuthenticatedHttp;
|
||||
import org.alfresco.rest.api.tests.client.AuthenticationDetailsProvider;
|
||||
import org.alfresco.rest.api.tests.client.HttpClientProvider;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.UserAuthenticationDetailsProviderImpl;
|
||||
import org.alfresco.rest.api.tests.client.UserData;
|
||||
import org.alfresco.rest.api.tests.client.UserDataService;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.Before;
|
||||
|
||||
public class EnterpriseWorkflowTestApi extends EnterpriseTestApi
|
||||
{
|
||||
protected ProcessEngine activitiProcessEngine;
|
||||
protected WorkflowApiClient publicApiClient;
|
||||
protected PersonService personService;
|
||||
protected ServiceRegistry serviceRegistry;
|
||||
protected NodeService nodeService;
|
||||
protected TestNetwork currentNetwork;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
this.applicationContext = getTestFixture().getApplicationContext();
|
||||
this.repoService = getTestFixture().getRepoService();
|
||||
this.transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
|
||||
this.personService = (PersonService) applicationContext.getBean("PersonService");
|
||||
this.nodeService = (NodeService) applicationContext.getBean("NodeService");
|
||||
this.serviceRegistry = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
|
||||
|
||||
HttpClientProvider httpClientProvider = (HttpClientProvider)applicationContext.getBean("httpClientProvider");
|
||||
|
||||
UserDataService userDataService = new UserDataService()
|
||||
{
|
||||
@Override
|
||||
public UserData findUserByUserName(String userName)
|
||||
{
|
||||
UserData userData = new UserData();
|
||||
if(userName.startsWith("admin"))
|
||||
{
|
||||
userData.setUserName(userName);
|
||||
userData.setPassword("admin");
|
||||
userData.setId(userName);
|
||||
}
|
||||
else
|
||||
{
|
||||
TestPerson person = getRepoService().getPerson(userName.toLowerCase());
|
||||
userData.setUserName(person.getId());
|
||||
userData.setPassword(person.getPassword());
|
||||
userData.setId(person.getId());
|
||||
}
|
||||
return userData;
|
||||
}
|
||||
};
|
||||
AuthenticationDetailsProvider authenticationDetailsProvider = new UserAuthenticationDetailsProviderImpl(userDataService, "admin", "admin");
|
||||
AuthenticatedHttp authenticatedHttp = new AuthenticatedHttp(httpClientProvider, authenticationDetailsProvider);
|
||||
this.httpClient = new PublicApiHttpClient("localhost", TestFixture.PORT, TestFixture.CONTEXT_PATH,
|
||||
TestFixture.PUBLIC_API_SERVLET_NAME, authenticatedHttp);
|
||||
this.publicApiClient = new WorkflowApiClient(httpClient, userDataService);
|
||||
activitiProcessEngine = (ProcessEngine) applicationContext.getBean("activitiProcessEngine");
|
||||
}
|
||||
|
||||
protected String deployProcessDefinition(String... artifacts) {
|
||||
DeploymentBuilder deploymentBuilder = activitiProcessEngine.getRepositoryService().createDeployment();
|
||||
boolean firstArtifact = true;
|
||||
for (String artifact : artifacts)
|
||||
{
|
||||
InputStream bpmnInputStream = getClass().getClassLoader().getResourceAsStream(artifact);
|
||||
String name = artifact.substring(artifact.lastIndexOf("/") + 1);
|
||||
if (firstArtifact)
|
||||
{
|
||||
deploymentBuilder.name(name);
|
||||
}
|
||||
deploymentBuilder.addInputStream(name, bpmnInputStream);
|
||||
}
|
||||
String deploymentId = deploymentBuilder.deploy().getId();
|
||||
return deploymentId;
|
||||
}
|
||||
|
||||
protected RequestContext initApiClientWithTestUser() throws Exception {
|
||||
currentNetwork = getTestFixture().getRandomNetwork();
|
||||
final String personId = currentNetwork.getPeople().iterator().next().getId();
|
||||
RequestContext requestContext = new RequestContext(currentNetwork.getId(), personId);
|
||||
publicApiClient.setRequestContext(requestContext);
|
||||
return requestContext;
|
||||
}
|
||||
|
||||
protected Date parseDate(JSONObject entry, String fieldName) {
|
||||
String dateText = (String) entry.get(fieldName);
|
||||
if (dateText!=null) {
|
||||
try
|
||||
{
|
||||
return WorkflowApiClient.DATE_FORMAT_ISO8601.parse(dateText);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("couldn't parse date "+dateText+": "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String formatDate(Date date) {
|
||||
if(date == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return WorkflowApiClient.DATE_FORMAT_ISO8601.format(date);
|
||||
}
|
||||
|
||||
protected ActivitiScriptNode getPersonNodeRef(String name)
|
||||
{
|
||||
ActivitiScriptNode authority = null;
|
||||
if (name != null)
|
||||
{
|
||||
if (personService.personExists(name))
|
||||
{
|
||||
authority = new ActivitiScriptNode(personService.getPerson(name), serviceRegistry);
|
||||
}
|
||||
}
|
||||
return authority;
|
||||
}
|
||||
|
||||
protected void assertErrorSummary(String expectedBriefSummary, HttpResponse response)
|
||||
{
|
||||
JSONObject error = (JSONObject) response.getJsonResponse().get("error");
|
||||
assertNotNull(error);
|
||||
|
||||
String actualBriefSummary = (String) error.get("briefSummary");
|
||||
assertNotNull(actualBriefSummary);
|
||||
|
||||
// Error starts with exception-number, check if actual message part matches
|
||||
assertTrue("Wrong summary of error: " + actualBriefSummary, actualBriefSummary.endsWith(expectedBriefSummary));
|
||||
}
|
||||
|
||||
protected NodeRef[] createTestDocuments(final RequestContext requestContext) {
|
||||
NodeRef[] docNodeRefs = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef[]>()
|
||||
{
|
||||
@Override
|
||||
public NodeRef[] doWork() throws Exception
|
||||
{
|
||||
String siteName = "site" + GUID.generate();
|
||||
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
|
||||
TestSite site = currentNetwork.createSite(siteInfo);
|
||||
NodeRef nodeRefDoc1 = getTestFixture().getRepoService().createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Doc1 Title", "Test Doc1 Description", "Test Content");
|
||||
NodeRef nodeRefDoc2 = getTestFixture().getRepoService().createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Doc2 Title", "Test Doc2 Description", "Test Content");
|
||||
|
||||
NodeRef[] result = new NodeRef[2];
|
||||
result[0] = nodeRefDoc1;
|
||||
result[1] = nodeRefDoc2;
|
||||
|
||||
return result;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
return docNodeRefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an adhoc-process through the public REST-API.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ProcessInfo startAdhocProcess(final RequestContext requestContext, NodeRef[] documentRefs) throws PublicApiException {
|
||||
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine
|
||||
.getRepositoryService()
|
||||
.createProcessDefinitionQuery()
|
||||
.processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc")
|
||||
.singleResult();
|
||||
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
final JSONObject createProcessObject = new JSONObject();
|
||||
createProcessObject.put("processDefinitionId", processDefinition.getId());
|
||||
final JSONObject variablesObject = new JSONObject();
|
||||
variablesObject.put("bpm_priority", 1);
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
|
||||
return null;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
if (documentRefs != null && documentRefs.length > 0)
|
||||
{
|
||||
final JSONArray itemsObject = new JSONArray();
|
||||
for (NodeRef nodeRef : documentRefs)
|
||||
{
|
||||
itemsObject.add(nodeRef.toString());
|
||||
}
|
||||
createProcessObject.put("items", itemsObject);
|
||||
}
|
||||
|
||||
createProcessObject.put("variables", variablesObject);
|
||||
|
||||
return processesClient.createProcess(createProcessObject.toJSONString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public abstract class ListParser<T>
|
||||
{
|
||||
|
||||
public ListResponse<T> parseList(JSONObject jsonResponse)
|
||||
{
|
||||
List<T> deployments = new ArrayList<T>();
|
||||
|
||||
JSONObject jsonList = (JSONObject)jsonResponse.get("list");
|
||||
assertNotNull(jsonList);
|
||||
|
||||
JSONArray jsonEntries = (JSONArray)jsonList.get("entries");
|
||||
assertNotNull(jsonEntries);
|
||||
|
||||
for(int i = 0; i < jsonEntries.size(); i++)
|
||||
{
|
||||
JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
|
||||
JSONObject entry = (JSONObject)jsonEntry.get("entry");
|
||||
deployments.add(parseEntry(entry));
|
||||
}
|
||||
|
||||
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
|
||||
|
||||
ListResponse<T> resp = new ListResponse<T>(paging, deployments);
|
||||
return resp;
|
||||
}
|
||||
|
||||
public abstract T parseEntry(JSONObject entry);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import org.alfresco.rest.workflow.api.model.ProcessDefinition;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ProcessDefinitionParser extends ListParser<ProcessDefinition>
|
||||
{
|
||||
public static ProcessDefinitionParser INSTANCE = new ProcessDefinitionParser();
|
||||
|
||||
@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.setCategory((String) entry.get("category"));
|
||||
processDefinition.setStartFormResourceKey((String) entry.get("startFormResourceKey"));
|
||||
processDefinition.setGraphicNotationDefined((Boolean) entry.get("graphicNotationDefined"));
|
||||
return processDefinition;
|
||||
}
|
||||
}
|
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessDefinition;
|
||||
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Frederik Heremans
|
||||
*/
|
||||
public class ProcessDefinitionWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
{
|
||||
|
||||
@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(createProcessDefinitionKey("activitiReviewPooled", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelGroupReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
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 adhocDefinition = processDefinitionMap.get(adhocKey);
|
||||
|
||||
assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
|
||||
assertEquals(activitiDefinition.getKey(), 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());
|
||||
}
|
||||
|
||||
@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(createProcessDefinitionKey("activitiReviewPooled", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelGroupReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
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(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
assertEquals(1, processDefinitionMap.size());
|
||||
|
||||
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name = 'unexisting')");
|
||||
assertEquals(0, processDefinitionMap.size());
|
||||
|
||||
// Filter on key equals
|
||||
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key='" + adhocKey +"')");
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
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(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
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(createProcessDefinitionKey("activitiReviewPooled", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelGroupReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiParallelReview", requestContext)));
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
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(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
assertEquals(1, processDefinitionMap.size());
|
||||
|
||||
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(name matches('unexisting'))");
|
||||
assertEquals(0, processDefinitionMap.size());
|
||||
|
||||
// Filter on key matches
|
||||
processDefinitionMap = getProcessDefinitions(processDefinitionsClient, "(key matches('" + adhocKey.substring(0, adhocKey.length() - 3) +"%'))");
|
||||
assertTrue(processDefinitionMap.containsKey(createProcessDefinitionKey("activitiAdhoc", requestContext)));
|
||||
assertEquals(1, processDefinitionMap.size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessDefinitionById() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
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(activitiDefinition.getKey(), 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessDefinitionByIdUnexisting() throws Exception
|
||||
{
|
||||
initApiClientWithTestUser();
|
||||
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
|
||||
try
|
||||
{
|
||||
processDefinitionsClient.findProcessDefinitionById("unexisting");
|
||||
fail("Exception expected");
|
||||
}
|
||||
catch(PublicApiException expected)
|
||||
{
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessDefinitionStartModel() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
|
||||
|
||||
String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
|
||||
org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService()
|
||||
.createProcessDefinitionQuery()
|
||||
.processDefinitionKey(adhocKey)
|
||||
.singleResult();
|
||||
|
||||
assertNotNull(activitiDefinition);
|
||||
|
||||
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_description");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Description", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/bpm/1.0}description", modelEntry.get("qualifiedName"));
|
||||
assertEquals("d:text", modelEntry.get("dataType"));
|
||||
assertFalse((Boolean)modelEntry.get("required"));
|
||||
|
||||
// Validate bpm:description
|
||||
modelEntry = modelFieldsByName.get("bpm_completionDate");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Completion Date", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/bpm/1.0}completionDate", modelEntry.get("qualifiedName"));
|
||||
assertEquals("d:date", modelEntry.get("dataType"));
|
||||
assertFalse((Boolean)modelEntry.get("required"));
|
||||
|
||||
// Validate cm:owner
|
||||
modelEntry = modelFieldsByName.get("cm_owner");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Owner", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/content/1.0}owner", modelEntry.get("qualifiedName"));
|
||||
assertEquals("d:text", modelEntry.get("dataType"));
|
||||
assertFalse((Boolean)modelEntry.get("required"));
|
||||
|
||||
// Validate bpm:sendEmailNotifications
|
||||
modelEntry = modelFieldsByName.get("bpm_sendEMailNotifications");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Send Email Notifications", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/bpm/1.0}sendEMailNotifications", modelEntry.get("qualifiedName"));
|
||||
assertEquals("d:boolean", modelEntry.get("dataType"));
|
||||
assertFalse((Boolean)modelEntry.get("required"));
|
||||
|
||||
// Validate bpm:priority
|
||||
modelEntry = modelFieldsByName.get("bpm_priority");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Priority", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/bpm/1.0}priority", modelEntry.get("qualifiedName"));
|
||||
assertEquals("d:int", modelEntry.get("dataType"));
|
||||
assertEquals("2", modelEntry.get("defaultValue"));
|
||||
assertTrue((Boolean)modelEntry.get("required"));
|
||||
|
||||
// Validate bpm:package
|
||||
modelEntry = modelFieldsByName.get("bpm_package");
|
||||
assertNotNull(modelEntry);
|
||||
assertEquals("Content Package", modelEntry.get("title"));
|
||||
assertEquals("{http://www.alfresco.org/model/bpm/1.0}package", modelEntry.get("qualifiedName"));
|
||||
assertEquals("bpm:workflowPackage", modelEntry.get("dataType"));
|
||||
assertFalse((Boolean)modelEntry.get("required"));
|
||||
}
|
||||
|
||||
protected String createProcessDefinitionKey(String key, RequestContext requestContext)
|
||||
{
|
||||
return "@" + requestContext.getNetworkId() + "@" + key;
|
||||
}
|
||||
|
||||
protected Map<String, ProcessDefinition> getProcessDefinitionMapByKey(List<ProcessDefinition> processDefinitions)
|
||||
{
|
||||
Map<String, ProcessDefinition> processDefinitionMap = new HashMap<String, ProcessDefinition>();
|
||||
for (ProcessDefinition processDefinition : processDefinitions)
|
||||
{
|
||||
processDefinitionMap.put(processDefinition.getKey(), processDefinition);
|
||||
}
|
||||
return processDefinitionMap;
|
||||
}
|
||||
|
||||
protected Map<String, ProcessDefinition> getProcessDefinitions(ProcessDefinitionsClient processDefinitionsClient, String whereClause) throws PublicApiException
|
||||
{
|
||||
Map<String, String> params = null;
|
||||
if(whereClause != null)
|
||||
{
|
||||
params = Collections.singletonMap("where", whereClause);
|
||||
}
|
||||
ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(params);
|
||||
return getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
|
||||
}
|
||||
}
|
@@ -0,0 +1,781 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.activiti.engine.history.HistoricProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Process related Rest api tests using http client to communicate with the rest apis in the repository.
|
||||
*
|
||||
* @author Tijs Rademakers
|
||||
*
|
||||
*/
|
||||
public class ProcessWorkflowApiTest extends EnterpriseWorkflowTestApi
|
||||
{
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCreateProcessInstanceWithId() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine
|
||||
.getRepositoryService()
|
||||
.createProcessDefinitionQuery()
|
||||
.processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc")
|
||||
.singleResult();
|
||||
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
JSONObject createProcessObject = new JSONObject();
|
||||
createProcessObject.put("processDefinitionId", processDefinition.getId());
|
||||
final JSONObject variablesObject = new JSONObject();
|
||||
variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date()));
|
||||
variablesObject.put("bpm_priority", 1);
|
||||
variablesObject.put("bpm_description", "test description");
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
|
||||
return null;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
|
||||
createProcessObject.put("variables", variablesObject);
|
||||
|
||||
final ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
|
||||
assertNotNull(processRest);
|
||||
|
||||
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
|
||||
|
||||
assertEquals("test description", variables.get("bpm_description"));
|
||||
assertEquals(1, variables.get("bpm_priority"));
|
||||
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
|
||||
// Try with unexisting process definition ID
|
||||
createProcessObject = new JSONObject();
|
||||
createProcessObject.put("processDefinitionId", "unexisting");
|
||||
try
|
||||
{
|
||||
processesClient.createProcess(createProcessObject.toJSONString());
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
// Exception expected because of wrong process definition id
|
||||
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("No workflow definition could be found with id 'unexisting'.", e.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCreateProcessInstanceWithKey() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
JSONObject createProcessObject = new JSONObject();
|
||||
createProcessObject.put("processDefinitionKey", "activitiAdhoc");
|
||||
final JSONObject variablesObject = new JSONObject();
|
||||
variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date()));
|
||||
variablesObject.put("bpm_priority", 1);
|
||||
variablesObject.put("bpm_description", "test description");
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
|
||||
return null;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
|
||||
createProcessObject.put("variables", variablesObject);
|
||||
|
||||
ProcessInfo processRest = processesClient.createProcess(createProcessObject.toJSONString());
|
||||
assertNotNull(processRest);
|
||||
|
||||
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
|
||||
|
||||
assertEquals("test description", variables.get("bpm_description"));
|
||||
assertEquals(1, variables.get("bpm_priority"));
|
||||
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
|
||||
createProcessObject = new JSONObject();
|
||||
createProcessObject.put("processDefinitionKey", "activitiAdhoc2");
|
||||
|
||||
try
|
||||
{
|
||||
processRest = processesClient.createProcess(createProcessObject.toJSONString());
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
// Exception expected because of wrong process definition key
|
||||
assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("No workflow definition could be found with key 'activitiAdhoc2'.", e.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProcessInstanceWithItems() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
|
||||
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
|
||||
assertNotNull(processRest);
|
||||
|
||||
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
|
||||
assertEquals(1, variables.get("bpm_priority"));
|
||||
final ActivitiScriptNode packageScriptNode = (ActivitiScriptNode) variables.get("bpm_package");
|
||||
assertNotNull(packageScriptNode);
|
||||
|
||||
final Map<String, Document> documentMap = new HashMap<String, Document>();
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
|
||||
for (ChildAssociationRef childAssociationRef : documentList)
|
||||
{
|
||||
Document doc = getTestFixture().getRepoService().getDocument(requestContext.getNetworkId(), childAssociationRef.getChildRef());
|
||||
documentMap.put(doc.getName(), doc);
|
||||
}
|
||||
|
||||
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
|
||||
assertEquals(requestContext.getRunAsUser(), task.getAssignee());
|
||||
|
||||
activitiProcessEngine.getTaskService().complete(task.getId());
|
||||
|
||||
final Task task2 = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
|
||||
assertEquals(requestContext.getRunAsUser(), task2.getAssignee());
|
||||
|
||||
activitiProcessEngine.getTaskService().complete(task2.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
assertEquals(2, documentMap.size());
|
||||
assertTrue(documentMap.containsKey("Test Doc1"));
|
||||
Document doc = documentMap.get("Test Doc1");
|
||||
assertEquals("Test Doc1", doc.getName());
|
||||
assertEquals("Test Doc1 Title", doc.getTitle());
|
||||
|
||||
assertTrue(documentMap.containsKey("Test Doc2"));
|
||||
doc = documentMap.get("Test Doc2");
|
||||
assertEquals("Test Doc2", doc.getName());
|
||||
assertEquals("Test Doc2 Title", doc.getTitle());
|
||||
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessInstanceById() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
final ProcessInfo process = startAdhocProcess(requestContext, null);
|
||||
try
|
||||
{
|
||||
ProcessInfo processInfo = processesClient.findProcessById(process.getId());
|
||||
assertNotNull(processInfo);
|
||||
|
||||
assertEquals(process.getId(), processInfo.getId());
|
||||
assertEquals(process.getBusinessKey(), processInfo.getBusinessKey());
|
||||
assertNull(processInfo.getDeleteReason());
|
||||
assertEquals(process.getDurationInMillis(), processInfo.getDurationInMillis());
|
||||
assertEquals(process.getEndedAt(), processInfo.getEndedAt());
|
||||
assertEquals(process.getProcessDefinitionId(), processInfo.getProcessDefinitionId());
|
||||
assertEquals(process.getProcessDefinitionKey(), processInfo.getProcessDefinitionKey());
|
||||
assertEquals(process.getStartedAt(), processInfo.getStartedAt());
|
||||
assertEquals(process.getSuperProcessInstanceId(), processInfo.getSuperProcessInstanceId());
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(process.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessInstanceByIdUnexisting() throws Exception
|
||||
{
|
||||
initApiClientWithTestUser();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
try {
|
||||
processesClient.findProcessById("unexisting");
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProcessInstanceById() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
final ProcessInfo process = startAdhocProcess(requestContext, null);
|
||||
try
|
||||
{
|
||||
processesClient.deleteProcessById(process.getId());
|
||||
|
||||
// Check if the process was actually deleted
|
||||
assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery()
|
||||
.processInstanceId(process.getId()).singleResult());
|
||||
|
||||
HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService()
|
||||
.createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
|
||||
assertNotNull(deletedInstance);
|
||||
assertNotNull(deletedInstance.getEndTime());
|
||||
assertNull(deletedInstance.getDeleteReason());
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(process.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProcessInstanceByIdUnexisting() throws Exception
|
||||
{
|
||||
initApiClientWithTestUser();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
try {
|
||||
processesClient.deleteProcessById("unexisting");
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessInstances() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
final ProcessInfo process1 = startAdhocProcess(requestContext, null);
|
||||
final ProcessInfo process2 = startAdhocProcess(requestContext, null);
|
||||
final ProcessInfo process3 = startAdhocProcess(requestContext, null);
|
||||
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
Map<String, String> paramMap = new HashMap<String, String>();
|
||||
ListResponse<ProcessInfo> processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(3, processList.getList().size());
|
||||
|
||||
Map<String, ProcessInfo> processMap = new HashMap<String, ProcessInfo>();
|
||||
for (ProcessInfo processRest : processList.getList())
|
||||
{
|
||||
processMap.put(processRest.getId(), processRest);
|
||||
}
|
||||
|
||||
assertTrue(processMap.containsKey(process1.getId()));
|
||||
assertTrue(processMap.containsKey(process2.getId()));
|
||||
assertTrue(processMap.containsKey(process3.getId()));
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(3, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc2')");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(0, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
|
||||
paramMap.put("maxItems", "2");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(2, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
|
||||
paramMap.put("maxItems", "3");
|
||||
paramMap.put("skipCount", "1");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(2, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
|
||||
paramMap.put("maxItems", "5");
|
||||
paramMap.put("skipCount", "2");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(1, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(processDefinitionKey = 'activitiAdhoc')");
|
||||
paramMap.put("maxItems", "5");
|
||||
paramMap.put("skipCount", "5");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(0, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(status = 'completed')");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(0, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(status = 'any')");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(3, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(status = 'active')");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(3, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(status = 'active2')");
|
||||
try
|
||||
{
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
// expected exception
|
||||
}
|
||||
|
||||
// Test the variable where-clause
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(variables/bpm_priority = 'd_int 1'))");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(3, processList.getList().size());
|
||||
|
||||
paramMap = new HashMap<String, String>();
|
||||
paramMap.put("where", "(variables/bpm_priority = 'd_int 5'))");
|
||||
processList = processesClient.getProcesses(paramMap);
|
||||
assertNotNull(processList);
|
||||
assertEquals(0, processList.getList().size());
|
||||
|
||||
cleanupProcessInstance(process1.getId(), process2.getId(), process3.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessItems() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
|
||||
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
|
||||
assertNotNull(processRest);
|
||||
|
||||
final String newProcessInstanceId = processRest.getId();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
JSONObject itemsJSON = processesClient.findProcessItems(newProcessInstanceId);
|
||||
assertNotNull(itemsJSON);
|
||||
JSONArray entriesJSON = (JSONArray) itemsJSON.get("entries");
|
||||
assertNotNull(entriesJSON);
|
||||
assertTrue(entriesJSON.size() == 2);
|
||||
boolean doc1Found = false;
|
||||
boolean doc2Found = false;
|
||||
for (Object entryObject : entriesJSON)
|
||||
{
|
||||
JSONObject entryObjectJSON = (JSONObject) entryObject;
|
||||
JSONObject entryJSON = (JSONObject) entryObjectJSON.get("entry");
|
||||
if (entryJSON.get("name").equals("Test Doc1")) {
|
||||
doc1Found = true;
|
||||
assertEquals(docNodeRefs[0].toString(), entryJSON.get("id"));
|
||||
assertEquals("Test Doc1", entryJSON.get("name"));
|
||||
assertEquals("Test Doc1 Title", entryJSON.get("title"));
|
||||
assertEquals("Test Doc1 Description", entryJSON.get("description"));
|
||||
assertNotNull(entryJSON.get("createdAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
|
||||
assertNotNull(entryJSON.get("modifiedAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
|
||||
assertNotNull(entryJSON.get("size"));
|
||||
assertNotNull(entryJSON.get("mimeType"));
|
||||
} else {
|
||||
doc2Found = true;
|
||||
assertEquals(docNodeRefs[1].toString(), entryJSON.get("id"));
|
||||
assertEquals("Test Doc2", entryJSON.get("name"));
|
||||
assertEquals("Test Doc2 Title", entryJSON.get("title"));
|
||||
assertEquals("Test Doc2 Description", entryJSON.get("description"));
|
||||
assertNotNull(entryJSON.get("createdAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), entryJSON.get("createdBy"));
|
||||
assertNotNull(entryJSON.get("modifiedAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), entryJSON.get("modifiedBy"));
|
||||
assertNotNull(entryJSON.get("size"));
|
||||
assertNotNull(entryJSON.get("mimeType"));
|
||||
}
|
||||
}
|
||||
assertTrue(doc1Found);
|
||||
assertTrue(doc2Found);
|
||||
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessItem() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
|
||||
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
|
||||
assertNotNull(processRest);
|
||||
|
||||
final String newProcessInstanceId = processRest.getId();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
JSONObject itemJSON = processesClient.findProcessItem(newProcessInstanceId, docNodeRefs[0].toString());
|
||||
assertNotNull(itemJSON);
|
||||
|
||||
assertEquals(docNodeRefs[0].toString(), itemJSON.get("id"));
|
||||
assertEquals("Test Doc1", itemJSON.get("name"));
|
||||
assertEquals("Test Doc1 Title", itemJSON.get("title"));
|
||||
assertEquals("Test Doc1 Description", itemJSON.get("description"));
|
||||
assertNotNull(itemJSON.get("createdAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), itemJSON.get("createdBy"));
|
||||
assertNotNull(itemJSON.get("modifiedAt"));
|
||||
assertEquals(requestContext.getRunAsUser(), itemJSON.get("modifiedBy"));
|
||||
assertNotNull(itemJSON.get("size"));
|
||||
assertNotNull(itemJSON.get("mimeType"));
|
||||
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProcessItem() throws Exception
|
||||
{
|
||||
final RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
|
||||
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
|
||||
try
|
||||
{
|
||||
assertNotNull(processRest);
|
||||
|
||||
final String newProcessInstanceId = processRest.getId();
|
||||
ProcessesClient processesClient = publicApiClient.processesClient();
|
||||
|
||||
// Delete the item
|
||||
processesClient.deleteProcessItem(newProcessInstanceId, docNodeRefs[0].toString());
|
||||
|
||||
// Fetching the item should result in 404
|
||||
try {
|
||||
publicApiClient.processesClient().findProcessItem(newProcessInstanceId, docNodeRefs[0].toString());
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: " + docNodeRefs[0].toString() + " was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProcessVariables() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
ProcessInfo processRest = startAdhocProcess(requestContext, null);
|
||||
|
||||
try
|
||||
{
|
||||
assertNotNull(processRest);
|
||||
String processInstanceId = processRest.getId();
|
||||
|
||||
JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
|
||||
assertNotNull(processvariables);
|
||||
|
||||
// Add process variables to map for easy lookup
|
||||
Map<String, JSONObject> variablesByName = new HashMap<String, JSONObject>();
|
||||
JSONObject entry = null;
|
||||
JSONArray entries = (JSONArray) processvariables.get("entries");
|
||||
assertNotNull(entries);
|
||||
for(int i=0; i<entries.size(); i++)
|
||||
{
|
||||
entry = (JSONObject) entries.get(i);
|
||||
assertNotNull(entry);
|
||||
entry = (JSONObject) entry.get("entry");
|
||||
assertNotNull(entry);
|
||||
variablesByName.put((String) entry.get("name"), entry);
|
||||
}
|
||||
|
||||
// Test some well-known variables
|
||||
JSONObject variable = variablesByName.get("bpm_description");
|
||||
assertNotNull(variable);
|
||||
assertEquals("d:text", variable.get("type"));
|
||||
assertNull(variable.get("value"));
|
||||
|
||||
variable = variablesByName.get("bpm_percentComplete");
|
||||
assertNotNull(variable);
|
||||
assertEquals("d:int", variable.get("type"));
|
||||
assertEquals(0L, variable.get("value"));
|
||||
|
||||
variable = variablesByName.get("bpm_sendEMailNotifications");
|
||||
assertNotNull(variable);
|
||||
assertEquals("d:boolean", variable.get("type"));
|
||||
assertEquals(Boolean.FALSE, variable.get("value"));
|
||||
|
||||
variable = variablesByName.get("bpm_package");
|
||||
assertNotNull(variable);
|
||||
assertEquals("bpm:workflowPackage", variable.get("type"));
|
||||
assertNotNull(variable.get("value"));
|
||||
|
||||
variable = variablesByName.get("bpm_assignee");
|
||||
assertNotNull(variable);
|
||||
assertEquals("cm:person", variable.get("type"));
|
||||
assertEquals(requestContext.getRunAsUser(), variable.get("value"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testUpdateProcessVariables() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
|
||||
ProcessInfo processRest = startAdhocProcess(requestContext, null);
|
||||
|
||||
try
|
||||
{
|
||||
assertNotNull(processRest);
|
||||
String processId = processRest.getId();
|
||||
|
||||
// Update an unexisting variable, creates a new one using explicit typing (d:long)
|
||||
JSONObject variableJson = new JSONObject();
|
||||
variableJson.put("name", "newVariable");
|
||||
variableJson.put("value", 1234L);
|
||||
variableJson.put("type", "d:long");
|
||||
|
||||
JSONObject resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
|
||||
assertNotNull(resultEntry);
|
||||
JSONObject result = (JSONObject) resultEntry.get("entry");
|
||||
|
||||
assertEquals("newVariable", result.get("name"));
|
||||
assertEquals(1234L, result.get("value"));
|
||||
assertEquals("d:long", result.get("type"));
|
||||
assertEquals(1234L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
|
||||
|
||||
|
||||
// Update an unexisting variable, creates a new one using no tying
|
||||
variableJson = new JSONObject();
|
||||
variableJson.put("name", "stringVariable");
|
||||
variableJson.put("value", "This is a string value");
|
||||
|
||||
resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
|
||||
assertNotNull(resultEntry);
|
||||
result = (JSONObject) resultEntry.get("entry");
|
||||
|
||||
assertEquals("stringVariable", result.get("name"));
|
||||
assertEquals("This is a string value", result.get("value"));
|
||||
assertEquals("d:text", result.get("type"));
|
||||
assertEquals("This is a string value", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
|
||||
|
||||
|
||||
// Update an existing variable, creates a new one using explicit typing (d:long)
|
||||
variableJson = new JSONObject();
|
||||
variableJson.put("name", "newVariable");
|
||||
variableJson.put("value", 4567L);
|
||||
variableJson.put("type", "d:long");
|
||||
|
||||
resultEntry = publicApiClient.processesClient().updateVariable(processId, "newVariable", variableJson);
|
||||
assertNotNull(resultEntry);
|
||||
result = (JSONObject) resultEntry.get("entry");
|
||||
|
||||
assertEquals("newVariable", result.get("name"));
|
||||
assertEquals(4567L, result.get("value"));
|
||||
assertEquals("d:long", result.get("type"));
|
||||
assertEquals(4567L, activitiProcessEngine.getRuntimeService().getVariable(processId, "newVariable"));
|
||||
|
||||
|
||||
// Update an existing variable, creates a new one using no explicit typing
|
||||
variableJson = new JSONObject();
|
||||
variableJson.put("name", "stringVariable");
|
||||
variableJson.put("value", "Updated string variable");
|
||||
|
||||
resultEntry = publicApiClient.processesClient().updateVariable(processId, "stringVariable", variableJson);
|
||||
assertNotNull(resultEntry);
|
||||
result = (JSONObject) resultEntry.get("entry");
|
||||
|
||||
assertEquals("stringVariable", result.get("name"));
|
||||
assertEquals("Updated string variable", result.get("value"));
|
||||
assertEquals("d:text", result.get("type"));
|
||||
assertEquals("Updated string variable", activitiProcessEngine.getRuntimeService().getVariable(processId, "stringVariable"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteProcessVariable() throws Exception
|
||||
{
|
||||
RequestContext requestContext = initApiClientWithTestUser();
|
||||
ProcessInfo processRest = startAdhocProcess(requestContext, null);
|
||||
|
||||
try
|
||||
{
|
||||
assertNotNull(processRest);
|
||||
String processId = processRest.getId();
|
||||
|
||||
// Create a variable to be deleted
|
||||
activitiProcessEngine.getRuntimeService().setVariable(processId, "deleteMe", "This is a string");
|
||||
|
||||
// Delete variable
|
||||
publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
|
||||
assertFalse(activitiProcessEngine.getRuntimeService().hasVariable(processId, "deleteMe"));
|
||||
|
||||
// Deleting again should fail with 404, as variable doesn't exist anymore
|
||||
try {
|
||||
publicApiClient.processesClient().deleteVariable(processId, "deleteMe");
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: deleteMe was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cleanupProcessInstance(processRest.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeleteProcessVariableUnexistingProcess() throws Exception
|
||||
{
|
||||
initApiClientWithTestUser();
|
||||
|
||||
try {
|
||||
publicApiClient.processesClient().deleteVariable("unexisting", "deleteMe");
|
||||
fail("Exception expected");
|
||||
} catch(PublicApiException expected) {
|
||||
assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
|
||||
assertErrorSummary("The entity with id: unexisting was not found", expected.getHttpResponse());
|
||||
}
|
||||
}
|
||||
|
||||
protected void completeAdhocTasks(String instanceId, RequestContext requestContext) {
|
||||
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(instanceId).singleResult();
|
||||
assertEquals(requestContext.getRunAsUser(), task.getAssignee());
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
activitiProcessEngine.getTaskService().complete(task.getId());
|
||||
return null;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
final Task task2 = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(instanceId).singleResult();
|
||||
assertEquals(requestContext.getRunAsUser(), task2.getAssignee());
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
activitiProcessEngine.getTaskService().complete(task2.getId());
|
||||
return null;
|
||||
}
|
||||
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
|
||||
|
||||
assertEquals(0, activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(instanceId).count());
|
||||
cleanupProcessInstance(instanceId);
|
||||
}
|
||||
|
||||
protected void cleanupProcessInstance(String... processInstances)
|
||||
{
|
||||
// Clean up process-instance regardless of test success/failure
|
||||
try
|
||||
{
|
||||
for (String processInstanceId : processInstances)
|
||||
{
|
||||
// try catch because runtime process may not exist anymore
|
||||
try
|
||||
{
|
||||
activitiProcessEngine.getRuntimeService().deleteProcessInstance(processInstanceId, null);
|
||||
}
|
||||
catch(Exception e) {}
|
||||
activitiProcessEngine.getHistoryService().deleteHistoricProcessInstance(processInstanceId);
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// Ignore error during cleanup
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class ProcessesParser extends ListParser<ProcessInfo>
|
||||
{
|
||||
public static ProcessesParser INSTANCE = new ProcessesParser();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ProcessInfo parseEntry(JSONObject entry)
|
||||
{
|
||||
ProcessInfo processesRest = new ProcessInfo();
|
||||
processesRest.setId((String) entry.get("id"));
|
||||
processesRest.setProcessDefinitionId((String) entry.get("processDefinitionId"));
|
||||
processesRest.setProcessDefinitionKey((String) entry.get("processDefinitionKey"));
|
||||
processesRest.setStartedAt(WorkflowApiClient.parseDate(entry, "startedAt"));
|
||||
processesRest.setEndedAt(WorkflowApiClient.parseDate(entry, "endedAt"));
|
||||
processesRest.setDurationInMillis((Long) entry.get("durationInMillis"));
|
||||
processesRest.setDeleteReason((String) entry.get("deleteReason"));
|
||||
processesRest.setBusinessKey((String) entry.get("businessKey"));
|
||||
processesRest.setSuperProcessInstanceId((String) entry.get("superProcessInstanceId"));
|
||||
processesRest.setVariables((Map<String,Object>) entry.get("variables"));
|
||||
processesRest.setItems((Set<String>) entry.get("item"));
|
||||
return processesRest;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,270 @@
|
||||
package org.alfresco.rest.workflow.api.tests;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient;
|
||||
import org.alfresco.rest.api.tests.client.UserDataService;
|
||||
import org.alfresco.rest.workflow.api.model.Deployment;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessDefinition;
|
||||
import org.alfresco.rest.workflow.api.model.ProcessInfo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class WorkflowApiClient extends PublicApiClient
|
||||
{
|
||||
public static final DateFormat DATE_FORMAT_ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
private DeploymentsClient deploymentsClient;
|
||||
private ProcessDefinitionsClient processDefinitionsClient;
|
||||
private ProcessesClient processesClient;
|
||||
private TasksClient tasksClient;
|
||||
|
||||
public WorkflowApiClient(PublicApiHttpClient client, UserDataService userDataService) {
|
||||
super(client, userDataService);
|
||||
initWorkflowClients();
|
||||
}
|
||||
|
||||
public void initWorkflowClients()
|
||||
{
|
||||
deploymentsClient = new DeploymentsClient();
|
||||
processDefinitionsClient = new ProcessDefinitionsClient();
|
||||
processesClient = new ProcessesClient();
|
||||
tasksClient = new TasksClient();
|
||||
}
|
||||
|
||||
public DeploymentsClient deploymentsClient()
|
||||
{
|
||||
return deploymentsClient;
|
||||
}
|
||||
|
||||
|
||||
public ProcessDefinitionsClient processDefinitionsClient()
|
||||
{
|
||||
return processDefinitionsClient;
|
||||
}
|
||||
|
||||
public ProcessesClient processesClient()
|
||||
{
|
||||
return processesClient;
|
||||
}
|
||||
|
||||
public TasksClient tasksClient()
|
||||
{
|
||||
return tasksClient;
|
||||
}
|
||||
|
||||
public class DeploymentsClient extends AbstractProxy
|
||||
{
|
||||
public ListResponse<Deployment> getDeployments(Map<String, String> params) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("deployments", null, null, null, params, "Failed to get deploymentsClient");
|
||||
return DeploymentParser.INSTANCE.parseList(response.getJsonResponse());
|
||||
}
|
||||
|
||||
public ListResponse<Deployment> getDeployments() throws PublicApiException
|
||||
{
|
||||
return getDeployments(null);
|
||||
}
|
||||
|
||||
/*public ListResponse<Deployment> createNewDeployment(String name, byte[] bytes) throws PublicApiException
|
||||
{
|
||||
Part[] parts = new Part[]{
|
||||
new StringPart("name", name),
|
||||
new FilePart("file", new ByteArrayPartSource("bytes", bytes))
|
||||
};
|
||||
RequestEntity requestEntity = new MultipartRequestEntity(parts, null);
|
||||
HttpResponse response = create("deployments", null, null, null, requestEntity, "Failed to create new deployment");
|
||||
return DeploymentParser.INSTANCE.parseList(response.getJsonResponse());
|
||||
}*/
|
||||
|
||||
public Deployment findDeploymentById(String deploymentId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getSingle("deployments", deploymentId, null, null, "Failed to get deployment");
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return DeploymentParser.INSTANCE.parseEntry(entry);
|
||||
}
|
||||
|
||||
public void deleteDeployment(String deploymentId) throws PublicApiException
|
||||
{
|
||||
remove("deployments", deploymentId, null, null, "Failed to delete deployment");
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessDefinitionsClient extends AbstractProxy
|
||||
{
|
||||
public ListResponse<ProcessDefinition> getProcessDefinitions(Map<String, String> params) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("process-definitions", null, null, null, params, "Failed to get process definitions");
|
||||
return ProcessDefinitionParser.INSTANCE.parseList(response.getJsonResponse());
|
||||
}
|
||||
|
||||
public ProcessDefinition findProcessDefinitionById(String processDefinitionId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getSingle("process-definitions", processDefinitionId, null, null, "Failed to get process definition");
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return ProcessDefinitionParser.INSTANCE.parseEntry(entry);
|
||||
}
|
||||
|
||||
public JSONObject findStartFormModel(String processDefinitionId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("process-definitions", processDefinitionId, "start-form-model", null, null,
|
||||
"Failed to get the start form model of the process definition");
|
||||
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcessesClient extends AbstractProxy
|
||||
{
|
||||
public ProcessInfo createProcess(String body) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = create("processes", null, null, null, body, "Failed to start new process instance");
|
||||
return ProcessesParser.INSTANCE.parseEntry((JSONObject) response.getJsonResponse().get("entry"));
|
||||
}
|
||||
|
||||
public ListResponse<ProcessInfo> getProcesses(Map<String, String> params) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("processes", null, null, null, params, "Failed to get process instances");
|
||||
return ProcessesParser.INSTANCE.parseList(response.getJsonResponse());
|
||||
}
|
||||
|
||||
public ProcessInfo findProcessById(String processInstanceId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getSingle("processes", processInstanceId, null, null, "Failed to find process instance by id");
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return ProcessesParser.INSTANCE.parseEntry(entry);
|
||||
}
|
||||
|
||||
public JSONObject findProcessItems(String processInstanceId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("processes", processInstanceId, "items", null, null,
|
||||
"Failed to get the items of the process instance");
|
||||
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
|
||||
return list;
|
||||
}
|
||||
|
||||
public JSONObject getProcessvariables(String processInstanceId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("processes", processInstanceId, "variables", null, null,
|
||||
"Failed to get the variables of the process instance");
|
||||
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
|
||||
return list;
|
||||
}
|
||||
|
||||
public JSONObject updateVariable(String processId, String variableName, JSONObject variable) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = update("processes", processId, "variables", variableName, variable.toJSONString(), "Failed to update variable");
|
||||
return response.getJsonResponse();
|
||||
}
|
||||
|
||||
public void deleteVariable(String processId, String variableName) throws PublicApiException
|
||||
{
|
||||
remove("processes", processId, "variables", variableName, "Failed to delete variable");
|
||||
}
|
||||
|
||||
public void deleteProcessItem(String processId, String itemId) throws PublicApiException
|
||||
{
|
||||
remove("processes", processId, "items", itemId, "Failed to delete item");
|
||||
}
|
||||
|
||||
public JSONObject findProcessItem(String processInstanceId, String itemId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("processes", processInstanceId, "items", itemId, null,
|
||||
"Failed to get the item of the process instance");
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void deleteProcessById(String processId) throws PublicApiException
|
||||
{
|
||||
remove("processes", processId, null, null, "Failed to delete process");
|
||||
}
|
||||
}
|
||||
|
||||
public class TasksClient extends AbstractProxy
|
||||
{
|
||||
public JSONObject findTaskById(String taskId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getSingle("tasks", taskId, null, null, "Failed to get task");
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return entry;
|
||||
}
|
||||
|
||||
public JSONObject updateTask(String taskId, JSONObject task, List<String> selectedFields) throws PublicApiException
|
||||
{
|
||||
String selectedFieldsValue = StringUtils.join(selectedFields, ",");
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("select", selectedFieldsValue);
|
||||
|
||||
HttpResponse response = update("tasks", taskId, null, null, task.toJSONString(), "Failed to update task", params);
|
||||
|
||||
JSONObject entry = (JSONObject) response.getJsonResponse().get("entry");
|
||||
return entry;
|
||||
}
|
||||
|
||||
public JSONObject findTasks(Map<String, String> params) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("tasks", null, null, null, params, "Failed to get all tasks");
|
||||
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
|
||||
return list;
|
||||
}
|
||||
|
||||
public JSONObject findTaskCandidates(String taskId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("tasks", taskId, "candidates", null, null, "Failed to get task candidates");
|
||||
return response.getJsonResponse();
|
||||
}
|
||||
|
||||
public JSONObject findTaskVariables(String taskId, Map<String, String> params) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("tasks", taskId, "variables", null, params, "Failed to get task variables");
|
||||
return response.getJsonResponse();
|
||||
}
|
||||
|
||||
public JSONObject findTaskVariables(String taskId) throws PublicApiException
|
||||
{
|
||||
return findTaskVariables(taskId, null);
|
||||
}
|
||||
|
||||
public JSONObject updateTaskVariable(String taskId, String variableName, JSONObject variable) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = update("tasks", taskId, "variables", variableName, variable.toJSONString(), "Failed to update task variable");
|
||||
return response.getJsonResponse();
|
||||
}
|
||||
|
||||
public void deleteTaskVariable(String taskId, String variableName) throws PublicApiException
|
||||
{
|
||||
remove("tasks", taskId, "variables", variableName, "Failed to delete task variable");
|
||||
}
|
||||
|
||||
public JSONObject findTaskFormModel(String taskId) throws PublicApiException
|
||||
{
|
||||
HttpResponse response = getAll("tasks", taskId, "task-form-model", null, null, "Failed to get task form model");
|
||||
JSONObject list = (JSONObject) response.getJsonResponse().get("list");
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public static Date parseDate(JSONObject entry, String fieldName) {
|
||||
String dateText = (String) entry.get(fieldName);
|
||||
if (dateText!=null) {
|
||||
try
|
||||
{
|
||||
return DATE_FORMAT_ISO8601.parse(dateText);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException("couldn't parse date "+dateText+": "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user