Fixes to Invite Service to expose internal invite workflow instance ID externally as invite ID for all Invite Web Scripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9822 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Glen Johnson
2008-07-11 17:10:46 +00:00
parent 56d2fb57f7
commit a3412c899e
7 changed files with 64 additions and 56 deletions

View File

@@ -2,7 +2,7 @@
<shortname>Invite</shortname>
<description>Processes Inviter actions ('start' or 'cancel' invite)</description>
<url>/api/invite/start?inviteeEmail={inviteeEmailAddress}&amp;siteShortName={siteShortName}</url>
<url>/api/invite/cancel?workflowId={workflowId}</url>
<url>/api/invite/cancel?inviteId={inviteId}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>

View File

@@ -1,7 +1,7 @@
<#if action == "start">
<p>Invite to join site ${siteShortName} has been sent to ${inviteeUserName}</p>
<#elseif action == "cancel">
<p>Invite process with workflow ID ${workflowId} has been cancelled</p>
<p>Invite with ID ${inviteId} has been cancelled</p>
<#else>
<p>Error: unknown invite action ${action}</p>
</#if>

View File

@@ -1,9 +1,9 @@
{
"action" : "${action}",
<#if workflowId??>
"workflowId" : "${workflowId}",
<#if inviteId??>
"inviteId" : "${inviteId}",
<#else>
"workflowId" : undefined,
"inviteId" : undefined,
</#if>
<#if inviteeUserName??>
"inviteeUserName" : "${inviteeUserName}",

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Invite Response</shortname>
<description>Processes invite response from Invitee</description>
<url>/api/inviteresponse/{response}?workflowId={workflowId}&amp;inviteeUserName={inviteeUserName}&amp;siteShortName={siteShortName}</url>
<url>/api/inviteresponse/{response}?inviteId={inviteId}&amp;inviteeUserName={inviteeUserName}&amp;siteShortName={siteShortName}</url>
<format default="json"/>
<authentication>guest</authentication>
<transaction>required</transaction>

View File

@@ -64,14 +64,14 @@ public class Invite extends DeclarativeWebScript
private static final String TRANSITION_SEND_INVITE = "sendInvite";
private static final String MODEL_PROP_KEY_ACTION = "action";
private static final String MODEL_PROP_KEY_WORKFLOW_ID = "workflowId";
private static final String MODEL_PROP_KEY_INVITE_ID = "inviteId";
private static final String MODEL_PROP_KEY_INVITEE_USER_NAME = "inviteeUserName";
private static final String MODEL_PROP_KEY_SITE_SHORT_NAME = "siteShortName";
// URL request parameter names
private static final String PARAM_INVITEE_EMAIL = "inviteeEmail";
private static final String PARAM_SITE_SHORT_NAME = "siteShortName";
private static final String PARAM_WORKFLOW_ID = "workflowId";
private static final String PARAM_INVITE_ID = "inviteId";
// services
private WorkflowService workflowService;
@@ -255,19 +255,19 @@ public class Invite extends DeclarativeWebScript
// else handle if provided 'action' is 'cancel'
else if (action.equals(ACTION_CANCEL))
{
// check for 'workflowId' parameter not provided
String workflowId = req.getParameter(PARAM_WORKFLOW_ID);
if ((workflowId == null) || (workflowId.length() == 0))
// check for 'inviteId' parameter not provided
String inviteId = req.getParameter(PARAM_INVITE_ID);
if ((inviteId == null) || (inviteId.length() == 0))
{
// handle workflowId URL parameter not provided
// handle inviteId URL parameter not provided
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"'workflowId' parameter has "
"'inviteId' parameter has "
+ "not been provided in URL for action '"
+ ACTION_CANCEL + "'");
}
// process action 'cancel' with provided parameters
cancelInvite(model, workflowId);
cancelInvite(model, inviteId);
}
// handle action not recognised
else
@@ -401,7 +401,7 @@ public class Invite extends DeclarativeWebScript
// add model properties for template to render
model.put(MODEL_PROP_KEY_ACTION, ACTION_START);
model.put(MODEL_PROP_KEY_WORKFLOW_ID, workflowId);
model.put(MODEL_PROP_KEY_INVITE_ID, workflowId);
model.put(MODEL_PROP_KEY_INVITEE_USER_NAME, inviteeUserName);
model.put(MODEL_PROP_KEY_SITE_SHORT_NAME, siteShortName);
}
@@ -413,25 +413,25 @@ public class Invite extends DeclarativeWebScript
* @param model
* model to add objects to, which will be passed to the template
* for rendering
* @param workflowId
* workflow id of the invite process that inviter wishes to
* @param inviteId
* invite id of the invitation that inviter wishes to
* cancel
*/
private void cancelInvite(Map<String, Object> model, String workflowId)
private void cancelInvite(Map<String, Object> model, String inviteId)
{
// handle workflow instance for given workflow ID does not exist
if ((workflowId == null) || (workflowId.length() == 0))
// handle given invite ID null or empty
if ((inviteId == null) || (inviteId.length() == 0))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"Workflow instance for given " + "workflow ID "
+ workflowId + " does not exist");
"Given invite ID " + inviteId + " null or empty");
}
// cancel the workflow
this.workflowService.cancelWorkflow(workflowId);
// cancel the workflow with the given invite ID
// which is actually the workflow ID
this.workflowService.cancelWorkflow(inviteId);
// add model properties for template to render
model.put(MODEL_PROP_KEY_ACTION, ACTION_CANCEL);
model.put(MODEL_PROP_KEY_WORKFLOW_ID, workflowId);
model.put(MODEL_PROP_KEY_INVITE_ID, inviteId);
}
}

