View Javadoc

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  public class HelpAction extends KewKualiAction {
48      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          HelpForm helpForm = (HelpForm) form;
55          HelpEntry helpEntry = helpForm.getHelpEntry();
56          getHelpService().save(helpEntry);
57          GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, "helpentry.saved");
58          return mapping.findForward("summary");
59      }
60  
61      public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
62      	HelpForm helpForm=(HelpForm)form;
63      	HelpEntry helpEntry=helpForm.getHelpEntry();
64      	LOG.info(helpEntry.getHelpName());
65      	getHelpService().delete(helpEntry);
66          helpForm.setShowDelete("no");
67          GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, "helpentry.deleted");
68      	return mapping.findForward("delete");
69      }
70  
71      public ActionForward getSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
72      	LOG.debug("getSearch");
73          HelpForm helpForm = (HelpForm) form;
74          // TODO hook up KIM permissions to this
75          helpForm.setIsAdmin(false);
76         	return mapping.findForward("getSearch");
77      }
78  
79      public ActionForward search (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
80          HelpForm helpForm = (HelpForm) form;
81          HelpEntry helpEntry = helpForm.getHelpEntry();
82          if(helpForm.getHelpId() != null && !StringUtils.isNumeric(helpForm.getHelpId())){
83              GlobalVariables.getMessageMap().putError(HELP_ID_KEY, ID_INVALID);
84          } else {
85              if (helpForm.getHelpId() != null) {
86                  helpEntry.setHelpId(helpForm.getHelpId());
87              }
88          }
89  
90          List searchResults = getHelpService().search(helpEntry);
91  
92          if(searchResults != null && searchResults.size() > 0){
93              request.setAttribute("reqSearchResults", searchResults);
94          }
95          // TODO hook up KIM permissions to this
96          helpForm.setIsAdmin(false);
97  
98          return mapping.findForward("getSearch");
99      }
100 
101     public ActionForward clearSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
102         HelpForm helpForm = (HelpForm) form;
103         helpForm.getHelpEntry().setHelpId(null);
104         helpForm.getHelpEntry().setHelpName(null);
105         helpForm.getHelpEntry().setHelpText(null);
106         request.setAttribute("reqSearchResults", null);
107         // TODO hook up KIM permissions to this
108         helpForm.setIsAdmin(false);
109         return mapping.findForward("getSearch");
110     }
111 
112     public ActionForward report(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
113         HelpForm helpForm = (HelpForm) form;
114         helpForm.setHelpEntry(getHelpService().findById(request.getParameter("helpId")));
115         return mapping.findForward("report");
116     }
117 
118     public ActionForward showEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
119         HelpForm helpForm = (HelpForm) form;
120         if(helpForm.getHelpEntry().getHelpId() == null){
121             String helpId = request.getParameter("helpId");
122             helpForm.setHelpEntry(getHelpService().findById(helpId));
123         }
124         return mapping.findForward("basic");
125     }
126 
127     public ActionForward showDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
128     	HelpForm helpForm=(HelpForm)form;
129     	if(helpForm.getHelpEntry().getHelpId()==null){
130     		String helpId=request.getParameter("helpId");
131     		helpForm.setHelpEntry(getHelpService().findById(helpId));
132     	}
133         // TOOD hook up KIM permissions to this
134         helpForm.setIsAdmin(false);
135     	return mapping.findForward("delete");
136     }
137 
138     private HelpService getHelpService(){
139         return  (HelpService) KEWServiceLocator.getService(KEWServiceLocator.HELP_SERVICE);
140     }
141 
142     public ActionForward getHelpEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
143         HelpForm helpForm = (HelpForm) form;
144         String helpKey = request.getParameter("helpKey");
145         helpForm.setHelpEntry(getHelpService().findByKey(helpKey));
146         helpForm.setShowEdit(KEWConstants.NO_LABEL);
147         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         HelpForm helpForm = (HelpForm) form;
155         HelpEntry helpEntry = helpForm.getHelpEntry();
156         List searchResults = getHelpService().search(helpEntry);
157         if(searchResults == null) {
158         	searchResults = new ArrayList();
159         }
160         //ExportDataSet dataSet = new ExportDataSet();
161         KewExportDataSet dataSet = new KewExportDataSet();
162         dataSet.getHelp().addAll(searchResults);
163         request.getSession().setAttribute(ExportServlet.EXPORT_DATA_SET_KEY, dataSet);
164         return new ActionForward(ExportServlet.generateExportPath(request, dataSet.createExportDataSet()), true);
165     }
166 
167 }