001    /**
002     * Copyright 2005-2013 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 org.kuali.rice.kew.quicklinks.web;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.http.HttpServletResponse;
023    
024    import org.apache.struts.action.ActionForm;
025    import org.apache.struts.action.ActionForward;
026    import org.apache.struts.action.ActionMapping;
027    import org.kuali.rice.kew.quicklinks.service.QuickLinksService;
028    import org.kuali.rice.kew.service.KEWServiceLocator;
029    import org.kuali.rice.kew.web.KewKualiAction;
030    import org.kuali.rice.krad.UserSession;
031    import org.kuali.rice.krad.util.GlobalVariables;
032    
033    
034    /**
035     * A Struts Action for interfacing with the Quick Links system
036     *
037     * @author Kuali Rice Team (rice.collab@kuali.org)
038     */
039    public class QuickLinksAction extends KewKualiAction {
040    
041        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(QuickLinksAction.class);
042    
043        @Override
044        public ActionForward execute(ActionMapping mapping, ActionForm form,
045                HttpServletRequest request, HttpServletResponse response)
046                throws Exception {
047            initForm(request, form);
048            return super.execute(mapping, form, request, response);
049        }
050    
051        public void initForm(HttpServletRequest request, ActionForm form) throws Exception {
052            QuickLinksForm quickLinksForm = (QuickLinksForm)form;
053            String principalId = getUserSession().getPrincipalId();
054            LOG.debug("getting Action List Stats");
055            quickLinksForm.setActionListStats(getQuickLinksService().getActionListStats(principalId));
056            LOG.debug("finished getting Action List Stats");
057    
058            LOG.debug("getting Initiated Document Types");
059            quickLinksForm.setInitiatedDocumentTypes(getQuickLinksService().getInitiatedDocumentTypesList(principalId));
060            LOG.debug("finished getting Initiated Document Types");
061    
062            LOG.debug("getting Named Searches");
063            List namedSearches = new ArrayList();
064            namedSearches.addAll(getQuickLinksService().getNamedSearches(principalId));
065            quickLinksForm.setNamedSearches(namedSearches);
066            request.setAttribute("namedSearches",namedSearches);
067            LOG.debug("finished getting Named Searches");
068    
069            LOG.debug("getting Recent Searches");
070            quickLinksForm.setRecentSearches(getQuickLinksService().getRecentSearches(principalId));
071            LOG.debug("finished getting Recent Searches");
072    
073            LOG.debug("getting Watched Documents");
074            quickLinksForm.setWatchedDocuments(getQuickLinksService().getWatchedDocuments(principalId));
075            LOG.debug("finished getting Watched Documents");
076        }
077    
078    
079    
080        private QuickLinksService getQuickLinksService() {
081            return ((QuickLinksService)KEWServiceLocator.getService(KEWServiceLocator.QUICK_LINKS_SERVICE));
082        }
083        private static UserSession getUserSession() {
084            return GlobalVariables.getUserSession();
085        }
086    
087    }