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.util.RiceConstants;
 30  
 import org.kuali.rice.kew.export.ExportDataSet;
 31  
 import org.kuali.rice.kew.export.web.ExportServlet;
 32  
 import org.kuali.rice.kew.help.HelpEntry;
 33  
 import org.kuali.rice.kew.help.service.HelpService;
 34  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 35  
 import org.kuali.rice.kew.util.KEWConstants;
 36  
 import org.kuali.rice.kew.web.KewKualiAction;
 37  
 import org.kuali.rice.kns.exception.ValidationException;
 38  
 import org.kuali.rice.kns.util.GlobalVariables;
 39  
 import org.kuali.rice.kns.util.KNSConstants;
 40  
 
 41  
 
 42  
 /**
 43  
  * Struts action for interfacing with the Help system.
 44  
  *
 45  
  * @see HelpService
 46  
  * @see HelpEntry
 47  
  *
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  */
 50  0
 public class HelpAction extends KewKualiAction {
 51  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HelpAction.class);
 52  
     private static final String HELP_ID_KEY = "helpId";
 53  
     private static final String ID_INVALID = "helpentry.id.invalid";
 54  
 
 55  
 
 56  
     public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 57  0
         HelpForm helpForm = (HelpForm) form;
 58  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 59  0
         getHelpService().save(helpEntry);
 60  0
         GlobalVariables.getMessageMap().putInfo(KNSConstants.GLOBAL_MESSAGES, "helpentry.saved");
 61  0
         return mapping.findForward("summary");
 62  
     }
 63  
 
 64  
     public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
 65  0
             HelpForm helpForm=(HelpForm)form;
 66  0
             HelpEntry helpEntry=helpForm.getHelpEntry();
 67  0
             LOG.info(helpEntry.getHelpName());
 68  0
             getHelpService().delete(helpEntry);
 69  0
         helpForm.setShowDelete("no");
 70  0
         GlobalVariables.getMessageMap().putInfo(KNSConstants.GLOBAL_MESSAGES, "helpentry.deleted");
 71  0
             return mapping.findForward("delete");
 72  
     }
 73  
 
 74  
     public ActionForward getSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 75  0
             LOG.debug("getSearch");
 76  0
         HelpForm helpForm = (HelpForm) form;
 77  
         // TODO hook up KIM permissions to this
 78  0
         helpForm.setIsAdmin(false);
 79  0
                return mapping.findForward("getSearch");
 80  
     }
 81  
 
 82  
     public ActionForward search (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 83  0
         HelpForm helpForm = (HelpForm) form;
 84  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 85  0
         if(helpForm.getHelpId() != null && !StringUtils.isNumeric(helpForm.getHelpId())){
 86  0
             GlobalVariables.getMessageMap().putError(HELP_ID_KEY, ID_INVALID);
 87  
         } else {
 88  0
             if (helpForm.getHelpId() != null) {
 89  0
                 helpEntry.setHelpId(new Long(helpForm.getHelpId()));
 90  
             }
 91  
         }
 92  
 
 93  0
         List searchResults = getHelpService().search(helpEntry);
 94  
 
 95  0
         if(searchResults != null && searchResults.size() > 0){
 96  0
             request.setAttribute("reqSearchResults", searchResults);
 97  
         }
 98  
         // TODO hook up KIM permissions to this
 99  0
         helpForm.setIsAdmin(false);
 100  
 
 101  0
         return mapping.findForward("getSearch");
 102  
     }
 103  
 
 104  
     public ActionForward clearSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 105  0
         HelpForm helpForm = (HelpForm) form;
 106  0
         helpForm.getHelpEntry().setHelpId(null);
 107  0
         helpForm.getHelpEntry().setHelpName(null);
 108  0
         helpForm.getHelpEntry().setHelpText(null);
 109  0
         request.setAttribute("reqSearchResults", null);
 110  
         // TODO hook up KIM permissions to this
 111  0
         helpForm.setIsAdmin(false);
 112  0
         return mapping.findForward("getSearch");
 113  
     }
 114  
 
 115  
     public ActionForward report(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 116  0
         HelpForm helpForm = (HelpForm) form;
 117  0
         helpForm.setHelpEntry(getHelpService().findById(new Long(request.getParameter("helpId"))));
 118  0
         return mapping.findForward("report");
 119  
     }
 120  
 
 121  
     public ActionForward showEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 122  0
         HelpForm helpForm = (HelpForm) form;
 123  0
         if(helpForm.getHelpEntry().getHelpId() == null){
 124  0
             Long helpId = new Long(request.getParameter("helpId"));
 125  0
             helpForm.setHelpEntry(getHelpService().findById(helpId));
 126  
         }
 127  0
         return mapping.findForward("basic");
 128  
     }
 129  
 
 130  
     public ActionForward showDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
 131  0
             HelpForm helpForm=(HelpForm)form;
 132  0
             if(helpForm.getHelpEntry().getHelpId()==null){
 133  0
                     Long helpId=new Long(request.getParameter("helpId"));
 134  0
                     helpForm.setHelpEntry(getHelpService().findById(helpId));
 135  
             }
 136  
         // TOOD hook up KIM permissions to this
 137  0
         helpForm.setIsAdmin(false);
 138  0
             return mapping.findForward("delete");
 139  
     }
 140  
 
 141  
     private HelpService getHelpService(){
 142  0
         return  (HelpService) KEWServiceLocator.getService(KEWServiceLocator.HELP_SERVICE);
 143  
     }
 144  
 
 145  
     public ActionForward getHelpEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 146  0
         HelpForm helpForm = (HelpForm) form;
 147  0
         String helpKey = request.getParameter("helpKey");
 148  0
         helpForm.setHelpEntry(getHelpService().findByKey(helpKey));
 149  0
         helpForm.setShowEdit(KEWConstants.NO_LABEL);
 150  0
         return mapping.findForward("popHelp");
 151  
     }
 152  
 
 153  
     /**
 154  
      * TODO implement the help search as a lookupable, rendering this code redundant
 155  
      */
 156  
     public ActionForward export(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 157  0
         HelpForm helpForm = (HelpForm) form;
 158  0
         HelpEntry helpEntry = helpForm.getHelpEntry();
 159  0
         List searchResults = getHelpService().search(helpEntry);
 160  0
         if(searchResults == null) {
 161  0
                 searchResults = new ArrayList();
 162  
         }
 163  0
         ExportDataSet dataSet = new ExportDataSet();
 164  0
         dataSet.getHelp().addAll(searchResults);
 165  0
         request.getSession().setAttribute(ExportServlet.EXPORT_DATA_SET_KEY, dataSet);
 166  0
         return new ActionForward(ExportServlet.generateExportPath(request, dataSet), true);
 167  
     }
 168  
 
 169  
 }