001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.applicationconstants.web;
018:
019: import java.io.IOException;
020:
021: import javax.servlet.ServletException;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.apache.struts.action.ActionMessages;
029:
030: import edu.iu.uis.eden.KEWServiceLocator;
031: import edu.iu.uis.eden.WorkflowServiceErrorException;
032: import edu.iu.uis.eden.applicationconstants.ApplicationConstant;
033: import edu.iu.uis.eden.applicationconstants.ApplicationConstantsService;
034: import edu.iu.uis.eden.web.WorkflowAction;
035:
036: /**
037: * Stuts Action for interaction with application constants.
038: *
039: * @author rkirkend
040: * @author ewestfal
041: */
042: public class ApplicationConstantsAction extends WorkflowAction {
043:
044: public ActionForward start(ActionMapping mapping, ActionForm form,
045: HttpServletRequest request, HttpServletResponse response)
046: throws IOException, ServletException {
047: return mapping.findForward("start");
048: }
049:
050: public ActionForward cancel(ActionMapping mapping, ActionForm form,
051: HttpServletRequest request, HttpServletResponse response)
052: throws IOException, ServletException {
053: return mapping.findForward("restart");
054: }
055:
056: public ActionForward clear(ActionMapping mapping, ActionForm form,
057: HttpServletRequest request, HttpServletResponse response)
058: throws IOException, ServletException {
059: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
060: clearFields(applicationConstantsForm);
061: return mapping.findForward("restart");
062: }
063:
064: public ActionForward create(ActionMapping mapping, ActionForm form,
065: HttpServletRequest request, HttpServletResponse response)
066: throws IOException, ServletException {
067: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
068: try {
069: getService().save(applicationConstantsForm.getConstant());
070: } catch (WorkflowServiceErrorException e) {
071: applicationConstantsForm.setMethodToCall("create");
072: throw e;
073: }
074: return mapping.findForward("restart");
075: }
076:
077: public ActionForward edit(ActionMapping mapping, ActionForm form,
078: HttpServletRequest request, HttpServletResponse response)
079: throws IOException, ServletException {
080: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
081: ApplicationConstant constant = getService().findByName(
082: request.getParameter("applicationConstantName"));
083: applicationConstantsForm.setApplicationConstantName(constant
084: .getApplicationConstantName());
085: applicationConstantsForm.setApplicationConstantValue(constant
086: .getApplicationConstantValue());
087: return mapping.findForward("edit");
088: }
089:
090: public ActionForward save(ActionMapping mapping, ActionForm form,
091: HttpServletRequest request, HttpServletResponse response)
092: throws IOException, ServletException {
093: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
094: ApplicationConstant constant = getService().findByName(
095: applicationConstantsForm.getConstant()
096: .getApplicationConstantName());
097: constant.setApplicationConstantValue(applicationConstantsForm
098: .getConstant().getApplicationConstantValue());
099:
100: try {
101: getService().save(constant);
102: } catch (WorkflowServiceErrorException e) {
103: applicationConstantsForm.setMethodToCall("edit");
104: throw e;
105: }
106: return mapping.findForward("restart");
107: }
108:
109: public ActionForward delete(ActionMapping mapping, ActionForm form,
110: HttpServletRequest request, HttpServletResponse response)
111: throws IOException, ServletException {
112: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
113: getService().delete(applicationConstantsForm.getConstant());
114: return mapping.findForward("restart");
115: }
116:
117: public ActionForward confirmDelete(ActionMapping mapping,
118: ActionForm form, HttpServletRequest request,
119: HttpServletResponse response) throws IOException,
120: ServletException {
121: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
122: ApplicationConstant constant = getService().findByName(
123: request.getParameter("applicationConstantName"));
124: applicationConstantsForm.setConstant(constant);
125: return mapping.findForward("confirmDelete");
126: }
127:
128: public ActionMessages establishRequiredState(
129: HttpServletRequest request, ActionForm form)
130: throws Exception {
131: ApplicationConstantsService service = (ApplicationConstantsService) KEWServiceLocator
132: .getService(KEWServiceLocator.APPLICATION_CONSTANTS_SRV);
133: ApplicationConstantsForm applicationConstantsForm = (ApplicationConstantsForm) form;
134: applicationConstantsForm.setApplicationConstants(service
135: .findAll());
136: return null;
137: }
138:
139: private ApplicationConstantsService getService() {
140: return (ApplicationConstantsService) KEWServiceLocator
141: .getService(KEWServiceLocator.APPLICATION_CONSTANTS_SRV);
142: }
143:
144: public ActionMessages establishFinalState(
145: HttpServletRequest request, ActionForm form) {
146: return null;
147: }
148:
149: private void clearFields(
150: ApplicationConstantsForm applicationConstantsForm) {
151: applicationConstantsForm.getConstant()
152: .setApplicationConstantName(null);
153: applicationConstantsForm.getConstant()
154: .setApplicationConstantValue(null);
155: }
156: }
|