View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.web.struts;
17  
18  import java.util.ArrayList;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.struts.action.ActionForm;
24  import org.apache.struts.action.ActionForward;
25  import org.apache.struts.action.ActionMapping;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.document.Correctable;
29  import org.kuali.ole.sys.service.impl.OleParameterConstants;
30  import org.kuali.rice.core.api.util.RiceConstants;
31  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32  import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
33  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
34  import org.kuali.rice.kns.web.ui.ExtraButton;
35  import org.kuali.rice.krad.document.Document;
36  import org.kuali.rice.krad.util.KRADConstants;
37  
38  /**
39   * This class...
40   */
41  public class FinancialSystemTransactionalDocumentActionBase extends KualiTransactionalDocumentActionBase {
42      public static final String MODULE_LOCKED_MESSAGE = "moduleLockedMessage";
43      public static final String MODULE_LOCKED_URL_SUFFIX = "/moduleLocked.do";
44  
45      /**
46       * This action method triggers a correct of the transactional document.
47       *
48       * @param mapping
49       * @param form
50       * @param request
51       * @param response
52       * @return ActionForward
53       * @throws Exception
54       * KRAD Conversion: Customizing the extra buttons on the form
55       */
56      public ActionForward correct(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
57          KualiTransactionalDocumentFormBase tmpForm = (KualiTransactionalDocumentFormBase) form;
58  
59          Document document = tmpForm.getDocument();
60  
61          ((Correctable) tmpForm.getTransactionalDocument()).toErrorCorrection();
62          tmpForm.setExtraButtons(new ArrayList<ExtraButton>());
63  
64          return mapping.findForward(RiceConstants.MAPPING_BASIC);
65      }
66  
67      @Override
68      /**
69       * KFSMI-4452
70       */
71      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
72  
73          ActionForward returnForward =  super.execute(mapping, form, request, response);
74          if( isDocumentLocked(mapping, form, request)) {
75              String message  = SpringContext.getBean(ParameterService.class).getParameterValueAsString(OLEConstants.CoreModuleNamespaces.OLE, OleParameterConstants.PARAMETER_ALL_DETAIL_TYPE, OLEConstants.DOCUMENT_LOCKOUT_DEFAULT_MESSAGE);
76              request.setAttribute(MODULE_LOCKED_MESSAGE, message);
77              returnForward = mapping.findForward(RiceConstants.MODULE_LOCKED_MAPPING);
78          }
79  
80          return returnForward;
81  
82      }
83  
84      /**
85       * KFSMI-4452
86       */
87      protected boolean isDocumentLocked(ActionMapping mapping , ActionForm form, HttpServletRequest request) {
88          KualiTransactionalDocumentFormBase tmpForm = (KualiTransactionalDocumentFormBase) form;
89          Document document = tmpForm.getDocument();
90  
91          boolean exists = SpringContext.getBean(ParameterService.class).parameterExists(document.getClass(),OLEConstants.DOCUMENT_LOCKOUT_PARM_NM );
92          if(exists) {
93              boolean documentLockedOut = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(document.getClass(),OLEConstants.DOCUMENT_LOCKOUT_PARM_NM );
94              if(documentLockedOut) {
95                  return tmpForm.getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT);
96              }
97          }
98  
99          return false;
100     }
101 }
102