Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)

85567: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud)
      85475: MNT-12398 : FeedNotifier - Users mixed up, fail to send notification email
      Fixed formatting.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94504 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 09:31:48 +00:00
parent 9c0e08b45d
commit 33cb8d37d6

View File

@@ -76,14 +76,14 @@ import org.springframework.context.ApplicationContextAware;
public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
{ {
protected static Log logger = LogFactory.getLog(FeedNotifier.class); protected static Log logger = LogFactory.getLog(FeedNotifier.class);
private static final QName LOCK_QNAME = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "ActivityFeedNotifier"); private static final QName LOCK_QNAME = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "ActivityFeedNotifier");
private static final long LOCK_TTL = 30000L; private static final long LOCK_TTL = 30000L;
private static VmShutdownListener vmShutdownListener = new VmShutdownListener(FeedNotifierImpl.class.getName()); private static VmShutdownListener vmShutdownListener = new VmShutdownListener(FeedNotifierImpl.class.getName());
private static final String MSG_EMAIL_SUBJECT = "activities.feed.notifier.email.subject"; private static final String MSG_EMAIL_SUBJECT = "activities.feed.notifier.email.subject";
private NamespaceService namespaceService; private NamespaceService namespaceService;
private FileFolderService fileFolderService; private FileFolderService fileFolderService;
private SearchService searchService; private SearchService searchService;
@@ -94,49 +94,49 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
private SysAdminParams sysAdminParams; private SysAdminParams sysAdminParams;
private RepoAdminService repoAdminService; private RepoAdminService repoAdminService;
private UserNotifier userNotifier; private UserNotifier userNotifier;
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private RepositoryLocation feedEmailTemplateLocation; private RepositoryLocation feedEmailTemplateLocation;
private int numThreads = 4; private int numThreads = 4;
private int batchSize = 200; private int batchSize = 200;
public void setNumThreads(int numThreads) public void setNumThreads(int numThreads)
{ {
this.numThreads = numThreads; this.numThreads = numThreads;
} }
public void setBatchSize(int batchSize) public void setBatchSize(int batchSize)
{ {
this.batchSize = batchSize; this.batchSize = batchSize;
} }
public void setUserNotifier(UserNotifier userNotifier) public void setUserNotifier(UserNotifier userNotifier)
{ {
this.userNotifier = userNotifier; this.userNotifier = userNotifier;
} }
public void setFileFolderService(FileFolderService fileFolderService) public void setFileFolderService(FileFolderService fileFolderService)
{ {
this.fileFolderService = fileFolderService; this.fileFolderService = fileFolderService;
} }
public void setSearchService(SearchService searchService) public void setSearchService(SearchService searchService)
{ {
this.searchService = searchService; this.searchService = searchService;
} }
public void setNamespaceService(NamespaceService namespaceService) public void setNamespaceService(NamespaceService namespaceService)
{ {
this.namespaceService = namespaceService; this.namespaceService = namespaceService;
} }
public void setPersonService(PersonService personService) public void setPersonService(PersonService personService)
{ {
this.personService = personService; this.personService = personService;
} }
public void setNodeService(NodeService nodeService) public void setNodeService(NodeService nodeService)
{ {
this.nodeService = nodeService; this.nodeService = nodeService;
@@ -146,22 +146,22 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
{ {
this.jobLockService = jobLockService; this.jobLockService = jobLockService;
} }
public void setTransactionService(TransactionService transactionService) public void setTransactionService(TransactionService transactionService)
{ {
this.transactionService = transactionService; this.transactionService = transactionService;
} }
public void setSysAdminParams(SysAdminParams sysAdminParams) public void setSysAdminParams(SysAdminParams sysAdminParams)
{ {
this.sysAdminParams = sysAdminParams; this.sysAdminParams = sysAdminParams;
} }
public void setRepoAdminService(RepoAdminService repoAdminService) public void setRepoAdminService(RepoAdminService repoAdminService)
{ {
this.repoAdminService = repoAdminService; this.repoAdminService = repoAdminService;
} }
/** /**
* Perform basic checks to ensure that the necessary dependencies were injected. * Perform basic checks to ensure that the necessary dependencies were injected.
*/ */
@@ -173,11 +173,11 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
PropertyCheck.mandatory(this, "transactionService", transactionService); PropertyCheck.mandatory(this, "transactionService", transactionService);
PropertyCheck.mandatory(this, "sysAdminParams", sysAdminParams); PropertyCheck.mandatory(this, "sysAdminParams", sysAdminParams);
} }
public void execute(int repeatIntervalMins) public void execute(int repeatIntervalMins)
{ {
checkProperties(); checkProperties();
// Bypass if the system is in read-only mode // Bypass if the system is in read-only mode
if (transactionService.isReadOnly()) if (transactionService.isReadOnly())
{ {
@@ -200,7 +200,7 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
logger.info("Can't get lock. Assume multiple feed notifiers..."); logger.info("Can't get lock. Assume multiple feed notifiers...");
return; return;
} }
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
logger.trace("Activities email notification started"); logger.trace("Activities email notification started");
@@ -222,7 +222,7 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
}); });
executeInternal(repeatIntervalMins); executeInternal(repeatIntervalMins);
// Done // Done
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {
@@ -260,38 +260,38 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
{ {
this.feedEmailTemplateLocation = feedEmailTemplateLocation; this.feedEmailTemplateLocation = feedEmailTemplateLocation;
} }
protected String getEmailTemplateRef() protected String getEmailTemplateRef()
{ {
String locationType = feedEmailTemplateLocation.getQueryLanguage(); String locationType = feedEmailTemplateLocation.getQueryLanguage();
if (locationType.equals(SearchService.LANGUAGE_XPATH)) if (locationType.equals(SearchService.LANGUAGE_XPATH))
{ {
StoreRef store = feedEmailTemplateLocation.getStoreRef(); StoreRef store = feedEmailTemplateLocation.getStoreRef();
String xpath = feedEmailTemplateLocation.getPath(); String xpath = feedEmailTemplateLocation.getPath();
try try
{ {
if (! feedEmailTemplateLocation.getQueryLanguage().equals(SearchService.LANGUAGE_XPATH)) if (!feedEmailTemplateLocation.getQueryLanguage().equals(SearchService.LANGUAGE_XPATH))
{ {
logger.error("Cannot find the activities email template - repository location query language is not 'xpath': "+feedEmailTemplateLocation.getQueryLanguage()); logger.error("Cannot find the activities email template - repository location query language is not 'xpath': " + feedEmailTemplateLocation.getQueryLanguage());
return null; return null;
} }
List<NodeRef> nodeRefs = searchService.selectNodes(nodeService.getRootNode(store), xpath, null, namespaceService, false); List<NodeRef> nodeRefs = searchService.selectNodes(nodeService.getRootNode(store), xpath, null, namespaceService, false);
if (nodeRefs.size() != 1) if (nodeRefs.size() != 1)
{ {
logger.error("Cannot find the activities email template: "+xpath); logger.error("Cannot find the activities email template: " + xpath);
return null; return null;
} }
return fileFolderService.getLocalizedSibling(nodeRefs.get(0)).toString(); return fileFolderService.getLocalizedSibling(nodeRefs.get(0)).toString();
} }
catch (SearcherException e) catch (SearcherException e)
{ {
logger.error("Cannot find the email template!", e); logger.error("Cannot find the email template!", e);
} }
return null; return null;
} }
else if (locationType.equals(RepositoryLocation.LANGUAGE_CLASSPATH)) else if (locationType.equals(RepositoryLocation.LANGUAGE_CLASSPATH))
@@ -300,21 +300,21 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
} }
else else
{ {
logger.error("Unsupported location type: "+locationType); logger.error("Unsupported location type: " + locationType);
return null; return null;
} }
} }
private void executeInternal(final int repeatIntervalMins) private void executeInternal(final int repeatIntervalMins)
{ {
final String emailTemplateRef = getEmailTemplateRef(); final String emailTemplateRef = getEmailTemplateRef();
if (emailTemplateRef == null) if (emailTemplateRef == null)
{ {
return; return;
} }
final String shareUrl = UrlUtil.getShareUrl(sysAdminParams); final String shareUrl = UrlUtil.getShareUrl(sysAdminParams);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -335,28 +335,28 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
final String tenantDomain = TenantUtil.getCurrentDomain(); final String tenantDomain = TenantUtil.getCurrentDomain();
// process the feeds using the batch processor {@link BatchProcessor} // process the feeds using the batch processor {@link BatchProcessor}
BatchProcessor.BatchProcessWorker<PersonInfo> worker = new BatchProcessor.BatchProcessWorker<PersonInfo>() BatchProcessor.BatchProcessWorker<PersonInfo> worker = new BatchProcessor.BatchProcessWorker<PersonInfo>()
{ {
public String getIdentifier(final PersonInfo person) public String getIdentifier(final PersonInfo person)
{ {
StringBuilder sb = new StringBuilder("Person "); StringBuilder sb = new StringBuilder("Person ");
sb.append(person.getUserName()); sb.append(person.getUserName());
return sb.toString(); return sb.toString();
} }
public void beforeProcess() throws Throwable public void beforeProcess() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(currentUser); AuthenticationUtil.setFullyAuthenticatedUser(currentUser);
} }
public void afterProcess() throws Throwable public void afterProcess() throws Throwable
{ {
AuthenticationUtil.clearCurrentSecurityContext(); AuthenticationUtil.clearCurrentSecurityContext();
} }
public void process(final PersonInfo person) throws Throwable public void process(final PersonInfo person) throws Throwable
{ {
final RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper(); final RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper();
txHelper.setMaxRetries(0); txHelper.setMaxRetries(0);
TenantUtil.runAsTenant(new TenantRunAsWork<Void>() TenantUtil.runAsTenant(new TenantRunAsWork<Void>()
@@ -375,8 +375,8 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
return null; return null;
} }
}, tenantDomain); }, tenantDomain);
} }
private void processInternal(final PersonInfo person) throws Exception private void processInternal(final PersonInfo person) throws Exception
{ {
final NodeRef personNodeRef = person.getNodeRef(); final NodeRef personNodeRef = person.getNodeRef();
@@ -388,38 +388,38 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
int entryCnt = result.getFirst(); int entryCnt = result.getFirst();
final long maxFeedId = result.getSecond(); final long maxFeedId = result.getSecond();
Long currentMaxFeedId = (Long)nodeService.getProperty(personNodeRef, ContentModel.PROP_EMAIL_FEED_ID); Long currentMaxFeedId = (Long) nodeService.getProperty(personNodeRef, ContentModel.PROP_EMAIL_FEED_ID);
if ((currentMaxFeedId == null) || (currentMaxFeedId < maxFeedId)) if ((currentMaxFeedId == null) || (currentMaxFeedId < maxFeedId))
{ {
nodeService.setProperty(personNodeRef, ContentModel.PROP_EMAIL_FEED_ID, maxFeedId); nodeService.setProperty(personNodeRef, ContentModel.PROP_EMAIL_FEED_ID, maxFeedId);
} }
userCnt.incrementAndGet(); userCnt.incrementAndGet();
feedEntryCnt.addAndGet(entryCnt); feedEntryCnt.addAndGet(entryCnt);
} }
} }
catch (InvalidNodeRefException inre) catch (InvalidNodeRefException inre)
{ {
// skip this person - eg. no longer exists ? // skip this person - eg. no longer exists ?
logger.warn("Skip feed notification for user ("+personNodeRef+"): " + inre.getMessage()); logger.warn("Skip feed notification for user (" + personNodeRef + "): " + inre.getMessage());
} }
} }
}; };
// grab people for the batch processor in chunks of size batchSize // grab people for the batch processor in chunks of size batchSize
BatchProcessWorkProvider<PersonInfo> provider = new BatchProcessWorkProvider<PersonInfo>() BatchProcessWorkProvider<PersonInfo> provider = new BatchProcessWorkProvider<PersonInfo>()
{ {
private int skip = 0; private int skip = 0;
private int maxItems = batchSize; private int maxItems = batchSize;
private boolean hasMore = true; private boolean hasMore = true;
@Override @Override
public int getTotalEstimatedWorkSize() public int getTotalEstimatedWorkSize()
{ {
return personService.countPeople(); return personService.countPeople();
} }
@Override @Override
public Collection<PersonInfo> getNextWork() public Collection<PersonInfo> getNextWork()
{ {
if (!hasMore) if (!hasMore)
@@ -432,18 +432,18 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
hasMore = people.hasMoreItems(); hasMore = people.hasMoreItems();
return page; return page;
} }
}; };
final RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper(); final RetryingTransactionHelper txHelper = transactionService.getRetryingTransactionHelper();
txHelper.setMaxRetries(0); txHelper.setMaxRetries(0);
new BatchProcessor<PersonInfo>( new BatchProcessor<PersonInfo>(
"FeedNotifier", "FeedNotifier",
txHelper, txHelper,
provider, provider,
numThreads, batchSize, numThreads, batchSize,
applicationContext, applicationContext,
logger, 100).process(worker, true); logger, 100).process(worker, true);
} }
catch (Throwable e) catch (Throwable e)
{ {
@@ -459,8 +459,8 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
} }
finally finally
{ {
int count = userCnt.get(); int count = userCnt.get();
int entryCount = feedEntryCnt.get(); int entryCount = feedEntryCnt.get();
// assume sends are synchronous - hence bump up to last max feed id // assume sends are synchronous - hence bump up to last max feed id
if (count > 0) if (count > 0)
@@ -485,9 +485,9 @@ public class FeedNotifierImpl implements FeedNotifier, ApplicationContextAware
} }
} }
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{ {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
} }