Coverage Report - org.kuali.rice.kew.mail.service.impl.BaseEmailContentServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseEmailContentServiceImpl
0%
0/26
0%
0/8
1.5
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.kew.mail.service.impl;
 18  
 
 19  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 20  
 import org.kuali.rice.core.framework.services.CoreFrameworkServiceLocator;
 21  
 import org.kuali.rice.kew.actionitem.ActionItem;
 22  
 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
 23  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 24  
 import org.kuali.rice.kew.dto.ActionRequestDTO;
 25  
 import org.kuali.rice.kew.dto.DTOConverter;
 26  
 import org.kuali.rice.kew.dto.RouteHeaderDTO;
 27  
 import org.kuali.rice.kew.exception.WorkflowException;
 28  
 import org.kuali.rice.kew.mail.CustomEmailAttribute;
 29  
 import org.kuali.rice.kew.mail.service.EmailContentService;
 30  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 31  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 32  
 import org.kuali.rice.kew.util.KEWConstants;
 33  
 import org.kuali.rice.kim.bo.Person;
 34  
 import org.kuali.rice.krad.util.KRADConstants;
 35  
 
 36  
 /**
 37  
  * Base EmailContentService implementation with a default email from address that can be
 38  
  * configured via Spring property injection
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  0
 public abstract class BaseEmailContentServiceImpl implements EmailContentService {
 42  0
     protected String defaultEmailFromAddress = "admin@localhost";
 43  
     protected String deploymentEnvironment;
 44  
 
 45  
     public void setDefaultEmailFromAddress(String defaultEmailFromAddress) {
 46  0
         this.defaultEmailFromAddress = defaultEmailFromAddress;
 47  0
     }
 48  
 
 49  
     public String getApplicationEmailAddress() {
 50  
         // first check the configured value
 51  0
         String fromAddress = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KEWConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.MAILER_DETAIL_TYPE, KEWConstants.EMAIL_REMINDER_FROM_ADDRESS);
 52  
         // if there's no value configured, use the default
 53  0
         if (org.apache.commons.lang.StringUtils.isEmpty(fromAddress)) {
 54  0
             fromAddress = defaultEmailFromAddress;
 55  
         }
 56  0
         return fromAddress;
 57  
     }
 58  
 
 59  
     public String getDocumentTypeEmailAddress(DocumentType documentType) {
 60  0
         String fromAddress = (documentType == null ? null : documentType.getNotificationFromAddress());
 61  0
         if (org.apache.commons.lang.StringUtils.isEmpty(fromAddress)) {
 62  0
             fromAddress = getApplicationEmailAddress();
 63  
         }
 64  0
         return fromAddress;
 65  
     }
 66  
 
 67  
     public String getDeploymentEnvironment() {
 68  0
         return deploymentEnvironment;
 69  
     }
 70  
 
 71  
     public void setDeploymentEnvironment(String deploymentEnvironment) {
 72  0
         this.deploymentEnvironment = deploymentEnvironment;
 73  0
     }
 74  
 
 75  
     protected static CustomEmailAttribute getCustomEmailAttribute(Person user, ActionItem actionItem) throws WorkflowException {
 76  0
             DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId());
 77  0
         CustomEmailAttribute customEmailAttribute = routeHeader.getCustomEmailAttribute();
 78  0
         if (customEmailAttribute != null) {
 79  0
             RouteHeaderDTO routeHeaderVO = DTOConverter.convertRouteHeader(routeHeader, user.getPrincipalId());
 80  0
             ActionRequestValue actionRequest = KEWServiceLocator.getActionRequestService().findByActionRequestId(actionItem.getActionRequestId());
 81  0
             ActionRequestDTO actionRequestVO = DTOConverter.convertActionRequest(actionRequest);
 82  0
             customEmailAttribute.setRouteHeaderVO(routeHeaderVO);
 83  0
             customEmailAttribute.setActionRequestVO(actionRequestVO);
 84  
         }
 85  0
         return customEmailAttribute;
 86  
     }
 87  
 
 88  
     protected String getActionListUrl() {
 89  0
         return ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.WORKFLOW_URL_KEY) + "/" + "ActionList.do";
 90  
     }
 91  
 
 92  
     protected String getPreferencesUrl() {
 93  0
         return ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.WORKFLOW_URL_KEY) + "/" + "Preferences.do";
 94  
     }
 95  
 }