Coverage Report - org.kuali.rice.kew.help.web.HelpAction
 
Classes in this File Line Coverage Branch Coverage Complexity
HelpAction
0%
0/65
0%
0/16
1.727
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.help.web;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.servlet.http.HttpServletRequest;
 23  
 import javax.servlet.http.HttpServletResponse;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.apache.struts.action.ActionForm;
 27  
 import org.apache.struts.action.ActionForward;
 28  
 import org.apache.struts.action.ActionMapping;
 29  
 import org.kuali.rice.core.web.impex.ExportServlet;
 30  
 import org.kuali.rice.kew.export.KewExportDataSet;
 31  
 import org.kuali.rice.kew.help.HelpEntry;
 32  
 import org.kuali.rice.kew.help.service.HelpService;
 33  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 34  
 import org.kuali.rice.kew.util.KEWConstants;
 35  
 import org.kuali.rice.kew.web.KewKualiAction;
 36  
 import org.kuali.rice.krad.util.GlobalVariables;
 37  
 import org.kuali.rice.krad.util.KRADConstants;
 38  
 
 39  
 /**
 40  
  * Struts action for interfacing with the Help system.
 41  
  *
 42  
  * @see HelpService
 43  
  * @see HelpEntry
 44  
  *
 45  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 46  
  */
 47  0
 public class HelpAction extends KewKualiAction {
 48  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HelpAction.class);
 49  
     private static final String HELP_ID_KEY = "helpId";
 50  
     private static final String ID_INVALID = "helpentry.id.invalid";
 51  
 
 52  
 
 53  
     public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 54  0
         HelpForm helpForm = (HelpForm) form;
 55  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 56  0
         getHelpService().save(helpEntry);
 57  0
         GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, "helpentry.saved");
 58  0
         return mapping.findForward("summary");
 59  
     }
 60  
 
 61  
     public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
 62  0
             HelpForm helpForm=(HelpForm)form;
 63  0
             HelpEntry helpEntry=helpForm.getHelpEntry();
 64  0
             LOG.info(helpEntry.getHelpName());
 65  0
             getHelpService().delete(helpEntry);
 66  0
         helpForm.setShowDelete("no");
 67  0
         GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, "helpentry.deleted");
 68  0
             return mapping.findForward("delete");
 69  
     }
 70  
 
 71  
     public ActionForward getSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 72  0
             LOG.debug("getSearch");
 73  0
         HelpForm helpForm = (HelpForm) form;
 74  
         // TODO hook up KIM permissions to this
 75  0
         helpForm.setIsAdmin(false);
 76  0
                return mapping.findForward("getSearch");
 77  
     }
 78  
 
 79  
     public ActionForward search (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 80  0
         HelpForm helpForm = (HelpForm) form;
 81  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 82  0
         if(helpForm.getHelpId() != null && !StringUtils.isNumeric(helpForm.getHelpId())){
 83  0
             GlobalVariables.getMessageMap().putError(HELP_ID_KEY, ID_INVALID);
 84  
         } else {
 85  0
             if (helpForm.getHelpId() != null) {
 86  0
                 helpEntry.setHelpId(helpForm.getHelpId());
 87  
             }
 88  
         }
 89  
 
 90  0
         List searchResults = getHelpService().search(helpEntry);
 91  
 
 92  0
         if(searchResults != null && searchResults.size() > 0){
 93  0
             request.setAttribute("reqSearchResults", searchResults);
 94  
         }
 95  
         // TODO hook up KIM permissions to this
 96  0
         helpForm.setIsAdmin(false);
 97  
 
 98  0
         return mapping.findForward("getSearch");
 99  
     }
 100  
 
 101  
     public ActionForward clearSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 102  0
         HelpForm helpForm = (HelpForm) form;
 103  0
         helpForm.getHelpEntry().setHelpId(null);
 104  0
         helpForm.getHelpEntry().setHelpName(null);
 105  0
         helpForm.getHelpEntry().setHelpText(null);
 106  0
         request.setAttribute("reqSearchResults", null);
 107  
         // TODO hook up KIM permissions to this
 108  0
         helpForm.setIsAdmin(false);
 109  0
         return mapping.findForward("getSearch");
 110  
     }
 111  
 
 112  
     public ActionForward report(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 113  0
         HelpForm helpForm = (HelpForm) form;
 114  0
         helpForm.setHelpEntry(getHelpService().findById(request.getParameter("helpId")));
 115  0
         return mapping.findForward("report");
 116  
     }
 117  
 
 118  
     public ActionForward showEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 119  0
         HelpForm helpForm = (HelpForm) form;
 120  0
         if(helpForm.getHelpEntry().getHelpId() == null){
 121  0
             String helpId = request.getParameter("helpId");
 122  0
             helpForm.setHelpEntry(getHelpService().findById(helpId));
 123  
         }
 124  0
         return mapping.findForward("basic");
 125  
     }
 126  
 
 127  
     public ActionForward showDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
 128  0
             HelpForm helpForm=(HelpForm)form;
 129  0
             if(helpForm.getHelpEntry().getHelpId()==null){
 130  0
                     String helpId=request.getParameter("helpId");
 131  0
                     helpForm.setHelpEntry(getHelpService().findById(helpId));
 132  
             }
 133  
         // TOOD hook up KIM permissions to this
 134  0
         helpForm.setIsAdmin(false);
 135  0
             return mapping.findForward("delete");
 136  
     }
 137  
 
 138  
     private HelpService getHelpService(){
 139  0
         return  (HelpService) KEWServiceLocator.getService(KEWServiceLocator.HELP_SERVICE);
 140  
     }
 141  
 
 142  
     public ActionForward getHelpEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 143  0
         HelpForm helpForm = (HelpForm) form;
 144  0
         String helpKey = request.getParameter("helpKey");
 145  0
         helpForm.setHelpEntry(getHelpService().findByKey(helpKey));
 146  0
         helpForm.setShowEdit(KEWConstants.NO_LABEL);
 147  0
         return mapping.findForward("popHelp");
 148  
     }
 149  
 
 150  
     /**
 151  
      * TODO implement the help search as a lookupable, rendering this code redundant
 152  
      */
 153  
     public ActionForward export(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 154  0
         HelpForm helpForm = (HelpForm) form;
 155  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 156  0
         List searchResults = getHelpService().search(helpEntry);
 157  0
         if(searchResults == null) {
 158  0
                 searchResults = new ArrayList();
 159  
         }
 160  
         //ExportDataSet dataSet = new ExportDataSet();
 161  0
         KewExportDataSet dataSet = new KewExportDataSet();
 162  0
         dataSet.getHelp().addAll(searchResults);
 163  0
         request.getSession().setAttribute(ExportServlet.EXPORT_DATA_SET_KEY, dataSet);
 164  0
         return new ActionForward(ExportServlet.generateExportPath(request, dataSet.createExportDataSet()), true);
 165  
     }
 166  
 
 167  
 }