View Javadoc

1   /*
2    * Copyright 2007-2008 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 mocks;
17  
18  import java.sql.Timestamp;
19  import java.util.Collection;
20  import java.util.Date;
21  import java.util.Map;
22  
23  import org.kuali.rice.core.mail.EmailContent;
24  import org.kuali.rice.kew.actionitem.ActionItem;
25  import org.kuali.rice.kew.doctype.bo.DocumentType;
26  import org.kuali.rice.kew.feedback.web.FeedbackForm;
27  import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
28  import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
29  import org.kuali.rice.kew.util.KEWConstants;
30  import org.kuali.rice.kim.bo.Person;
31  
32  
33  /**
34   * This is a class used to substitute for a StyleableEmailContentServiceImpl class
35   *
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class MockStyleableEmailContentServiceImpl extends StyleableEmailContentServiceImpl implements MockStyleableEmailContentService {
40  
41      private boolean wasAccessed = false;
42  
43      @Override
44      public EmailContent generateImmediateReminder(Person user, ActionItem actionItem, DocumentType documentType) {
45          wasAccessed = true;
46          return super.generateImmediateReminder(user, actionItem, documentType);
47      }
48  
49      @Override
50      public EmailContent generateDailyReminder(Person user, Collection<ActionItem> actionItems) {
51          wasAccessed = true;
52          return super.generateDailyReminder(user, actionItems);
53      }
54  
55      @Override
56      public EmailContent generateWeeklyReminder(Person user, Collection<ActionItem> actionItems) {
57          wasAccessed = true;
58          return super.generateWeeklyReminder(user, actionItems);
59      }
60  
61      @Override
62      public EmailContent generateFeedback(FeedbackForm form) {
63          wasAccessed = true;
64          return super.generateFeedback(form);
65      }
66  
67      /**
68       * This overridden method is used in case the action item has an null route header attached
69       *
70       * @see org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl#getRouteHeader(org.kuali.rice.kew.actionitem.ActionItem)
71       */
72      @Override
73      public DocumentRouteHeaderValue getRouteHeader(ActionItem actionItem) {
74      	DocumentRouteHeaderValue routeHeader = null;
75          if (actionItem.getDocumentId() != null) {
76              routeHeader = super.getRouteHeader(actionItem);
77          }
78          if (routeHeader == null) {
79          	routeHeader = new DocumentRouteHeaderValue();
80          	routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_ENROUTE_CD);
81          	routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
82          }
83          return routeHeader;
84      }
85  
86      @Override
87      public Map<String,DocumentRouteHeaderValue> getRouteHeaders(Collection<ActionItem> actionItems) {
88      	Map<String,DocumentRouteHeaderValue> routeHeaders = super.getRouteHeaders(actionItems);
89      	DocumentRouteHeaderValue routeHeader = null;
90      	for (ActionItem actionItem : actionItems) {
91      		if (routeHeaders.get(actionItem.getDocumentId()) == null) {
92      			routeHeader = new DocumentRouteHeaderValue();
93              	routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_ENROUTE_CD);
94              	routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
95              	routeHeaders.put(actionItem.getDocumentId(), routeHeader);
96      		}
97      	}
98      	return routeHeaders;
99      }
100     
101     /**
102      * This method returns whether this service is being used
103      */
104     public boolean wasServiceAccessed() {
105         return this.wasAccessed;
106     }
107 
108     /**
109      * This method returns whether this service is being used
110      */
111     public void resetServiceAccessed() {
112         this.wasAccessed = false;
113     }
114 
115 }