mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged V3.2 to HEAD
Merged in r17325. Fixing ETHREEOH-3030 Moved some behaviour out of Javascript embedded in nomination-invitation-processdefinition.xml into a Java class SendInviteAction. Added tests to ensure whitespace and special characters are handled properly. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18303 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -12,46 +12,7 @@
|
|||||||
<task name="inwf:inviteToSiteTask" swimlane="initiator" />
|
<task name="inwf:inviteToSiteTask" swimlane="initiator" />
|
||||||
|
|
||||||
<transition name="sendInvite" to="invitePending">
|
<transition name="sendInvite" to="invitePending">
|
||||||
<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
|
<action class="org.alfresco.repo.invitation.site.SendInviteAction" />
|
||||||
<script>
|
|
||||||
var workflowId = workflowinstanceid;
|
|
||||||
var inviterPerson = people.getPerson(inwf_inviterUserName);
|
|
||||||
var inviteePerson = people.getPerson(inwf_inviteeUserName);
|
|
||||||
var site = siteService.getSite(inwf_resourceName);
|
|
||||||
var siteName = site.shortName;
|
|
||||||
if (site.title.length() > 0)
|
|
||||||
{
|
|
||||||
siteName = site.title;
|
|
||||||
}
|
|
||||||
var params = "?inviteId=" + workflowId +
|
|
||||||
"&inviteeUserName=" + inwf_inviteeUserName +
|
|
||||||
"&siteShortName=" + inwf_resourceName +
|
|
||||||
"&inviteTicket=" + inwf_inviteTicket;
|
|
||||||
var acceptLink = inwf_serverPath + inwf_acceptUrl + params;
|
|
||||||
var rejectLink = inwf_serverPath + inwf_rejectUrl + params;
|
|
||||||
var mail = actions.create("mail");
|
|
||||||
mail.parameters.from = inviterPerson.properties["cm:email"];
|
|
||||||
mail.parameters.to = inviteePerson.properties["cm:email"];
|
|
||||||
mail.parameters.subject = "Invitation to join '" + siteName + "' site";
|
|
||||||
|
|
||||||
var results = search.luceneSearch(" PATH:\"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.ftl\"");
|
|
||||||
var template = results[0];
|
|
||||||
|
|
||||||
var args = [];
|
|
||||||
args["inviteePersonRef"] = inviteePerson.nodeRef.toString();
|
|
||||||
args["inviterPersonRef"] = inviterPerson.nodeRef.toString();
|
|
||||||
args["siteName"] = siteName;
|
|
||||||
args["inviteeSiteRole"] = inwf_inviteeRole;
|
|
||||||
args["inviteeUserName"] = inwf_inviteeUserName;
|
|
||||||
args["inviteeGenPassword"] = inwf_inviteeGenPassword;
|
|
||||||
args["acceptLink"] = acceptLink;
|
|
||||||
args["rejectLink"] = rejectLink;
|
|
||||||
var mail_text = inviteePerson.processTemplate(template, args);
|
|
||||||
|
|
||||||
mail.parameters.text = mail_text;
|
|
||||||
mail.execute(bpm_package);
|
|
||||||
</script>
|
|
||||||
</action>
|
|
||||||
</transition>
|
</transition>
|
||||||
</start-state>
|
</start-state>
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,7 @@
|
|||||||
* the FLOSS exception, and it is also available here:
|
* the FLOSS exception, and it is also available here:
|
||||||
* http://www.alfresco.com/legal/licensing"
|
* http://www.alfresco.com/legal/licensing"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.alfresco.repo.invitation;
|
package org.alfresco.repo.invitation;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -45,9 +46,7 @@ import org.alfresco.util.BaseAlfrescoSpringTest;
|
|||||||
import org.alfresco.util.PropertyMap;
|
import org.alfresco.util.PropertyMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Unit tests of Invitation Service
|
* Unit tests of Invitation Service
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
||||||
{
|
{
|
||||||
@@ -60,7 +59,9 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
private final String SITE_SHORT_NAME_RED = "InvitationTestRed";
|
private final String SITE_SHORT_NAME_RED = "InvitationTestRed";
|
||||||
private final String SITE_SHORT_NAME_BLUE = "InvitationTestBlue";
|
private final String SITE_SHORT_NAME_BLUE = "InvitationTestBlue";
|
||||||
public static String PERSON_FIRSTNAME = "InvitationFirstName123";
|
public static String PERSON_FIRSTNAME = "InvitationFirstName123";
|
||||||
|
public static String PERSON_FIRSTNAME_SPACES = "Invitation First\tName\n1\r2\r\n3";
|
||||||
public static String PERSON_LASTNAME = "InvitationLastName123";
|
public static String PERSON_LASTNAME = "InvitationLastName123";
|
||||||
|
public static String PERSON_LASTNAME_SPACES = "Invitation Last\tName\n1\r2\r\n3";
|
||||||
public static String PERSON_JOBTITLE = "JobTitle123";
|
public static String PERSON_JOBTITLE = "JobTitle123";
|
||||||
public static String PERSON_ORG = "Organisation123";
|
public static String PERSON_ORG = "Organisation123";
|
||||||
|
|
||||||
@@ -72,20 +73,20 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
public static String USER_ONE_LASTNAME = "Test";
|
public static String USER_ONE_LASTNAME = "Test";
|
||||||
public static String USER_ONE_EMAIL = USER_ONE + "@alfrescotesting.com";
|
public static String USER_ONE_EMAIL = USER_ONE + "@alfrescotesting.com";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called during the transaction setup
|
* Called during the transaction setup
|
||||||
*/
|
*/
|
||||||
protected void onSetUpInTransaction() throws Exception
|
protected void onSetUpInTransaction() throws Exception
|
||||||
{
|
{
|
||||||
super.onSetUpInTransaction();
|
super.onSetUpInTransaction();
|
||||||
|
|
||||||
this.invitationService = (InvitationService) this.applicationContext.getBean("InvitationService");
|
this.invitationService = (InvitationService) this.applicationContext.getBean("InvitationService");
|
||||||
this.siteService = (SiteService) this.applicationContext.getBean("SiteService");
|
this.siteService = (SiteService) this.applicationContext.getBean("SiteService");
|
||||||
this.personService = (PersonService) this.applicationContext.getBean("PersonService");
|
this.personService = (PersonService) this.applicationContext.getBean("PersonService");
|
||||||
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
|
this.authenticationComponent = (AuthenticationComponent) this.applicationContext
|
||||||
|
.getBean("authenticationComponent");
|
||||||
|
|
||||||
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors during unit testing
|
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
|
||||||
|
// during unit testing
|
||||||
// (or sending out email by accident from tests)
|
// (or sending out email by accident from tests)
|
||||||
MailActionExecuter mail = (MailActionExecuter) this.applicationContext.getBean("mail");
|
MailActionExecuter mail = (MailActionExecuter) this.applicationContext.getBean("mail");
|
||||||
mail.setTestMode(true);
|
mail.setTestMode(true);
|
||||||
@@ -100,34 +101,23 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME_INVITE);
|
SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME_INVITE);
|
||||||
if (siteInfo == null)
|
if (siteInfo == null)
|
||||||
{
|
{
|
||||||
siteService.createSite("InviteSitePreset",
|
siteService.createSite("InviteSitePreset", SITE_SHORT_NAME_INVITE, "InviteSiteTitle",
|
||||||
SITE_SHORT_NAME_INVITE,
|
"InviteSiteDescription", SiteVisibility.MODERATED);
|
||||||
"InviteSiteTitle",
|
|
||||||
"InviteSiteDescription",
|
|
||||||
SiteVisibility.MODERATED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SiteInfo siteInfoRed = siteService.getSite(SITE_SHORT_NAME_RED);
|
SiteInfo siteInfoRed = siteService.getSite(SITE_SHORT_NAME_RED);
|
||||||
if (siteInfoRed == null)
|
if (siteInfoRed == null)
|
||||||
{
|
{
|
||||||
siteService.createSite("InviteSiteRed",
|
siteService.createSite("InviteSiteRed", SITE_SHORT_NAME_RED, "InviteSiteTitle", "InviteSiteDescription",
|
||||||
SITE_SHORT_NAME_RED,
|
|
||||||
"InviteSiteTitle",
|
|
||||||
"InviteSiteDescription",
|
|
||||||
SiteVisibility.MODERATED);
|
SiteVisibility.MODERATED);
|
||||||
}
|
}
|
||||||
SiteInfo siteInfoBlue = siteService.getSite(SITE_SHORT_NAME_BLUE);
|
SiteInfo siteInfoBlue = siteService.getSite(SITE_SHORT_NAME_BLUE);
|
||||||
if (siteInfoBlue == null)
|
if (siteInfoBlue == null)
|
||||||
{
|
{
|
||||||
siteService.createSite("InviteSiteBlue",
|
siteService.createSite("InviteSiteBlue", SITE_SHORT_NAME_BLUE, "InviteSiteTitle", "InviteSiteDescription",
|
||||||
SITE_SHORT_NAME_BLUE,
|
|
||||||
"InviteSiteTitle",
|
|
||||||
"InviteSiteDescription",
|
|
||||||
SiteVisibility.MODERATED);
|
SiteVisibility.MODERATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onTearDownInTransaction() throws Exception
|
protected void onTearDownInTransaction() throws Exception
|
||||||
@@ -177,16 +167,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(
|
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
|
||||||
inviteeFirstName,
|
inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
inviteeLastName,
|
|
||||||
inviteeEmail,
|
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
|
|
||||||
assertNotNull("nominated invitation is null", nominatedInvitation);
|
assertNotNull("nominated invitation is null", nominatedInvitation);
|
||||||
String inviteId = nominatedInvitation.getInviteId();
|
String inviteId = nominatedInvitation.getInviteId();
|
||||||
@@ -212,7 +194,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
|
assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now we have an invitation get it and check the details have been returned correctly.
|
* Now we have an invitation get it and check the details have been
|
||||||
|
* returned correctly.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
|
NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
|
||||||
@@ -250,7 +233,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
/**
|
/**
|
||||||
* Now accept the invitation
|
* Now accept the invitation
|
||||||
*/
|
*/
|
||||||
NominatedInvitation acceptedInvitation = (NominatedInvitation)invitationService.accept(firstInvite.getInviteId(), firstInvite.getTicket());
|
NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(firstInvite
|
||||||
|
.getInviteId(), firstInvite.getTicket());
|
||||||
assertEquals("invite id wrong", firstInvite.getInviteId(), acceptedInvitation.getInviteId());
|
assertEquals("invite id wrong", firstInvite.getInviteId(), acceptedInvitation.getInviteId());
|
||||||
assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
|
assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
|
||||||
@@ -262,7 +246,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
/**
|
/**
|
||||||
* Now get the invitation that we accepted
|
* Now get the invitation that we accepted
|
||||||
*/
|
*/
|
||||||
NominatedInvitation acceptedInvitation2 = (NominatedInvitation)invitationService.getInvitation(firstInvite.getInviteId());
|
NominatedInvitation acceptedInvitation2 = (NominatedInvitation) invitationService.getInvitation(firstInvite
|
||||||
|
.getInviteId());
|
||||||
assertNotNull("get after accept does not return", acceptedInvitation2);
|
assertNotNull("get after accept does not return", acceptedInvitation2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -276,6 +261,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
// TODO MER START
|
// TODO MER START
|
||||||
/**
|
/**
|
||||||
* Test nominated user - new user who rejects invitation
|
* Test nominated user - new user who rejects invitation
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testNominatedInvitationNewUserReject() throws Exception
|
public void testNominatedInvitationNewUserReject() throws Exception
|
||||||
@@ -295,19 +281,10 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(
|
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
|
||||||
inviteeFirstName,
|
inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
inviteeLastName,
|
|
||||||
inviteeEmail,
|
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
|
|
||||||
assertNotNull("nominated invitation is null", nominatedInvitation);
|
assertNotNull("nominated invitation is null", nominatedInvitation);
|
||||||
String inviteId = nominatedInvitation.getInviteId();
|
|
||||||
assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
|
assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
|
||||||
assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
|
assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
|
||||||
@@ -322,11 +299,11 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
|
assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now reject the invitation
|
* Now reject the invitation
|
||||||
*/
|
*/
|
||||||
NominatedInvitation rejectedInvitation = (NominatedInvitation)invitationService.reject(nominatedInvitation.getInviteId(), "dont want it");
|
NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.reject(nominatedInvitation
|
||||||
|
.getInviteId(), "dont want it");
|
||||||
assertEquals("invite id wrong", nominatedInvitation.getInviteId(), rejectedInvitation.getInviteId());
|
assertEquals("invite id wrong", nominatedInvitation.getInviteId(), rejectedInvitation.getInviteId());
|
||||||
assertEquals("first name wrong", inviteeFirstName, rejectedInvitation.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeFirstName, rejectedInvitation.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeLastName, rejectedInvitation.getInviteeLastName());
|
assertEquals("last name wrong", inviteeLastName, rejectedInvitation.getInviteeLastName());
|
||||||
@@ -353,16 +330,11 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO MER END
|
// TODO MER END
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test nominated user - new user
|
* Test nominated user - new user Creates two separate users with two the
|
||||||
*
|
* same email address.
|
||||||
* Creates two separate users with two the same email address.
|
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -387,15 +359,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
NominatedInvitation nominatedInvitationA = invitationService.inviteNominated(
|
NominatedInvitation nominatedInvitationA = invitationService.inviteNominated(inviteeAFirstName,
|
||||||
inviteeAFirstName,
|
inviteeALastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
|
||||||
inviteeALastName,
|
|
||||||
inviteeEmail,
|
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl);
|
rejectUrl);
|
||||||
|
|
||||||
assertNotNull("nominated invitation is null", nominatedInvitationA);
|
assertNotNull("nominated invitation is null", nominatedInvitationA);
|
||||||
@@ -408,15 +373,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
inviteeAUserName = nominatedInvitationA.getInviteeUserName();
|
inviteeAUserName = nominatedInvitationA.getInviteeUserName();
|
||||||
assertNotNull("generated user name is null", inviteeAUserName);
|
assertNotNull("generated user name is null", inviteeAUserName);
|
||||||
|
|
||||||
NominatedInvitation nominatedInvitationB = invitationService.inviteNominated(
|
NominatedInvitation nominatedInvitationB = invitationService.inviteNominated(inviteeBFirstName,
|
||||||
inviteeBFirstName,
|
inviteeBLastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
|
||||||
inviteeBLastName,
|
|
||||||
inviteeEmail,
|
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl);
|
rejectUrl);
|
||||||
|
|
||||||
assertNotNull("nominated invitation is null", nominatedInvitationB);
|
assertNotNull("nominated invitation is null", nominatedInvitationB);
|
||||||
@@ -433,19 +391,20 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
/**
|
/**
|
||||||
* Now accept the invitation
|
* Now accept the invitation
|
||||||
*/
|
*/
|
||||||
NominatedInvitation acceptedInvitationA = (NominatedInvitation)invitationService.accept(inviteAId, nominatedInvitationA.getTicket());
|
NominatedInvitation acceptedInvitationA = (NominatedInvitation) invitationService.accept(inviteAId,
|
||||||
|
nominatedInvitationA.getTicket());
|
||||||
assertEquals("invite id wrong", inviteAId, acceptedInvitationA.getInviteId());
|
assertEquals("invite id wrong", inviteAId, acceptedInvitationA.getInviteId());
|
||||||
assertEquals("first name wrong", inviteeAFirstName, acceptedInvitationA.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeAFirstName, acceptedInvitationA.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeALastName, acceptedInvitationA.getInviteeLastName());
|
assertEquals("last name wrong", inviteeALastName, acceptedInvitationA.getInviteeLastName());
|
||||||
assertEquals("user name wrong", inviteeAUserName, acceptedInvitationA.getInviteeUserName());
|
assertEquals("user name wrong", inviteeAUserName, acceptedInvitationA.getInviteeUserName());
|
||||||
|
|
||||||
NominatedInvitation acceptedInvitationB = (NominatedInvitation)invitationService.accept(inviteBId, nominatedInvitationB.getTicket());
|
NominatedInvitation acceptedInvitationB = (NominatedInvitation) invitationService.accept(inviteBId,
|
||||||
|
nominatedInvitationB.getTicket());
|
||||||
assertEquals("invite id wrong", inviteBId, acceptedInvitationB.getInviteId());
|
assertEquals("invite id wrong", inviteBId, acceptedInvitationB.getInviteId());
|
||||||
assertEquals("first name wrong", inviteeBFirstName, acceptedInvitationB.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeBFirstName, acceptedInvitationB.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeBLastName, acceptedInvitationB.getInviteeLastName());
|
assertEquals("last name wrong", inviteeBLastName, acceptedInvitationB.getInviteeLastName());
|
||||||
assertEquals("user name wrong", inviteeBUserName, acceptedInvitationB.getInviteeUserName());
|
assertEquals("user name wrong", inviteeBUserName, acceptedInvitationB.getInviteeUserName());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now verify access control list
|
* Now verify access control list
|
||||||
*/
|
*/
|
||||||
@@ -457,20 +416,60 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
siteService.removeMembership(resourceName, inviteeBUserName);
|
siteService.removeMembership(resourceName, inviteeBUserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test nominated user - new user with whitespace in name. Related to
|
||||||
|
* ETHREEOH-3030.
|
||||||
|
*/
|
||||||
|
public void testNominatedInvitationNewUserWhitespace() throws Exception
|
||||||
|
{
|
||||||
|
String inviteeFirstName = PERSON_FIRSTNAME_SPACES;
|
||||||
|
String inviteeLastName = PERSON_LASTNAME_SPACES;
|
||||||
|
String resourceName = SITE_SHORT_NAME_INVITE;
|
||||||
|
String inviteeEmail = "123@alfrescotesting.com";
|
||||||
|
Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
|
||||||
|
String inviteeRole = SiteModel.SITE_COLLABORATOR;
|
||||||
|
String serverPath = "wibble";
|
||||||
|
String acceptUrl = "froob";
|
||||||
|
String rejectUrl = "marshmallow";
|
||||||
|
String expectedUserName = (inviteeFirstName + "_" + inviteeLastName).toLowerCase();
|
||||||
|
|
||||||
|
authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
|
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
|
||||||
|
inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
|
|
||||||
|
assertNotNull("nominated invitation is null", nominatedInvitation);
|
||||||
|
assertEquals("Wrong username!", expectedUserName, nominatedInvitation.getInviteeUserName());
|
||||||
|
|
||||||
|
String inviteId = nominatedInvitation.getInviteId();
|
||||||
|
|
||||||
|
// Now we have an invitation get it and check the details have been
|
||||||
|
// returned correctly.
|
||||||
|
NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
|
||||||
|
assertNotNull("invitation is null", invitation);
|
||||||
|
assertEquals("first name wrong", inviteeFirstName, invitation.getInviteeFirstName());
|
||||||
|
assertEquals("last name wrong", inviteeLastName, invitation.getInviteeLastName());
|
||||||
|
assertEquals("user name wrong", expectedUserName, invitation.getInviteeUserName());
|
||||||
|
|
||||||
|
// Now accept the invitation
|
||||||
|
NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(invitation
|
||||||
|
.getInviteId(), invitation.getTicket());
|
||||||
|
|
||||||
|
assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
|
||||||
|
assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
|
||||||
|
assertEquals("user name wrong", expectedUserName, acceptedInvitation.getInviteeUserName());
|
||||||
|
|
||||||
|
// Now verify access control list
|
||||||
|
String roleName = siteService.getMembersRole(resourceName, expectedUserName);
|
||||||
|
assertEquals("role name wrong", roleName, inviteeRole);
|
||||||
|
siteService.removeMembership(resourceName, expectedUserName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Nominated Invitation (for existing user, USER_ONE)
|
* Create a Nominated Invitation (for existing user, USER_ONE) read it.
|
||||||
* read it.
|
* search for it cancel it search for it again (and fail to find it) Create
|
||||||
* search for it
|
* a Nominated Invitation read it. search for it reject it Create a
|
||||||
* cancel it
|
* Nominated Invitation read it. accept it
|
||||||
* search for it again (and fail to find it)
|
|
||||||
* Create a Nominated Invitation
|
|
||||||
* read it.
|
|
||||||
* search for it
|
|
||||||
* reject it
|
|
||||||
* Create a Nominated Invitation
|
|
||||||
* read it.
|
|
||||||
* accept it
|
|
||||||
*/
|
*/
|
||||||
public void testNominatedInvitationExistingUser() throws Exception
|
public void testNominatedInvitationExistingUser() throws Exception
|
||||||
{
|
{
|
||||||
@@ -488,14 +487,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(
|
NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
|
|
||||||
assertNotNull("nominated invitation is null", nominatedInvitation);
|
assertNotNull("nominated invitation is null", nominatedInvitation);
|
||||||
String inviteId = nominatedInvitation.getInviteId();
|
String inviteId = nominatedInvitation.getInviteId();
|
||||||
@@ -513,7 +506,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
|
assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now we have an invitation get it and check the details have been returned correctly.
|
* Now we have an invitation get it and check the details have been
|
||||||
|
* returned correctly.
|
||||||
*/
|
*/
|
||||||
NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
|
NominatedInvitation invitation = (NominatedInvitation) invitationService.getInvitation(inviteId);
|
||||||
|
|
||||||
@@ -562,16 +556,11 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
/**
|
/**
|
||||||
* Now invite and reject
|
* Now invite and reject
|
||||||
*/
|
*/
|
||||||
NominatedInvitation secondInvite = invitationService.inviteNominated(
|
NominatedInvitation secondInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
|
|
||||||
NominatedInvitation rejectedInvitation = (NominatedInvitation)invitationService.cancel(secondInvite.getInviteId());
|
NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.cancel(secondInvite
|
||||||
|
.getInviteId());
|
||||||
assertEquals("invite id wrong", secondInvite.getInviteId(), rejectedInvitation.getInviteId());
|
assertEquals("invite id wrong", secondInvite.getInviteId(), rejectedInvitation.getInviteId());
|
||||||
assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
|
assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
|
||||||
|
|
||||||
@@ -581,16 +570,11 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
/**
|
/**
|
||||||
* Now invite and accept
|
* Now invite and accept
|
||||||
*/
|
*/
|
||||||
NominatedInvitation thirdInvite = invitationService.inviteNominated(
|
NominatedInvitation thirdInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
|
|
||||||
NominatedInvitation acceptedInvitation = (NominatedInvitation)invitationService.accept(thirdInvite.getInviteId(), thirdInvite.getTicket());
|
NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(thirdInvite
|
||||||
|
.getInviteId(), thirdInvite.getTicket());
|
||||||
assertEquals("invite id wrong", thirdInvite.getInviteId(), acceptedInvitation.getInviteId());
|
assertEquals("invite id wrong", thirdInvite.getInviteId(), acceptedInvitation.getInviteId());
|
||||||
assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
|
assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
|
||||||
assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
|
assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
|
||||||
@@ -608,15 +592,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a moderated invitation
|
* Create a moderated invitation Get it Search for it Cancel it Create a
|
||||||
* Get it
|
* moderated invitation Reject the invitation Create a moderated invitation
|
||||||
* Search for it
|
|
||||||
* Cancel it
|
|
||||||
*
|
|
||||||
* Create a moderated invitation
|
|
||||||
* Reject the invitation
|
|
||||||
*
|
|
||||||
* Create a moderated invitation
|
|
||||||
* Approve the invitation
|
* Approve the invitation
|
||||||
*/
|
*/
|
||||||
public void testModeratedInvitation()
|
public void testModeratedInvitation()
|
||||||
@@ -628,11 +605,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
String comments = "please sir, let me in!";
|
String comments = "please sir, let me in!";
|
||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
ModeratedInvitation invitation = invitationService.inviteModerated(comments,
|
ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
assertNotNull("moderated invitation is null", invitation);
|
assertNotNull("moderated invitation is null", invitation);
|
||||||
String inviteId = invitation.getInviteId();
|
String inviteId = invitation.getInviteId();
|
||||||
@@ -643,7 +617,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("resource name wrong", resourceName, invitation.getResourceName());
|
assertEquals("resource name wrong", resourceName, invitation.getResourceName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now we have an invitation get it and check the details have been returned correctly.
|
* Now we have an invitation get it and check the details have been
|
||||||
|
* returned correctly.
|
||||||
*/
|
*/
|
||||||
ModeratedInvitation mi2 = (ModeratedInvitation) invitationService.getInvitation(inviteId);
|
ModeratedInvitation mi2 = (ModeratedInvitation) invitationService.getInvitation(inviteId);
|
||||||
assertEquals("invite id", inviteId, mi2.getInviteId());
|
assertEquals("invite id", inviteId, mi2.getInviteId());
|
||||||
@@ -679,11 +654,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
* New invitation
|
* New invitation
|
||||||
*/
|
*/
|
||||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
ModeratedInvitation invite2 = invitationService.inviteModerated(comments,
|
ModeratedInvitation invite2 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
String secondInvite = invite2.getInviteId();
|
String secondInvite = invite2.getInviteId();
|
||||||
|
|
||||||
@@ -694,11 +666,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
* New invitation
|
* New invitation
|
||||||
*/
|
*/
|
||||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
ModeratedInvitation invite3 = invitationService.inviteModerated(comments,
|
ModeratedInvitation invite3 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
String thirdInvite = invite3.getInviteId();
|
String thirdInvite = invite3.getInviteId();
|
||||||
|
|
||||||
@@ -729,17 +698,13 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
* New invitation from User TWO
|
* New invitation from User TWO
|
||||||
*/
|
*/
|
||||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
ModeratedInvitation invitation = invitationService.inviteModerated(comments,
|
ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
String invitationId = invitation.getInviteId();
|
String invitationId = invitation.getInviteId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test
|
* Negative test Attempt to approve without the necessary role
|
||||||
* Attempt to approve without the necessary role
|
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -767,8 +732,8 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("role name wrong", roleName, inviteeRole);
|
assertEquals("role name wrong", roleName, inviteeRole);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test
|
* Negative test attempt to approve an invitation that has aready been
|
||||||
* attempt to approve an invitation that has aready been approved
|
* approved
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -782,8 +747,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
System.out.println(e.toString());
|
System.out.println(e.toString());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Negative test
|
* Negative test User is already a member of the site
|
||||||
* User is already a member of the site
|
|
||||||
*/
|
*/
|
||||||
siteService.removeMembership(resourceName, inviteeUserName);
|
siteService.removeMembership(resourceName, inviteeUserName);
|
||||||
}
|
}
|
||||||
@@ -803,17 +767,13 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
* New invitation from User TWO
|
* New invitation from User TWO
|
||||||
*/
|
*/
|
||||||
this.authenticationComponent.setCurrentUser(USER_TWO);
|
this.authenticationComponent.setCurrentUser(USER_TWO);
|
||||||
ModeratedInvitation invitation = invitationService.inviteModerated(comments,
|
ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
|
||||||
inviteeUserName,
|
resourceName, inviteeRole);
|
||||||
resourceType,
|
|
||||||
resourceName,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
String invitationId = invitation.getInviteId();
|
String invitationId = invitation.getInviteId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test
|
* Negative test Attempt to reject without the necessary role
|
||||||
* Attempt to reject without the necessary role
|
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -835,8 +795,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
invitationService.reject(invitationId, "Go away!");
|
invitationService.reject(invitationId, "Go away!");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test
|
* Negative test attempt to approve an invitation that has been rejected
|
||||||
* attempt to approve an invitation that has been rejected
|
|
||||||
*/
|
*/
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -857,14 +816,9 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
public void testSearchInvitation()
|
public void testSearchInvitation()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Make up a tree of invitations and then search
|
* Make up a tree of invitations and then search Resource, User,
|
||||||
*
|
* Workflow 1) RED, One, Moderated 2) RED, One, Nominated 3) BLUE, One,
|
||||||
* Resource, User, Workflow
|
* Nominated 4) RED, Two, Moderated
|
||||||
* 1) RED, One, Moderated
|
|
||||||
* 2) RED, One, Nominated
|
|
||||||
* 3) BLUE, One, Nominated
|
|
||||||
* 4) RED, Two, Moderated
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
|
Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
|
||||||
String inviteeRole = SiteModel.SITE_COLLABORATOR;
|
String inviteeRole = SiteModel.SITE_COLLABORATOR;
|
||||||
@@ -874,51 +828,30 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
String rejectUrl = "marshmallow";
|
String rejectUrl = "marshmallow";
|
||||||
|
|
||||||
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
this.authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
ModeratedInvitation invitationOne = invitationService.inviteModerated(comments,
|
invitationService.inviteModerated(comments, USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
|
||||||
USER_ONE,
|
|
||||||
resourceType,
|
|
||||||
SITE_SHORT_NAME_RED,
|
|
||||||
inviteeRole);
|
|
||||||
|
|
||||||
String oneId = invitationOne.getInviteId();
|
invitationService.inviteNominated(USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole, serverPath,
|
||||||
NominatedInvitation invitationTwo = invitationService.inviteNominated(
|
acceptUrl, rejectUrl);
|
||||||
USER_ONE,
|
|
||||||
resourceType,
|
|
||||||
SITE_SHORT_NAME_RED,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
String twoId = invitationTwo.getInviteId();
|
|
||||||
|
|
||||||
NominatedInvitation invitationThree = invitationService.inviteNominated(
|
NominatedInvitation invitationThree = invitationService.inviteNominated(USER_ONE, resourceType,
|
||||||
USER_ONE,
|
SITE_SHORT_NAME_BLUE, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
resourceType,
|
|
||||||
SITE_SHORT_NAME_BLUE,
|
|
||||||
inviteeRole,
|
|
||||||
serverPath,
|
|
||||||
acceptUrl,
|
|
||||||
rejectUrl) ;
|
|
||||||
String threeId = invitationThree.getInviteId();
|
String threeId = invitationThree.getInviteId();
|
||||||
|
|
||||||
ModeratedInvitation invitationFour = invitationService.inviteModerated(comments,
|
invitationService.inviteModerated(comments, USER_TWO, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
|
||||||
USER_TWO,
|
|
||||||
resourceType,
|
|
||||||
SITE_SHORT_NAME_RED,
|
|
||||||
inviteeRole);
|
|
||||||
String fourId = invitationFour.getInviteId();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for invitations for BLUE
|
* Search for invitations for BLUE
|
||||||
*/
|
*/
|
||||||
List<Invitation> resOne = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE, SITE_SHORT_NAME_BLUE);
|
List<Invitation> resOne = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
|
||||||
|
SITE_SHORT_NAME_BLUE);
|
||||||
assertEquals("blue invites not 1", 1, resOne.size());
|
assertEquals("blue invites not 1", 1, resOne.size());
|
||||||
assertEquals("blue id wrong", threeId, resOne.get(0).getInviteId());
|
assertEquals("blue id wrong", threeId, resOne.get(0).getInviteId());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for invitations for RED
|
* Search for invitations for RED
|
||||||
*/
|
*/
|
||||||
List<Invitation> resTwo = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE, SITE_SHORT_NAME_RED);
|
List<Invitation> resTwo = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
|
||||||
|
SITE_SHORT_NAME_RED);
|
||||||
assertEquals("red invites not 3", 3, resTwo.size());
|
assertEquals("red invites not 3", 3, resTwo.size());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -943,18 +876,16 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
List<Invitation> resFive = invitationService.searchInvitation(crit1);
|
List<Invitation> resFive = invitationService.searchInvitation(crit1);
|
||||||
assertEquals("user one does not have 2 nominated", 2, resFive.size());
|
assertEquals("user one does not have 2 nominated", 2, resFive.size());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search with an empty criteria - should find all open invitations
|
* Search with an empty criteria - should find all open invitations
|
||||||
*/
|
*/
|
||||||
InvitationSearchCriteria crit2 = new InvitationSearchCriteriaImpl();
|
InvitationSearchCriteria crit2 = new InvitationSearchCriteriaImpl();
|
||||||
|
|
||||||
List<Invitation> resSix = invitationService.searchInvitation(crit2);
|
invitationService.searchInvitation(crit2);
|
||||||
assertTrue("search everything returned 0 elements", resFive.size() > 0);
|
assertTrue("search everything returned 0 elements", resFive.size() > 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -980,8 +911,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
if (this.authenticationService.authenticationExists(userName) == false)
|
if (this.authenticationService.authenticationExists(userName) == false)
|
||||||
{
|
{
|
||||||
// create user
|
// create user
|
||||||
this.authenticationService.createAuthentication(userName,
|
this.authenticationService.createAuthentication(userName, "password".toCharArray());
|
||||||
"password".toCharArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if person node with given user name doesn't already exist then create
|
// if person node with given user name doesn't already exist then create
|
||||||
|
@@ -81,5 +81,10 @@ public interface WorkflowModelNominatedInvitation
|
|||||||
public static final String wfVarResourceType = "inwf_resourceType";
|
public static final String wfVarResourceType = "inwf_resourceType";
|
||||||
public static final String wfVarWorkflowInstanceId = "workflowinstanceid";
|
public static final String wfVarWorkflowInstanceId = "workflowinstanceid";
|
||||||
public static final String wfVarRole = "inwf_inviteeRole";
|
public static final String wfVarRole = "inwf_inviteeRole";
|
||||||
|
public static final String wfVarInviteTicket = "inwf_inviteTicket";
|
||||||
|
public static final String wfVarServerPath = "inwf_serverPath";
|
||||||
|
public static final String wfVarAcceptUrl = "inwf_acceptUrl";
|
||||||
|
public static final String wfVarRejectUrl = "inwf_rejectUrl";
|
||||||
|
public static final String wfVarInviteeGenPassword = "inwf_inviteeGenPassword";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
255
source/java/org/alfresco/repo/invitation/site/InviteSender.java
Normal file
255
source/java/org/alfresco/repo/invitation/site/InviteSender.java
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 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 recieved 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.invitation.site;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.repo.search.SearcherException;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||||
|
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.repository.TemplateService;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||||
|
import org.springframework.extensions.surf.util.URLEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for sending email invitations, allowing nominated
|
||||||
|
* user's to join a Site.
|
||||||
|
*
|
||||||
|
* @author Nick Smith
|
||||||
|
*/
|
||||||
|
public class InviteSender
|
||||||
|
{
|
||||||
|
public static final String WF_INSTANCE_ID = "wf_instanceId";
|
||||||
|
public static final String WF_PACKAGE = "wf_package";
|
||||||
|
|
||||||
|
private static final List<String> expectedProperties = Arrays.asList(wfVarInviteeUserName,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviterUserName,//
|
||||||
|
wfVarInviteeUserName,//
|
||||||
|
wfVarRole,//
|
||||||
|
wfVarInviteeGenPassword,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviteTicket,//
|
||||||
|
wfVarServerPath,//
|
||||||
|
wfVarAcceptUrl,//
|
||||||
|
wfVarRejectUrl, WF_INSTANCE_ID,//
|
||||||
|
WF_PACKAGE);
|
||||||
|
|
||||||
|
private final ActionService actionService;
|
||||||
|
private final NodeService nodeService;
|
||||||
|
private final PersonService personService;
|
||||||
|
private final SearchService searchService;
|
||||||
|
private final SiteService siteService;
|
||||||
|
private final TemplateService templateService;
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
public InviteSender(ServiceRegistry services, Repository repository)
|
||||||
|
{
|
||||||
|
this.actionService = services.getActionService();
|
||||||
|
this.nodeService = services.getNodeService();
|
||||||
|
this.personService = services.getPersonService();
|
||||||
|
this.searchService = services.getSearchService();
|
||||||
|
this.siteService = services.getSiteService();
|
||||||
|
this.templateService = services.getTemplateService();
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an invitation email.
|
||||||
|
*
|
||||||
|
* @param properties A Map containing the properties needed to send the
|
||||||
|
* email.
|
||||||
|
*/
|
||||||
|
public void sendMail(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
checkProperties(properties);
|
||||||
|
ParameterCheck.mandatory("Properties", properties);
|
||||||
|
NodeRef inviter = personService.getPerson(properties.get(wfVarInviterUserName));
|
||||||
|
String inviteeName = properties.get(wfVarInviteeUserName);
|
||||||
|
NodeRef invitee = personService.getPerson(inviteeName);
|
||||||
|
Action mail = actionService.createAction(MailActionExecuter.NAME);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_FROM, getEmail(inviter));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TO, getEmail(invitee));
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_SUBJECT, buildSubject(properties));
|
||||||
|
String mailText = buildMailText(properties, inviter, invitee);
|
||||||
|
mail.setParameterValue(MailActionExecuter.PARAM_TEXT, mailText);
|
||||||
|
actionService.executeAction(mail, getWorkflowPackage(properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param properties
|
||||||
|
*/
|
||||||
|
private void checkProperties(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
Set<String> keys = properties.keySet();
|
||||||
|
if (!keys.containsAll(expectedProperties))
|
||||||
|
{
|
||||||
|
LinkedList<String> missingProperties = new LinkedList<String>(expectedProperties);
|
||||||
|
missingProperties.removeAll(keys);
|
||||||
|
throw new InvitationException("The following mandatory properties are missing:\n" + missingProperties);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildSubject(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
return "Invitation to join '" + getSiteName(properties) + "' site";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildMailText(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||||
|
{
|
||||||
|
String template = getEmailTemplate();
|
||||||
|
Map<String, Object> model = makeDefaultModel();
|
||||||
|
Map<String, String> args = buildArgs(properties, inviter, invitee);
|
||||||
|
model.put("args", args);
|
||||||
|
return templateService.processTemplate(template, model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEmailTemplate()
|
||||||
|
{
|
||||||
|
NodeRef template = getEmailTemplateNodeRef();
|
||||||
|
return template.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildArgs(Map<String, String> properties, NodeRef inviter, NodeRef invitee)
|
||||||
|
{
|
||||||
|
String params = buildUrlParamString(properties);
|
||||||
|
String serverPath = properties.get(wfVarServerPath);
|
||||||
|
String acceptLink = serverPath + properties.get(wfVarAcceptUrl) + params;
|
||||||
|
String rejectLink = serverPath + properties.get(wfVarRejectUrl) + params;
|
||||||
|
|
||||||
|
Map<String, String> args = new HashMap<String, String>();
|
||||||
|
args.put("inviteePersonRef", invitee.toString());
|
||||||
|
args.put("inviterPersonRef", inviter.toString());
|
||||||
|
args.put("siteName", getSiteName(properties));
|
||||||
|
args.put("inviteeSiteRole", properties.get(wfVarRole));
|
||||||
|
args.put("inviteeUserName", properties.get(wfVarInviteeUserName));
|
||||||
|
args.put("inviteeGenPassword", properties.get(wfVarInviteeGenPassword));
|
||||||
|
args.put("acceptLink", acceptLink);
|
||||||
|
args.put("rejectLink", rejectLink);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> makeDefaultModel()
|
||||||
|
{
|
||||||
|
NodeRef person = repository.getPerson();
|
||||||
|
NodeRef companyHome = repository.getCompanyHome();
|
||||||
|
NodeRef userHome = repository.getUserHome(person);
|
||||||
|
Map<String, Object> model = templateService.buildDefaultModel(person, companyHome, userHome, null, null);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEmail(NodeRef person)
|
||||||
|
{
|
||||||
|
return (String) nodeService.getProperty(person, ContentModel.PROP_EMAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef getWorkflowPackage(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
String packageRef = properties.get(WF_PACKAGE);
|
||||||
|
return new NodeRef(packageRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef getEmailTemplateNodeRef()
|
||||||
|
{
|
||||||
|
StoreRef spacesStore = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||||
|
String query = " PATH:\"app:company_home/app:dictionary/app:email_templates/cm:invite/cm:invite-email.ftl\"";
|
||||||
|
|
||||||
|
SearchParameters searchParams = new SearchParameters();
|
||||||
|
searchParams.addStore(spacesStore);
|
||||||
|
searchParams.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||||
|
searchParams.setQuery(query);
|
||||||
|
|
||||||
|
ResultSet results = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
results = searchService.query(searchParams);
|
||||||
|
List<NodeRef> nodeRefs = results.getNodeRefs();
|
||||||
|
if (nodeRefs.size() == 1)
|
||||||
|
return nodeRefs.get(0);
|
||||||
|
else
|
||||||
|
throw new InvitationException("Cannot find the email templatte!");
|
||||||
|
}
|
||||||
|
catch (SearcherException e)
|
||||||
|
{
|
||||||
|
throw new InvitationException("Cannot find the email templatte!", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (results != null)
|
||||||
|
results.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildUrlParamString(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
StringBuilder params = new StringBuilder("?inviteId=");
|
||||||
|
params.append(properties.get(WF_INSTANCE_ID));
|
||||||
|
params.append("&inviteeUserName=");
|
||||||
|
params.append(URLEncoder.encode(properties.get(wfVarInviteeUserName)));
|
||||||
|
params.append("&siteShortName=");
|
||||||
|
params.append(properties.get(wfVarResourceName));
|
||||||
|
params.append("&inviteTicket=");
|
||||||
|
params.append(properties.get(wfVarInviteTicket));
|
||||||
|
return params.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSiteName(Map<String, String> properties)
|
||||||
|
{
|
||||||
|
String siteFullName = properties.get(wfVarResourceName);
|
||||||
|
SiteInfo site = siteService.getSite(siteFullName);
|
||||||
|
if (site == null)
|
||||||
|
throw new InvitationException("The site " + siteFullName + " could not be found.");
|
||||||
|
|
||||||
|
String siteName = site.getShortName();
|
||||||
|
String siteTitle = site.getTitle();
|
||||||
|
if (siteTitle != null && siteTitle.length() > 0)
|
||||||
|
{
|
||||||
|
siteName = siteTitle;
|
||||||
|
}
|
||||||
|
return siteName;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,332 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 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 recieved 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.invitation.site;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||||
|
import static org.mockito.Matchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
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.repository.TemplateService;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.extensions.surf.util.URLEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nick Smith
|
||||||
|
*/
|
||||||
|
public class InviteSenderTest extends TestCase
|
||||||
|
{
|
||||||
|
private static final StoreRef testStore = new StoreRef(StoreRef.PROTOCOL_TEST, "test");
|
||||||
|
|
||||||
|
private static final Person inviter = new Person("inviter");
|
||||||
|
private static final Person invitee = new Person("invitee");
|
||||||
|
private static final Person whitespaceInvitee = new Person("First Second\tthird\nFourth\r\nFifth");
|
||||||
|
private static final Person specialCharInvitee = new Person("àâæçéèêëîïôœùûüÿñ");
|
||||||
|
|
||||||
|
private static final NodeRef template = new NodeRef(testStore, "template");
|
||||||
|
|
||||||
|
private static final String siteName = "Full Site Name";
|
||||||
|
private static final String siteShortName = "Site Name";
|
||||||
|
private static final String mailText = "Mail Text";
|
||||||
|
|
||||||
|
private static final String acceptUrl = "/accpet";
|
||||||
|
private static final String rejectUrl = "/reject";
|
||||||
|
private static final String role = "Role";
|
||||||
|
private static final String password = "password";
|
||||||
|
private static final String ticket = "Ticket";
|
||||||
|
private static final String path = testStore + "/path";
|
||||||
|
private static final String packageId = testStore + "/Package";
|
||||||
|
private static final String instanceId = "InstanceId";
|
||||||
|
|
||||||
|
private Action mailAction = mock(Action.class);
|
||||||
|
private SiteInfo siteInfo = mock(SiteInfo.class);
|
||||||
|
private TemplateService templateService;
|
||||||
|
private InviteSender sender;
|
||||||
|
|
||||||
|
public void testSendMailWorkingPath() throws Exception
|
||||||
|
{
|
||||||
|
Map<String, String> properties = buildDefaultProperties();
|
||||||
|
sender.sendMail(properties);
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_FROM), eq(inviter.email));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_TO), eq(invitee.email));
|
||||||
|
verify(mailAction).setParameterValue(eq(MailActionExecuter.PARAM_SUBJECT),
|
||||||
|
eq("Invitation to join '" + siteShortName + "' site"));
|
||||||
|
|
||||||
|
Map<String, String> argsMap = getArgsMap();
|
||||||
|
assertNotNull(argsMap);
|
||||||
|
assertEquals(siteShortName, argsMap.get("siteName"));
|
||||||
|
assertEquals(invitee.node.toString(), argsMap.get("inviteePersonRef"));
|
||||||
|
assertEquals(inviter.node.toString(), argsMap.get("inviterPersonRef"));
|
||||||
|
assertEquals(siteShortName, argsMap.get("siteName"));
|
||||||
|
assertEquals(role, argsMap.get("inviteeSiteRole"));
|
||||||
|
assertEquals(invitee.name, argsMap.get("inviteeUserName"));
|
||||||
|
assertEquals(password, argsMap.get("inviteeGenPassword"));
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=invitee&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
argsMap.get("acceptLink"));
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=invitee&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
argsMap.get("rejectLink"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSendMailWithWhitespaceUserName() throws Exception
|
||||||
|
{
|
||||||
|
Map<String, String> properties = buildDefaultProperties();
|
||||||
|
properties.put(wfVarInviteeUserName, whitespaceInvitee.name);
|
||||||
|
sender.sendMail(properties);
|
||||||
|
Map<String, String> argsMap = getArgsMap();
|
||||||
|
String acceptLink = argsMap.get("acceptLink");
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=First%20Second%09third%0aFourth%0d%0aFifth&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
acceptLink);
|
||||||
|
String rejectLink = argsMap.get("rejectLink");
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=First%20Second%09third%0aFourth%0d%0aFifth&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
rejectLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSendMailWithSpecialCharUserName() throws Exception
|
||||||
|
{
|
||||||
|
Map<String, String> properties = buildDefaultProperties();
|
||||||
|
properties.put(wfVarInviteeUserName, specialCharInvitee.name);
|
||||||
|
sender.sendMail(properties);
|
||||||
|
Map<String, String> argsMap = getArgsMap();
|
||||||
|
String acceptLink = argsMap.get("acceptLink");
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/accpet?inviteId=InstanceId&inviteeUserName=%c3%a0%c3%a2%c3%a6%c3%a7%c3%a9%c3%a8%c3%aa%c3%ab%c3%ae%c3%af%c3%b4%c5%93%c3%b9%c3%bb%c3%bc%c3%bf%c3%b1&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
acceptLink);
|
||||||
|
String rejectLink = argsMap.get("rejectLink");
|
||||||
|
assertEquals(
|
||||||
|
"test://test/path/reject?inviteId=InstanceId&inviteeUserName=%c3%a0%c3%a2%c3%a6%c3%a7%c3%a9%c3%a8%c3%aa%c3%ab%c3%ae%c3%af%c3%b4%c5%93%c3%b9%c3%bb%c3%bc%c3%bf%c3%b1&siteShortName=Full Site Name&inviteTicket=Ticket",
|
||||||
|
rejectLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> buildDefaultProperties()
|
||||||
|
{
|
||||||
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
|
properties.put(wfVarResourceName, siteName);
|
||||||
|
properties.put(wfVarInviteeUserName, invitee.name);
|
||||||
|
properties.put(wfVarInviterUserName, inviter.name);
|
||||||
|
properties.put(wfVarAcceptUrl, acceptUrl);
|
||||||
|
properties.put(wfVarRejectUrl, rejectUrl);
|
||||||
|
properties.put(wfVarRole, role);
|
||||||
|
properties.put(wfVarInviteeGenPassword, password);
|
||||||
|
properties.put(wfVarInviteTicket, ticket);
|
||||||
|
properties.put(wfVarServerPath, path);
|
||||||
|
properties.put(InviteSender.WF_PACKAGE, packageId);
|
||||||
|
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Map<String, String> getArgsMap()
|
||||||
|
{
|
||||||
|
ArgumentCaptor<Map> modelCaptor = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(templateService).processTemplate(eq(template.toString()), modelCaptor.capture());
|
||||||
|
Map<String, Serializable> model = modelCaptor.getValue();
|
||||||
|
Map<String, String> argsMap = (Map<String, String>) model.get("args");
|
||||||
|
return argsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
ServiceRegistry services = mockServices();
|
||||||
|
Repository repository = mockRepository();
|
||||||
|
sender = new InviteSender(services, repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a Repository that will return the inviter as the current user.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Repository mockRepository()
|
||||||
|
{
|
||||||
|
Repository repository = mock(Repository.class);
|
||||||
|
when(repository.getPerson()).thenReturn(inviter.node);
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private ServiceRegistry mockServices()
|
||||||
|
{
|
||||||
|
ActionService mockActionService = mockActionService();
|
||||||
|
NodeService mockNodeService = mockNodeService();
|
||||||
|
PersonService mockPersonService = mockPersonService();
|
||||||
|
SearchService mockSearchService = mockSearchService();
|
||||||
|
SiteService mockSiteService = mockSiteService();
|
||||||
|
TemplateService mockTemplateService = mockTemplateService();
|
||||||
|
|
||||||
|
ServiceRegistry services = mock(ServiceRegistry.class);
|
||||||
|
when(services.getActionService()).thenReturn(mockActionService);
|
||||||
|
when(services.getNodeService()).thenReturn(mockNodeService);
|
||||||
|
when(services.getPersonService()).thenReturn(mockPersonService);
|
||||||
|
when(services.getSearchService()).thenReturn(mockSearchService);
|
||||||
|
when(services.getSiteService()).thenReturn(mockSiteService);
|
||||||
|
when(services.getTemplateService()).thenReturn(mockTemplateService);
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a TemplateService that returns an empty HashMap when
|
||||||
|
* buildDefaultModel() is called.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private TemplateService mockTemplateService()
|
||||||
|
{
|
||||||
|
this.templateService = mock(TemplateService.class);
|
||||||
|
when(templateService.buildDefaultModel(inviter.node, null, null, null, null)).thenAnswer(
|
||||||
|
new Answer<Map<String, Object>>()
|
||||||
|
{
|
||||||
|
public Map<String, Object> answer(InvocationOnMock invocation) throws Throwable
|
||||||
|
{
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
when(templateService.processTemplate(anyString(), any())).thenReturn(mailText);
|
||||||
|
return templateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a SiteService that returns appropriate SiteInfo.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private SiteService mockSiteService()
|
||||||
|
{
|
||||||
|
SiteService siteService = mock(SiteService.class);
|
||||||
|
when(siteInfo.getShortName()).thenReturn(siteShortName);
|
||||||
|
when(siteService.getSite(siteName)).thenReturn(siteInfo);
|
||||||
|
return siteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a SearchService that will return the template NodeRef when
|
||||||
|
* queried.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private SearchService mockSearchService()
|
||||||
|
{
|
||||||
|
SearchService searchService = mock(SearchService.class);
|
||||||
|
ResultSet results = mock(ResultSet.class);
|
||||||
|
List<NodeRef> nodeRefs = Arrays.asList(template);
|
||||||
|
when(results.getNodeRefs()).thenReturn(nodeRefs);
|
||||||
|
when(searchService.query((SearchParameters) any())).thenReturn(results);
|
||||||
|
return searchService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up a PersonService that returns the correct NodeRef when given a
|
||||||
|
* user name.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private PersonService mockPersonService()
|
||||||
|
{
|
||||||
|
PersonService personService = mock(PersonService.class);
|
||||||
|
when(personService.getPerson(inviter.name)).thenReturn(inviter.node);
|
||||||
|
when(personService.getPerson(invitee.name)).thenReturn(invitee.node);
|
||||||
|
when(personService.getPerson(whitespaceInvitee.name)).thenReturn(whitespaceInvitee.node);
|
||||||
|
when(personService.getPerson(specialCharInvitee.name)).thenReturn(specialCharInvitee.node);
|
||||||
|
return personService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up NodeService to return email adresses for inviter and invitee.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private NodeService mockNodeService()
|
||||||
|
{
|
||||||
|
NodeService nodeService = mock(NodeService.class);
|
||||||
|
when(nodeService.getProperty(inviter.node, ContentModel.PROP_EMAIL)).thenReturn(inviter.email);
|
||||||
|
when(nodeService.getProperty(invitee.node, ContentModel.PROP_EMAIL)).thenReturn(invitee.email);
|
||||||
|
when(nodeService.getProperty(whitespaceInvitee.node, ContentModel.PROP_EMAIL)).thenReturn(
|
||||||
|
whitespaceInvitee.email);
|
||||||
|
when(nodeService.getProperty(specialCharInvitee.node, ContentModel.PROP_EMAIL)).thenReturn(
|
||||||
|
specialCharInvitee.email);
|
||||||
|
return nodeService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mocks up an ActionService which returns the mailAction field when
|
||||||
|
* createAction() is called.
|
||||||
|
*
|
||||||
|
* @return ActionService
|
||||||
|
*/
|
||||||
|
private ActionService mockActionService()
|
||||||
|
{
|
||||||
|
ActionService actionService = mock(ActionService.class);
|
||||||
|
when(actionService.createAction(MailActionExecuter.NAME)).thenReturn(mailAction);
|
||||||
|
return actionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Person
|
||||||
|
{
|
||||||
|
public final String name;
|
||||||
|
public final String email;
|
||||||
|
public final NodeRef node;
|
||||||
|
|
||||||
|
public Person(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
String encName = URLEncoder.encode(name);
|
||||||
|
this.email = encName + "@test.com";
|
||||||
|
this.node = new NodeRef(testStore, encName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2009 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 recieved 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.invitation.site;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.invitation.WorkflowModelNominatedInvitation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.repo.jscript.ScriptNode;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.repo.workflow.WorkflowModel;
|
||||||
|
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
|
||||||
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.jbpm.graph.exe.ExecutionContext;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
|
||||||
|
public class SendInviteAction extends JBPMSpringActionHandler
|
||||||
|
{
|
||||||
|
// TODO Select Version Id.
|
||||||
|
private static final long serialVersionUID = 8133039174866049136L;
|
||||||
|
|
||||||
|
private InviteSender inviteSender;
|
||||||
|
private NamespaceService namespaceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initialiseHandler(BeanFactory factory)
|
||||||
|
{
|
||||||
|
Repository repository = (Repository) factory.getBean("repositoryHelper");
|
||||||
|
ServiceRegistry services = (ServiceRegistry) factory.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||||
|
inviteSender = new InviteSender(services, repository);
|
||||||
|
namespaceService = services.getNamespaceService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(final ExecutionContext context) throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
Collection<String> propertyNames = Arrays.asList(wfVarInviteeUserName,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviterUserName,//
|
||||||
|
wfVarInviteeUserName,//
|
||||||
|
wfVarRole,//
|
||||||
|
wfVarInviteeGenPassword,//
|
||||||
|
wfVarResourceName,//
|
||||||
|
wfVarInviteTicket,//
|
||||||
|
wfVarServerPath,//
|
||||||
|
wfVarAcceptUrl,//
|
||||||
|
wfVarRejectUrl,
|
||||||
|
InviteSender.WF_INSTANCE_ID);
|
||||||
|
Map<String, String> properties = makePropertiesFromContext(context, propertyNames);
|
||||||
|
|
||||||
|
String packageName = WorkflowModel.ASSOC_PACKAGE.toPrefixString(namespaceService).replace(":", "_");
|
||||||
|
ScriptNode packageNode = (ScriptNode) context.getVariable(packageName);
|
||||||
|
String packageRef = packageNode.getNodeRef().toString();
|
||||||
|
properties.put(InviteSender.WF_PACKAGE, packageRef);
|
||||||
|
|
||||||
|
String instanceName=WorkflowModel.PROP_WORKFLOW_INSTANCE_ID.toPrefixString(namespaceService).replace(":", "_");
|
||||||
|
String instanceId = (String) context.getVariable(instanceName);
|
||||||
|
properties.put(InviteSender.WF_INSTANCE_ID, instanceId);
|
||||||
|
inviteSender.sendMail(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> makePropertiesFromContext(ExecutionContext context, Collection<String> propertyNames)
|
||||||
|
{
|
||||||
|
Map<String, String> props = new HashMap<String, String>();
|
||||||
|
for (String name : propertyNames)
|
||||||
|
{
|
||||||
|
String value = (String) context.getVariable(name);
|
||||||
|
props.put(name, value);
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user