|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.krad.web.struts.form;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.util.HashMap;  | 
  |  19 |     | 
   import java.util.Map;  | 
  |  20 |     | 
     | 
  |  21 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  22 |     | 
     | 
  |  23 |     | 
   import org.apache.commons.lang.StringUtils;  | 
  |  24 |     | 
   import org.apache.log4j.Logger;  | 
  |  25 |     | 
   import org.kuali.rice.core.api.CoreApiServiceLocator;  | 
  |  26 |     | 
   import org.kuali.rice.kim.util.KimConstants;  | 
  |  27 |     | 
   import org.kuali.rice.krad.document.TransactionalDocument;  | 
  |  28 |     | 
   import org.kuali.rice.krad.service.DataDictionaryService;  | 
  |  29 |     | 
   import org.kuali.rice.krad.service.KRADServiceLocatorWeb;  | 
  |  30 |     | 
   import org.kuali.rice.krad.util.KRADConstants;  | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
     | 
  |  35 |     | 
     | 
  |  36 |     | 
   public class KualiTransactionalDocumentFormBase extends KualiDocumentFormBase { | 
  |  37 |    0 |            private static final Logger LOG = Logger.getLogger(KualiTransactionalDocumentFormBase.class);  | 
  |  38 |     | 
         | 
  |  39 |     | 
     | 
  |  40 |     | 
     | 
  |  41 |     | 
           private static final long serialVersionUID = 6463383454050206811L;  | 
  |  42 |     | 
           @SuppressWarnings("unchecked") | 
  |  43 |     | 
           protected Map forcedReadOnlyFields;  | 
  |  44 |     | 
     | 
  |  45 |     | 
         | 
  |  46 |     | 
     | 
  |  47 |     | 
     | 
  |  48 |     | 
       @SuppressWarnings("unchecked") | 
  |  49 |     | 
           public KualiTransactionalDocumentFormBase() { | 
  |  50 |    0 |            super();  | 
  |  51 |     | 
     | 
  |  52 |     | 
             | 
  |  53 |    0 |            forcedReadOnlyFields = new HashMap();  | 
  |  54 |    0 |        }  | 
  |  55 |     | 
     | 
  |  56 |     | 
         | 
  |  57 |     | 
     | 
  |  58 |     | 
     | 
  |  59 |     | 
       @SuppressWarnings("unchecked") | 
  |  60 |     | 
           @Override  | 
  |  61 |     | 
           public void populate(HttpServletRequest request) { | 
  |  62 |    0 |                    super.populate(request);  | 
  |  63 |    0 |                    populationSpecialEmptyFields (request);  | 
  |  64 |    0 |            }  | 
  |  65 |     | 
     | 
  |  66 |     | 
             | 
  |  67 |     | 
     | 
  |  68 |     | 
     | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |     | 
       public TransactionalDocument getTransactionalDocument() { | 
  |  72 |    0 |            return (TransactionalDocument) getDocument();  | 
  |  73 |     | 
       }  | 
  |  74 |     | 
         | 
  |  75 |     | 
     | 
  |  76 |     | 
         | 
  |  77 |     | 
     | 
  |  78 |     | 
     | 
  |  79 |     | 
     | 
  |  80 |     | 
     | 
  |  81 |     | 
       protected String discoverDocumentTypeName() { | 
  |  82 |    0 |            return ((DataDictionaryService) KRADServiceLocatorWeb.getDataDictionaryService()).getDataDictionary().getDocumentEntry(getDocument().getClass().getName()).getDocumentTypeName();  | 
  |  83 |     | 
       }  | 
  |  84 |     | 
     | 
  |  85 |     | 
         | 
  |  86 |     | 
     | 
  |  87 |     | 
     | 
  |  88 |     | 
     | 
  |  89 |     | 
     | 
  |  90 |     | 
     | 
  |  91 |     | 
     | 
  |  92 |     | 
       protected static String formatReversalDate(java.sql.Date reversalDate) { | 
  |  93 |    0 |            if (reversalDate == null) { | 
  |  94 |    0 |                return "";  | 
  |  95 |     | 
           }  | 
  |  96 |     | 
             | 
  |  97 |    0 |            return CoreApiServiceLocator.getDateTimeService().toString(reversalDate, "MMM d, yyyy");  | 
  |  98 |     | 
       }  | 
  |  99 |     | 
     | 
  |  100 |     | 
         | 
  |  101 |     | 
     | 
  |  102 |     | 
     | 
  |  103 |     | 
     | 
  |  104 |     | 
     | 
  |  105 |     | 
       @SuppressWarnings("unchecked") | 
  |  106 |     | 
           public Map getForcedReadOnlyFields() { | 
  |  107 |    0 |            return forcedReadOnlyFields;  | 
  |  108 |     | 
       }  | 
  |  109 |     | 
     | 
  |  110 |     | 
         | 
  |  111 |     | 
     | 
  |  112 |     | 
     | 
  |  113 |     | 
     | 
  |  114 |     | 
     | 
  |  115 |     | 
       @SuppressWarnings("unchecked") | 
  |  116 |     | 
           public void setForcedReadOnlyFields(Map forcedReadOnlyFields) { | 
  |  117 |    0 |            this.forcedReadOnlyFields = forcedReadOnlyFields;  | 
  |  118 |    0 |        }  | 
  |  119 |     | 
         | 
  |  120 |     | 
         | 
  |  121 |     | 
     | 
  |  122 |     | 
     | 
  |  123 |     | 
     | 
  |  124 |     | 
     | 
  |  125 |     | 
     | 
  |  126 |     | 
       protected void populateFalseCheckboxes(HttpServletRequest request) { | 
  |  127 |    0 |                Map<String, String[]> parameterMap = request.getParameterMap();  | 
  |  128 |    0 |                if (parameterMap.get("checkboxToReset") != null) { | 
  |  129 |    0 |                        final String[] checkboxesToReset = request.getParameterValues("checkboxToReset"); | 
  |  130 |    0 |                if(checkboxesToReset != null && checkboxesToReset.length > 0) { | 
  |  131 |    0 |                    for (int i = 0; i < checkboxesToReset.length; i++) { | 
  |  132 |    0 |                        String propertyName = (String) checkboxesToReset[i];  | 
  |  133 |    0 |                        if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) == null ) { | 
  |  134 |    0 |                                populateForProperty(propertyName, KimConstants.KIM_ATTRIBUTE_BOOLEAN_FALSE_STR_VALUE_DISPLAY, parameterMap);  | 
  |  135 |     | 
                       }    | 
  |  136 |    0 |                        else if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) != null && parameterMap.get(propertyName).length >= 1 && parameterMap.get(propertyName)[0].equalsIgnoreCase("on") ) { | 
  |  137 |    0 |                                populateForProperty(propertyName, KimConstants.KIM_ATTRIBUTE_BOOLEAN_TRUE_STR_VALUE_DISPLAY, parameterMap);   | 
  |  138 |     | 
                       }  | 
  |  139 |     | 
                   }  | 
  |  140 |     | 
               }  | 
  |  141 |     | 
               }  | 
  |  142 |    0 |        }  | 
  |  143 |     | 
         | 
  |  144 |     | 
         | 
  |  145 |     | 
     | 
  |  146 |     | 
     | 
  |  147 |     | 
     | 
  |  148 |     | 
     | 
  |  149 |     | 
     | 
  |  150 |     | 
       protected void populateEmptyMultiSelect(HttpServletRequest request) { | 
  |  151 |    0 |                Map<String, String[]> parameterMap = request.getParameterMap();  | 
  |  152 |    0 |                if (parameterMap.get("multiSelectToReset") != null) { | 
  |  153 |    0 |                        final String[] multiSelectToReset = request.getParameterValues("multiSelectToReset"); | 
  |  154 |    0 |                if(multiSelectToReset != null && multiSelectToReset.length > 0) { | 
  |  155 |    0 |                    for (int i = 0; i < multiSelectToReset.length; i++) { | 
  |  156 |    0 |                        String propertyName = (String) multiSelectToReset[i];  | 
  |  157 |    0 |                        if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) == null ) { | 
  |  158 |    0 |                                populateForProperty(propertyName, "", parameterMap);  | 
  |  159 |     | 
                       }    | 
  |  160 |    0 |                        else if ( !StringUtils.isBlank(propertyName) && parameterMap.get(propertyName) != null && parameterMap.get(propertyName).length >= 1 && parameterMap.get(propertyName)[0].equalsIgnoreCase("on") ) { | 
  |  161 |    0 |                                populateForProperty(propertyName, request.getParameter(propertyName), parameterMap);   | 
  |  162 |     | 
                       }  | 
  |  163 |     | 
                   }  | 
  |  164 |     | 
               }  | 
  |  165 |     | 
               }  | 
  |  166 |    0 |        }  | 
  |  167 |     | 
         | 
  |  168 |     | 
       protected void populationSpecialEmptyFields (HttpServletRequest request) { | 
  |  169 |    0 |                populateFalseCheckboxes(request);  | 
  |  170 |    0 |                    populateEmptyMultiSelect(request);  | 
  |  171 |    0 |        }  | 
  |  172 |     | 
     | 
  |  173 |     | 
       @SuppressWarnings("unchecked") | 
  |  174 |     | 
           protected TransactionalDocument instantiateTransactionalDocumentByDocumentTypeName( String documentTypeName ) { | 
  |  175 |    0 |                Class<TransactionalDocument> transDocClass = KRADServiceLocatorWeb.getTransactionalDocumentDictionaryService().getDocumentClassByName(documentTypeName);  | 
  |  176 |    0 |                if ( transDocClass != null ) { | 
  |  177 |     | 
                       try { | 
  |  178 |    0 |                                return transDocClass.newInstance();  | 
  |  179 |    0 |                        } catch (Exception ex) { | 
  |  180 |    0 |                                    LOG.error( "Unable to instantiate transDocClass: " + transDocClass, ex);  | 
  |  181 |    0 |                            }  | 
  |  182 |     | 
               } else { | 
  |  183 |    0 |                        LOG.error( "Unable to retrieve transactional document class for type: " + documentTypeName);  | 
  |  184 |     | 
               }  | 
  |  185 |    0 |                return null;  | 
  |  186 |     | 
       }  | 
  |  187 |     | 
     | 
  |  188 |     | 
         | 
  |  189 |     | 
     | 
  |  190 |     | 
     | 
  |  191 |     | 
     | 
  |  192 |     | 
     | 
  |  193 |     | 
           @Override  | 
  |  194 |     | 
           public boolean shouldMethodToCallParameterBeUsed(  | 
  |  195 |     | 
                           String methodToCallParameterName,  | 
  |  196 |     | 
                           String methodToCallParameterValue, HttpServletRequest request) { | 
  |  197 |    0 |                    if (methodToCallParameterName.startsWith(KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.POST_TEXT_AREA_TO_PARENT)) { | 
  |  198 |    0 |                            return true;  | 
  |  199 |     | 
                   }  | 
  |  200 |    0 |                    return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);   | 
  |  201 |     | 
           }  | 
  |  202 |     | 
   }  |