001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: // Created on Mar 21, 2007
018: package edu.iu.uis.eden.mail;
019:
020: import org.kuali.rice.core.Core;
021:
022: import edu.iu.uis.eden.EdenConstants;
023: import edu.iu.uis.eden.KEWServiceLocator;
024: import edu.iu.uis.eden.actionitem.ActionItem;
025: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
026: import edu.iu.uis.eden.clientapp.vo.ActionRequestVO;
027: import edu.iu.uis.eden.clientapp.vo.RouteHeaderVO;
028: import edu.iu.uis.eden.doctype.DocumentType;
029: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
030: import edu.iu.uis.eden.exception.WorkflowException;
031: import edu.iu.uis.eden.plugin.attributes.CustomEmailAttribute;
032: import edu.iu.uis.eden.server.BeanConverter;
033: import edu.iu.uis.eden.user.WorkflowUser;
034: import edu.iu.uis.eden.util.Utilities;
035:
036: /**
037: * Base EmailContentService implementation with a default email from address that can be
038: * configured via Spring property injection
039: * @author Aaron Hamid (arh14 at cornell dot edu)
040: */
041: public abstract class BaseEmailContentServiceImpl implements
042: EmailContentService {
043: protected String defaultEmailFromAddress = "workflow@indiana.edu";
044: protected String deploymentEnvironment;
045:
046: public void setDefaultEmailFromAddress(
047: String defaultEmailFromAddress) {
048: this .defaultEmailFromAddress = defaultEmailFromAddress;
049: }
050:
051: public String getApplicationEmailAddress() {
052: // first check the configured value
053: String fromAddress = Utilities
054: .getApplicationConstant(EdenConstants.EMAIL_REMINDER_FROM_ADDRESS_KEY);
055: // if there's no value configured, use the default
056: if (Utilities.isEmpty(fromAddress)) {
057: fromAddress = defaultEmailFromAddress;
058: }
059: return fromAddress;
060: }
061:
062: public String getDocumentTypeEmailAddress(DocumentType documentType) {
063: String fromAddress = (documentType == null ? null
064: : documentType.getNotificationFromAddress());
065: if (Utilities.isEmpty(fromAddress)) {
066: fromAddress = getApplicationEmailAddress();
067: }
068: return fromAddress;
069: }
070:
071: public String getDeploymentEnvironment() {
072: return deploymentEnvironment;
073: }
074:
075: public void setDeploymentEnvironment(String deploymentEnvironment) {
076: this .deploymentEnvironment = deploymentEnvironment;
077: }
078:
079: protected static CustomEmailAttribute getCustomEmailAttribute(
080: WorkflowUser user, ActionItem actionItem)
081: throws EdenUserNotFoundException, WorkflowException {
082: CustomEmailAttribute customEmailAttribute = actionItem
083: .getRouteHeader().getCustomEmailAttribute();
084: if (customEmailAttribute != null) {
085: RouteHeaderVO routeHeaderVO = BeanConverter
086: .convertRouteHeader(actionItem.getRouteHeader(),
087: user);
088: ActionRequestValue actionRequest = KEWServiceLocator
089: .getActionRequestService().findByActionRequestId(
090: actionItem.getActionRequestId());
091: ActionRequestVO actionRequestVO = BeanConverter
092: .convertActionRequest(actionRequest);
093: customEmailAttribute.setRouteHeaderVO(routeHeaderVO);
094: customEmailAttribute.setActionRequestVO(actionRequestVO);
095: }
096: return customEmailAttribute;
097: }
098:
099: protected String getActionListUrl() {
100: return Core.getCurrentContextConfig().getBaseUrl()
101: + Utilities
102: .getApplicationConstant(EdenConstants.APPLICATION_CONTEXT_KEY)
103: + "/" + "ActionList.do";
104: }
105:
106: protected String getPreferencesUrl() {
107: return Core.getCurrentContextConfig().getBaseUrl()
108: + Utilities
109: .getApplicationConstant(EdenConstants.APPLICATION_CONTEXT_KEY)
110: + "/" + "Preferences.do";
111: }
112: }
|