001/**
002 * Copyright 2005-2011 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 */
016package mocks;
017
018import java.sql.Timestamp;
019import java.util.Collection;
020import java.util.Date;
021import java.util.Map;
022
023import org.kuali.rice.core.api.mail.EmailContent;
024import org.kuali.rice.kew.api.action.ActionItem;
025import org.kuali.rice.kew.doctype.bo.DocumentType;
026import org.kuali.rice.kew.feedback.web.FeedbackForm;
027import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
028import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
029import org.kuali.rice.kew.api.KewApiConstants;
030import org.kuali.rice.kim.api.identity.Person;
031
032/**
033 * This is a class used to substitute for a StyleableEmailContentServiceImpl class
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 *
037 */
038public class MockStyleableEmailContentServiceImpl extends StyleableEmailContentServiceImpl implements MockStyleableEmailContentService {
039
040    private boolean wasAccessed = false;
041
042    @Override
043    public EmailContent generateImmediateReminder(Person user, ActionItem actionItem, DocumentType documentType) {
044        wasAccessed = true;
045        return super.generateImmediateReminder(user, actionItem, documentType);
046    }
047
048    @Override
049    public EmailContent generateDailyReminder(Person user, Collection<ActionItem> actionItems) {
050        wasAccessed = true;
051        return super.generateDailyReminder(user, actionItems);
052    }
053
054    @Override
055    public EmailContent generateWeeklyReminder(Person user, Collection<ActionItem> actionItems) {
056        wasAccessed = true;
057        return super.generateWeeklyReminder(user, actionItems);
058    }
059
060    @Override
061    public EmailContent generateFeedback(FeedbackForm form) {
062        wasAccessed = true;
063        return super.generateFeedback(form);
064    }
065
066    /**
067     * This overridden method is used in case the action item has an null route header attached
068     *
069     * @see org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl#getRouteHeader(org.kuali.rice.kew.actionitem.ActionItem)
070     */
071    @Override
072    public DocumentRouteHeaderValue getRouteHeader(ActionItem actionItem) {
073        DocumentRouteHeaderValue routeHeader = null;
074        if (actionItem.getDocumentId() != null) {
075            routeHeader = super.getRouteHeader(actionItem);
076        }
077        if (routeHeader == null) {
078                routeHeader = new DocumentRouteHeaderValue();
079                routeHeader.setDocRouteStatus(KewApiConstants.ROUTE_HEADER_ENROUTE_CD);
080                routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
081        }
082        return routeHeader;
083    }
084
085    @Override
086    public Map<String,DocumentRouteHeaderValue> getRouteHeaders(Collection<ActionItem> actionItems) {
087        Map<String,DocumentRouteHeaderValue> routeHeaders = super.getRouteHeaders(actionItems);
088        DocumentRouteHeaderValue routeHeader = null;
089        for (ActionItem actionItem : actionItems) {
090                if (routeHeaders.get(actionItem.getDocumentId()) == null) {
091                        routeHeader = new DocumentRouteHeaderValue();
092                routeHeader.setDocRouteStatus(KewApiConstants.ROUTE_HEADER_ENROUTE_CD);
093                routeHeader.setCreateDate(new Timestamp(new Date().getTime()));
094                routeHeaders.put(actionItem.getDocumentId(), routeHeader);
095                }
096        }
097        return routeHeaders;
098    }
099    
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}