View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.coreservice.framework.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   * Base EmailContentService implementation with a default email from address that can be
36   * configured via Spring property injection
37   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // first check the configured value
49          String fromAddress = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.MAILER_DETAIL_TYPE, KewApiConstants.EMAIL_REMINDER_FROM_ADDRESS);
50          // if there's no value configured, use the default
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  }