| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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.api.impex.ExportDataSet; |
| 30 | |
import org.kuali.rice.core.web.impex.ExportServlet; |
| 31 | |
import org.kuali.rice.kew.export.KewExportDataSet; |
| 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.util.GlobalVariables; |
| 38 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public class HelpAction extends KewKualiAction { |
| 50 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HelpAction.class); |
| 51 | |
private static final String HELP_ID_KEY = "helpId"; |
| 52 | |
private static final String ID_INVALID = "helpentry.id.invalid"; |
| 53 | |
|
| 54 | |
|
| 55 | |
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 56 | 0 | HelpForm helpForm = (HelpForm) form; |
| 57 | 0 | HelpEntry helpEntry = helpForm.getHelpEntry(); |
| 58 | 0 | getHelpService().save(helpEntry); |
| 59 | 0 | GlobalVariables.getMessageMap().putInfo(KNSConstants.GLOBAL_MESSAGES, "helpentry.saved"); |
| 60 | 0 | return mapping.findForward("summary"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ |
| 64 | 0 | HelpForm helpForm=(HelpForm)form; |
| 65 | 0 | HelpEntry helpEntry=helpForm.getHelpEntry(); |
| 66 | 0 | LOG.info(helpEntry.getHelpName()); |
| 67 | 0 | getHelpService().delete(helpEntry); |
| 68 | 0 | helpForm.setShowDelete("no"); |
| 69 | 0 | GlobalVariables.getMessageMap().putInfo(KNSConstants.GLOBAL_MESSAGES, "helpentry.deleted"); |
| 70 | 0 | return mapping.findForward("delete"); |
| 71 | |
} |
| 72 | |
|
| 73 | |
public ActionForward getSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 74 | 0 | LOG.debug("getSearch"); |
| 75 | 0 | HelpForm helpForm = (HelpForm) form; |
| 76 | |
|
| 77 | 0 | helpForm.setIsAdmin(false); |
| 78 | 0 | return mapping.findForward("getSearch"); |
| 79 | |
} |
| 80 | |
|
| 81 | |
public ActionForward search (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 82 | 0 | HelpForm helpForm = (HelpForm) form; |
| 83 | 0 | HelpEntry helpEntry = helpForm.getHelpEntry(); |
| 84 | 0 | if(helpForm.getHelpId() != null && !StringUtils.isNumeric(helpForm.getHelpId())){ |
| 85 | 0 | GlobalVariables.getMessageMap().putError(HELP_ID_KEY, ID_INVALID); |
| 86 | |
} else { |
| 87 | 0 | if (helpForm.getHelpId() != null) { |
| 88 | 0 | helpEntry.setHelpId(new Long(helpForm.getHelpId())); |
| 89 | |
} |
| 90 | |
} |
| 91 | |
|
| 92 | 0 | List searchResults = getHelpService().search(helpEntry); |
| 93 | |
|
| 94 | 0 | if(searchResults != null && searchResults.size() > 0){ |
| 95 | 0 | request.setAttribute("reqSearchResults", searchResults); |
| 96 | |
} |
| 97 | |
|
| 98 | 0 | helpForm.setIsAdmin(false); |
| 99 | |
|
| 100 | 0 | return mapping.findForward("getSearch"); |
| 101 | |
} |
| 102 | |
|
| 103 | |
public ActionForward clearSearch (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 104 | 0 | HelpForm helpForm = (HelpForm) form; |
| 105 | 0 | helpForm.getHelpEntry().setHelpId(null); |
| 106 | 0 | helpForm.getHelpEntry().setHelpName(null); |
| 107 | 0 | helpForm.getHelpEntry().setHelpText(null); |
| 108 | 0 | request.setAttribute("reqSearchResults", null); |
| 109 | |
|
| 110 | 0 | helpForm.setIsAdmin(false); |
| 111 | 0 | return mapping.findForward("getSearch"); |
| 112 | |
} |
| 113 | |
|
| 114 | |
public ActionForward report(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 115 | 0 | HelpForm helpForm = (HelpForm) form; |
| 116 | 0 | helpForm.setHelpEntry(getHelpService().findById(new Long(request.getParameter("helpId")))); |
| 117 | 0 | return mapping.findForward("report"); |
| 118 | |
} |
| 119 | |
|
| 120 | |
public ActionForward showEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 121 | 0 | HelpForm helpForm = (HelpForm) form; |
| 122 | 0 | if(helpForm.getHelpEntry().getHelpId() == null){ |
| 123 | 0 | Long helpId = new Long(request.getParameter("helpId")); |
| 124 | 0 | helpForm.setHelpEntry(getHelpService().findById(helpId)); |
| 125 | |
} |
| 126 | 0 | return mapping.findForward("basic"); |
| 127 | |
} |
| 128 | |
|
| 129 | |
public ActionForward showDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ |
| 130 | 0 | HelpForm helpForm=(HelpForm)form; |
| 131 | 0 | if(helpForm.getHelpEntry().getHelpId()==null){ |
| 132 | 0 | Long helpId=new Long(request.getParameter("helpId")); |
| 133 | 0 | helpForm.setHelpEntry(getHelpService().findById(helpId)); |
| 134 | |
} |
| 135 | |
|
| 136 | 0 | helpForm.setIsAdmin(false); |
| 137 | 0 | return mapping.findForward("delete"); |
| 138 | |
} |
| 139 | |
|
| 140 | |
private HelpService getHelpService(){ |
| 141 | 0 | return (HelpService) KEWServiceLocator.getService(KEWServiceLocator.HELP_SERVICE); |
| 142 | |
} |
| 143 | |
|
| 144 | |
public ActionForward getHelpEntry(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 145 | 0 | HelpForm helpForm = (HelpForm) form; |
| 146 | 0 | String helpKey = request.getParameter("helpKey"); |
| 147 | 0 | helpForm.setHelpEntry(getHelpService().findByKey(helpKey)); |
| 148 | 0 | helpForm.setShowEdit(KEWConstants.NO_LABEL); |
| 149 | 0 | return mapping.findForward("popHelp"); |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public ActionForward export(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 156 | 0 | HelpForm helpForm = (HelpForm) form; |
| 157 | 0 | HelpEntry helpEntry = helpForm.getHelpEntry(); |
| 158 | 0 | List searchResults = getHelpService().search(helpEntry); |
| 159 | 0 | if(searchResults == null) { |
| 160 | 0 | searchResults = new ArrayList(); |
| 161 | |
} |
| 162 | |
|
| 163 | 0 | KewExportDataSet dataSet = new KewExportDataSet(); |
| 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.createExportDataSet()), true); |
| 167 | |
} |
| 168 | |
|
| 169 | |
} |