001    /*
002     * Copyright 2007-2008 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package mocks;
017    
018    import java.sql.Timestamp;
019    import java.util.Collection;
020    import java.util.Date;
021    import java.util.Map;
022    
023    import org.kuali.rice.core.mail.EmailContent;
024    import org.kuali.rice.kew.actionitem.ActionItem;
025    import org.kuali.rice.kew.doctype.bo.DocumentType;
026    import org.kuali.rice.kew.feedback.web.FeedbackForm;
027    import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
028    import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
029    import org.kuali.rice.kew.util.KEWConstants;
030    import org.kuali.rice.kim.bo.Person;
031    
032    
033    /**
034     * This is a class used to substitute for a StyleableEmailContentServiceImpl class
035     *
036     * @author Kuali Rice Team (rice.collab@kuali.org)
037     *
038     */
039    public class MockStyleableEmailContentServiceImpl extends StyleableEmailContentServiceImpl implements MockStyleableEmailContentService {
040    
041        private boolean wasAccessed = false;
042    
043        @Override
044        public EmailContent generateImmediateReminder(Person user, ActionItem actionItem, DocumentType documentType) {
045            wasAccessed = true;
046            return super.generateImmediateReminder(user, actionItem, documentType);
047        }
048    
049        @Override
050        public EmailContent generateDailyReminder(Person user, Collection<ActionItem> actionItems) {
051            wasAccessed = true;
052            return super.generateDailyReminder(user, actionItems);
053        }
054    
055        @Override
056        public EmailContent generateWeeklyReminder(Person user, Collection<ActionItem> actionItems) {
057            wasAccessed = true;
058            return super.generateWeeklyReminder(user, actionItems);
059        }
060    
061        @Override
062        public EmailContent generateFeedback(FeedbackForm form) {
063            wasAccessed = true;
064            return super.generateFeedback(form);
065        }
066    
067        /**
068         * This overridden method is used in case the action item has an null route header attached
069         *
070         * @see org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl#getRouteHeader(org.kuali.rice.kew.actionitem.ActionItem)
071         */
072        @Override
073        public DocumentRouteHeaderValue getRouteHeader(ActionItem actionItem) {
074            DocumentRouteHeaderValue routeHeader = null;
075            if (actionItem.getDocumentId() != null) {
076                routeHeader = super.getRouteHeader(actionItem);
077            }
078            if (routeHeader == null) {
079                    routeHeader = new DocumentRouteHeaderValue();
080                    routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_ENROUTE_CD);
081                    routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
082            }
083            return routeHeader;
084        }
085    
086        @Override
087        public Map<String,DocumentRouteHeaderValue> getRouteHeaders(Collection<ActionItem> actionItems) {
088            Map<String,DocumentRouteHeaderValue> routeHeaders = super.getRouteHeaders(actionItems);
089            DocumentRouteHeaderValue routeHeader = null;
090            for (ActionItem actionItem : actionItems) {
091                    if (routeHeaders.get(actionItem.getDocumentId()) == null) {
092                            routeHeader = new DocumentRouteHeaderValue();
093                    routeHeader.setDocRouteStatus(KEWConstants.ROUTE_HEADER_ENROUTE_CD);
094                    routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
095                    routeHeaders.put(actionItem.getDocumentId(), routeHeader);
096                    }
097            }
098            return routeHeaders;
099        }
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    }