View Javadoc
1   /**
2    * Copyright 2005-2014 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.krad.service.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.krad.exception.ExceptionIncident;
20  import org.kuali.rice.krad.exception.KualiExceptionIncident;
21  import org.kuali.rice.krad.service.KualiExceptionIncidentService;
22  
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Map;
26  
27  /**
28   * Modified this service so that it now extends the KualiFeedbackServiceImpl.
29   * This has been done to allow user feedback and exception incidents to be
30   * reported in the same way, but to potentially different email lists.  Part
31   * of this refactor included moving the mailer and messageTemplate properties
32   * and the emailReport and createMailMessage methods to the new parent class.
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  public class KualiExceptionIncidentServiceImpl extends KualiFeedbackServiceImpl implements KualiExceptionIncidentService {
38      private Logger LOG=Logger.getLogger(KualiExceptionIncidentServiceImpl.class);
39      
40      /**
41       * An list to send incident emails to.
42       */
43      private String incidentMailingList;
44      
45      /**
46       * This property must be defined in the base configuration file for specifying
47       * the mailing list for the report to be sent.
48       * <p>Example:
49       * <code>
50       * <param name="KualiReporterServiceImpl.REPORT_MAIL_LIST">a@y,b@z</param>
51       * </code>
52       */
53      public static final String REPORT_MAIL_LIST=String.format("%s.REPORT_MAIL_LIST", KualiExceptionIncidentServiceImpl.class.getSimpleName());
54  
55      @Override
56      protected String getToAddressesPropertyName() {
57          return REPORT_MAIL_LIST;
58      }
59  
60      /**
61       * This overridden method send email to the specified list of addresses.
62       * 
63       * @see org.kuali.rice.krad.service.KualiExceptionIncidentService#report(org.kuali.rice.krad.exception.KualiExceptionIncident)
64       */
65      @Override
66  	public void report(KualiExceptionIncident exceptionIncident) throws Exception {
67          if (LOG.isTraceEnabled()) {
68              String lm=String.format("ENTRY %s",
69                      (exceptionIncident==null)?"null":exceptionIncident.toString());
70              LOG.trace(lm);
71          }
72          
73          emailReport(
74                  exceptionIncident.getProperty(
75                          KualiExceptionIncident.EXCEPTION_REPORT_SUBJECT),
76                  exceptionIncident.getProperty(
77                          KualiExceptionIncident.EXCEPTION_REPORT_MESSAGE));
78          
79          if (LOG.isTraceEnabled()) {
80              String lm=String.format("EXIT");
81              LOG.trace(lm);
82          }
83          
84      }
85  
86      /**
87       * This method first separate a composite string of the format
88       * "string token string".
89       * <p>Example: 1,2,a,b where ',' is the token
90       * 
91       * @param s
92       * @param token
93       * @return
94       */
95      public List<String> split(String s, String token) {
96          if (LOG.isTraceEnabled()) {
97              String lm=String.format("ENTRY %s;%s", s, token);
98              LOG.trace(lm);
99          }
100                 
101         String[] sarray=s.split(token);
102         List<String> list=new ArrayList<String>();
103         for (int i=0; i<sarray.length && sarray[i].length() > 0; i++) {
104             list.add(sarray[i]);
105         }
106         
107         if (LOG.isTraceEnabled()) {
108             String lm=String.format("EXIT %s", list.toString());
109             LOG.trace(lm);
110         }
111         
112         return list;
113     }
114 
115     /**
116      * This overridden method create an instance of the KualiExceptionIncident.
117      * 
118      * @see org.kuali.rice.krad.service.KualiExceptionIncidentService#getExceptionIncident(
119      * java.lang.Exception,java.util.Map)
120      */
121     @Override
122 	public KualiExceptionIncident getExceptionIncident(Exception exception,
123             Map<String, String> properties) {
124     	if ( exception == null ) {
125     		return getExceptionIncident(properties);
126     	}
127         if (LOG.isTraceEnabled()) {
128             String lm=String.format("ENTRY %s;%s", exception.getMessage(),
129                     properties.toString());
130             LOG.trace(lm);
131         }
132         
133         KualiExceptionIncident ei=new ExceptionIncident(exception, properties);
134         
135         if (LOG.isTraceEnabled()) {
136             String lm=String.format("EXIT %s", ei.toProperties().toString());
137             LOG.trace(lm);
138         }
139                 
140         return ei;
141     }
142 
143     /**
144      * This overridden method create an instance of ExceptionIncident from list of
145      * name-value pairs as exception incident information.
146      * 
147      * @see org.kuali.rice.krad.service.KualiExceptionIncidentService#getExceptionIncident(java.util.Map)
148      */
149     @Override
150 	public KualiExceptionIncident getExceptionIncident(Map<String, String> properties) {
151         if (LOG.isTraceEnabled()) {
152             String lm=String.format("ENTRY %s", properties.toString());
153             LOG.trace(lm);
154         }
155         
156         ExceptionIncident ei=new ExceptionIncident(properties);
157                 
158         if (LOG.isTraceEnabled()) {
159             String lm=String.format("EXIT %s", ei.toProperties().toString());
160             LOG.trace(lm);
161         }
162                 
163         return ei;
164     }
165     
166 	/**
167      * Returns the incident report mailing list.
168 	 * @return the incidentMailingList
169 	 */
170 	public String getIncidentMailingList() {
171 		return this.incidentMailingList;
172 	}
173 
174 	/**
175      * Sets the incident report mailing list.
176 	 * @param incidentMailingList the incidentMailingList to set
177 	 */
178 	public void setIncidentMailingList(String incidentMailingList) {
179 		this.incidentMailingList = incidentMailingList;
180 	}
181 
182 }