1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.mail.service.impl;
17
18 import org.kuali.rice.core.api.config.property.ConfigContext;
19 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
20 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
21 import org.kuali.rice.kew.api.action.ActionItem;
22 import org.kuali.rice.kew.api.action.ActionRequest;
23 import org.kuali.rice.kew.api.document.Document;
24 import org.kuali.rice.kew.api.exception.WorkflowException;
25 import org.kuali.rice.kew.doctype.bo.DocumentType;
26 import org.kuali.rice.kew.mail.CustomEmailAttribute;
27 import org.kuali.rice.kew.mail.service.EmailContentService;
28 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29 import org.kuali.rice.kew.service.KEWServiceLocator;
30 import org.kuali.rice.kew.api.KewApiConstants;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.krad.util.KRADConstants;
33
34
35
36
37
38
39 public abstract class BaseEmailContentServiceImpl implements EmailContentService {
40 protected String defaultEmailFromAddress = "admin@localhost";
41 protected String deploymentEnvironment;
42
43 public void setDefaultEmailFromAddress(String defaultEmailFromAddress) {
44 this.defaultEmailFromAddress = defaultEmailFromAddress;
45 }
46
47 public String getApplicationEmailAddress() {
48
49 String fromAddress = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.MAILER_DETAIL_TYPE, KewApiConstants.EMAIL_REMINDER_FROM_ADDRESS);
50
51 if (org.apache.commons.lang.StringUtils.isEmpty(fromAddress)) {
52 fromAddress = defaultEmailFromAddress;
53 }
54 return fromAddress;
55 }
56
57 public String getDocumentTypeEmailAddress(DocumentType documentType) {
58 String fromAddress = (documentType == null ? null : documentType.getNotificationFromAddress());
59 if (org.apache.commons.lang.StringUtils.isEmpty(fromAddress)) {
60 fromAddress = getApplicationEmailAddress();
61 }
62 return fromAddress;
63 }
64
65 public String getDeploymentEnvironment() {
66 return deploymentEnvironment;
67 }
68
69 public void setDeploymentEnvironment(String deploymentEnvironment) {
70 this.deploymentEnvironment = deploymentEnvironment;
71 }
72
73 protected static CustomEmailAttribute getCustomEmailAttribute(Person user, ActionItem actionItem) throws WorkflowException {
74 DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId());
75 CustomEmailAttribute customEmailAttribute = routeHeader.getCustomEmailAttribute();
76 if (customEmailAttribute != null) {
77 Document routeHeaderVO = DocumentRouteHeaderValue.to(routeHeader);
78 ActionRequestValue actionRequest = KEWServiceLocator.getActionRequestService().findByActionRequestId(actionItem.getActionRequestId());
79 ActionRequest actionRequestVO = ActionRequestValue.to(actionRequest);
80 customEmailAttribute.setRouteHeaderVO(routeHeaderVO);
81 customEmailAttribute.setActionRequestVO(actionRequestVO);
82 }
83 return customEmailAttribute;
84 }
85
86 protected String getActionListUrl() {
87 return ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.WORKFLOW_URL_KEY) + "/" + "ActionList.do";
88 }
89
90 protected String getPreferencesUrl() {
91 return ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.WORKFLOW_URL_KEY) + "/" + "Preferences.do";
92 }
93 }