Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

59881: Merged V4.2-BUG-FIX (4.2.2) to HEAD-BUG-FIX (Cloud/4.3)
      59606: Merged DEV to V4.2-BUG-FIX
         58106: Fixed formatting in MailActionExecuter found during investigations
         58107: Fixed formatting issues in ActionExecuterAbstractBase found during investigations
         58108: Further detection of transaction state in the base action code (MNT-9806)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@62197 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-02-12 08:11:23 +00:00
parent dc3d804dfe
commit ad6ffbde8c
2 changed files with 67 additions and 60 deletions

View File

@@ -24,6 +24,8 @@ import java.util.Set;
import org.alfresco.repo.action.ActionDefinitionImpl; import org.alfresco.repo.action.ActionDefinitionImpl;
import org.alfresco.repo.action.ParameterizedItemAbstractBase; import org.alfresco.repo.action.ParameterizedItemAbstractBase;
import org.alfresco.repo.lock.LockUtils; import org.alfresco.repo.lock.LockUtils;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -77,10 +79,10 @@ public abstract class ActionExecuterAbstractBase extends ParameterizedItemAbstra
public void setMlAwareNodeService(NodeService mlAwareNodeService) public void setMlAwareNodeService(NodeService mlAwareNodeService)
{ {
this.mlAwareNodeService = mlAwareNodeService; this.mlAwareNodeService = mlAwareNodeService;
} }
public void setLockService(LockService lockService) public void setLockService(LockService lockService)
{ {
this.lockService = lockService; this.lockService = lockService;
} }
@@ -236,6 +238,11 @@ public abstract class ActionExecuterAbstractBase extends ParameterizedItemAbstra
*/ */
public void execute(Action action, NodeRef actionedUponNodeRef) public void execute(Action action, NodeRef actionedUponNodeRef)
{ {
if (AlfrescoTransactionSupport.getTransactionReadState() == TxnReadState.TXN_NONE)
{
throw new IllegalStateException("Actions invariably access the repository. Doing so without a transaction is not recommended.");
}
// Check the mandatory properties // Check the mandatory properties
checkMandatoryProperties(action, getActionDefinition()); checkMandatoryProperties(action, getActionDefinition());

View File

@@ -230,7 +230,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
public void setPreferenceService(PreferenceService preferenceService) public void setPreferenceService(PreferenceService preferenceService)
{ {
this.preferenceService = preferenceService; this.preferenceService = preferenceService;
} }
/** /**
@@ -400,10 +400,10 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
@Override @Override
public void init() public void init()
{ {
if(logger.isDebugEnabled()) if(logger.isDebugEnabled())
{ {
logger.debug("Init called, testMessageTo=" + testMessageTo); logger.debug("Init called, testMessageTo=" + testMessageTo);
} }
numberSuccessfulSends.set(0); numberSuccessfulSends.set(0);
numberFailedSends.set(0); numberFailedSends.set(0);
@@ -451,17 +451,17 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
final NodeRef actionedUponNodeRef) final NodeRef actionedUponNodeRef)
{ {
//Prepare our messages before the commit, in-case of deletes //Prepare our messages before the commit, in-case of deletes
MimeMessageHelper[] messages = null; MimeMessageHelper[] messages = null;
if (validNodeRefIfPresent(actionedUponNodeRef)) if (validNodeRefIfPresent(actionedUponNodeRef))
{ {
messages = prepareEmails(ruleAction, actionedUponNodeRef); messages = prepareEmails(ruleAction, actionedUponNodeRef);
} }
final MimeMessageHelper[] finalMessages = messages; final MimeMessageHelper[] finalMessages = messages;
//Send out messages //Send out messages
if(finalMessages!=null){ if(finalMessages!=null){
if (sendAfterCommit(ruleAction)) if (sendAfterCommit(ruleAction))
{ {
AlfrescoTransactionSupport.bindListener(new TransactionListenerAdapter() AlfrescoTransactionSupport.bindListener(new TransactionListenerAdapter()
{ {
@@ -474,9 +474,9 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
@Override @Override
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
for (MimeMessageHelper message : finalMessages) { for (MimeMessageHelper message : finalMessages) {
sendEmail(ruleAction, message); sendEmail(ruleAction, message);
} }
return null; return null;
} }
@@ -486,11 +486,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
} }
else else
{ {
for (MimeMessageHelper message : finalMessages) { for (MimeMessageHelper message : finalMessages) {
sendEmail(ruleAction, message); sendEmail(ruleAction, message);
} }
} }
} }
} }
@@ -838,7 +838,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
} }
if (locale == null) if (locale == null)
{ {
locale = sender.getSecond(); locale = sender.getSecond();
} }
// set subject line // set subject line
@@ -847,13 +847,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
String localizedSubject = getLocalizedSubject(subject, subjectParams, locale); String localizedSubject = getLocalizedSubject(subject, subjectParams, locale);
if (locale == null) if (locale == null)
{ {
// process the template against the model // process the template against the model
text = templateService.processTemplate("freemarker", templateRef, model); text = templateService.processTemplate("freemarker", templateRef, model);
} }
else else
{ {
// process the template against the model // process the template against the model
text = templateService.processTemplate("freemarker", templateRef, model, locale); text = templateService.processTemplate("freemarker", templateRef, model, locale);
} }
if ((testModeRecipient != null) && (testModeRecipient.length() > 0) && (! testModeRecipient.equals("${dev.email.recipient.address}"))) if ((testModeRecipient != null) && (testModeRecipient.length() > 0) && (! testModeRecipient.equals("${dev.email.recipient.address}")))
{ {
@@ -974,23 +974,23 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
*/ */
private String getLocalizedSubject(String subject, Object[] params, Locale locale) private String getLocalizedSubject(String subject, Object[] params, Locale locale)
{ {
String localizedSubject = null; String localizedSubject = null;
if (locale == null) if (locale == null)
{ {
localizedSubject = I18NUtil.getMessage(subject, params); localizedSubject = I18NUtil.getMessage(subject, params);
} }
else else
{ {
localizedSubject = I18NUtil.getMessage(subject, locale, params); localizedSubject = I18NUtil.getMessage(subject, locale, params);
} }
if (localizedSubject == null) if (localizedSubject == null)
{ {
return subject; return subject;
} }
else else
{ {
return localizedSubject; return localizedSubject;
} }
} }
@@ -1036,11 +1036,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{ {
try try
{ {
address = new InternetAddress(from, fromPersonalName); address = new InternetAddress(from, fromPersonalName);
} }
catch (UnsupportedEncodingException error) catch (UnsupportedEncodingException error)
{ {
address = new InternetAddress(from); address = new InternetAddress(from);
} }
} }
else else
@@ -1102,18 +1102,18 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
private List<Pair<String, Locale>> getRecipients(Action ruleAction) private List<Pair<String, Locale>> getRecipients(Action ruleAction)
{ {
List<Pair<String, Locale>> recipients = new LinkedList<Pair<String,Locale>>(); List<Pair<String, Locale>> recipients = new LinkedList<Pair<String,Locale>>();
// set recipient // set recipient
String to = (String)ruleAction.getParameterValue(PARAM_TO); String to = (String)ruleAction.getParameterValue(PARAM_TO);
if (to != null && to.length() != 0) if (to != null && to.length() != 0)
{ {
Locale locale = null; Locale locale = null;
if (personExists(to)) if (personExists(to))
{ {
locale = getLocaleForUser(to); locale = getLocaleForUser(to);
} }
recipients.add(new Pair<String, Locale>(to, locale)); recipients.add(new Pair<String, Locale>(to, locale));
} }
else else
{ {
@@ -1241,13 +1241,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
String domain = tenantService.getPrimaryDomain(user); // get primary tenant String domain = tenantService.getPrimaryDomain(user); // get primary tenant
if (domain != null) if (domain != null)
{ {
exists = TenantUtil.runAsTenant(new TenantRunAsWork<Boolean>() exists = TenantUtil.runAsTenant(new TenantRunAsWork<Boolean>()
{ {
public Boolean doWork() throws Exception public Boolean doWork() throws Exception
{ {
return personService.personExists(user); return personService.personExists(user);
} }
}, domain); }, domain);
} }
else else
{ {
@@ -1262,13 +1262,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
String domain = tenantService.getPrimaryDomain(user); // get primary tenant String domain = tenantService.getPrimaryDomain(user); // get primary tenant
if (domain != null) if (domain != null)
{ {
person = TenantUtil.runAsTenant(new TenantRunAsWork<NodeRef>() person = TenantUtil.runAsTenant(new TenantRunAsWork<NodeRef>()
{ {
public NodeRef doWork() throws Exception public NodeRef doWork() throws Exception
{ {
return personService.getPerson(user); return personService.getPerson(user);
} }
}, domain); }, domain);
} }
else else
{ {