View Javadoc

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