diff --git a/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java b/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java
new file mode 100644
index 0000000000..ac69417298
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteHelper.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program 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 General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have received a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.web.scripts.invite;
+
+import java.util.Date;
+import java.util.List;
+
+import org.alfresco.service.cmr.workflow.WorkflowService;
+import org.alfresco.service.cmr.workflow.WorkflowTask;
+import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
+import org.alfresco.service.cmr.workflow.WorkflowTaskState;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
+
+/**
+ * Helper class to house utility methods common to
+ * more than one Invite Service Web Script
+ */
+public class InviteHelper
+{
+ /**
+ * Gets the invitee site role from the invite
+ * workflow instance associated with the given invite ID.
+ * i.e. if the inviter 'starts' an invite (which is allocated some invite ID
+ * '12345' when it is processed), and that invite is requesting an invitee to
+ * to join some site under a given site role, then that site role is returned
+ * by this method when invite ID '12345' is passed in.
+ *
+ * @param inviteId the ID of the invitation (invite workflow instance)
+ * from which to retrieve the invitee site role
+ * @return the site role under which the invitee was invited to
+ * join the site. Returns
null
if no invite
+ * workflow instance was found matching the given invite ID
+ */
+ static String getInviteeSiteRoleFromInvite(String inviteId, WorkflowService workflowService,
+ NamespaceService namespaceService)
+ {
+ // create workflow task query
+ WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery();
+
+ wfTaskQuery.setProcessId(inviteId);
+
+ // set process name to "wf:invite" so that only tasks associated with
+ // invite workflow instances are returned by query
+ wfTaskQuery.setProcessName(QName.createQName("wf:invite", namespaceService));
+
+ // pick up the start task because it has the "wf:inviteeSiteRole" property set with the
+ // site role value that we want to retrieve
+ wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);
+ wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, namespaceService));
+
+ // query for invite workflow task associate
+ List inviteStartTasks = workflowService
+ .queryTasks(wfTaskQuery);
+
+ // if no results were returned for given inviteID, then return
+ // site role as null
+ if (inviteStartTasks.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+ // there should be only one start task returned for the given invite ID
+ // so just take the first one in the list
+ WorkflowTask inviteStartTask = inviteStartTasks.get(0);
+
+ String inviteeSiteRole = (String) inviteStartTask.properties.get(
+ QName.createQName(Invite.WF_PROP_INVITEE_SITE_ROLE, namespaceService));
+
+ return inviteeSiteRole;
+ }
+ }
+
+ /**
+ * Gets the date that the invite, with the given invite ID, was sent to the invitee
+ *
+ * @param inviteId the ID of the invitation
+ * from which to retrieve the sent date
+ * @return the date that the invite was sent to the invitee
+ * Returns null
if no invitation
+ * found matching the given invite ID
+ */
+ static Date getSentDateFromInvite(String inviteId, WorkflowService workflowService,
+ NamespaceService namespaceService)
+ {
+ // create workflow task query
+ WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery();
+
+ wfTaskQuery.setProcessId(inviteId);
+
+ // set process name to "wf:invite" so that only tasks associated with
+ // invite workflow instances are returned by query
+ wfTaskQuery.setProcessName(QName.createQName("wf:invite", namespaceService));
+
+ // pick up the start task because it has the "wf:inviteeSiteRole" property set with the
+ // site role value that we want to retrieve
+ wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);
+ wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, namespaceService));
+
+ // query for invite workflow task associate
+ List inviteStartTasks = workflowService
+ .queryTasks(wfTaskQuery);
+
+ // if no results were returned for given inviteID, then return
+ // site role as null
+ if (inviteStartTasks.size() == 0)
+ {
+ return null;
+ }
+ else
+ {
+ // there should be only one start task returned for the given invite ID
+ // so just take the first one in the list
+ WorkflowTask inviteStartTask = inviteStartTasks.get(0);
+
+ Date sentInviteDate = (Date) inviteStartTask.properties.get(
+ QName.createQName(Invite.WF_PROP_SENT_INVITE_DATE, namespaceService));
+
+ return sentInviteDate;
+ }
+ }
+}
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 0f9e1c9a19..50789d4b44 100644
--- a/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java
+++ b/source/java/org/alfresco/repo/web/scripts/invite/InviteResponse.java
@@ -251,7 +251,7 @@ public class InviteResponse extends DeclarativeWebScript
String inviteeUserName, String siteShortName)
{
// complete the wf:invitePendingTask task because the invitation has been accepted
- completeInviteTask(QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_ACCEPT);
+ completeInviteTask(inviteId, QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_ACCEPT);
// TODO glen dot johnson at alfresco dot com - farm the code that follows (up until adding properties onto
// the model) out into workflow action class that gets run when task wf:acceptInviteTask
@@ -267,7 +267,8 @@ public class InviteResponse extends DeclarativeWebScript
}
// retrieve the site role with which the invitee was invited to the site
- String inviteeSiteRole = getInviteeSiteRoleFromInvite(inviteId);
+ String inviteeSiteRole = InviteHelper.getInviteeSiteRoleFromInvite(inviteId, this.workflowService,
+ this.namespaceService);
// add Invitee to Site with the site role that the inviter "started" the invite process with
RunAsWork setSiteMembershipWorker = new InviteResponse.SetSiteMembershipWorker(
@@ -279,7 +280,7 @@ public class InviteResponse extends DeclarativeWebScript
// starting from above where wf:invitePendingTask is completed, up to here). This code
// block will soon be farmed out into a workflow action which gets executed when
// wf:acceptInviteTask gets completed
- completeInviteTask(QName.createQName(WF_TASK_ACCEPT_INVITE, this.namespaceService), WF_TRANSITION_ACCEPT_INVITE_END);
+ completeInviteTask(inviteId, QName.createQName(WF_TASK_ACCEPT_INVITE, this.namespaceService), WF_TRANSITION_ACCEPT_INVITE_END);
// add model properties for template to render
model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_ACCEPT);
@@ -304,7 +305,7 @@ public class InviteResponse extends DeclarativeWebScript
String inviteeUserName, String siteShortName)
{
// complete the wf:invitePendingTask task because the invitation has been accepted
- completeInviteTask(QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_REJECT);
+ completeInviteTask(inviteId, QName.createQName(WF_TASK_INVITE_PENDING, this.namespaceService), WF_TRANSITION_REJECT);
// TODO glen dot johnson at alfresco dot com - farm the code that follows (up until adding properties onto
// the model) out into workflow action class that gets run when task wf:rejectInviteTask
@@ -330,7 +331,7 @@ public class InviteResponse extends DeclarativeWebScript
// starting from above where wf:invitePendingTask is completed, up to here). This code
// block will soon be farmed out into a workflow action which gets executed when
// wf:rejectInviteTask gets completed
- completeInviteTask(QName.createQName(WF_TASK_REJECT_INVITE, this.namespaceService), WF_TRANSITION_REJECT_INVITE_END);
+ completeInviteTask(inviteId, QName.createQName(WF_TASK_REJECT_INVITE, this.namespaceService), WF_TRANSITION_REJECT_INVITE_END);
// add model properties for template to render
model.put(MODEL_PROP_KEY_RESPONSE, RESPONSE_REJECT);
@@ -338,17 +339,23 @@ public class InviteResponse extends DeclarativeWebScript
}
/**
- * Complete the specified Invite Workflow Task and follow the given
+ * Complete the specified Invite Workflow Task for the invite workflow
+ * instance associated with the given invite ID, and follow the given
* transition upon completing the task
*
+ * @param inviteId the invite ID of the invite workflow instance for which
+ * we want to complete the given task
* @param fullTaskName qualified name of invite workflow task to complete
* @param transitionId the task transition to take on completion of
* the task (or null, for the default transition)
*/
- private void completeInviteTask(QName fullTaskName, String transitionId)
+ private void completeInviteTask(String inviteId, QName fullTaskName, String transitionId)
{
// create workflow task query
WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery();
+
+ // set the given invite ID as the workflow process ID in the workflow query
+ wfTaskQuery.setProcessId(inviteId);
// find incomplete invite workflow tasks with given task name
wfTaskQuery.setActive(Boolean.TRUE);
@@ -369,57 +376,4 @@ public class InviteResponse extends DeclarativeWebScript
this.workflowService.endTask(workflowTask.id, transitionId);
}
}
-
- /**
- * Gets the invitee site role from the invite
- * workflow instance associated with the given invite ID.
- * i.e. if the inviter 'starts' an invite (which is allocated some invite ID
- * '12345' when it is processed), and that invite is requesting an invitee to
- * to join some site under a given site role, then that site role is returned
- * by this method when invite ID '12345' is passed in.
- *
- * @param inviteId the ID of the invitation (invite workflow instance)
- * from which to retrieve the invitee site role
- * @return the site role under which the invitee was invited to
- * join the site. Returns null
if no invite
- * workflow instance was found matching the given invite ID
- */
- private String getInviteeSiteRoleFromInvite(String inviteId)
- {
- // create workflow task query
- WorkflowTaskQuery wfTaskQuery = new WorkflowTaskQuery();
-
- wfTaskQuery.setProcessId(inviteId);
-
- // set process name to "wf:invite" so that only tasks associated with
- // invite workflow instances are returned by query
- wfTaskQuery.setProcessName(QName.createQName("wf:invite", this.namespaceService));
-
- // pick up the start task because it has the "wf:inviteeSiteRole" property set with the
- // site role value that we want to retrieve
- wfTaskQuery.setTaskState(WorkflowTaskState.COMPLETED);
- wfTaskQuery.setTaskName(QName.createQName(Invite.WF_INVITE_TASK_INVITE_TO_SITE, this.namespaceService));
-
- // query for invite workflow task associate
- List inviteStartTasks = this.workflowService
- .queryTasks(wfTaskQuery);
-
- // if no results were returned for given inviteID, then return
- // site role as null
- if (inviteStartTasks.size() == 0)
- {
- return null;
- }
- else
- {
- // there should be only one start task returned for the given invite ID
- // so just take the first one in the list
- WorkflowTask inviteStartTask = inviteStartTasks.get(0);
-
- String inviteeSiteRole = (String) inviteStartTask.properties.get(
- QName.createQName(Invite.WF_PROP_INVITEE_SITE_ROLE, this.namespaceService));
-
- return inviteeSiteRole;
- }
- }
}