mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Feature/acs 3015 analyse error prone action executor action (#1153)
* ACS-3015 move ErrorProneAction code to test folder * ACS-3015 remove old commented out code * ACS-3015 fix context * ACS-3015 fix context path * ACS-3015 move test context to test resources * ACS-3015 correct path to moved test context * ACS-3015 fix context problem for TestCase tests * ACS-3015 moved MockUserNotifier to test folder
This commit is contained in:
@@ -530,13 +530,7 @@
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="errorProneActionExecutor" class="org.alfresco.repo.activities.feed.ErrorProneActionExecutor" parent="action-executer">
|
||||
<property name="publicAction">
|
||||
<value>false</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- Import MailService from the OutboundSMTP subsystem (needed for email space/invited users actions) -->
|
||||
<bean id="mailService" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory">
|
||||
<property name="sourceApplicationContextFactory">
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -23,100 +23,100 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.action.executer.TestModeable;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
public class ErrorProneActionExecutor extends ActionExecuterAbstractBase
|
||||
implements InitializingBean, TestModeable
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(ErrorProneActionExecutor.class);
|
||||
|
||||
public static final String PARAM_FAILING_PERSON_NODEREF = "failingPersonNodeRef";
|
||||
public static final String PARAM_PERSON_NODEREF = "personNodeRef";
|
||||
public static final String PARAM_USERNAME = "userName";
|
||||
|
||||
public static final String NAME = "errorProneActionExecutor";
|
||||
|
||||
// count of number of successful notifications
|
||||
private AtomicInteger numSuccessful = new AtomicInteger();
|
||||
|
||||
// count of number of failed notifications
|
||||
private AtomicInteger numFailed = new AtomicInteger();
|
||||
|
||||
public int getNumSuccess()
|
||||
{
|
||||
return numSuccessful.get();
|
||||
}
|
||||
|
||||
public int getNumFailed()
|
||||
{
|
||||
return numFailed.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email message
|
||||
*
|
||||
* @throws AlfrescoRuntimeException
|
||||
*/
|
||||
@Override
|
||||
protected void executeImpl(
|
||||
final Action ruleAction,
|
||||
final NodeRef actionedUponNodeRef)
|
||||
{
|
||||
NodeRef failingPersonNodeRef = (NodeRef)ruleAction.getParameterValue(PARAM_FAILING_PERSON_NODEREF);
|
||||
NodeRef personNodeRef = (NodeRef)ruleAction.getParameterValue(PARAM_PERSON_NODEREF);
|
||||
String userName = (String)ruleAction.getParameterValue(PARAM_USERNAME);
|
||||
|
||||
System.out.println("userName = " + userName);
|
||||
|
||||
if(personNodeRef.equals(failingPersonNodeRef))
|
||||
{
|
||||
numFailed.incrementAndGet();
|
||||
throw new AlfrescoRuntimeException("");
|
||||
}
|
||||
|
||||
numSuccessful.incrementAndGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the parameter definitions
|
||||
*/
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_FAILING_PERSON_NODEREF, DataTypeDefinition.NODE_REF, true, "Failing Person NodeRef"));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_PERSON_NODEREF, DataTypeDefinition.NODE_REF, true, "Person NodeRef"));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_USERNAME, DataTypeDefinition.TEXT, true, "Username"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestMode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestMode(boolean testMode)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.action.ParameterDefinitionImpl;
|
||||
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||
import org.alfresco.repo.action.executer.TestModeable;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
public class ErrorProneActionExecutor extends ActionExecuterAbstractBase
|
||||
implements InitializingBean, TestModeable
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(ErrorProneActionExecutor.class);
|
||||
|
||||
public static final String PARAM_FAILING_PERSON_NODEREF = "failingPersonNodeRef";
|
||||
public static final String PARAM_PERSON_NODEREF = "personNodeRef";
|
||||
public static final String PARAM_USERNAME = "userName";
|
||||
|
||||
public static final String NAME = "errorProneActionExecutor";
|
||||
|
||||
// count of number of successful notifications
|
||||
private AtomicInteger numSuccessful = new AtomicInteger();
|
||||
|
||||
// count of number of failed notifications
|
||||
private AtomicInteger numFailed = new AtomicInteger();
|
||||
|
||||
public int getNumSuccess()
|
||||
{
|
||||
return numSuccessful.get();
|
||||
}
|
||||
|
||||
public int getNumFailed()
|
||||
{
|
||||
return numFailed.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email message
|
||||
*
|
||||
* @throws AlfrescoRuntimeException
|
||||
*/
|
||||
@Override
|
||||
protected void executeImpl(
|
||||
final Action ruleAction,
|
||||
final NodeRef actionedUponNodeRef)
|
||||
{
|
||||
NodeRef failingPersonNodeRef = (NodeRef)ruleAction.getParameterValue(PARAM_FAILING_PERSON_NODEREF);
|
||||
NodeRef personNodeRef = (NodeRef)ruleAction.getParameterValue(PARAM_PERSON_NODEREF);
|
||||
String userName = (String)ruleAction.getParameterValue(PARAM_USERNAME);
|
||||
|
||||
System.out.println("userName = " + userName);
|
||||
|
||||
if(personNodeRef.equals(failingPersonNodeRef))
|
||||
{
|
||||
numFailed.incrementAndGet();
|
||||
throw new AlfrescoRuntimeException("");
|
||||
}
|
||||
|
||||
numSuccessful.incrementAndGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the parameter definitions
|
||||
*/
|
||||
@Override
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_FAILING_PERSON_NODEREF, DataTypeDefinition.NODE_REF, true, "Failing Person NodeRef"));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_PERSON_NODEREF, DataTypeDefinition.NODE_REF, true, "Person NodeRef"));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_USERNAME, DataTypeDefinition.TEXT, true, "Username"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestMode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTestMode(boolean testMode)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -23,96 +23,72 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class ErrorProneUserNotifier extends AbstractUserNotifier
|
||||
{
|
||||
// private AtomicInteger numSuccessful = new AtomicInteger();
|
||||
// private AtomicInteger numFailed = new AtomicInteger();
|
||||
|
||||
private NodeRef failingPersonNodeRef;
|
||||
private ActionService actionService;
|
||||
|
||||
public ErrorProneUserNotifier(NodeRef failingPersonNodeRef)
|
||||
{
|
||||
this.failingPersonNodeRef = failingPersonNodeRef;
|
||||
}
|
||||
|
||||
public void setActionService(ActionService actionService)
|
||||
{
|
||||
this.actionService = actionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean skipUser(NodeRef personNodeRef)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getFeedId(NodeRef personNodeRef)
|
||||
{
|
||||
Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
|
||||
|
||||
// where did we get up to ?
|
||||
Long emailFeedDBID = (Long)personProps.get(ContentModel.PROP_EMAIL_FEED_ID);
|
||||
if (emailFeedDBID != null)
|
||||
{
|
||||
// increment min feed id
|
||||
emailFeedDBID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
emailFeedDBID = -1L;
|
||||
}
|
||||
|
||||
return emailFeedDBID;
|
||||
}
|
||||
|
||||
// public int getNumSuccess()
|
||||
// {
|
||||
// return numSuccessful.get();
|
||||
// }
|
||||
//
|
||||
// public int getNumFailed()
|
||||
// {
|
||||
// return numFailed.get();
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected void notifyUser(NodeRef personNodeRef, String subjectText, Object[] subjectParams,
|
||||
Map<String, Object> model, String templateNodeRef)
|
||||
{
|
||||
// super.notifyUser(personNodeRef, subjectText, model, templateNodeRef);
|
||||
|
||||
String userName = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
|
||||
|
||||
Action action = actionService.createAction(ErrorProneActionExecutor.NAME);
|
||||
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_FAILING_PERSON_NODEREF, failingPersonNodeRef);
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_PERSON_NODEREF, personNodeRef);
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_USERNAME, userName);
|
||||
|
||||
actionService.executeAction(action, null);
|
||||
// String userName = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
|
||||
//
|
||||
// System.out.println("userName = " + userName);
|
||||
//
|
||||
// if(personNodeRef.equals(failingPersonNodeRef))
|
||||
// {
|
||||
// numFailed.incrementAndGet();
|
||||
// throw new AlfrescoRuntimeException("");
|
||||
// }
|
||||
//
|
||||
// numSuccessful.incrementAndGet();
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class ErrorProneUserNotifier extends AbstractUserNotifier
|
||||
{
|
||||
|
||||
private NodeRef failingPersonNodeRef;
|
||||
private ActionService actionService;
|
||||
|
||||
public ErrorProneUserNotifier(NodeRef failingPersonNodeRef)
|
||||
{
|
||||
this.failingPersonNodeRef = failingPersonNodeRef;
|
||||
}
|
||||
|
||||
public void setActionService(ActionService actionService)
|
||||
{
|
||||
this.actionService = actionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean skipUser(NodeRef personNodeRef)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getFeedId(NodeRef personNodeRef)
|
||||
{
|
||||
Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
|
||||
|
||||
// where did we get up to ?
|
||||
Long emailFeedDBID = (Long)personProps.get(ContentModel.PROP_EMAIL_FEED_ID);
|
||||
if (emailFeedDBID != null)
|
||||
{
|
||||
// increment min feed id
|
||||
emailFeedDBID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
emailFeedDBID = -1L;
|
||||
}
|
||||
|
||||
return emailFeedDBID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyUser(NodeRef personNodeRef, String subjectText, Object[] subjectParams,
|
||||
Map<String, Object> model, String templateNodeRef)
|
||||
{
|
||||
|
||||
String userName = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
|
||||
|
||||
Action action = actionService.createAction(ErrorProneActionExecutor.NAME);
|
||||
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_FAILING_PERSON_NODEREF, failingPersonNodeRef);
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_PERSON_NODEREF, personNodeRef);
|
||||
action.setParameterValue(ErrorProneActionExecutor.PARAM_USERNAME, userName);
|
||||
|
||||
actionService.executeAction(action, null);
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -25,10 +25,6 @@
|
||||
*/
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.activities.post.lookup.PostLookup;
|
||||
import org.alfresco.repo.domain.activities.ActivitiesDAO;
|
||||
@@ -52,6 +48,7 @@ import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.json.JSONObject;
|
||||
@@ -62,6 +59,7 @@ import org.quartz.JobDetail;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -71,10 +69,10 @@ import java.util.List;
|
||||
*
|
||||
* @author steveglover
|
||||
*/
|
||||
public class FeedNotifierTest
|
||||
@ContextConfiguration({"classpath:alfresco/application-context.xml",
|
||||
"classpath:alfresco/feednotifier-tests/test-action-services-context.xml"})
|
||||
public class FeedNotifierTest extends BaseSpringTest
|
||||
{
|
||||
private static ApplicationContext ctx = null;
|
||||
|
||||
private PersonService personService;
|
||||
private NodeService nodeService;
|
||||
private NamespaceService namespaceService;
|
||||
@@ -104,14 +102,12 @@ public class FeedNotifierTest
|
||||
{
|
||||
ApplicationContextHelper.setUseLazyLoading(false);
|
||||
ApplicationContextHelper.setNoAutoStart(true);
|
||||
|
||||
ctx = ApplicationContextHelper.getApplicationContext();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) ctx.getBean("ActivitiesFeed");
|
||||
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) applicationContext.getBean("ActivitiesFeed");
|
||||
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
|
||||
this.feedNotifier = (FeedNotifierImpl) activitiesFeedCtx.getBean("feedNotifier");
|
||||
this.activityService = (ActivityService) activitiesFeedCtx.getBean("activityService");
|
||||
@@ -119,7 +115,7 @@ public class FeedNotifierTest
|
||||
this.feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
|
||||
ObjectFactory<ActivitiesFeedModelBuilder> feedModelBuilderFactory = (ObjectFactory<ActivitiesFeedModelBuilder>) activitiesFeedCtx.getBean("feedModelBuilderFactory");
|
||||
|
||||
Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
|
||||
Scheduler scheduler = (Scheduler) applicationContext.getBean("schedulerFactory");
|
||||
|
||||
JobDetail feedGeneratorJobDetail = (JobDetail) activitiesFeedCtx.getBean("feedGeneratorJobDetail");
|
||||
JobDetail postLookupJobDetail = (JobDetail) activitiesFeedCtx.getBean("postLookupJobDetail");
|
||||
@@ -134,17 +130,17 @@ public class FeedNotifierTest
|
||||
scheduler.pauseJob(postCleanerJobDetail.getKey());
|
||||
scheduler.pauseJob(feedNotifierJobDetail.getKey());
|
||||
|
||||
this.personService = (PersonService) ctx.getBean("personService");
|
||||
this.nodeService = (NodeService) ctx.getBean("nodeService");
|
||||
this.namespaceService = (NamespaceService) ctx.getBean("namespaceService");
|
||||
this.siteService = (SiteService) ctx.getBean("siteService");
|
||||
this.repoAdminService = (RepoAdminService) ctx.getBean("repoAdminService");
|
||||
this.transactionService = (TransactionService) ctx.getBean("transactionService");
|
||||
this.postDAO = (ActivityPostDAO) ctx.getBean("postDAO");
|
||||
this.fileFolderService = (FileFolderService) ctx.getBean("fileFolderService");
|
||||
this.subscriptionService = (SubscriptionService) ctx.getBean("SubscriptionService");
|
||||
this.errorProneActionExecutor = (ErrorProneActionExecutor) ctx.getBean("errorProneActionExecutor");
|
||||
this.actionService = (ActionService) ctx.getBean("ActionService");
|
||||
this.personService = (PersonService) applicationContext.getBean("personService");
|
||||
this.nodeService = (NodeService) applicationContext.getBean("nodeService");
|
||||
this.namespaceService = (NamespaceService) applicationContext.getBean("namespaceService");
|
||||
this.siteService = (SiteService) applicationContext.getBean("siteService");
|
||||
this.repoAdminService = (RepoAdminService) applicationContext.getBean("repoAdminService");
|
||||
this.transactionService = (TransactionService) applicationContext.getBean("transactionService");
|
||||
this.postDAO = (ActivityPostDAO) applicationContext.getBean("postDAO");
|
||||
this.fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
|
||||
this.subscriptionService = (SubscriptionService) applicationContext.getBean("SubscriptionService");
|
||||
this.errorProneActionExecutor = (ErrorProneActionExecutor) applicationContext.getBean("errorProneActionExecutor");
|
||||
this.actionService = (ActionService) applicationContext.getBean("ActionService");
|
||||
|
||||
// create some users
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -23,95 +23,95 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* A test user notifier.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MockUserNotifier extends AbstractUserNotifier
|
||||
{
|
||||
/**
|
||||
* Default alfresco installation url
|
||||
*/
|
||||
private BitSet notifiedPersonsTracker = new BitSet();
|
||||
private AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
protected boolean skipUser(NodeRef personNodeRef)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getFeedId(NodeRef personNodeRef)
|
||||
{
|
||||
Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
|
||||
|
||||
// where did we get up to ?
|
||||
Long emailFeedDBID = (Long)personProps.get(ContentModel.PROP_EMAIL_FEED_ID);
|
||||
if (emailFeedDBID != null)
|
||||
{
|
||||
// increment min feed id
|
||||
emailFeedDBID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
emailFeedDBID = -1L;
|
||||
}
|
||||
|
||||
return emailFeedDBID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyUser(NodeRef personNodeRef, String subjectText, Object[] subjectParams, Map<String, Object> model, String templateNodeRef)
|
||||
{
|
||||
String username = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
|
||||
if(username.startsWith("user"))
|
||||
{
|
||||
int id = Integer.parseInt(username.substring(4));
|
||||
|
||||
boolean b = false;
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
b = notifiedPersonsTracker.get(id);
|
||||
}
|
||||
if(b)
|
||||
{
|
||||
System.out.println("Already set: " + id);
|
||||
}
|
||||
else
|
||||
{
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
notifiedPersonsTracker.set(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
count.incrementAndGet();
|
||||
}
|
||||
|
||||
public int countNotifications()
|
||||
{
|
||||
return count.get();
|
||||
}
|
||||
|
||||
public int nextUserId()
|
||||
{
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
return notifiedPersonsTracker.nextClearBit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.activities.feed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* A test user notifier.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MockUserNotifier extends AbstractUserNotifier
|
||||
{
|
||||
/**
|
||||
* Default alfresco installation url
|
||||
*/
|
||||
private BitSet notifiedPersonsTracker = new BitSet();
|
||||
private AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
protected boolean skipUser(NodeRef personNodeRef)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getFeedId(NodeRef personNodeRef)
|
||||
{
|
||||
Map<QName, Serializable> personProps = nodeService.getProperties(personNodeRef);
|
||||
|
||||
// where did we get up to ?
|
||||
Long emailFeedDBID = (Long)personProps.get(ContentModel.PROP_EMAIL_FEED_ID);
|
||||
if (emailFeedDBID != null)
|
||||
{
|
||||
// increment min feed id
|
||||
emailFeedDBID++;
|
||||
}
|
||||
else
|
||||
{
|
||||
emailFeedDBID = -1L;
|
||||
}
|
||||
|
||||
return emailFeedDBID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyUser(NodeRef personNodeRef, String subjectText, Object[] subjectParams, Map<String, Object> model, String templateNodeRef)
|
||||
{
|
||||
String username = (String)nodeService.getProperty(personNodeRef, ContentModel.PROP_USERNAME);
|
||||
if(username.startsWith("user"))
|
||||
{
|
||||
int id = Integer.parseInt(username.substring(4));
|
||||
|
||||
boolean b = false;
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
b = notifiedPersonsTracker.get(id);
|
||||
}
|
||||
if(b)
|
||||
{
|
||||
System.out.println("Already set: " + id);
|
||||
}
|
||||
else
|
||||
{
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
notifiedPersonsTracker.set(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
count.incrementAndGet();
|
||||
}
|
||||
|
||||
public int countNotifications()
|
||||
{
|
||||
return count.get();
|
||||
}
|
||||
|
||||
public int nextUserId()
|
||||
{
|
||||
synchronized(notifiedPersonsTracker)
|
||||
{
|
||||
return notifiedPersonsTracker.nextClearBit(1);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="errorProneActionExecutor" class="org.alfresco.repo.activities.feed.ErrorProneActionExecutor" parent="action-executer">
|
||||
<property name="publicAction">
|
||||
<value>false</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
Reference in New Issue
Block a user