From f8d631f9f1ae80401ad9656eb828d255203b2cb0 Mon Sep 17 00:00:00 2001 From: Glen Johnson Date: Thu, 10 Jul 2008 10:10:03 +0000 Subject: [PATCH] Latest fixes for Java-backed Invite REST API Web Scripts - but invites.get (pending invites) still failing on Unit Tests git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9714 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/web/scripts/invite/Invite.java | 15 ++++---- .../web/scripts/invite/InviteResponse.java | 38 ++++++++++++++++++- .../repo/web/scripts/invite/Invites.java | 5 +-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java index 3db87012f3..007ca2cf3b 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invite.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invite.java @@ -53,7 +53,6 @@ import org.alfresco.web.scripts.WebScriptRequest; */ public class Invite extends DeclarativeWebScript { - private static final String WORKFLOW_DEFINITION_NAME = "jbpm$wf:invite"; private static final String ACTION_START = "start"; private static final String ACTION_CANCEL = "cancel"; private static final String TRANSITION_SEND_INVITE = "sendInvite"; @@ -68,12 +67,6 @@ public class Invite extends DeclarativeWebScript private static final String PARAM_SITE_SHORT_NAME = "siteShortName"; private static final String PARAM_WORKFLOW_ID = "workflowId"; - // workflow properties - public static final String WF_PROP_INVITER_USER_NAME = "wf:inviterUserName"; - public static final String WF_PROP_INVITEE_USER_NAME = "wf:inviteeUserName"; - public static final String WF_PROP_SITE_SHORT_NAME = "wf:siteShortName"; - private static final String WF_PROP_INVITEE_GEN_PASSWORD = "wf:inviteeGenPassword"; - // services private WorkflowService workflowService; private PersonService personService; @@ -84,6 +77,14 @@ public class Invite extends DeclarativeWebScript private UserNameGenerator usernameGenerator; private PasswordGenerator passwordGenerator; + // workflow properties + public static final String WF_PROP_INVITER_USER_NAME = "wf:inviterUserName"; + public static final String WF_PROP_INVITEE_USER_NAME = "wf:inviteeUserName"; + public static final String WF_PROP_SITE_SHORT_NAME = "wf:siteShortName"; + private static final String WF_PROP_INVITEE_GEN_PASSWORD = "wf:inviteeGenPassword"; + + public static final String WORKFLOW_DEFINITION_NAME = "jbpm$wf:invite"; + /** * Sets the workflowService property * diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java index ad248888a9..7a10a8eace 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java @@ -25,12 +25,14 @@ package org.alfresco.repo.web.scripts.invite; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.alfresco.repo.security.authentication.MutableAuthenticationDao; import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.site.SiteService; import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.cmr.workflow.WorkflowPath; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.web.scripts.DeclarativeWebScript; import org.alfresco.web.scripts.Status; @@ -193,7 +195,23 @@ public class InviteResponse extends DeclarativeWebScript private void acceptInvite(Map model, String workflowId, String inviteeUserName, String siteShortName) { - this.workflowService.signal(workflowId, TRANSITION_ACCEPT); + // get workflow paths associated with given workflow ID + List wfPaths = this.workflowService.getWorkflowPaths(workflowId); + + // throw web script exception if there is not at least one workflow path + // associated with this workflow ID + if ((wfPaths == null) || (wfPaths.size() == 0)) + { + throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, + "There are no workflow paths associated with workflow ID: " + + workflowId); + } + + // get workflow path ID for path matching workflow ID + WorkflowPath wfPath = wfPaths.get(0); + String wfPathID = wfPath.id; + + this.workflowService.signal(wfPathID, TRANSITION_ACCEPT); // enable invitee person's user account because he/she has accepted the // site invitation @@ -225,7 +243,23 @@ public class InviteResponse extends DeclarativeWebScript private void rejectInvite(Map model, String workflowId, String inviteeUserName, String siteShortName) { - this.workflowService.signal(workflowId, TRANSITION_REJECT); + // get workflow paths associated with given workflow ID + List wfPaths = this.workflowService.getWorkflowPaths(workflowId); + + // throw web script exception if there is not at least one workflow path + // associated with this workflow ID + if ((wfPaths == null) || (wfPaths.size() == 0)) + { + throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, + "There are no workflow paths associated with workflow ID: " + + workflowId); + } + + // get workflow path ID for path matching workflow ID + WorkflowPath wfPath = wfPaths.get(0); + String wfPathID = wfPath.id; + + this.workflowService.signal(wfPathID, TRANSITION_REJECT); // delete the person created for invitee this.personService.deletePerson(inviteeUserName); diff --git a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java index a1f05af8c0..9e0ef50ad3 100644 --- a/source/java/org/alfresco/repo/web/scripts/invite/Invites.java +++ b/source/java/org/alfresco/repo/web/scripts/invite/Invites.java @@ -71,9 +71,6 @@ public class Invites extends DeclarativeWebScript // model key names private static final String MODEL_KEY_NAME_INVITES = "invites"; - // invite process definition name - private static final QName WF_INVITE_PROCESS_DEFINITION_QNAME = QName.createQName("wf:invite"); - // service instances private WorkflowService workflowService; @@ -183,7 +180,7 @@ public class Invites extends DeclarativeWebScript // set process name to "wf:invite" so that only tasks associated with invite workflow instances // are returned by query - wfTaskQuery.setProcessName(WF_INVITE_PROCESS_DEFINITION_QNAME); + wfTaskQuery.setProcessName(QName.createQName(Invite.WORKFLOW_DEFINITION_NAME)); // query for invite workflow tasks List wf_invite_tasks = this.workflowService.queryTasks(wfTaskQuery);