schemaReferenceUrls)
{
- this.schemaReferenceUrl = schemaReferenceUrl;
+ this.schemaReferenceUrls = schemaReferenceUrls;
}
/**
@@ -629,7 +645,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
/**
* @return Returns the number of applied patches
*/
- private boolean didPatchSucceed(Connection connection, String patchId) throws Exception
+ private boolean didPatchSucceed(Connection connection, String patchId, boolean alternative) throws Exception
{
String patchTableName = getAppliedPatchTableName(connection);
if (patchTableName == null)
@@ -640,13 +656,22 @@ public class SchemaBootstrap extends AbstractLifecycleBean
Statement stmt = connection.createStatement();
try
{
- ResultSet rs = stmt.executeQuery("select succeeded from " + patchTableName + " where id = '" + patchId + "'");
+ ResultSet rs = stmt.executeQuery("select succeeded, was_executed from " + patchTableName + " where id = '" + patchId + "'");
if (!rs.next())
{
return false;
}
boolean succeeded = rs.getBoolean(1);
- return succeeded;
+ boolean wasExecuted = rs.getBoolean(2);
+
+ if (alternative)
+ {
+ return succeeded && wasExecuted;
+ }
+ else
+ {
+ return succeeded;
+ }
}
finally
{
@@ -911,7 +936,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
for (Patch alternativePatch : alternatives)
{
String alternativePatchId = alternativePatch.getId();
- boolean alternativeSucceeded = didPatchSucceed(connection, alternativePatchId);
+ boolean alternativeSucceeded = didPatchSucceed(connection, alternativePatchId, true);
if (alternativeSucceeded)
{
continue nextPatch;
@@ -919,7 +944,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
}
// check if the script was successfully executed
- boolean wasSuccessfullyApplied = didPatchSucceed(connection, patchId);
+ boolean wasSuccessfullyApplied = didPatchSucceed(connection, patchId, false);
if (wasSuccessfullyApplied)
{
// Either the patch was executed before or the system was bootstrapped
@@ -979,7 +1004,7 @@ public class SchemaBootstrap extends AbstractLifecycleBean
private Resource getDialectResource(Class dialectClass, String resourceUrl)
{
// replace the dialect placeholder
- String dialectResourceUrl = resourceUrl.replaceAll(PLACEHOLDER_DIALECT, dialectClass.getName());
+ String dialectResourceUrl = resolveDialectUrl(dialectClass, resourceUrl);
// get a handle on the resource
Resource resource = rpr.getResource(dialectResourceUrl);
if (!resource.exists())
@@ -1003,6 +1028,28 @@ public class SchemaBootstrap extends AbstractLifecycleBean
return resource;
}
}
+
+ /**
+ * Takes resource URL containing the {@link SchemaBootstrap#PLACEHOLDER_DIALECT dialect placeholder text}
+ * and substitutes the placeholder with the name of the given dialect's class.
+ *
+ * For example:
+ *
+ * resolveDialectUrl(MySQLInnoDBDialect.class, "classpath:alfresco/db/${db.script.dialect}/myfile.xml")
+ *
+ * would give the following String:
+ *
+ * classpath:alfresco/db/org.hibernate.dialect.MySQLInnoDBDialect/myfile.xml
+ *
+ *
+ * @param dialectClass
+ * @param resourceUrl
+ * @return
+ */
+ private String resolveDialectUrl(Class dialectClass, String resourceUrl)
+ {
+ return resourceUrl.replaceAll(PLACEHOLDER_DIALECT, dialectClass.getName());
+ }
/**
* Replaces the dialect placeholder in the script URL and attempts to find a file for
@@ -1035,15 +1082,17 @@ public class SchemaBootstrap extends AbstractLifecycleBean
if (executedStatements == null)
{
// Validate the schema, pre-upgrade
- validateSchema("Alfresco-{0}-Validation-Pre-Upgrade-");
+ validateSchema("Alfresco-{0}-Validation-Pre-Upgrade-{1}-");
// Dump the normalized, pre-upgrade Alfresco schema. We keep the file for later reporting.
- xmlPreSchemaOutputFile = dumpSchema(
+ xmlPreSchemaOutputFile34 = dumpSchema34(
this.dialect,
TempFileProvider.createTempFile(
"AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-",
"-Startup.xml").getPath(),
"Failed to dump normalized, pre-upgrade schema to file.");
+
+ dumpSchema("pre-upgrade");
// There is no lock at this stage. This process can fall out if the lock can't be applied.
setBootstrapStarted(connection);
@@ -1538,34 +1587,37 @@ public class SchemaBootstrap extends AbstractLifecycleBean
if (executedStatements != null)
{
// Validate the schema, post-upgrade
- validateSchema("Alfresco-{0}-Validation-Post-Upgrade-");
+ validateSchema("Alfresco-{0}-Validation-Post-Upgrade-{1}-");
// Dump the normalized, post-upgrade Alfresco schema.
- File xmlPostSchemaOutputFile = dumpSchema(
+ File xmlPostSchemaOutputFile34 = dumpSchema34(
this.dialect,
TempFileProvider.createTempFile(
"AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-",
".xml").getPath(),
"Failed to dump normalized, post-upgrade schema to file.");
+ // 4.0+ schema dump
+ dumpSchema("post-upgrade");
+
if (createdSchema)
{
// This is a new schema
- if (xmlPostSchemaOutputFile != null)
+ if (xmlPostSchemaOutputFile34 != null)
{
- LogUtil.info(logger, MSG_NORMALIZED_SCHEMA, xmlPostSchemaOutputFile.getPath());
+ LogUtil.info(logger, MSG_NORMALIZED_SCHEMA, xmlPostSchemaOutputFile34.getPath());
}
}
else
{
// We upgraded, so have to report pre- and post- schema dumps
- if (xmlPreSchemaOutputFile != null)
+ if (xmlPreSchemaOutputFile34 != null)
{
- LogUtil.info(logger, MSG_NORMALIZED_SCHEMA_PRE, xmlPreSchemaOutputFile.getPath());
+ LogUtil.info(logger, MSG_NORMALIZED_SCHEMA_PRE, xmlPreSchemaOutputFile34.getPath());
}
- if (xmlPostSchemaOutputFile != null)
+ if (xmlPostSchemaOutputFile34 != null)
{
- LogUtil.info(logger, MSG_NORMALIZED_SCHEMA_POST, xmlPostSchemaOutputFile.getPath());
+ LogUtil.info(logger, MSG_NORMALIZED_SCHEMA_POST, xmlPostSchemaOutputFile34.getPath());
}
}
}
@@ -1579,12 +1631,16 @@ public class SchemaBootstrap extends AbstractLifecycleBean
{
// We have been forced to stop, so we do one last dump of the schema and throw an exception to
// escape further startup procedures
- File xmlStopSchemaOutputFile = dumpSchema(
+ File xmlStopSchemaOutputFile = dumpSchema34(
this.dialect,
TempFileProvider.createTempFile(
"AlfrescoSchema-" + this.dialect.getClass().getSimpleName() + "-",
"-ForcedExit.xml").getPath(),
"Failed to dump normalized, post-upgrade, forced-exit schema to file.");
+
+ // 4.0+ schema dump
+ dumpSchema("forced-exit");
+
if (xmlStopSchemaOutputFile != null)
{
LogUtil.info(logger, MSG_NORMALIZED_SCHEMA, xmlStopSchemaOutputFile);
@@ -1639,19 +1695,55 @@ public class SchemaBootstrap extends AbstractLifecycleBean
* Collate differences and validation problems with the schema with respect to an appropriate
* reference schema.
*
+ * @param outputFileNameTemplate
* @return the number of potential problems found.
*/
- public int validateSchema(String outputFileNameTemplate)
+ public synchronized int validateSchema(String outputFileNameTemplate)
{
- Date startTime = new Date();
+ int totalProblems = 0;
- Resource referenceResource = getDialectResource(dialect.getClass(), schemaReferenceUrl);
- if (referenceResource == null || !referenceResource.exists())
+ // Discover available reference files (e.g. for prefixes alf_, avm_ etc.)
+ // and process each in turn.
+ for (String schemaReferenceUrl : schemaReferenceUrls)
{
- String resourceUrl = schemaReferenceUrl.replaceAll(PLACEHOLDER_DIALECT, dialect.getClass().getName());
- LogUtil.debug(logger, DEBUG_SCHEMA_COMP_NO_REF_FILE, resourceUrl);
+ Resource referenceResource = getDialectResource(dialect.getClass(), schemaReferenceUrl);
+
+ if (referenceResource == null || !referenceResource.exists())
+ {
+ String resourceUrl = resolveDialectUrl(dialect.getClass(), schemaReferenceUrl);
+ LogUtil.debug(logger, DEBUG_SCHEMA_COMP_NO_REF_FILE, resourceUrl);
+ }
+ else
+ {
+ // Validate schema against each reference file
+ int problems = validateSchema(referenceResource, outputFileNameTemplate);
+ totalProblems += problems;
+ }
+ }
+
+ // Return number of problems found across all reference files.
+ return totalProblems;
+ }
+
+ private int validateSchema(Resource referenceResource, String outputFileNameTemplate)
+ {
+ try
+ {
+ return attemptValidateSchema(referenceResource, outputFileNameTemplate);
+ }
+ catch (Throwable e)
+ {
+ if (logger.isErrorEnabled())
+ {
+ logger.error("Unable to validate database schema.", e);
+ }
return 0;
}
+ }
+
+ private int attemptValidateSchema(Resource referenceResource, String outputFileNameTemplate)
+ {
+ Date startTime = new Date();
InputStream is = null;
try
@@ -1667,7 +1759,10 @@ public class SchemaBootstrap extends AbstractLifecycleBean
xmlToSchema.parse();
Schema reference = xmlToSchema.getSchema();
- ExportDb exporter = new ExportDb(dataSource, dialect);
+ ExportDb exporter = new ExportDb(dataSource, dialect, descriptorService);
+ // Ensure that the database objects we're validating are filtered
+ // by the same prefix as the reference file.
+ exporter.setNamePrefix(reference.getDbPrefix());
exporter.execute();
Schema target = exporter.getSchema();
@@ -1677,9 +1772,12 @@ public class SchemaBootstrap extends AbstractLifecycleBean
Results results = schemaComparator.getComparisonResults();
- String outputFileName = MessageFormat.format(
- outputFileNameTemplate,
- new Object[] { dialect.getClass().getSimpleName() });
+ Object[] outputFileNameParams = new Object[]
+ {
+ dialect.getClass().getSimpleName(),
+ reference.getDbPrefix()
+ };
+ String outputFileName = MessageFormat.format(outputFileNameTemplate, outputFileNameParams);
File outputFile = TempFileProvider.createTempFile(outputFileName, ".txt");
@@ -1723,9 +1821,13 @@ public class SchemaBootstrap extends AbstractLifecycleBean
}
/**
+ * Older schema dump tool. Left here for the moment but is essentially duplicated
+ * by the newer XML dumper which is used in automatic diff/validation of the schema
+ * against a known good reference.
+ *
* @return Returns the file that was written to or null if it failed
*/
- private File dumpSchema(Dialect dialect, String fileName, String err)
+ private File dumpSchema34(Dialect dialect, String fileName, String err)
{
File xmlSchemaOutputFile = new File(fileName);
try
@@ -1749,6 +1851,121 @@ public class SchemaBootstrap extends AbstractLifecycleBean
return xmlSchemaOutputFile;
}
+ /**
+ * Produces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if
+ * changes are made to the schema) and can made upon demand via JMX.
+ *
+ * @return List of output files.
+ */
+ public List dumpSchema()
+ {
+ return dumpSchema("", null);
+ }
+
+ /**
+ * Produces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if
+ * changes are made to the schema) and can made upon demand via JMX.
+ *
+ * @param dbPrefixes Array of database object prefixes to produce the dump for, e.g. "alf_".
+ * @return List of output files.
+ */
+ public List dumpSchema(String[] dbPrefixes)
+ {
+ return dumpSchema("", dbPrefixes);
+ }
+
+ /**
+ * Dumps the DB schema to temporary file(s), named similarly to:
+ *
+ * Alfresco-schema-DialectName-whenDumped-dbPrefix-23498732.xml
+ *
+ * Where the digits serve to create a unique temp file name. If whenDumped is empty or null,
+ * then the output is similar to:
+ *
+ * Alfresco-schema-DialectName-dbPrefix-23498732.xml
+ *
+ * If dbPrefixes is null, then the default list is used (see {@link MultiFileDumper#DEFAULT_PREFIXES})
+ * The dump files' paths are logged at info level.
+ *
+ * @param whenDumped
+ * @param dbPrefixes Array of database object prefixes to filter by, e.g. "alf_"
+ * @return List of output files.
+ */
+ private List dumpSchema(String whenDumped, String[] dbPrefixes)
+ {
+ // Build a string to use as the file name template,
+ // e.g. "Alfresco-schema-MySQLDialect-pre-upgrade-{0}-"
+ StringBuilder sb = new StringBuilder(64);
+ sb.append("Alfresco-schema-").
+ append(dialect.getClass().getSimpleName());
+ if (whenDumped != null && whenDumped.length() > 0)
+ {
+ sb.append("-");
+ sb.append(whenDumped);
+ }
+ sb.append("-{0}-");
+
+ File outputDir = TempFileProvider.getTempDir();
+ String fileNameTemplate = sb.toString();
+ return dumpSchema(outputDir, fileNameTemplate, dbPrefixes);
+ }
+
+ /**
+ * Same as for {@link #dumpSchema(String, String[])} - except that the default list
+ * of database object prefixes is used for filtering.
+ *
+ * @see #dumpSchema(String, String[])
+ * @param whenDumped
+ * @return
+ */
+ private List dumpSchema(String whenDumped)
+ {
+ return dumpSchema(whenDumped, null);
+ }
+
+ private List dumpSchema(File outputDir, String fileNameTemplate, String[] dbPrefixes)
+ {
+ try
+ {
+ return attemptDumpSchema(outputDir, fileNameTemplate, dbPrefixes);
+ }
+ catch (Throwable e)
+ {
+ if (logger.isErrorEnabled())
+ {
+ logger.error("Unable to dump schema to directory " + outputDir, e);
+ }
+ return null;
+ }
+ }
+
+ private List attemptDumpSchema(File outputDir, String fileNameTemplate, String[] dbPrefixes)
+ {
+ DbToXMLFactory dbToXMLFactory = new MultiFileDumper.DbToXMLFactoryImpl(getApplicationContext());
+
+ MultiFileDumper dumper;
+
+ if (dbPrefixes == null)
+ {
+ dumper = new MultiFileDumper(outputDir, fileNameTemplate, dbToXMLFactory);
+ }
+ else
+ {
+ dumper = new MultiFileDumper(dbPrefixes, outputDir, fileNameTemplate, dbToXMLFactory);
+ }
+ List files = dumper.dumpFiles();
+
+ for (File file : files)
+ {
+ if (logger.isInfoEnabled())
+ {
+ LogUtil.info(logger, MSG_NORMALIZED_SCHEMA, file.getAbsolutePath());
+ }
+ }
+
+ return files;
+ }
+
@Override
protected void onShutdown(ApplicationEvent event)
{
diff --git a/source/java/org/alfresco/repo/imap/ImapServiceImpl.java b/source/java/org/alfresco/repo/imap/ImapServiceImpl.java
index e2631a9330..4066e368c4 100644
--- a/source/java/org/alfresco/repo/imap/ImapServiceImpl.java
+++ b/source/java/org/alfresco/repo/imap/ImapServiceImpl.java
@@ -84,6 +84,7 @@ import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.model.SubFolderFilter;
import org.alfresco.service.cmr.preference.PreferenceService;
+import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -95,6 +96,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
+import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -882,7 +884,10 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
logger.debug("Subscribing: " + user + ", " + mailbox);
}
AlfrescoImapFolder mailFolder = getOrCreateMailbox(user, mailbox, true, false);
- nodeService.removeAspect(mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED);
+ PersonService personService = serviceRegistry.getPersonService();
+ NodeRef userRef = personService.getPerson(user.getLogin());
+
+ nodeService.removeAssociation(userRef, mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
}
public void unsubscribe(AlfrescoImapUser user, String mailbox)
@@ -894,8 +899,9 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
AlfrescoImapFolder mailFolder = getOrCreateMailbox(user, mailbox, true, false);
if(mailFolder.getFolderInfo() != null)
{
- logger.debug("Unsubscribing by ASPECT_IMAP_FOLDER_NONSUBSCRIBED");
- nodeService.addAspect(mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED, null);
+ PersonService personService = serviceRegistry.getPersonService();
+ NodeRef userRef = personService.getPerson(user.getLogin());
+ nodeService.createAssociation(userRef, mailFolder.getFolderInfo().getNodeRef(), ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
}
else
{
@@ -993,6 +999,9 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
String rootPath = index == -1 ? mailboxPattern : mailboxPattern.substring(0, index);
boolean found = false;
+ String userName = user.getLogin();
+ Set unsubscribedFodlers = getUnsubscribedFolders(userName);
+
for (String mountPointName : imapConfigMountPoints.keySet())
{
if (mountPointName.matches(rootPath.replaceAll("[%\\*]", ".*")))
@@ -1005,8 +1014,8 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
ImapViewMode viewMode = imapConfigMountPoints.get(mountPointName).getMode();
if (index < 0)
{
- String userName = user.getLogin();
- if (!listSubscribed || isSubscribed(mountPointFileInfo, userName))
+
+ if (!listSubscribed || !unsubscribedFodlers.contains(mountPointFileInfo.getNodeRef()))
{
result.add(new AlfrescoImapFolder(mountPointFileInfo, userName, mountPointName, mountPointName, viewMode,
isExtractionEnabled(mountPointFileInfo.getNodeRef()), serviceRegistry, mountPointId));
@@ -1111,6 +1120,9 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
if (index < 0)
{
+ String userName = user.getLogin();
+ Set unsubscribedFodlers = getUnsubscribedFolders(userName);
+
// This is the last level
for (FileInfo fileInfo : list)
{
@@ -1119,8 +1131,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
continue;
}
String folderPath = rootPathPrefix + fileInfo.getName();
- String userName = user.getLogin();
- if (!listSubscribed || isSubscribed(fileInfo, userName))
+ if (!listSubscribed || !unsubscribedFodlers.contains(fileInfo.getNodeRef()))
{
fullList.add(new AlfrescoImapFolder(fileInfo, userName, fileInfo.getName(), folderPath, viewMode,
isExtractionEnabled(fileInfo.getNodeRef()), serviceRegistry, mountPointId));
@@ -1233,11 +1244,21 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
return userHome;
}
- private boolean isSubscribed(FileInfo fileInfo, String userName)
+ private Set getUnsubscribedFolders(String userName)
{
- return !nodeService.hasAspect(fileInfo.getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_NONSUBSCRIBED);
+ Set result = new HashSet();
+ PersonService personService = serviceRegistry.getPersonService();
+ NodeRef userRef = personService.getPerson(userName);
+ List unsubscribedFodlers = nodeService.getTargetAssocs(userRef, ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
+ for (AssociationRef asocRef : unsubscribedFodlers)
+ {
+ result.add(asocRef.getTargetRef());
+ }
+
+ return result;
}
+
private String getCurrentUser()
{
return AuthenticationUtil.getFullyAuthenticatedUser();
diff --git a/source/java/org/alfresco/repo/invitation/AbstractInvitationServiceImplTest.java b/source/java/org/alfresco/repo/invitation/AbstractInvitationServiceImplTest.java
index d747c6f0c2..8fefb6a93e 100644
--- a/source/java/org/alfresco/repo/invitation/AbstractInvitationServiceImplTest.java
+++ b/source/java/org/alfresco/repo/invitation/AbstractInvitationServiceImplTest.java
@@ -1,1077 +1,1076 @@
-/*
- * Copyright (C) 2005-2011 Alfresco Software Limited.
- *
- * This file is part of Alfresco
- *
- * Alfresco is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Alfresco is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Alfresco. If not, see .
- */
-
-package org.alfresco.repo.invitation;
-
-import java.lang.reflect.Field;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.internet.MimeMessage;
-
-import org.alfresco.model.ContentModel;
-import org.alfresco.repo.action.executer.MailActionExecuter;
-import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
-import org.alfresco.repo.security.authentication.AuthenticationComponent;
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.repo.site.SiteModel;
-import org.alfresco.repo.workflow.WorkflowAdminServiceImpl;
-import org.alfresco.service.cmr.invitation.Invitation;
-import org.alfresco.service.cmr.invitation.Invitation.ResourceType;
-import org.alfresco.service.cmr.invitation.InvitationSearchCriteria;
-import org.alfresco.service.cmr.invitation.InvitationService;
-import org.alfresco.service.cmr.invitation.ModeratedInvitation;
-import org.alfresco.service.cmr.invitation.NominatedInvitation;
-import org.alfresco.service.cmr.security.PersonService;
-import org.alfresco.service.cmr.site.SiteInfo;
-import org.alfresco.service.cmr.site.SiteService;
-import org.alfresco.service.cmr.site.SiteVisibility;
-import org.alfresco.util.BaseAlfrescoSpringTest;
-import org.alfresco.util.PropertyMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Unit tests of Invitation Service
- */
-public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpringTest
-{
- private static final Log logger = LogFactory.getLog(AbstractInvitationServiceImplTest.class);
-
- private SiteService siteService;
- protected AuthenticationComponent authenticationComponent;
- private PersonService personService;
- protected InvitationService invitationService;
- private MailActionExecuter mailService;
- private boolean startSendEmails;
- protected InvitationServiceImpl invitationServiceImpl;
- protected WorkflowAdminServiceImpl workflowAdminService;
-
- protected final static String SITE_SHORT_NAME_INVITE = "InvitationTest";
- protected final static String SITE_SHORT_NAME_RED = "InvitationTestRed";
- protected final static String SITE_SHORT_NAME_BLUE = "InvitationTestBlue";
- public final static String PERSON_FIRSTNAME = "InvitationFirstName123";
- public final static String PERSON_FIRSTNAME_SPACES = "Invitation First\tName\n1\r2\r\n3";
- public final static String PERSON_LASTNAME = "InvitationLastName123";
- public final static String PERSON_LASTNAME_SPACES = "Invitation Last\tName\n1\r2\r\n3";
- public final static String PERSON_JOBTITLE = "JobTitle123";
- public final static String PERSON_ORG = "Organisation123";
-
- public final static String USER_MANAGER = "InvitationServiceManagerOne";
- public final static String USER_ONE = "InvitationServiceAlice";
- public final static String USER_TWO = "InvitationServiceBob";
- public final static String USER_EVE = "InvitationServiceEve";
- public final static String USER_NOEMAIL = "InvitationServiceNoEmail";
- public final static String USER_ONE_FIRSTNAME = "One";
- public final static String USER_ONE_LASTNAME = "Test";
- public final static String USER_ONE_EMAIL = USER_ONE + "@alfrescotesting.com";
- public final static String USER_TWO_EMAIL = USER_TWO + "@alfrescotesting.com";
-
- private Collection enabledEngines;
- private Collection visibleEngines;
- /**
- * Called during the transaction setup
- */
- @SuppressWarnings("deprecation")
- @Override
- protected void onSetUpInTransaction() throws Exception
- {
- super.onSetUpInTransaction();
- this.invitationService = (InvitationService) this.applicationContext.getBean("InvitationService");
- this.siteService = (SiteService) this.applicationContext.getBean("SiteService");
- this.personService = (PersonService) this.applicationContext.getBean("PersonService");
- this.authenticationComponent = (AuthenticationComponent) this.applicationContext
- .getBean("authenticationComponent");
- this.invitationServiceImpl = (InvitationServiceImpl) applicationContext.getBean("invitationService");
- this.workflowAdminService = (WorkflowAdminServiceImpl)applicationContext.getBean(WorkflowAdminServiceImpl.NAME);
-
- this.startSendEmails = invitationServiceImpl.isSendEmails();
-
- this.enabledEngines = workflowAdminService.getEnabledEngines();
- this.visibleEngines = workflowAdminService.getVisibleEngines();
-
- invitationServiceImpl.setSendEmails(true);
-
- // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
- // during unit testing
- // (or sending out email by accident from tests)
- mailService = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
- .getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
- mailService.setTestMode(true);
-
-
- createPerson(USER_MANAGER, USER_MANAGER + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
- createPerson(USER_ONE, USER_ONE_EMAIL, USER_ONE_FIRSTNAME, USER_ONE_LASTNAME);
- createPerson(USER_TWO, USER_TWO + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
- createPerson(USER_EVE, USER_EVE + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
- createPerson(USER_NOEMAIL, null, USER_NOEMAIL, USER_NOEMAIL);
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
-
- SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME_INVITE);
- if (siteInfo == null)
- {
- siteInfo = siteService.createSite("InviteSitePreset", SITE_SHORT_NAME_INVITE, "InviteSiteTitle",
- "InviteSiteDescription", SiteVisibility.MODERATED);
-
- siteService.setMembership(SITE_SHORT_NAME_INVITE, USER_NOEMAIL, SiteModel.SITE_MANAGER);
- }
-
- SiteInfo siteInfoRed = siteService.getSite(SITE_SHORT_NAME_RED);
- if (siteInfoRed == null)
- {
- siteService.createSite("InviteSiteRed", SITE_SHORT_NAME_RED, "InviteSiteTitle", "InviteSiteDescription",
- SiteVisibility.MODERATED);
- }
- SiteInfo siteInfoBlue = siteService.getSite(SITE_SHORT_NAME_BLUE);
- if (siteInfoBlue == null)
- {
- siteService.createSite("InviteSiteBlue", SITE_SHORT_NAME_BLUE, "InviteSiteTitle", "InviteSiteDescription",
- SiteVisibility.MODERATED);
- }
-
- }
-
- @Override
- protected void onTearDownInTransaction() throws Exception
- {
- // Make sure both workflow engines are enabled.and visible
-
- this.authenticationComponent.setSystemUserAsCurrentUser();
-
- workflowAdminService.setEnabledEngines(enabledEngines);
- workflowAdminService.setVisibleEngines(visibleEngines);
-
-// invitationServiceImpl.setSendEmails(startSendEmails);
-// siteService.deleteSite(SITE_SHORT_NAME_INVITE);
-// siteService.deleteSite(SITE_SHORT_NAME_RED);
-// siteService.deleteSite(SITE_SHORT_NAME_BLUE);
-// deletePersonByUserName(USER_ONE);
-// deletePersonByUserName(USER_TWO);
-// deletePersonByUserName(USER_EVE);
-// deletePersonByUserName(USER_MANAGER);
- super.onTearDownInTransaction();
- }
-
- /*
- * end of setup now for some real tests
- */
-
- /**
- *
- */
- public void testConfiguration()
- {
- assertNotNull("Invitation service is null", invitationService);
- }
-
- /**
- * Test nominated user - new user
- *
- * @throws Exception
- */
- public void testNominatedInvitationNewUser() throws Exception
- {
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.SECOND, -1);
- Date startDate = calendar.getTime();
-
- String inviteeFirstName = PERSON_FIRSTNAME;
- String inviteeLastName = PERSON_LASTNAME;
- String inviteeEmail = "123@alfrescotesting.com";
- String inviteeUserName = null;
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
-
- NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
- inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitation);
- String inviteId = nominatedInvitation.getInviteId();
- assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
-
- // Generated User Name should be returned
- inviteeUserName = nominatedInvitation.getInviteeUserName();
- assertNotNull("generated user name is null", inviteeUserName);
- // sentInviteDate should be set to today
- {
- Date sentDate = nominatedInvitation.getSentInviteDate();
- assertTrue("sentDate wrong - too early. Start Date: " +startDate +"\nSent Date: "+sentDate, sentDate.after(startDate));
- assertTrue("sentDate wrong - too lateStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.before(new Date(new Date().getTime() + 1)));
- }
-
- assertEquals("resource type name wrong", resourceType, nominatedInvitation.getResourceType());
- assertEquals("resource name wrong", resourceName, nominatedInvitation.getResourceName());
- assertEquals("role name wrong", inviteeRole, nominatedInvitation.getRoleName());
- assertEquals("server path wrong", serverPath, nominatedInvitation.getServerPath());
- assertEquals("accept URL wrong", acceptUrl, nominatedInvitation.getAcceptUrl());
- assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
-
- /**
- * 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("invite id wrong", inviteId, invitation.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, invitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, invitation.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, invitation.getInviteeUserName());
- assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
- assertEquals("resource name wrong", resourceName, invitation.getResourceName());
- assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
- assertEquals("server path wrong", serverPath, invitation.getServerPath());
- assertEquals("accept URL wrong", acceptUrl, invitation.getAcceptUrl());
- assertEquals("reject URL wrong", rejectUrl, invitation.getRejectUrl());
-
- Date sentDate = invitation.getSentInviteDate();
- // sentInviteDate should be set to today
- assertTrue("sentDate wrong too early", sentDate.after(startDate));
- assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
- }
-
- /**
- * Check the email itself, and check it
- * is as we would expect it to be
- */
- {
- MimeMessage msg = mailService.retrieveLastTestMessage();
-
- assertEquals(1, msg.getAllRecipients().length);
- assertEquals(inviteeEmail, msg.getAllRecipients()[0].toString());
-
- assertEquals(1, msg.getFrom().length);
- assertEquals(USER_MANAGER + "@alfrescotesting.com", msg.getFrom()[0].toString());
-
- // Hasn't been sent, so no sent or received date
- assertNull("Not been sent yet", msg.getSentDate());
- assertNull("Not been sent yet", msg.getReceivedDate());
-
- // TODO - check some more details of the email
- assertTrue((msg.getSubject().indexOf("You have been invited to join the") != -1));
- }
-
- /**
- * Search for the new invitation
- */
- List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is empty", !invitations.isEmpty());
-
- NominatedInvitation firstInvite = (NominatedInvitation) invitations.get(0);
- assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, firstInvite.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, firstInvite.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, firstInvite.getInviteeUserName());
-
- /**
- * Now accept the invitation
- */
- NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(firstInvite
- .getInviteId(), firstInvite.getTicket());
- assertEquals("invite id wrong", firstInvite.getInviteId(), acceptedInvitation.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, acceptedInvitation.getInviteeUserName());
-
- List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is not empty", it4.isEmpty());
-
- /**
- * Now get the invitation that we accepted
- */
- NominatedInvitation acceptedInvitation2 = (NominatedInvitation) invitationService.getInvitation(firstInvite
- .getInviteId());
- assertNotNull("get after accept does not return", acceptedInvitation2);
-
- /**
- * Now verify access control list
- */
- String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
- assertEquals("role name wrong", roleName, inviteeRole);
- siteService.removeMembership(resourceName, inviteeUserName);
-
-
- /**
- * Check that system generated invitations can work as well
- */
- {
- Field faf = mailService.getClass().getDeclaredField("fromAddress");
- faf.setAccessible(true);
- String defaultFromAddress = (String)ReflectionUtils.getField(faf, mailService);
-
- AuthenticationUtil.setFullyAuthenticatedUser(USER_NOEMAIL);
-
- // Check invitiation
- NominatedInvitation nominatedInvitation2 = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
- USER_TWO_EMAIL, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitation2);
- inviteId = nominatedInvitation.getInviteId();
- assertEquals("first name wrong", inviteeFirstName, nominatedInvitation2.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, nominatedInvitation2.getInviteeLastName());
- assertEquals("email name wrong", USER_TWO_EMAIL, nominatedInvitation2.getInviteeEmail());
-
- // Check the email
- MimeMessage msg = mailService.retrieveLastTestMessage();
-
- assertEquals(1, msg.getAllRecipients().length);
- assertEquals(USER_TWO_EMAIL, msg.getAllRecipients()[0].toString());
-
- assertEquals(1, msg.getFrom().length);
- assertEquals(defaultFromAddress, msg.getFrom()[0].toString());
- }
- }
-
- // TODO MER START
- /**
- * Test nominated user - new user who rejects invitation
- *
- * @throws Exception
- */
- public void testNominatedInvitationNewUserReject() throws Exception
- {
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.SECOND, -1);
- Date startDate = calendar.getTime();
-
- String inviteeFirstName = PERSON_FIRSTNAME;
- String inviteeLastName = PERSON_LASTNAME;
- String inviteeEmail = "123@alfrescotesting.com";
- String inviteeUserName = null;
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
-
- NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
- inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitation);
- assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
-
- // Generated User Name should be returned
- inviteeUserName = nominatedInvitation.getInviteeUserName();
- assertNotNull("generated user name is null", inviteeUserName);
- // sentInviteDate should be set to today
- {
- Date sentDate = nominatedInvitation.getSentInviteDate();
- assertTrue("sentDate wrong - too earlyStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.after(startDate));
- assertTrue("sentDate wrong - too lateStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.before(new Date(new Date().getTime() + 1)));
- }
-
- /**
- * Now reject the invitation
- */
- NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.reject(nominatedInvitation
- .getInviteId(), "dont want it");
- assertEquals("invite id wrong", nominatedInvitation.getInviteId(), rejectedInvitation.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, rejectedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, rejectedInvitation.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
-
- List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is not empty", it4.isEmpty());
-
- /**
- * Now verify access control list inviteeUserName should not exist
- */
- String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
- if (roleName != null)
- {
- fail("role has been set for a rejected user");
- }
-
- /**
- * Now verify that the generated user has been removed
- */
- if (personService.personExists(inviteeUserName))
- {
- fail("generated user has not been cleaned up");
- }
- }
-
- // TODO MER END
-
- /**
- * Test nominated user - new user Creates two separate users with two the
- * same email address.
- *
- * @throws Exception
- */
- public void testNominatedInvitationNewUserSameEmails() throws Exception
- {
- String inviteeAFirstName = "John";
- String inviteeALastName = "Smith";
-
- String inviteeBFirstName = "Jane";
- String inviteeBLastName = "Smith";
-
- String inviteeEmail = "123@alfrescotesting.com";
- String inviteeAUserName = null;
- String inviteeBUserName = null;
-
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
-
- NominatedInvitation nominatedInvitationA = invitationService.inviteNominated(inviteeAFirstName,
- inviteeALastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
- rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitationA);
- String inviteAId = nominatedInvitationA.getInviteId();
- assertEquals("first name wrong", inviteeAFirstName, nominatedInvitationA.getInviteeFirstName());
- assertEquals("last name wrong", inviteeALastName, nominatedInvitationA.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, nominatedInvitationA.getInviteeEmail());
-
- // Generated User Name should be returned
- inviteeAUserName = nominatedInvitationA.getInviteeUserName();
- assertNotNull("generated user name is null", inviteeAUserName);
-
- NominatedInvitation nominatedInvitationB = invitationService.inviteNominated(inviteeBFirstName,
- inviteeBLastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
- rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitationB);
- String inviteBId = nominatedInvitationB.getInviteId();
- assertEquals("first name wrong", inviteeBFirstName, nominatedInvitationB.getInviteeFirstName());
- assertEquals("last name wrong", inviteeBLastName, nominatedInvitationB.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, nominatedInvitationB.getInviteeEmail());
-
- // Generated User Name should be returned
- inviteeBUserName = nominatedInvitationB.getInviteeUserName();
- assertNotNull("generated user name is null", inviteeBUserName);
- assertFalse("generated user names are the same", inviteeAUserName.equals(inviteeBUserName));
-
- /**
- * Now accept the invitation
- */
- NominatedInvitation acceptedInvitationA = (NominatedInvitation) invitationService.accept(inviteAId,
- nominatedInvitationA.getTicket());
- assertEquals("invite id wrong", inviteAId, acceptedInvitationA.getInviteId());
- assertEquals("first name wrong", inviteeAFirstName, acceptedInvitationA.getInviteeFirstName());
- assertEquals("last name wrong", inviteeALastName, acceptedInvitationA.getInviteeLastName());
- assertEquals("user name wrong", inviteeAUserName, acceptedInvitationA.getInviteeUserName());
-
- NominatedInvitation acceptedInvitationB = (NominatedInvitation) invitationService.accept(inviteBId,
- nominatedInvitationB.getTicket());
- assertEquals("invite id wrong", inviteBId, acceptedInvitationB.getInviteId());
- assertEquals("first name wrong", inviteeBFirstName, acceptedInvitationB.getInviteeFirstName());
- assertEquals("last name wrong", inviteeBLastName, acceptedInvitationB.getInviteeLastName());
- assertEquals("user name wrong", inviteeBUserName, acceptedInvitationB.getInviteeUserName());
-
- /**
- * Now verify access control list
- */
- String roleNameA = siteService.getMembersRole(resourceName, inviteeAUserName);
- assertEquals("role name wrong", roleNameA, inviteeRole);
- String roleNameB = siteService.getMembersRole(resourceName, inviteeBUserName);
- assertEquals("role name wrong", roleNameB, inviteeRole);
- siteService.removeMembership(resourceName, inviteeAUserName);
- 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();
- expectedUserName = expectedUserName.replaceAll("\\s+", "_");
- 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) read it.
- * search for it cancel 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
- {
- String inviteeUserName = USER_ONE;
- String inviteeEmail = USER_ONE_EMAIL;
- String inviteeFirstName = USER_ONE_FIRSTNAME;
- String inviteeLastName = USER_ONE_LASTNAME;
-
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- authenticationComponent.setCurrentUser(USER_MANAGER);
-
- NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeUserName, resourceType,
- resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- assertNotNull("nominated invitation is null", nominatedInvitation);
- String inviteId = nominatedInvitation.getInviteId();
- assertEquals("user name wrong", inviteeUserName, nominatedInvitation.getInviteeUserName());
- assertEquals("resource type name wrong", resourceType, nominatedInvitation.getResourceType());
- assertEquals("resource name wrong", resourceName, nominatedInvitation.getResourceName());
- assertEquals("role name wrong", inviteeRole, nominatedInvitation.getRoleName());
- assertEquals("server path wrong", serverPath, nominatedInvitation.getServerPath());
- assertEquals("accept URL wrong", acceptUrl, nominatedInvitation.getAcceptUrl());
- assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
-
- // These values should be read from the person record
- assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
-
- /**
- * 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("invite id wrong", inviteId, invitation.getInviteId());
- assertEquals("user name wrong", inviteeUserName, nominatedInvitation.getInviteeUserName());
- assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
- assertEquals("resource name wrong", resourceName, invitation.getResourceName());
- assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
- assertEquals("server path wrong", serverPath, invitation.getServerPath());
- assertEquals("accept URL wrong", acceptUrl, invitation.getAcceptUrl());
- assertEquals("reject URL wrong", rejectUrl, invitation.getRejectUrl());
-
- // These values should have been read from the DB
- assertEquals("first name wrong", inviteeFirstName, invitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, invitation.getInviteeLastName());
- assertEquals("email name wrong", inviteeEmail, invitation.getInviteeEmail());
-
- /**
- * Search for the new invitation
- */
- List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is empty", !invitations.isEmpty());
-
- NominatedInvitation firstInvite = (NominatedInvitation) invitations.get(0);
- assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, firstInvite.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, firstInvite.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, firstInvite.getInviteeUserName());
-
- /**
- * Now cancel the invitation
- */
- NominatedInvitation canceledInvitation = (NominatedInvitation) invitationService.cancel(inviteId);
- assertEquals("invite id wrong", inviteId, canceledInvitation.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, canceledInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, canceledInvitation.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, canceledInvitation.getInviteeUserName());
-
- /**
- * Do the query again - should no longer find anything
- */
- List it2 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is not empty", it2.isEmpty());
-
- /**
- * Now invite and reject
- */
- NominatedInvitation secondInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
- resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.cancel(secondInvite
- .getInviteId());
- assertEquals("invite id wrong", secondInvite.getInviteId(), rejectedInvitation.getInviteId());
- assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
-
- List it3 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is not empty", it3.isEmpty());
-
- /**
- * Now invite and accept
- */
- NominatedInvitation thirdInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
- resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(thirdInvite
- .getInviteId(), thirdInvite.getTicket());
- assertEquals("invite id wrong", thirdInvite.getInviteId(), acceptedInvitation.getInviteId());
- assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
- assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
- assertEquals("user name wrong", inviteeUserName, acceptedInvitation.getInviteeUserName());
-
- List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is not empty", it4.isEmpty());
-
- /**
- * Now verify access control list
- */
- String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
- assertEquals("role name wrong", inviteeRole, roleName);
- siteService.removeMembership(resourceName, inviteeUserName);
- }
-
- /**
- * Create a moderated invitation Get it Search for it Cancel it Create a
- * moderated invitation Reject the invitation Create a moderated invitation
- * Approve the invitation
- */
- public void testModeratedInvitation()
- {
- String inviteeUserName = USER_TWO;
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String comments = "please sir, let me in!";
-
- this.authenticationComponent.setCurrentUser(USER_TWO);
- ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
- resourceName, inviteeRole);
-
- assertNotNull("moderated invitation is null", invitation);
- String inviteId = invitation.getInviteId();
- assertEquals("user name wrong", inviteeUserName, invitation.getInviteeUserName());
- assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
- assertEquals("comments", comments, invitation.getInviteeComments());
- assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
- assertEquals("resource name wrong", resourceName, invitation.getResourceName());
-
- /**
- * Now we have an invitation get it and check the details have been
- * returned correctly.
- */
- ModeratedInvitation mi2 = (ModeratedInvitation) invitationService.getInvitation(inviteId);
- assertEquals("invite id", inviteId, mi2.getInviteId());
- assertEquals("user name wrong", inviteeUserName, mi2.getInviteeUserName());
- assertEquals("role name wrong", inviteeRole, mi2.getRoleName());
- assertEquals("comments", comments, mi2.getInviteeComments());
- assertEquals("resource type name wrong", resourceType, mi2.getResourceType());
- assertEquals("resource name wrong", resourceName, mi2.getResourceName());
-
- /**
- * Search for the new invitation
- */
- List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("invitations is empty", !invitations.isEmpty());
-
- ModeratedInvitation firstInvite = (ModeratedInvitation) invitations.get(0);
- assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
-
- /**
- * Cancel the invitation
- */
- ModeratedInvitation canceledInvitation = (ModeratedInvitation) invitationService.cancel(inviteId);
- assertEquals("invite id wrong", inviteId, canceledInvitation.getInviteId());
- assertEquals("comments wrong", comments, canceledInvitation.getInviteeComments());
-
- /**
- * Should now be no invitation
- */
- List inv2 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
- assertTrue("After cancel invitations is not empty", inv2.isEmpty());
-
- /**
- * New invitation
- */
- this.authenticationComponent.setCurrentUser(USER_TWO);
- ModeratedInvitation invite2 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
- resourceName, inviteeRole);
-
- String secondInvite = invite2.getInviteId();
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
- invitationService.reject(secondInvite, "This is a test reject");
-
- /**
- * New invitation
- */
- this.authenticationComponent.setCurrentUser(USER_TWO);
- ModeratedInvitation invite3 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
- resourceName, inviteeRole);
-
- String thirdInvite = invite3.getInviteId();
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
- invitationService.approve(thirdInvite, "Welcome in");
-
- /**
- * Now verify access control list
- */
- String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
- assertEquals("role name wrong", inviteeRole, roleName);
- siteService.removeMembership(resourceName, inviteeUserName);
-
- }
-
- /**
- * Test the approval of a moderated invitation
- */
- public void testModeratedApprove()
- {
- String inviteeUserName = USER_TWO;
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String comments = "please sir, let me in!";
-
- /**
- * New invitation from User TWO
- */
- this.authenticationComponent.setCurrentUser(USER_TWO);
- ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
- resourceName, inviteeRole);
-
- String invitationId = invitation.getInviteId();
-
- /**
- * Negative test Attempt to approve without the necessary role
- */
- try
- {
- invitationService.approve(invitationId, "No Way Hosea!");
- assertTrue("excetion not thrown", false);
-
- }
- catch (Exception e)
- {
- // An exception should have been thrown
- e.printStackTrace();
- System.out.println(e.toString());
- }
-
- /**
- * Approve the invitation
- */
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
- invitationService.approve(invitationId, "Come on in");
-
- /**
- * Now verify access control list contains user two
- */
- String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
- assertEquals("role name wrong", inviteeRole, roleName);
-
- /**
- * Negative test attempt to approve an invitation that has aready been
- * approved
- */
- try
- {
- invitationService.approve(invitationId, "Have I not already done this?");
- assertTrue("duplicate approve excetion not thrown", false);
- }
- catch (Exception e)
- {
- // An exception should have been thrown
- e.printStackTrace();
- System.out.println(e.toString());
- }
- /**
- * Negative test User is already a member of the site
- */
- siteService.removeMembership(resourceName, inviteeUserName);
- }
-
- /**
- * Tests of Moderated Reject
- */
- public void testModeratedReject()
- {
- String inviteeUserName = USER_TWO;
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String comments = "please sir, let me in!";
-
- /**
- * New invitation from User TWO
- */
- this.authenticationComponent.setCurrentUser(USER_TWO);
- ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
- resourceName, inviteeRole);
-
- String invitationId = invitation.getInviteId();
-
- /**
- * Negative test Attempt to reject without the necessary role
- */
- try
- {
- invitationService.reject(invitationId, "No Way Hosea!");
- assertTrue("excetion not thrown", false);
-
- }
- catch (Exception e)
- {
- // An exception should have been thrown
- e.printStackTrace();
- System.out.println(e.toString());
- }
-
- /**
- * Reject the invitation
- */
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
- invitationService.reject(invitationId, "Go away!");
-
- /**
- * Negative test attempt to approve an invitation that has been rejected
- */
- try
- {
- invitationService.approve(invitationId, "Have I not rejected this?");
- assertTrue("rejected invitation not working", false);
- }
- catch (Exception e)
- {
- // An exception should have been thrown
- e.printStackTrace();
- System.out.println(e.toString());
- }
- }
-
- /**
- * Test search invitation
- */
- public void testSearchInvitation()
- {
- /**
- * Make up a tree of invitations and then search Resource, User,
- * Workflow 1) RED, One, Moderated 2) RED, One, Nominated 3) BLUE, One,
- * Nominated 4) RED, Two, Moderated
- */
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String comments = "please sir, let me in!";
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- this.authenticationComponent.setCurrentUser(USER_MANAGER);
- invitationService.inviteModerated(comments, USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
-
- invitationService.inviteNominated(USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole, serverPath,
- acceptUrl, rejectUrl);
-
- NominatedInvitation invitationThree = invitationService.inviteNominated(USER_ONE, resourceType,
- SITE_SHORT_NAME_BLUE, inviteeRole, serverPath, acceptUrl, rejectUrl);
- String threeId = invitationThree.getInviteId();
-
- invitationService.inviteModerated(comments, USER_TWO, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
-
- /**
- * Search for invitations for BLUE
- */
- List resOne = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
- SITE_SHORT_NAME_BLUE);
- assertEquals("blue invites not 1", 1, resOne.size());
- assertEquals("blue id wrong", threeId, resOne.get(0).getInviteId());
-
- /**
- * Search for invitations for RED
- */
- List resTwo = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
- SITE_SHORT_NAME_RED);
- assertEquals("red invites not 3", 3, resTwo.size());
-
- /**
- * Search for invitations for USER_ONE
- */
- List resThree = invitationService.listPendingInvitationsForInvitee(USER_ONE);
- assertEquals("user one does not have 3 invitations", 3, resThree.size());
-
- /**
- * Search for invitations for USER_TWO
- */
- List resFour = invitationService.listPendingInvitationsForInvitee(USER_TWO);
- assertEquals("user two does not have 1 invitations", 1, resFour.size());
-
- /**
- * Search for user1's nominated invitations
- */
- InvitationSearchCriteriaImpl crit1 = new InvitationSearchCriteriaImpl();
- crit1.setInvitee(USER_ONE);
- crit1.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
-
- List resFive = invitationService.searchInvitation(crit1);
- assertEquals("user one does not have 2 nominated", 2, resFive.size());
-
- /**
- * Search with an empty criteria - should find all open invitations
- */
- InvitationSearchCriteria crit2 = new InvitationSearchCriteriaImpl();
- invitationService.searchInvitation(crit2);
- assertTrue("search everything returned 0 elements", resFive.size() > 0);
-
- InvitationSearchCriteriaImpl crit3 = new InvitationSearchCriteriaImpl();
- crit3.setInviter(USER_MANAGER);
- crit3.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
-
- List res3 = invitationService.searchInvitation(crit3);
- assertEquals("user one does not have 2 nominated", 2, res3.size());
-
- }
-
- public void disabled_test100Invites() throws Exception
- {
- Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
- String resourceName = SITE_SHORT_NAME_INVITE;
- String inviteeRole = SiteModel.SITE_COLLABORATOR;
- String serverPath = "wibble";
- String acceptUrl = "froob";
- String rejectUrl = "marshmallow";
-
- authenticationComponent.setCurrentUser(USER_MANAGER);
-
- // Create 1000 invites
- for (int i = 0; i < 1000; i++)
- {
- invitationService.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
- }
-
- // Invite USER_TWO
- NominatedInvitation invite = invitationService.inviteNominated(USER_TWO, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
-
- InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
- query.setInvitee(USER_TWO);
-
- long start = System.currentTimeMillis();
- List results = invitationService.searchInvitation(query);
- long end= System.currentTimeMillis();
- System.out.println("Invitation Search took " + (end - start) + "ms.");
-
- assertEquals(1, results.size());
- assertEquals(invite.getInviteId(), results.get(0).getInviteId());
- this.setComplete();
- this.endTransaction();
-
- }
-
- public void testGetInvitation()
- {
- try
- {
- /**
- * Get an invitation that does not exist.
- */
- invitationService.getInvitation("jbpm$99999999");
- fail("should have thrown an exception");
- }
- catch (Exception e)
- {
- // should have gone here
- }
- }
-
- private void createPerson(String userName, String emailAddress, String firstName, String lastName)
- {
- // if user with given user name doesn't already exist then create user
- if (this.authenticationService.authenticationExists(userName) == false)
- {
- // create user
- this.authenticationService.createAuthentication(userName, "password".toCharArray());
- }
-
- // if person node with given user name doesn't already exist then create
- // person
- if (this.personService.personExists(userName) == false)
- {
- // create person properties
- PropertyMap personProps = new PropertyMap();
- personProps.put(ContentModel.PROP_USERNAME, userName);
- personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
- personProps.put(ContentModel.PROP_LASTNAME, lastName);
- personProps.put(ContentModel.PROP_EMAIL, emailAddress);
- personProps.put(ContentModel.PROP_JOBTITLE, PERSON_JOBTITLE);
- personProps.put(ContentModel.PROP_ORGANIZATION, PERSON_ORG);
-
- // create person node for user
- this.personService.createPerson(personProps);
- }
- }
-
- private void deletePersonByUserName(String userName)
- {
- // delete person node associated with given user name
- // if one exists
- if (this.personService.personExists(userName))
- {
- this.personService.deletePerson(userName);
- }
- }
-}
+/*
+ * Copyright (C) 2005-2011 Alfresco Software Limited.
+ *
+ * This file is part of Alfresco
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ */
+
+package org.alfresco.repo.invitation;
+
+import java.lang.reflect.Field;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.internet.MimeMessage;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.action.executer.MailActionExecuter;
+import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
+import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.repo.site.SiteModel;
+import org.alfresco.repo.workflow.WorkflowAdminServiceImpl;
+import org.alfresco.service.cmr.invitation.Invitation;
+import org.alfresco.service.cmr.invitation.Invitation.ResourceType;
+import org.alfresco.service.cmr.invitation.InvitationSearchCriteria;
+import org.alfresco.service.cmr.invitation.InvitationService;
+import org.alfresco.service.cmr.invitation.ModeratedInvitation;
+import org.alfresco.service.cmr.invitation.NominatedInvitation;
+import org.alfresco.service.cmr.security.PersonService;
+import org.alfresco.service.cmr.site.SiteInfo;
+import org.alfresco.service.cmr.site.SiteService;
+import org.alfresco.service.cmr.site.SiteVisibility;
+import org.alfresco.util.BaseAlfrescoSpringTest;
+import org.alfresco.util.PropertyMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * Unit tests of Invitation Service
+ */
+public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpringTest
+{
+ private static final Log logger = LogFactory.getLog(AbstractInvitationServiceImplTest.class);
+
+ private SiteService siteService;
+ private PersonService personService;
+ protected InvitationService invitationService;
+ private MailActionExecuter mailService;
+ private boolean startSendEmails;
+ protected InvitationServiceImpl invitationServiceImpl;
+ protected WorkflowAdminServiceImpl workflowAdminService;
+
+ protected final static String SITE_SHORT_NAME_INVITE = "InvitationTest";
+ protected final static String SITE_SHORT_NAME_RED = "InvitationTestRed";
+ protected final static String SITE_SHORT_NAME_BLUE = "InvitationTestBlue";
+ public final static String PERSON_FIRSTNAME = "InvitationFirstName123";
+ public final static String PERSON_FIRSTNAME_SPACES = "Invitation First\tName\n1\r2\r\n3";
+ public final static String PERSON_LASTNAME = "InvitationLastName123";
+ public final static String PERSON_LASTNAME_SPACES = "Invitation Last\tName\n1\r2\r\n3";
+ public final static String PERSON_JOBTITLE = "JobTitle123";
+ public final static String PERSON_ORG = "Organisation123";
+
+ public final static String USER_MANAGER = "InvitationServiceManagerOne";
+ public final static String USER_ONE = "InvitationServiceAlice";
+ public final static String USER_TWO = "InvitationServiceBob";
+ public final static String USER_EVE = "InvitationServiceEve";
+ public final static String USER_NOEMAIL = "InvitationServiceNoEmail";
+ public final static String USER_ONE_FIRSTNAME = "One";
+ public final static String USER_ONE_LASTNAME = "Test";
+ public final static String USER_ONE_EMAIL = USER_ONE + "@alfrescotesting.com";
+ public final static String USER_TWO_EMAIL = USER_TWO + "@alfrescotesting.com";
+
+ private Collection enabledEngines;
+ private Collection visibleEngines;
+ /**
+ * Called during the transaction setup
+ */
+ @SuppressWarnings("deprecation")
+ @Override
+ protected void onSetUpInTransaction() throws Exception
+ {
+ super.onSetUpInTransaction();
+ this.invitationService = (InvitationService) this.applicationContext.getBean("InvitationService");
+ this.siteService = (SiteService) this.applicationContext.getBean("SiteService");
+ this.personService = (PersonService) this.applicationContext.getBean("PersonService");
+ this.authenticationComponent = (AuthenticationComponent) this.applicationContext
+ .getBean("authenticationComponent");
+ this.invitationServiceImpl = (InvitationServiceImpl) applicationContext.getBean("invitationService");
+ this.workflowAdminService = (WorkflowAdminServiceImpl)applicationContext.getBean(WorkflowAdminServiceImpl.NAME);
+
+ this.startSendEmails = invitationServiceImpl.isSendEmails();
+
+ this.enabledEngines = workflowAdminService.getEnabledEngines();
+ this.visibleEngines = workflowAdminService.getVisibleEngines();
+
+ invitationServiceImpl.setSendEmails(true);
+
+ // TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
+ // during unit testing
+ // (or sending out email by accident from tests)
+ mailService = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
+ .getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
+ mailService.setTestMode(true);
+
+
+ createPerson(USER_MANAGER, USER_MANAGER + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
+ createPerson(USER_ONE, USER_ONE_EMAIL, USER_ONE_FIRSTNAME, USER_ONE_LASTNAME);
+ createPerson(USER_TWO, USER_TWO + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
+ createPerson(USER_EVE, USER_EVE + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
+ createPerson(USER_NOEMAIL, null, USER_NOEMAIL, USER_NOEMAIL);
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ SiteInfo siteInfo = siteService.getSite(SITE_SHORT_NAME_INVITE);
+ if (siteInfo == null)
+ {
+ siteInfo = siteService.createSite("InviteSitePreset", SITE_SHORT_NAME_INVITE, "InviteSiteTitle",
+ "InviteSiteDescription", SiteVisibility.MODERATED);
+
+ siteService.setMembership(SITE_SHORT_NAME_INVITE, USER_NOEMAIL, SiteModel.SITE_MANAGER);
+ }
+
+ SiteInfo siteInfoRed = siteService.getSite(SITE_SHORT_NAME_RED);
+ if (siteInfoRed == null)
+ {
+ siteService.createSite("InviteSiteRed", SITE_SHORT_NAME_RED, "InviteSiteTitle", "InviteSiteDescription",
+ SiteVisibility.MODERATED);
+ }
+ SiteInfo siteInfoBlue = siteService.getSite(SITE_SHORT_NAME_BLUE);
+ if (siteInfoBlue == null)
+ {
+ siteService.createSite("InviteSiteBlue", SITE_SHORT_NAME_BLUE, "InviteSiteTitle", "InviteSiteDescription",
+ SiteVisibility.MODERATED);
+ }
+
+ }
+
+ @Override
+ protected void onTearDownInTransaction() throws Exception
+ {
+ // Make sure both workflow engines are enabled.and visible
+
+ this.authenticationComponent.setSystemUserAsCurrentUser();
+
+ workflowAdminService.setEnabledEngines(enabledEngines);
+ workflowAdminService.setVisibleEngines(visibleEngines);
+
+// invitationServiceImpl.setSendEmails(startSendEmails);
+// siteService.deleteSite(SITE_SHORT_NAME_INVITE);
+// siteService.deleteSite(SITE_SHORT_NAME_RED);
+// siteService.deleteSite(SITE_SHORT_NAME_BLUE);
+// deletePersonByUserName(USER_ONE);
+// deletePersonByUserName(USER_TWO);
+// deletePersonByUserName(USER_EVE);
+// deletePersonByUserName(USER_MANAGER);
+ super.onTearDownInTransaction();
+ }
+
+ /*
+ * end of setup now for some real tests
+ */
+
+ /**
+ *
+ */
+ public void testConfiguration()
+ {
+ assertNotNull("Invitation service is null", invitationService);
+ }
+
+ /**
+ * Test nominated user - new user
+ *
+ * @throws Exception
+ */
+ public void testNominatedInvitationNewUser() throws Exception
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -1);
+ Date startDate = calendar.getTime();
+
+ String inviteeFirstName = PERSON_FIRSTNAME;
+ String inviteeLastName = PERSON_LASTNAME;
+ String inviteeEmail = "123@alfrescotesting.com";
+ String inviteeUserName = null;
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
+ inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitation);
+ String inviteId = nominatedInvitation.getInviteId();
+ assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
+
+ // Generated User Name should be returned
+ inviteeUserName = nominatedInvitation.getInviteeUserName();
+ assertNotNull("generated user name is null", inviteeUserName);
+ // sentInviteDate should be set to today
+ {
+ Date sentDate = nominatedInvitation.getSentInviteDate();
+ assertTrue("sentDate wrong - too early. Start Date: " +startDate +"\nSent Date: "+sentDate, sentDate.after(startDate));
+ assertTrue("sentDate wrong - too lateStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.before(new Date(new Date().getTime() + 1)));
+ }
+
+ assertEquals("resource type name wrong", resourceType, nominatedInvitation.getResourceType());
+ assertEquals("resource name wrong", resourceName, nominatedInvitation.getResourceName());
+ assertEquals("role name wrong", inviteeRole, nominatedInvitation.getRoleName());
+ assertEquals("server path wrong", serverPath, nominatedInvitation.getServerPath());
+ assertEquals("accept URL wrong", acceptUrl, nominatedInvitation.getAcceptUrl());
+ assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
+
+ /**
+ * 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("invite id wrong", inviteId, invitation.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, invitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, invitation.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, invitation.getInviteeUserName());
+ assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
+ assertEquals("resource name wrong", resourceName, invitation.getResourceName());
+ assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
+ assertEquals("server path wrong", serverPath, invitation.getServerPath());
+ assertEquals("accept URL wrong", acceptUrl, invitation.getAcceptUrl());
+ assertEquals("reject URL wrong", rejectUrl, invitation.getRejectUrl());
+
+ Date sentDate = invitation.getSentInviteDate();
+ // sentInviteDate should be set to today
+ assertTrue("sentDate wrong too early", sentDate.after(startDate));
+ assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
+ }
+
+ /**
+ * Check the email itself, and check it
+ * is as we would expect it to be
+ */
+ {
+ MimeMessage msg = mailService.retrieveLastTestMessage();
+
+ assertEquals(1, msg.getAllRecipients().length);
+ assertEquals(inviteeEmail, msg.getAllRecipients()[0].toString());
+
+ assertEquals(1, msg.getFrom().length);
+ assertEquals(USER_MANAGER + "@alfrescotesting.com", msg.getFrom()[0].toString());
+
+ // Hasn't been sent, so no sent or received date
+ assertNull("Not been sent yet", msg.getSentDate());
+ assertNull("Not been sent yet", msg.getReceivedDate());
+
+ // TODO - check some more details of the email
+ assertTrue((msg.getSubject().indexOf("You have been invited to join the") != -1));
+ }
+
+ /**
+ * Search for the new invitation
+ */
+ List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is empty", !invitations.isEmpty());
+
+ NominatedInvitation firstInvite = (NominatedInvitation) invitations.get(0);
+ assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, firstInvite.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, firstInvite.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, firstInvite.getInviteeUserName());
+
+ /**
+ * Now accept the invitation
+ */
+ NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(firstInvite
+ .getInviteId(), firstInvite.getTicket());
+ assertEquals("invite id wrong", firstInvite.getInviteId(), acceptedInvitation.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, acceptedInvitation.getInviteeUserName());
+
+ List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is not empty", it4.isEmpty());
+
+ /**
+ * Now get the invitation that we accepted
+ */
+ NominatedInvitation acceptedInvitation2 = (NominatedInvitation) invitationService.getInvitation(firstInvite
+ .getInviteId());
+ assertNotNull("get after accept does not return", acceptedInvitation2);
+
+ /**
+ * Now verify access control list
+ */
+ String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
+ assertEquals("role name wrong", roleName, inviteeRole);
+ siteService.removeMembership(resourceName, inviteeUserName);
+
+
+ /**
+ * Check that system generated invitations can work as well
+ */
+ {
+ Field faf = mailService.getClass().getDeclaredField("fromAddress");
+ faf.setAccessible(true);
+ String defaultFromAddress = (String)ReflectionUtils.getField(faf, mailService);
+
+ AuthenticationUtil.setFullyAuthenticatedUser(USER_NOEMAIL);
+
+ // Check invitiation
+ NominatedInvitation nominatedInvitation2 = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
+ USER_TWO_EMAIL, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitation2);
+ inviteId = nominatedInvitation.getInviteId();
+ assertEquals("first name wrong", inviteeFirstName, nominatedInvitation2.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, nominatedInvitation2.getInviteeLastName());
+ assertEquals("email name wrong", USER_TWO_EMAIL, nominatedInvitation2.getInviteeEmail());
+
+ // Check the email
+ MimeMessage msg = mailService.retrieveLastTestMessage();
+
+ assertEquals(1, msg.getAllRecipients().length);
+ assertEquals(USER_TWO_EMAIL, msg.getAllRecipients()[0].toString());
+
+ assertEquals(1, msg.getFrom().length);
+ assertEquals(defaultFromAddress, msg.getFrom()[0].toString());
+ }
+ }
+
+ // TODO MER START
+ /**
+ * Test nominated user - new user who rejects invitation
+ *
+ * @throws Exception
+ */
+ public void testNominatedInvitationNewUserReject() throws Exception
+ {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -1);
+ Date startDate = calendar.getTime();
+
+ String inviteeFirstName = PERSON_FIRSTNAME;
+ String inviteeLastName = PERSON_LASTNAME;
+ String inviteeEmail = "123@alfrescotesting.com";
+ String inviteeUserName = null;
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeFirstName, inviteeLastName,
+ inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitation);
+ assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
+
+ // Generated User Name should be returned
+ inviteeUserName = nominatedInvitation.getInviteeUserName();
+ assertNotNull("generated user name is null", inviteeUserName);
+ // sentInviteDate should be set to today
+ {
+ Date sentDate = nominatedInvitation.getSentInviteDate();
+ assertTrue("sentDate wrong - too earlyStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.after(startDate));
+ assertTrue("sentDate wrong - too lateStart Date: " +startDate +"\nSent Date: "+sentDate, sentDate.before(new Date(new Date().getTime() + 1)));
+ }
+
+ /**
+ * Now reject the invitation
+ */
+ NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.reject(nominatedInvitation
+ .getInviteId(), "dont want it");
+ assertEquals("invite id wrong", nominatedInvitation.getInviteId(), rejectedInvitation.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, rejectedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, rejectedInvitation.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
+
+ List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is not empty", it4.isEmpty());
+
+ /**
+ * Now verify access control list inviteeUserName should not exist
+ */
+ String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
+ if (roleName != null)
+ {
+ fail("role has been set for a rejected user");
+ }
+
+ /**
+ * Now verify that the generated user has been removed
+ */
+ if (personService.personExists(inviteeUserName))
+ {
+ fail("generated user has not been cleaned up");
+ }
+ }
+
+ // TODO MER END
+
+ /**
+ * Test nominated user - new user Creates two separate users with two the
+ * same email address.
+ *
+ * @throws Exception
+ */
+ public void testNominatedInvitationNewUserSameEmails() throws Exception
+ {
+ String inviteeAFirstName = "John";
+ String inviteeALastName = "Smith";
+
+ String inviteeBFirstName = "Jane";
+ String inviteeBLastName = "Smith";
+
+ String inviteeEmail = "123@alfrescotesting.com";
+ String inviteeAUserName = null;
+ String inviteeBUserName = null;
+
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ NominatedInvitation nominatedInvitationA = invitationService.inviteNominated(inviteeAFirstName,
+ inviteeALastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
+ rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitationA);
+ String inviteAId = nominatedInvitationA.getInviteId();
+ assertEquals("first name wrong", inviteeAFirstName, nominatedInvitationA.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeALastName, nominatedInvitationA.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, nominatedInvitationA.getInviteeEmail());
+
+ // Generated User Name should be returned
+ inviteeAUserName = nominatedInvitationA.getInviteeUserName();
+ assertNotNull("generated user name is null", inviteeAUserName);
+
+ NominatedInvitation nominatedInvitationB = invitationService.inviteNominated(inviteeBFirstName,
+ inviteeBLastName, inviteeEmail, resourceType, resourceName, inviteeRole, serverPath, acceptUrl,
+ rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitationB);
+ String inviteBId = nominatedInvitationB.getInviteId();
+ assertEquals("first name wrong", inviteeBFirstName, nominatedInvitationB.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeBLastName, nominatedInvitationB.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, nominatedInvitationB.getInviteeEmail());
+
+ // Generated User Name should be returned
+ inviteeBUserName = nominatedInvitationB.getInviteeUserName();
+ assertNotNull("generated user name is null", inviteeBUserName);
+ assertFalse("generated user names are the same", inviteeAUserName.equals(inviteeBUserName));
+
+ /**
+ * Now accept the invitation
+ */
+ NominatedInvitation acceptedInvitationA = (NominatedInvitation) invitationService.accept(inviteAId,
+ nominatedInvitationA.getTicket());
+ assertEquals("invite id wrong", inviteAId, acceptedInvitationA.getInviteId());
+ assertEquals("first name wrong", inviteeAFirstName, acceptedInvitationA.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeALastName, acceptedInvitationA.getInviteeLastName());
+ assertEquals("user name wrong", inviteeAUserName, acceptedInvitationA.getInviteeUserName());
+
+ NominatedInvitation acceptedInvitationB = (NominatedInvitation) invitationService.accept(inviteBId,
+ nominatedInvitationB.getTicket());
+ assertEquals("invite id wrong", inviteBId, acceptedInvitationB.getInviteId());
+ assertEquals("first name wrong", inviteeBFirstName, acceptedInvitationB.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeBLastName, acceptedInvitationB.getInviteeLastName());
+ assertEquals("user name wrong", inviteeBUserName, acceptedInvitationB.getInviteeUserName());
+
+ /**
+ * Now verify access control list
+ */
+ String roleNameA = siteService.getMembersRole(resourceName, inviteeAUserName);
+ assertEquals("role name wrong", roleNameA, inviteeRole);
+ String roleNameB = siteService.getMembersRole(resourceName, inviteeBUserName);
+ assertEquals("role name wrong", roleNameB, inviteeRole);
+ siteService.removeMembership(resourceName, inviteeAUserName);
+ 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();
+ expectedUserName = expectedUserName.replaceAll("\\s+", "_");
+ 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) read it.
+ * search for it cancel 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
+ {
+ String inviteeUserName = USER_ONE;
+ String inviteeEmail = USER_ONE_EMAIL;
+ String inviteeFirstName = USER_ONE_FIRSTNAME;
+ String inviteeLastName = USER_ONE_LASTNAME;
+
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ NominatedInvitation nominatedInvitation = invitationService.inviteNominated(inviteeUserName, resourceType,
+ resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ assertNotNull("nominated invitation is null", nominatedInvitation);
+ String inviteId = nominatedInvitation.getInviteId();
+ assertEquals("user name wrong", inviteeUserName, nominatedInvitation.getInviteeUserName());
+ assertEquals("resource type name wrong", resourceType, nominatedInvitation.getResourceType());
+ assertEquals("resource name wrong", resourceName, nominatedInvitation.getResourceName());
+ assertEquals("role name wrong", inviteeRole, nominatedInvitation.getRoleName());
+ assertEquals("server path wrong", serverPath, nominatedInvitation.getServerPath());
+ assertEquals("accept URL wrong", acceptUrl, nominatedInvitation.getAcceptUrl());
+ assertEquals("reject URL wrong", rejectUrl, nominatedInvitation.getRejectUrl());
+
+ // These values should be read from the person record
+ assertEquals("first name wrong", inviteeFirstName, nominatedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, nominatedInvitation.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, nominatedInvitation.getInviteeEmail());
+
+ /**
+ * 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("invite id wrong", inviteId, invitation.getInviteId());
+ assertEquals("user name wrong", inviteeUserName, nominatedInvitation.getInviteeUserName());
+ assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
+ assertEquals("resource name wrong", resourceName, invitation.getResourceName());
+ assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
+ assertEquals("server path wrong", serverPath, invitation.getServerPath());
+ assertEquals("accept URL wrong", acceptUrl, invitation.getAcceptUrl());
+ assertEquals("reject URL wrong", rejectUrl, invitation.getRejectUrl());
+
+ // These values should have been read from the DB
+ assertEquals("first name wrong", inviteeFirstName, invitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, invitation.getInviteeLastName());
+ assertEquals("email name wrong", inviteeEmail, invitation.getInviteeEmail());
+
+ /**
+ * Search for the new invitation
+ */
+ List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is empty", !invitations.isEmpty());
+
+ NominatedInvitation firstInvite = (NominatedInvitation) invitations.get(0);
+ assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, firstInvite.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, firstInvite.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, firstInvite.getInviteeUserName());
+
+ /**
+ * Now cancel the invitation
+ */
+ NominatedInvitation canceledInvitation = (NominatedInvitation) invitationService.cancel(inviteId);
+ assertEquals("invite id wrong", inviteId, canceledInvitation.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, canceledInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, canceledInvitation.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, canceledInvitation.getInviteeUserName());
+
+ /**
+ * Do the query again - should no longer find anything
+ */
+ List it2 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is not empty", it2.isEmpty());
+
+ /**
+ * Now invite and reject
+ */
+ NominatedInvitation secondInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
+ resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ NominatedInvitation rejectedInvitation = (NominatedInvitation) invitationService.cancel(secondInvite
+ .getInviteId());
+ assertEquals("invite id wrong", secondInvite.getInviteId(), rejectedInvitation.getInviteId());
+ assertEquals("user name wrong", inviteeUserName, rejectedInvitation.getInviteeUserName());
+
+ List it3 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is not empty", it3.isEmpty());
+
+ /**
+ * Now invite and accept
+ */
+ NominatedInvitation thirdInvite = invitationService.inviteNominated(inviteeUserName, resourceType,
+ resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ NominatedInvitation acceptedInvitation = (NominatedInvitation) invitationService.accept(thirdInvite
+ .getInviteId(), thirdInvite.getTicket());
+ assertEquals("invite id wrong", thirdInvite.getInviteId(), acceptedInvitation.getInviteId());
+ assertEquals("first name wrong", inviteeFirstName, acceptedInvitation.getInviteeFirstName());
+ assertEquals("last name wrong", inviteeLastName, acceptedInvitation.getInviteeLastName());
+ assertEquals("user name wrong", inviteeUserName, acceptedInvitation.getInviteeUserName());
+
+ List it4 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is not empty", it4.isEmpty());
+
+ /**
+ * Now verify access control list
+ */
+ String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
+ assertEquals("role name wrong", inviteeRole, roleName);
+ siteService.removeMembership(resourceName, inviteeUserName);
+ }
+
+ /**
+ * Create a moderated invitation Get it Search for it Cancel it Create a
+ * moderated invitation Reject the invitation Create a moderated invitation
+ * Approve the invitation
+ */
+ public void testModeratedInvitation()
+ {
+ String inviteeUserName = USER_TWO;
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String comments = "please sir, let me in!";
+
+ this.authenticationComponent.setCurrentUser(USER_TWO);
+ ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
+ resourceName, inviteeRole);
+
+ assertNotNull("moderated invitation is null", invitation);
+ String inviteId = invitation.getInviteId();
+ assertEquals("user name wrong", inviteeUserName, invitation.getInviteeUserName());
+ assertEquals("role name wrong", inviteeRole, invitation.getRoleName());
+ assertEquals("comments", comments, invitation.getInviteeComments());
+ assertEquals("resource type name wrong", resourceType, invitation.getResourceType());
+ assertEquals("resource name wrong", resourceName, invitation.getResourceName());
+
+ /**
+ * Now we have an invitation get it and check the details have been
+ * returned correctly.
+ */
+ ModeratedInvitation mi2 = (ModeratedInvitation) invitationService.getInvitation(inviteId);
+ assertEquals("invite id", inviteId, mi2.getInviteId());
+ assertEquals("user name wrong", inviteeUserName, mi2.getInviteeUserName());
+ assertEquals("role name wrong", inviteeRole, mi2.getRoleName());
+ assertEquals("comments", comments, mi2.getInviteeComments());
+ assertEquals("resource type name wrong", resourceType, mi2.getResourceType());
+ assertEquals("resource name wrong", resourceName, mi2.getResourceName());
+
+ /**
+ * Search for the new invitation
+ */
+ List invitations = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("invitations is empty", !invitations.isEmpty());
+
+ ModeratedInvitation firstInvite = (ModeratedInvitation) invitations.get(0);
+ assertEquals("invite id wrong", inviteId, firstInvite.getInviteId());
+
+ /**
+ * Cancel the invitation
+ */
+ ModeratedInvitation canceledInvitation = (ModeratedInvitation) invitationService.cancel(inviteId);
+ assertEquals("invite id wrong", inviteId, canceledInvitation.getInviteId());
+ assertEquals("comments wrong", comments, canceledInvitation.getInviteeComments());
+
+ /**
+ * Should now be no invitation
+ */
+ List inv2 = invitationService.listPendingInvitationsForResource(resourceType, resourceName);
+ assertTrue("After cancel invitations is not empty", inv2.isEmpty());
+
+ /**
+ * New invitation
+ */
+ this.authenticationComponent.setCurrentUser(USER_TWO);
+ ModeratedInvitation invite2 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
+ resourceName, inviteeRole);
+
+ String secondInvite = invite2.getInviteId();
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+ invitationService.reject(secondInvite, "This is a test reject");
+
+ /**
+ * New invitation
+ */
+ this.authenticationComponent.setCurrentUser(USER_TWO);
+ ModeratedInvitation invite3 = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
+ resourceName, inviteeRole);
+
+ String thirdInvite = invite3.getInviteId();
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+ invitationService.approve(thirdInvite, "Welcome in");
+
+ /**
+ * Now verify access control list
+ */
+ String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
+ assertEquals("role name wrong", inviteeRole, roleName);
+ siteService.removeMembership(resourceName, inviteeUserName);
+
+ }
+
+ /**
+ * Test the approval of a moderated invitation
+ */
+ public void testModeratedApprove()
+ {
+ String inviteeUserName = USER_TWO;
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String comments = "please sir, let me in!";
+
+ /**
+ * New invitation from User TWO
+ */
+ this.authenticationComponent.setCurrentUser(USER_TWO);
+ ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
+ resourceName, inviteeRole);
+
+ String invitationId = invitation.getInviteId();
+
+ /**
+ * Negative test Attempt to approve without the necessary role
+ */
+ try
+ {
+ invitationService.approve(invitationId, "No Way Hosea!");
+ assertTrue("excetion not thrown", false);
+
+ }
+ catch (Exception e)
+ {
+ // An exception should have been thrown
+ e.printStackTrace();
+ System.out.println(e.toString());
+ }
+
+ /**
+ * Approve the invitation
+ */
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+ invitationService.approve(invitationId, "Come on in");
+
+ /**
+ * Now verify access control list contains user two
+ */
+ String roleName = siteService.getMembersRole(resourceName, inviteeUserName);
+ assertEquals("role name wrong", inviteeRole, roleName);
+
+ /**
+ * Negative test attempt to approve an invitation that has aready been
+ * approved
+ */
+ try
+ {
+ invitationService.approve(invitationId, "Have I not already done this?");
+ assertTrue("duplicate approve excetion not thrown", false);
+ }
+ catch (Exception e)
+ {
+ // An exception should have been thrown
+ e.printStackTrace();
+ System.out.println(e.toString());
+ }
+ /**
+ * Negative test User is already a member of the site
+ */
+ siteService.removeMembership(resourceName, inviteeUserName);
+ }
+
+ /**
+ * Tests of Moderated Reject
+ */
+ public void testModeratedReject()
+ {
+ String inviteeUserName = USER_TWO;
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String comments = "please sir, let me in!";
+
+ /**
+ * New invitation from User TWO
+ */
+ this.authenticationComponent.setCurrentUser(USER_TWO);
+ ModeratedInvitation invitation = invitationService.inviteModerated(comments, inviteeUserName, resourceType,
+ resourceName, inviteeRole);
+
+ String invitationId = invitation.getInviteId();
+
+ /**
+ * Negative test Attempt to reject without the necessary role
+ */
+ try
+ {
+ invitationService.reject(invitationId, "No Way Hosea!");
+ assertTrue("excetion not thrown", false);
+
+ }
+ catch (Exception e)
+ {
+ // An exception should have been thrown
+ e.printStackTrace();
+ System.out.println(e.toString());
+ }
+
+ /**
+ * Reject the invitation
+ */
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+ invitationService.reject(invitationId, "Go away!");
+
+ /**
+ * Negative test attempt to approve an invitation that has been rejected
+ */
+ try
+ {
+ invitationService.approve(invitationId, "Have I not rejected this?");
+ assertTrue("rejected invitation not working", false);
+ }
+ catch (Exception e)
+ {
+ // An exception should have been thrown
+ e.printStackTrace();
+ System.out.println(e.toString());
+ }
+ }
+
+ /**
+ * Test search invitation
+ */
+ public void testSearchInvitation()
+ {
+ /**
+ * Make up a tree of invitations and then search Resource, User,
+ * Workflow 1) RED, One, Moderated 2) RED, One, Nominated 3) BLUE, One,
+ * Nominated 4) RED, Two, Moderated
+ */
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String comments = "please sir, let me in!";
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ this.authenticationComponent.setCurrentUser(USER_MANAGER);
+ invitationService.inviteModerated(comments, USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
+
+ invitationService.inviteNominated(USER_ONE, resourceType, SITE_SHORT_NAME_RED, inviteeRole, serverPath,
+ acceptUrl, rejectUrl);
+
+ NominatedInvitation invitationThree = invitationService.inviteNominated(USER_ONE, resourceType,
+ SITE_SHORT_NAME_BLUE, inviteeRole, serverPath, acceptUrl, rejectUrl);
+ String threeId = invitationThree.getInviteId();
+
+ invitationService.inviteModerated(comments, USER_TWO, resourceType, SITE_SHORT_NAME_RED, inviteeRole);
+
+ /**
+ * Search for invitations for BLUE
+ */
+ List resOne = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
+ SITE_SHORT_NAME_BLUE);
+ assertEquals("blue invites not 1", 1, resOne.size());
+ assertEquals("blue id wrong", threeId, resOne.get(0).getInviteId());
+
+ /**
+ * Search for invitations for RED
+ */
+ List resTwo = invitationService.listPendingInvitationsForResource(ResourceType.WEB_SITE,
+ SITE_SHORT_NAME_RED);
+ assertEquals("red invites not 3", 3, resTwo.size());
+
+ /**
+ * Search for invitations for USER_ONE
+ */
+ List resThree = invitationService.listPendingInvitationsForInvitee(USER_ONE);
+ assertEquals("user one does not have 3 invitations", 3, resThree.size());
+
+ /**
+ * Search for invitations for USER_TWO
+ */
+ List resFour = invitationService.listPendingInvitationsForInvitee(USER_TWO);
+ assertEquals("user two does not have 1 invitations", 1, resFour.size());
+
+ /**
+ * Search for user1's nominated invitations
+ */
+ InvitationSearchCriteriaImpl crit1 = new InvitationSearchCriteriaImpl();
+ crit1.setInvitee(USER_ONE);
+ crit1.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
+
+ List resFive = invitationService.searchInvitation(crit1);
+ assertEquals("user one does not have 2 nominated", 2, resFive.size());
+
+ /**
+ * Search with an empty criteria - should find all open invitations
+ */
+ InvitationSearchCriteria crit2 = new InvitationSearchCriteriaImpl();
+ invitationService.searchInvitation(crit2);
+ assertTrue("search everything returned 0 elements", resFive.size() > 0);
+
+ InvitationSearchCriteriaImpl crit3 = new InvitationSearchCriteriaImpl();
+ crit3.setInviter(USER_MANAGER);
+ crit3.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
+
+ List res3 = invitationService.searchInvitation(crit3);
+ assertEquals("user one does not have 2 nominated", 2, res3.size());
+
+ }
+
+ public void disabled_test100Invites() throws Exception
+ {
+ Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
+ String resourceName = SITE_SHORT_NAME_INVITE;
+ String inviteeRole = SiteModel.SITE_COLLABORATOR;
+ String serverPath = "wibble";
+ String acceptUrl = "froob";
+ String rejectUrl = "marshmallow";
+
+ authenticationComponent.setCurrentUser(USER_MANAGER);
+
+ // Create 1000 invites
+ for (int i = 0; i < 1000; i++)
+ {
+ invitationService.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+ }
+
+ // Invite USER_TWO
+ NominatedInvitation invite = invitationService.inviteNominated(USER_TWO, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
+
+ InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
+ query.setInvitee(USER_TWO);
+
+ long start = System.currentTimeMillis();
+ List results = invitationService.searchInvitation(query);
+ long end= System.currentTimeMillis();
+ System.out.println("Invitation Search took " + (end - start) + "ms.");
+
+ assertEquals(1, results.size());
+ assertEquals(invite.getInviteId(), results.get(0).getInviteId());
+ this.setComplete();
+ this.endTransaction();
+
+ }
+
+ public void testGetInvitation()
+ {
+ try
+ {
+ /**
+ * Get an invitation that does not exist.
+ */
+ invitationService.getInvitation("jbpm$99999999");
+ fail("should have thrown an exception");
+ }
+ catch (Exception e)
+ {
+ // should have gone here
+ }
+ }
+
+ private void createPerson(String userName, String emailAddress, String firstName, String lastName)
+ {
+ // if user with given user name doesn't already exist then create user
+ if (this.authenticationService.authenticationExists(userName) == false)
+ {
+ // create user
+ this.authenticationService.createAuthentication(userName, "password".toCharArray());
+ }
+
+ // if person node with given user name doesn't already exist then create
+ // person
+ if (this.personService.personExists(userName) == false)
+ {
+ // create person properties
+ PropertyMap personProps = new PropertyMap();
+ personProps.put(ContentModel.PROP_USERNAME, userName);
+ personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
+ personProps.put(ContentModel.PROP_LASTNAME, lastName);
+ personProps.put(ContentModel.PROP_EMAIL, emailAddress);
+ personProps.put(ContentModel.PROP_JOBTITLE, PERSON_JOBTITLE);
+ personProps.put(ContentModel.PROP_ORGANIZATION, PERSON_ORG);
+
+ // create person node for user
+ this.personService.createPerson(personProps);
+ }
+ }
+
+ private void deletePersonByUserName(String userName)
+ {
+ // delete person node associated with given user name
+ // if one exists
+ if (this.personService.personExists(userName))
+ {
+ this.personService.deletePerson(userName);
+ }
+ }
+}
diff --git a/source/java/org/alfresco/repo/invitation/InvitationServiceImpl.java b/source/java/org/alfresco/repo/invitation/InvitationServiceImpl.java
index 77269b53a2..2c346cef8d 100644
--- a/source/java/org/alfresco/repo/invitation/InvitationServiceImpl.java
+++ b/source/java/org/alfresco/repo/invitation/InvitationServiceImpl.java
@@ -22,6 +22,7 @@ package org.alfresco.repo.invitation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -34,13 +35,16 @@ import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.authentication.PasswordGenerator;
import org.alfresco.repo.security.authentication.UserNameGenerator;
+import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.site.SiteModel;
+import org.alfresco.repo.workflow.CancelWorkflowActionExecuter;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.jbpm.JBPMEngine;
+import org.alfresco.service.cmr.action.Action;
+import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.invitation.Invitation;
import org.alfresco.service.cmr.invitation.InvitationException;
@@ -94,6 +98,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
*/
private WorkflowService workflowService;
private WorkflowAdminService workflowAdminService;
+ private ActionService actionService;
private PersonService personService;
private SiteService siteService;
private MutableAuthenticationService authenticationService;
@@ -132,6 +137,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
{
PropertyCheck.mandatory(this, "nodeService", nodeService);
PropertyCheck.mandatory(this, "WorkflowService", workflowService);
+ PropertyCheck.mandatory(this, "ActionService", actionService);
PropertyCheck.mandatory(this, "PersonService", personService);
PropertyCheck.mandatory(this, "SiteService", siteService);
PropertyCheck.mandatory(this, "AuthenticationService", authenticationService);
@@ -515,6 +521,34 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
}
return invitation;
}
+
+ private Map getInvitationTasks(List invitationIds)
+ {
+ for (String invitationId: invitationIds)
+ {
+ validateInvitationId(invitationId);
+ }
+
+ // query for invite workflow task associate
+ long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
+ List inviteStartTasks = workflowService.getStartTasks(invitationIds, true);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(" getInvitationTask("+invitationIds.size()+") in "+ (System.currentTimeMillis()-start) + " ms");
+ }
+
+ Map result = new HashMap(inviteStartTasks.size() * 2);
+ for(WorkflowTask inviteStartTask: inviteStartTasks)
+ {
+ String invitationId = inviteStartTask.getPath().getInstance().getId();
+ // The following does not work for moderated tasks
+ // String invitationId = (String)
+ // inviteStartTask.getProperties().get(WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
+ result.put(invitationId, inviteStartTask);
+ }
+
+ return result;
+ }
private ModeratedInvitation getModeratedInvitation(WorkflowTask startTask)
{
@@ -586,44 +620,97 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
*/
public List listPendingInvitationsForResource(Invitation.ResourceType resourceType, String resourceName)
{
- InvitationSearchCriteriaImpl crit = new InvitationSearchCriteriaImpl();
- crit.setInvitationType(InvitationSearchCriteria.InvitationType.ALL);
- crit.setResourceType(resourceType);
- crit.setResourceName(resourceName);
- return searchInvitation(crit);
+ InvitationSearchCriteriaImpl criteria = getPendingInvitationCriteriaForResource(resourceType, resourceName);
+ return searchInvitation(criteria);
}
/**
- * This is the general search invitation method
+ * Returns search criteria to find pending invitations
+ * @param resourceType
+ * @param resourceName
+ * @return search criteria
+ */
+ private InvitationSearchCriteriaImpl getPendingInvitationCriteriaForResource(
+ Invitation.ResourceType resourceType, String resourceName)
+ {
+ InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl();
+ criteria.setInvitationType(InvitationSearchCriteria.InvitationType.ALL);
+ criteria.setResourceType(resourceType);
+ criteria.setResourceName(resourceName);
+ return criteria;
+ }
+
+ /**
+ * This is the general search invitation method returning {@link Invitation}s
*
* @param criteria
- * @return the list of invitations
+ * @return the list of start tasks for invitations
*/
public List searchInvitation(final InvitationSearchCriteria criteria)
{
- List searchResults = new ArrayList();
+ int limit = 200;
+ List invitationIds = searchInvitationsForIds(criteria, limit);
+ return invitationIds.isEmpty() ? Collections.emptyList() : searchInvitation(criteria, invitationIds);
+ }
+
+ private List searchInvitation(final InvitationSearchCriteria criteria, List invitationIds)
+ {
+ final Map taskCache = getInvitationTasks(invitationIds);
+ return CollectionUtils.transform(invitationIds, new Function()
+ {
+ public Invitation apply(String invitationId)
+ {
+ WorkflowTask startTask = taskCache.get(invitationId);
+ if (startTask == null)
+ {
+ return null;
+ }
+ Invitation invitation = getInvitation(startTask);
+ return invitationMatches(invitation, criteria) ? invitation : null;
+ }
+ });
+ }
+
+ /**
+ * This is a general search invitation method returning IDs
+ *
+ * @param criteria
+ * @param limit maximum number of IDs to return. If less than 1, there is no limit.
+ * @return the list of invitation IDs (the IDs of the invitations not the IDs of the invitation start tasks)
+ */
+ private List searchInvitationsForIds(final InvitationSearchCriteria criteria, int limit)
+ {
+ List invitationIds = new ArrayList();
InvitationSearchCriteria.InvitationType toSearch = criteria.getInvitationType();
if (toSearch == InvitationSearchCriteria.InvitationType.ALL
|| toSearch == InvitationSearchCriteria.InvitationType.NOMINATED)
{
- searchResults.addAll(searchNominatedInvitations(criteria));
- }
- if (toSearch == InvitationSearchCriteria.InvitationType.ALL
- || toSearch == InvitationSearchCriteria.InvitationType.MODERATED)
- {
- searchResults.addAll(searchModeratedInvitations(criteria));
- }
-
- return CollectionUtils.transform(searchResults, new Function()
- {
- public Invitation apply(WorkflowTask task)
+ for (WorkflowTask task : searchNominatedInvitations(criteria))
{
String invitationId = task.getPath().getInstance().getId();
- Invitation invitation = getInvitation(invitationId);
- return invitationMatches(invitation, criteria) ? invitation : null;
+ invitationIds.add(invitationId);
+ if (limit > 0 && invitationIds.size() >= limit)
+ {
+ break;
+ }
}
+ }
+ if ((limit <= 0 || invitationIds.size() < limit) &&
+ (toSearch == InvitationSearchCriteria.InvitationType.ALL
+ || toSearch == InvitationSearchCriteria.InvitationType.MODERATED))
+ {
+ for (WorkflowTask task: searchModeratedInvitations(criteria))
+ {
+ String invitationId = task.getPath().getInstance().getId();
+ invitationIds.add(invitationId);
+ if (limit > 0 && invitationIds.size() >= limit)
+ {
+ break;
+ }
+ }
+ }
+ return invitationIds;
- });
}
/**
@@ -665,6 +752,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
private List searchModeratedInvitations(InvitationSearchCriteria criteria)
{
+ long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
+
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
@@ -694,7 +783,8 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
if(workflowAdminService.isEngineEnabled(JBPMEngine.ENGINE_ID))
{
query.setTaskName(WorkflowModelModeratedInvitation.WF_REVIEW_TASK);
- List jbpmTasks = this.workflowService.queryTasks(query);
+ List jbpmTasks = this.workflowService.queryTasks(query, true);
+
if(jbpmTasks !=null)
{
results.addAll(jbpmTasks);
@@ -703,17 +793,23 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
if(workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID))
{
query.setTaskName(WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK);
- List jbpmTasks = this.workflowService.queryTasks(query);
+ List jbpmTasks = this.workflowService.queryTasks(query, true);
if(jbpmTasks !=null)
{
results.addAll(jbpmTasks);
}
}
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(" searchModeratedInvitations in "+ (System.currentTimeMillis()-start) + " ms");
+ }
return results;
}
private List searchNominatedInvitations(InvitationSearchCriteria criteria)
{
+ long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
+
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
@@ -749,7 +845,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
if(workflowAdminService.isEngineEnabled(JBPMEngine.ENGINE_ID))
{
query.setTaskName(WorkflowModelNominatedInvitation.WF_TASK_INVITE_PENDING);
- List jbpmTasks = this.workflowService.queryTasks(query);
+ List jbpmTasks = this.workflowService.queryTasks(query, true);
if(jbpmTasks !=null)
{
results.addAll(jbpmTasks);
@@ -758,12 +854,16 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
if(workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID))
{
query.setTaskName(WorkflowModelNominatedInvitation.WF_TASK_ACTIVIT_INVITE_PENDING);
- List jbpmTasks = this.workflowService.queryTasks(query);
+ List