mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged BRANCHES/DEV/BELARUS/HEAD_2010_08_09 to HEAD:
21702: ALF-3903 : F91 REST API to get workflow instances for a node git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21714 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 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.repo.web.scripts.workflow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowInstance;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* @author unknown
|
||||
* @since 3.4
|
||||
*
|
||||
*/
|
||||
public class WorkflowInstancesForNodeGet extends AbstractWorkflowWebscript
|
||||
{
|
||||
|
||||
public static final String PARAM_STORE_TYPE = "store_type";
|
||||
public static final String PARAM_STORE_ID = "store_id";
|
||||
public static final String PARAM_NODE_ID = "id";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
Map<String, String> params = req.getServiceMatch().getTemplateVars();
|
||||
|
||||
// get nodeRef from request
|
||||
NodeRef nodeRef = new NodeRef(params.get(PARAM_STORE_TYPE), params.get(PARAM_STORE_ID), params.get(PARAM_NODE_ID));
|
||||
|
||||
// list all active workflows for nodeRef
|
||||
List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent(nodeRef, true);
|
||||
|
||||
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(workflows.size());
|
||||
|
||||
for (WorkflowInstance workflow : workflows)
|
||||
{
|
||||
results.add(modelBuilder.buildSimple(workflow));
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
// build the model for ftl
|
||||
model.put("workflowInstances", results);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
@@ -25,12 +25,17 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.person.TestPersonManager;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.alfresco.repo.workflow.WorkflowModel;
|
||||
import org.alfresco.service.cmr.dictionary.TypeDefinition;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
|
||||
@@ -64,16 +69,22 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
||||
{
|
||||
private final static String USER1 = "Bob" + GUID.generate();
|
||||
private final static String USER2 = "Jane" + GUID.generate();
|
||||
private final static String USER3 = "Nick" + GUID.generate();
|
||||
private final static String USER3 = "Nick" + GUID.generate();
|
||||
private static final String URL_TASKS = "api/task-instances";
|
||||
private static final String URL_WORKFLOW_DEFINITIONS = "api/workflow-definitions";
|
||||
private static final String URL_WORKFLOW_INSTANCES = "api/workflow-instances";
|
||||
private static final String URL_WORKFLOW_INSTANCES_FOR_DEFINITION = "api/workflow-definitions/{0}/workflow-instances";
|
||||
private static final String URL_WORKFLOW_INSTANCES_FOR_NODE = "api/node/{0}/{1}/{2}/workflow-instances";
|
||||
|
||||
private static final String COMPANY_HOME = "/app:company_home";
|
||||
private static final String TEST_CONTENT = "TestContent";
|
||||
|
||||
private TestPersonManager personManager;
|
||||
private WorkflowService workflowService;
|
||||
private NodeService nodeService;
|
||||
private NamespaceService namespaceService;
|
||||
private NodeRef packageRef;
|
||||
private NodeRef contentNodeRef;
|
||||
|
||||
public void testTaskInstancesGet() throws Exception
|
||||
{
|
||||
@@ -473,7 +484,7 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
||||
JSONArray priorityFilteredResult = priorityFilteredJson.getJSONArray("data");
|
||||
assertNotNull(priorityFilteredResult);
|
||||
|
||||
assertTrue(priorityFilteredResult.length() > 1);
|
||||
assertTrue(priorityFilteredResult.length() > 0);
|
||||
|
||||
// filter by state
|
||||
String stateFilter = "?state=active";
|
||||
@@ -488,6 +499,48 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
||||
assertTrue(stateFilteredResult.length() > 1);
|
||||
}
|
||||
|
||||
public void testWorkflowInstancesForNodeGet() throws Exception
|
||||
{
|
||||
//Start workflow as USER1 and assign task to USER2.
|
||||
personManager.setUser(USER1);
|
||||
WorkflowDefinition adhocDef = workflowService.getDefinitionByName("jbpm$wf:adhoc");
|
||||
Map<QName, Serializable> params = new HashMap<QName, Serializable>();
|
||||
params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
|
||||
params.put(WorkflowModel.PROP_DUE_DATE, new Date());
|
||||
params.put(WorkflowModel.PROP_PRIORITY, 1);
|
||||
params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
|
||||
|
||||
nodeService.addChild(packageRef, contentNodeRef,
|
||||
WorkflowModel.ASSOC_PACKAGE_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
|
||||
QName.createValidLocalName((String)nodeService.getProperty(
|
||||
contentNodeRef, ContentModel.PROP_NAME))));
|
||||
|
||||
WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.id, params);
|
||||
|
||||
String url = MessageFormat.format(URL_WORKFLOW_INSTANCES_FOR_NODE, contentNodeRef.getStoreRef().getProtocol(), contentNodeRef.getStoreRef().getIdentifier(), contentNodeRef.getId());
|
||||
Response response = sendRequest(new GetRequest(url), 200);
|
||||
|
||||
assertEquals(Status.STATUS_OK, response.getStatus());
|
||||
String jsonStr = response.getContentAsString();
|
||||
JSONObject json = new JSONObject(jsonStr);
|
||||
JSONArray result = json.getJSONArray("data");
|
||||
assertNotNull(result);
|
||||
|
||||
assertTrue(result.length() > 0);
|
||||
|
||||
workflowService.cancelWorkflow(adhocPath.getInstance().getId());
|
||||
|
||||
Response afterCancelResponse = sendRequest(new GetRequest(url), 200);
|
||||
|
||||
assertEquals(Status.STATUS_OK, afterCancelResponse.getStatus());
|
||||
String afterCancelJsonStr = afterCancelResponse.getContentAsString();
|
||||
JSONObject afterCancelJson = new JSONObject(afterCancelJsonStr);
|
||||
JSONArray afterCancelResult = afterCancelJson.getJSONArray("data");
|
||||
assertNotNull(afterCancelResult);
|
||||
|
||||
assertTrue(afterCancelResult.length() == 0);
|
||||
}
|
||||
|
||||
public void testWorkflowInstanceDelete() throws Exception
|
||||
{
|
||||
//Start workflow as USER1 and assign task to USER2.
|
||||
@@ -523,7 +576,9 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
||||
workflowService = (WorkflowService)appContext.getBean("WorkflowService");
|
||||
MutableAuthenticationService authenticationService = (MutableAuthenticationService)appContext.getBean("AuthenticationService");
|
||||
PersonService personService = (PersonService)appContext.getBean("PersonService");
|
||||
NodeService nodeService = (NodeService)appContext.getBean("NodeService");
|
||||
SearchService searchService = (SearchService)appContext.getBean("SearchService");
|
||||
FileFolderService fileFolderService = (FileFolderService)appContext.getBean("FileFolderService");
|
||||
nodeService = (NodeService)appContext.getBean("NodeService");
|
||||
personManager = new TestPersonManager(authenticationService, personService, nodeService);
|
||||
|
||||
personManager.createPerson(USER1);
|
||||
@@ -531,6 +586,15 @@ public class WorkflowRestApiTest extends BaseWebScriptTest
|
||||
personManager.createPerson(USER3);
|
||||
|
||||
packageRef = workflowService.createPackage(null);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
NodeRef companyHome = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE),
|
||||
COMPANY_HOME, null, namespaceService, false).get(0);
|
||||
|
||||
contentNodeRef = fileFolderService.create(companyHome, TEST_CONTENT + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
Reference in New Issue
Block a user