View File

@@ -158,7 +158,7 @@ public class InviteResponse extends DeclarativeWebScript
Map<String, Object> model = new HashMap<String, Object>();
// get the URL parameter values
String workflowId = req.getParameter("workflowId");
String inviteId = req.getParameter("inviteId");
String inviteeUserName = req.getParameter("inviteeUserName");
String siteShortName = req.getParameter("siteShortName");
@@ -172,12 +172,12 @@ public class InviteResponse extends DeclarativeWebScript
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"response has not been provided as part of URL.");
}
// check that workflow id URL parameter has been provided
else if ((workflowId == null) || (workflowId.length() == 0))
// check that invite id URL parameter has been provided
else if ((inviteId == null) || (inviteId.length() == 0))
{
// handle workflow id not provided
// handle invite id not provided
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
"workflow id parameter has not been provided in the URL.");
"invite id parameter has not been provided in the URL.");
}
// check that inviteeUserName URL parameter has been provided
else if ((inviteeUserName == null) || (inviteeUserName.length() == 0))
@@ -197,10 +197,10 @@ public class InviteResponse extends DeclarativeWebScript
// process response
if (response.equals(RESPONSE_ACCEPT))
{
acceptInvite(model, workflowId, inviteeUserName, siteShortName);
acceptInvite(model, inviteId, inviteeUserName, siteShortName);
} else if (response.equals(RESPONSE_REJECT))
{
rejectInvite(model, workflowId, inviteeUserName, siteShortName);
rejectInvite(model, inviteId, inviteeUserName, siteShortName);
} else
{
/* handle unrecognised response */
@@ -219,18 +219,22 @@ public class InviteResponse extends DeclarativeWebScript
* @param model
* model to add objects to, which will be passed to the template
* for rendering
* @param workflowId
* string id of invite process workflow instance
* @param inviteId
* ID of invite
* @param inviteeUserName
* string user name of invitee
* user name of invitee
* @param siteShortName
* string short name of site for which invitee is accepting
* short name of site for which invitee is accepting
* invitation to join
*/
private void acceptInvite(Map<String, Object> model, String workflowId,
private void acceptInvite(Map<String, Object> model, String inviteId,
String inviteeUserName, String siteShortName)
{
// get workflow paths associated with given workflow ID
// get workflow ID from invite ID (of which the value is actually
// just the ID of the invite workflow instance)
String workflowId = inviteId;
// get workflow paths associated with workflow ID
List<WorkflowPath> wfPaths = this.workflowService
.getWorkflowPaths(workflowId);
@@ -269,18 +273,22 @@ public class InviteResponse extends DeclarativeWebScript
* @param model
* model to add objects to, which will be passed to the template
* for rendering
* @param workflowId
* string id of invite process workflow instance
* @param inviteId
* ID of invite
* @param inviteeUserName
* string user name of invitee
* user name of invitee
* @param siteShortName
* string short name of site for which invitee is rejecting
* short name of site for which invitee is rejecting
* invitation to join
*/
private void rejectInvite(Map<String, Object> model, String workflowId,
private void rejectInvite(Map<String, Object> model, String inviteId,
String inviteeUserName, String siteShortName)
{
// get workflow paths associated with given workflow ID
// get workflow ID from invite ID (of which the value is actually
// just the ID of the invite workflow instance)
String workflowId = inviteId;
// get workflow paths associated with workflow ID
List<WorkflowPath> wfPaths = this.workflowService
.getWorkflowPaths(workflowId);

View File

@@ -235,24 +235,24 @@ public class InviteServiceTest extends BaseWebScriptTest
JSONObject result = startInvite(INVITEE_EMAIL, SITE_SHORT_NAME_INVITE,
Status.STATUS_OK);
// get hold of workflow ID of started invite workflow instance
String workflowId = result.getString("workflowId");
// get hold of invite ID of started invite
String inviteId = result.getString("inviteId");
// Inviter cancels pending invitation
String cancelInviteUrl = URL_INVITE_SERVICE + "/"
+ INVITE_ACTION_CANCEL + "?workflowId=" + workflowId;
+ INVITE_ACTION_CANCEL + "?inviteId=" + inviteId;
MockHttpServletResponse response = getRequest(cancelInviteUrl,
Status.STATUS_OK);
}
public void testAcceptInvite() throws Exception
{
// inviter starts invite workflow
// inviter starts invite (sends out invitation)
JSONObject result = startInvite(INVITEE_EMAIL, SITE_SHORT_NAME_INVITE,
Status.STATUS_OK);
// get hold of workflow ID of started invite workflow instance
String workflowId = result.getString("workflowId");
// get hold of invite ID of started invite
String inviteId = result.getString("inviteId");
// get hold of invitee user name that was generated as part of starting
// the invite
@@ -260,7 +260,7 @@ public class InviteServiceTest extends BaseWebScriptTest
// Invitee accepts invitation to a Site from Inviter
String acceptInviteUrl = URL_INVITERSP_SERVICE + "/"
+ INVITE_RSP_ACCEPT + "?workflowId=" + workflowId
+ INVITE_RSP_ACCEPT + "?inviteId=" + inviteId
+ "&inviteeUserName=" + inviteeUserName + "&siteShortName="
+ SITE_SHORT_NAME_INVITE;
MockHttpServletResponse response = getRequest(acceptInviteUrl,
@@ -269,12 +269,12 @@ public class InviteServiceTest extends BaseWebScriptTest
public void testRejectInvite() throws Exception
{
// inviter starts invite workflow
// inviter starts invite (sends out invitation)
JSONObject result = startInvite(INVITEE_EMAIL, SITE_SHORT_NAME_INVITE,
Status.STATUS_OK);
// get hold of workflow ID of started invite workflow instance
String workflowId = result.getString("workflowId");
// get hold of invite ID of started invite
String inviteId = result.getString("inviteId");
// get hold of invitee user name that was generated as part of starting
// the invite
@@ -282,7 +282,7 @@ public class InviteServiceTest extends BaseWebScriptTest
// Invitee rejects invitation to a Site from Inviter
String rejectInviteUrl = URL_INVITERSP_SERVICE + "/"
+ INVITE_RSP_REJECT + "?workflowId=" + workflowId
+ INVITE_RSP_REJECT + "?inviteId=" + inviteId
+ "&inviteeUserName=" + inviteeUserName + "&siteShortName="
+ SITE_SHORT_NAME_INVITE;
MockHttpServletResponse response = getRequest(rejectInviteUrl,
@@ -297,7 +297,7 @@ public class InviteServiceTest extends BaseWebScriptTest
// get hold of workflow ID of started invite workflow instance
String inviteId = startInviteResult.getString("workflowId");
String inviteId = startInviteResult.getString("inviteId");
assertEquals(true, ((inviteId != null) && (inviteId.length() != 0)));