| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kns.web.struts.action; |
| 18 | |
|
| 19 | |
import org.apache.commons.beanutils.PropertyUtils; |
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException; |
| 22 | |
import org.apache.struts.action.ActionForm; |
| 23 | |
import org.apache.struts.action.ActionForward; |
| 24 | |
import org.apache.struts.action.ActionMapping; |
| 25 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 26 | |
import org.kuali.rice.core.api.encryption.EncryptionService; |
| 27 | |
import org.kuali.rice.core.api.util.ClassLoaderUtils; |
| 28 | |
import org.kuali.rice.core.api.util.RiceConstants; |
| 29 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
| 30 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 31 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
| 32 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
| 33 | |
import org.kuali.rice.core.framework.persistence.jpa.metadata.EntityDescriptor; |
| 34 | |
import org.kuali.rice.core.framework.persistence.jpa.metadata.FieldDescriptor; |
| 35 | |
import org.kuali.rice.core.framework.persistence.jpa.metadata.MetadataManager; |
| 36 | |
import org.kuali.rice.core.web.format.Formatter; |
| 37 | |
import org.kuali.rice.kew.util.KEWConstants; |
| 38 | |
import org.kuali.rice.kim.bo.Person; |
| 39 | |
import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition; |
| 40 | |
import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry; |
| 41 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
| 42 | |
import org.kuali.rice.kns.document.MaintenanceDocumentBase; |
| 43 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions; |
| 44 | |
import org.kuali.rice.kns.lookup.LookupResultsService; |
| 45 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
| 46 | |
import org.kuali.rice.kns.rule.event.KualiAddLineEvent; |
| 47 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 48 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
| 49 | |
import org.kuali.rice.kns.util.KNSGlobalVariables; |
| 50 | |
import org.kuali.rice.kns.util.MaintenanceUtils; |
| 51 | |
import org.kuali.rice.kns.util.WebUtils; |
| 52 | |
import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; |
| 53 | |
import org.kuali.rice.kns.web.struts.form.KualiForm; |
| 54 | |
import org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm; |
| 55 | |
import org.kuali.rice.krad.bo.DocumentAttachment; |
| 56 | |
import org.kuali.rice.krad.bo.PersistableAttachment; |
| 57 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
| 58 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectExtension; |
| 59 | |
import org.kuali.rice.krad.document.authorization.MaintenanceDocumentAuthorizer; |
| 60 | |
import org.kuali.rice.krad.exception.DocumentTypeAuthorizationException; |
| 61 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 62 | |
import org.kuali.rice.krad.service.LookupService; |
| 63 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 64 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 65 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
| 66 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 67 | |
|
| 68 | |
import javax.persistence.PersistenceException; |
| 69 | |
import javax.servlet.http.HttpServletRequest; |
| 70 | |
import javax.servlet.http.HttpServletResponse; |
| 71 | |
import java.lang.reflect.Field; |
| 72 | |
import java.lang.reflect.InvocationTargetException; |
| 73 | |
import java.security.GeneralSecurityException; |
| 74 | |
import java.util.ArrayList; |
| 75 | |
import java.util.Collection; |
| 76 | |
import java.util.Enumeration; |
| 77 | |
import java.util.HashMap; |
| 78 | |
import java.util.Iterator; |
| 79 | |
import java.util.List; |
| 80 | |
import java.util.Map; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
public class KualiMaintenanceDocumentAction extends KualiDocumentActionBase { |
| 86 | 0 | protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiMaintenanceDocumentAction.class); |
| 87 | |
|
| 88 | 0 | protected MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService = null; |
| 89 | |
protected EncryptionService encryptionService; |
| 90 | |
protected LookupService lookupService; |
| 91 | |
protected LookupResultsService lookupResultsService; |
| 92 | |
|
| 93 | |
public KualiMaintenanceDocumentAction() { |
| 94 | 0 | super(); |
| 95 | 0 | maintenanceDocumentDictionaryService = KNSServiceLocator.getMaintenanceDocumentDictionaryService(); |
| 96 | 0 | encryptionService = CoreApiServiceLocator.getEncryptionService(); |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 101 | 0 | request.setAttribute(KRADConstants.PARAM_MAINTENANCE_VIEW_MODE, KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_MAINTENANCE); |
| 102 | 0 | return super.execute(mapping, form, request, response); |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 109 | 0 | request.setAttribute(KRADConstants.MAINTENANCE_ACTN, KRADConstants.MAINTENANCE_NEW_ACTION); |
| 110 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_NEW_ACTION); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 117 | |
|
| 118 | 0 | if (request.getParameter("document." + KRADPropertyConstants.DOCUMENT_NUMBER) == null) { |
| 119 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_COPY_ACTION); |
| 120 | |
} |
| 121 | |
else { |
| 122 | 0 | throw new UnsupportedOperationException("System does not support copying of maintenance documents."); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 130 | |
|
| 131 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_EDIT_ACTION); |
| 132 | |
} |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 138 | 0 | if (isFormRepresentingLockObject((KualiDocumentFormBase)form)) { |
| 139 | 0 | return super.delete(mapping, form, request, response); |
| 140 | |
} |
| 141 | 0 | KNSGlobalVariables.getMessageList().add(RiceKeyConstants.MESSAGE_DELETE); |
| 142 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_DELETE_ACTION); |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public ActionForward newWithExisting(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 149 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION); |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
protected ActionForward setupMaintenance(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String maintenanceAction) throws Exception { |
| 159 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form; |
| 160 | 0 | MaintenanceDocument document = null; |
| 161 | |
|
| 162 | |
|
| 163 | 0 | if (maintenanceForm.getDocument() == null) { |
| 164 | 0 | if (StringUtils.isEmpty(maintenanceForm.getBusinessObjectClassName()) && StringUtils.isEmpty(maintenanceForm.getDocTypeName())) { |
| 165 | 0 | throw new IllegalArgumentException("Document type name or bo class not given!"); |
| 166 | |
} |
| 167 | |
|
| 168 | 0 | String documentTypeName = maintenanceForm.getDocTypeName(); |
| 169 | |
|
| 170 | 0 | if (StringUtils.isEmpty(documentTypeName)) { |
| 171 | 0 | documentTypeName = maintenanceDocumentDictionaryService.getDocumentTypeName(Class.forName(maintenanceForm.getBusinessObjectClassName())); |
| 172 | 0 | maintenanceForm.setDocTypeName(documentTypeName); |
| 173 | |
} |
| 174 | |
|
| 175 | 0 | if (StringUtils.isEmpty(documentTypeName)) { |
| 176 | 0 | throw new RuntimeException("documentTypeName is empty; does this Business Object have a maintenance document definition? " + maintenanceForm.getBusinessObjectClassName()); |
| 177 | |
} |
| 178 | |
|
| 179 | |
|
| 180 | 0 | if (KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction) || KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) { |
| 181 | 0 | Class boClass = maintenanceDocumentDictionaryService.getDataObjectClass(documentTypeName); |
| 182 | 0 | boolean allowsNewOrCopy = getBusinessObjectAuthorizationService().canCreate(boClass, GlobalVariables.getUserSession().getPerson(), documentTypeName); |
| 183 | 0 | if (!allowsNewOrCopy) { |
| 184 | 0 | LOG.error("Document type " + documentTypeName + " does not allow new or copy actions."); |
| 185 | 0 | throw new DocumentTypeAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalId(), "newOrCopy", documentTypeName); |
| 186 | |
} |
| 187 | |
} |
| 188 | |
|
| 189 | |
|
| 190 | 0 | document = (MaintenanceDocument) getDocumentService().getNewDocument(maintenanceForm.getDocTypeName()); |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | 0 | maintenanceForm.setDocument(document); |
| 201 | 0 | } |
| 202 | |
else { |
| 203 | 0 | document = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 204 | |
} |
| 205 | |
|
| 206 | |
|
| 207 | 0 | if (!(KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)) && !(KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION.equals(maintenanceAction))) { |
| 208 | 0 | Map requestParameters = buildKeyMapFromRequest(document.getNewMaintainableObject(), request); |
| 209 | 0 | PersistableBusinessObject oldBusinessObject = null; |
| 210 | |
try { |
| 211 | 0 | oldBusinessObject = (PersistableBusinessObject) getLookupService().findObjectBySearch(Class.forName(maintenanceForm.getBusinessObjectClassName()), requestParameters); |
| 212 | 0 | } catch ( ClassNotPersistenceCapableException ex ) { |
| 213 | 0 | if ( !document.getOldMaintainableObject().isExternalBusinessObject() ) { |
| 214 | 0 | throw new RuntimeException( "BO Class: " + maintenanceForm.getBusinessObjectClassName() + " is not persistable and is not externalizable - configuration error" ); |
| 215 | |
} |
| 216 | |
|
| 217 | 0 | } |
| 218 | 0 | if (oldBusinessObject == null && !document.getOldMaintainableObject().isExternalBusinessObject()) { |
| 219 | 0 | throw new RuntimeException("Cannot retrieve old record for maintenance document, incorrect parameters passed on maint url: " + requestParameters ); |
| 220 | |
} |
| 221 | |
|
| 222 | 0 | if(document.getOldMaintainableObject().isExternalBusinessObject()){ |
| 223 | 0 | if ( oldBusinessObject == null ) { |
| 224 | |
try { |
| 225 | 0 | oldBusinessObject = (PersistableBusinessObject)document.getOldMaintainableObject().getBoClass().newInstance(); |
| 226 | 0 | } catch ( Exception ex ) { |
| 227 | 0 | throw new RuntimeException( "External BO maintainable was null and unable to instantiate for old maintainable object.", ex ); |
| 228 | 0 | } |
| 229 | |
} |
| 230 | 0 | populateBOWithCopyKeyValues(request, oldBusinessObject, document.getOldMaintainableObject()); |
| 231 | 0 | document.getOldMaintainableObject().prepareBusinessObject(oldBusinessObject); |
| 232 | 0 | oldBusinessObject = document.getOldMaintainableObject().getBusinessObject(); |
| 233 | |
} |
| 234 | |
|
| 235 | |
|
| 236 | 0 | final String TMP_NM = oldBusinessObject.getClass().getName(); |
| 237 | 0 | final int START_INDEX = TMP_NM.indexOf('.', TMP_NM.indexOf('.') + 1) + 1; |
| 238 | 0 | if ( ( OrmUtils.isJpaEnabled() || OrmUtils.isJpaEnabled(TMP_NM.substring(START_INDEX, TMP_NM.indexOf('.', TMP_NM.indexOf('.', START_INDEX) + 1))) ) && |
| 239 | |
OrmUtils.isJpaAnnotated(oldBusinessObject.getClass()) && oldBusinessObject.getExtension() != null && OrmUtils.isJpaAnnotated(oldBusinessObject.getExtension().getClass())) { |
| 240 | 0 | if (oldBusinessObject.getExtension() != null) { |
| 241 | 0 | PersistableBusinessObjectExtension boe = oldBusinessObject.getExtension(); |
| 242 | 0 | EntityDescriptor entity = MetadataManager.getEntityDescriptor(oldBusinessObject.getExtension().getClass()); |
| 243 | 0 | Criteria extensionCriteria = new Criteria(boe.getClass().getName()); |
| 244 | 0 | for (FieldDescriptor fieldDescriptor : entity.getPrimaryKeys()) { |
| 245 | |
try { |
| 246 | 0 | Field field = oldBusinessObject.getClass().getDeclaredField(fieldDescriptor.getName()); |
| 247 | 0 | field.setAccessible(true); |
| 248 | 0 | extensionCriteria.eq(fieldDescriptor.getName(), field.get(oldBusinessObject)); |
| 249 | 0 | } catch (Exception e) { |
| 250 | 0 | LOG.error(e.getMessage(),e); |
| 251 | 0 | } |
| 252 | |
} |
| 253 | |
try { |
| 254 | 0 | boe = (PersistableBusinessObjectExtension) new QueryByCriteria(getEntityManagerFactory().createEntityManager(), extensionCriteria).toQuery().getSingleResult(); |
| 255 | 0 | } catch (PersistenceException e) {} |
| 256 | 0 | oldBusinessObject.setExtension(boe); |
| 257 | |
} |
| 258 | |
} |
| 259 | |
|
| 260 | 0 | PersistableBusinessObject newBusinessObject = (PersistableBusinessObject) ObjectUtils.deepCopy(oldBusinessObject); |
| 261 | |
|
| 262 | |
|
| 263 | 0 | Class<? extends PersistableBusinessObject> businessObjectClass = ClassLoaderUtils.getClass(maintenanceForm.getBusinessObjectClassName(), PersistableBusinessObject.class); |
| 264 | 0 | document.getOldMaintainableObject().setBusinessObject(oldBusinessObject); |
| 265 | 0 | document.getOldMaintainableObject().setBoClass(businessObjectClass); |
| 266 | 0 | document.getNewMaintainableObject().setBusinessObject(newBusinessObject); |
| 267 | 0 | document.getNewMaintainableObject().setBoClass(businessObjectClass); |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | 0 | if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceAction)) { |
| 272 | 0 | if (!document.isFieldsClearedOnCopy()) { |
| 273 | |
|
| 274 | 0 | Class boClass = maintenanceDocumentDictionaryService.getDataObjectClass( |
| 275 | |
maintenanceForm.getDocTypeName()); |
| 276 | 0 | if(!maintenanceDocumentDictionaryService.getPreserveLockingKeysOnCopy(boClass)) |
| 277 | 0 | clearPrimaryKeyFields(document); |
| 278 | |
|
| 279 | 0 | clearUnauthorizedNewFields(document); |
| 280 | |
|
| 281 | 0 | Maintainable maintainable = document.getNewMaintainableObject(); |
| 282 | |
|
| 283 | 0 | maintainable.processAfterCopy( document, request.getParameterMap() ); |
| 284 | |
|
| 285 | |
|
| 286 | 0 | document.setFieldsClearedOnCopy(true); |
| 287 | |
|
| 288 | |
|
| 289 | 0 | maintainable.setGenerateBlankRequiredValues(maintenanceForm.getDocTypeName()); |
| 290 | 0 | } |
| 291 | |
} |
| 292 | 0 | else if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceAction)) { |
| 293 | 0 | boolean allowsEdit = getBusinessObjectAuthorizationService().canMaintain(oldBusinessObject, GlobalVariables.getUserSession().getPerson(), document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 294 | 0 | if (!allowsEdit) { |
| 295 | 0 | LOG.error("Document type " + document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName() + " does not allow edit actions."); |
| 296 | 0 | throw new DocumentTypeAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalId(), "edit", document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 297 | |
} |
| 298 | 0 | document.getNewMaintainableObject().processAfterEdit( document, request.getParameterMap() ); |
| 299 | 0 | } |
| 300 | |
|
| 301 | 0 | else if (KRADConstants.MAINTENANCE_DELETE_ACTION.equals(maintenanceAction)) { |
| 302 | 0 | boolean allowsDelete = getBusinessObjectAuthorizationService().canMaintain(oldBusinessObject, GlobalVariables.getUserSession().getPerson(), document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 303 | 0 | if (!allowsDelete) { |
| 304 | 0 | LOG.error("Document type " + document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName() + " does not allow delete actions."); |
| 305 | 0 | throw new DocumentTypeAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalId(), "delete", document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 306 | |
} |
| 307 | |
|
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
} |
| 317 | |
|
| 318 | 0 | if (KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION.equals(maintenanceAction)) { |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | 0 | PersistableBusinessObject newBO = document.getNewMaintainableObject().getBusinessObject(); |
| 323 | 0 | Map<String, String> parameters = buildKeyMapFromRequest(document.getNewMaintainableObject(), request); |
| 324 | 0 | copyParametersToBO(parameters, newBO); |
| 325 | 0 | newBO.refresh(); |
| 326 | 0 | document.getNewMaintainableObject().setupNewFromExisting( document, request.getParameterMap() ); |
| 327 | |
} |
| 328 | |
|
| 329 | |
|
| 330 | 0 | if (KRADConstants.MAINTENANCE_NEW_ACTION.equals(maintenanceAction)) { |
| 331 | 0 | document.getNewMaintainableObject().setGenerateDefaultValues(maintenanceForm.getDocTypeName()); |
| 332 | 0 | document.getNewMaintainableObject().processAfterNew( document, request.getParameterMap() ); |
| 333 | |
|
| 334 | |
|
| 335 | 0 | MaintenanceUtils.checkForLockingDocument(document.getNewMaintainableObject(), false); |
| 336 | |
} |
| 337 | |
|
| 338 | |
|
| 339 | 0 | document.getNewMaintainableObject().setMaintenanceAction(maintenanceAction); |
| 340 | 0 | maintenanceForm.setMaintenanceAction(maintenanceAction); |
| 341 | |
|
| 342 | |
|
| 343 | 0 | MaintenanceDocumentEntry entry = maintenanceDocumentDictionaryService.getMaintenanceDocumentEntry(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 344 | 0 | if (LOG.isDebugEnabled()) { |
| 345 | 0 | LOG.debug("maintenanceForm.getAdditionalScriptFiles(): " + maintenanceForm.getAdditionalScriptFiles()); |
| 346 | |
} |
| 347 | 0 | if (maintenanceForm.getAdditionalScriptFiles().isEmpty()) { |
| 348 | 0 | maintenanceForm.getAdditionalScriptFiles().addAll(entry.getWebScriptFiles()); |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | 0 | document.setDisplayTopicFieldInNotes(entry.getDisplayTopicFieldInNotes()); |
| 353 | |
|
| 354 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 355 | |
} |
| 356 | |
|
| 357 | |
protected void populateBOWithCopyKeyValues(HttpServletRequest request, PersistableBusinessObject oldBusinessObject, Maintainable oldMaintainableObject) throws Exception{ |
| 358 | 0 | List keyFieldNamesToCopy = new ArrayList(); |
| 359 | |
Map<String, String> parametersToCopy; |
| 360 | 0 | if (!StringUtils.isBlank(request.getParameter(KRADConstants.COPY_KEYS))) { |
| 361 | 0 | String[] copyKeys = request.getParameter(KRADConstants.COPY_KEYS).split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR); |
| 362 | 0 | for (String copyKey: copyKeys) { |
| 363 | 0 | keyFieldNamesToCopy.add(copyKey); |
| 364 | |
} |
| 365 | |
} |
| 366 | 0 | parametersToCopy = getRequestParameters(keyFieldNamesToCopy, oldMaintainableObject, request); |
| 367 | 0 | if(parametersToCopy!=null && parametersToCopy.size()>0){ |
| 368 | 0 | copyParametersToBO(parametersToCopy, oldBusinessObject); |
| 369 | |
} |
| 370 | 0 | } |
| 371 | |
|
| 372 | |
protected void copyParametersToBO(Map<String, String> parameters, PersistableBusinessObject newBO) throws Exception{ |
| 373 | 0 | for (String parmName : parameters.keySet()) { |
| 374 | 0 | String propertyValue = parameters.get(parmName); |
| 375 | |
|
| 376 | 0 | if (StringUtils.isNotBlank(propertyValue)) { |
| 377 | 0 | String propertyName = parmName; |
| 378 | |
|
| 379 | 0 | if (PropertyUtils.isWriteable(newBO, propertyName)) { |
| 380 | 0 | Class type = ObjectUtils.easyGetPropertyType(newBO, propertyName); |
| 381 | 0 | if (type != null && Formatter.getFormatter(type) != null) { |
| 382 | 0 | Formatter formatter = Formatter.getFormatter(type); |
| 383 | 0 | Object obj = formatter.convertFromPresentationFormat(propertyValue); |
| 384 | 0 | ObjectUtils.setObjectProperty(newBO, propertyName, obj.getClass(), obj); |
| 385 | 0 | } |
| 386 | |
else { |
| 387 | 0 | ObjectUtils.setObjectProperty(newBO, propertyName, String.class, propertyValue); |
| 388 | |
} |
| 389 | |
} |
| 390 | |
} |
| 391 | 0 | } |
| 392 | 0 | } |
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
public ActionForward downloadAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 405 | 0 | KualiDocumentFormBase documentForm = (KualiDocumentFormBase) form; |
| 406 | 0 | MaintenanceDocumentBase document = (MaintenanceDocumentBase) documentForm.getDocument(); |
| 407 | 0 | document.refreshReferenceObject("attachment"); |
| 408 | 0 | DocumentAttachment attachment = document.getAttachment(); |
| 409 | 0 | if(attachment != null) { |
| 410 | 0 | streamToResponse(attachment.getAttachmentContent(), attachment.getFileName(), attachment.getContentType(), response); |
| 411 | |
} |
| 412 | 0 | return null; |
| 413 | |
} |
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
public ActionForward replaceAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 427 | |
HttpServletResponse response) throws Exception { |
| 428 | 0 | KualiDocumentFormBase documentForm = (KualiDocumentFormBase) form; |
| 429 | 0 | MaintenanceDocumentBase document = (MaintenanceDocumentBase) documentForm.getDocument(); |
| 430 | 0 | document.refreshReferenceObject("attachment"); |
| 431 | 0 | getBusinessObjectService().delete(document.getAttachment()); |
| 432 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 433 | |
} |
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
@Override |
| 446 | |
public ActionForward route(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 447 | 0 | KualiDocumentFormBase documentForm = (KualiDocumentFormBase) form; |
| 448 | 0 | MaintenanceDocumentBase document = (MaintenanceDocumentBase) documentForm.getDocument(); |
| 449 | |
|
| 450 | 0 | ActionForward forward = super.route(mapping, form, request, response); |
| 451 | 0 | if(document.getNewMaintainableObject().getBusinessObject() instanceof PersistableAttachment) { |
| 452 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService().retrieve(document.getNewMaintainableObject().getBusinessObject()); |
| 453 | 0 | request.setAttribute("fileName", bo.getFileName()); |
| 454 | |
} |
| 455 | |
|
| 456 | 0 | return forward; |
| 457 | |
} |
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
@Override |
| 463 | |
public ActionForward docHandler(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 464 | 0 | super.docHandler(mapping, form, request, response); |
| 465 | 0 | KualiMaintenanceForm kualiMaintenanceForm = (KualiMaintenanceForm) form; |
| 466 | |
|
| 467 | 0 | if (KEWConstants.ACTIONLIST_COMMAND.equals(kualiMaintenanceForm.getCommand()) || KEWConstants.DOCSEARCH_COMMAND.equals(kualiMaintenanceForm.getCommand()) || KEWConstants.SUPERUSER_COMMAND.equals(kualiMaintenanceForm.getCommand()) || KEWConstants.HELPDESK_ACTIONLIST_COMMAND.equals(kualiMaintenanceForm.getCommand()) && kualiMaintenanceForm.getDocId() != null) { |
| 468 | 0 | if (kualiMaintenanceForm.getDocument() instanceof MaintenanceDocument) { |
| 469 | 0 | kualiMaintenanceForm.setReadOnly(true); |
| 470 | 0 | kualiMaintenanceForm.setMaintenanceAction(((MaintenanceDocument) kualiMaintenanceForm.getDocument()).getNewMaintainableObject().getMaintenanceAction()); |
| 471 | |
|
| 472 | |
|
| 473 | 0 | Maintainable tmpMaintainable = ((MaintenanceDocument) kualiMaintenanceForm.getDocument()).getNewMaintainableObject(); |
| 474 | 0 | if(tmpMaintainable.getBusinessObject() instanceof PersistableAttachment) { |
| 475 | 0 | PersistableAttachment bo = (PersistableAttachment) getBusinessObjectService().retrieve(tmpMaintainable.getBusinessObject()); |
| 476 | 0 | if(bo != null) |
| 477 | 0 | request.setAttribute("fileName", bo.getFileName()); |
| 478 | |
} |
| 479 | 0 | } |
| 480 | |
else { |
| 481 | 0 | LOG.error("Illegal State: document is not a maintenance document"); |
| 482 | 0 | throw new IllegalStateException("Document is not a maintenance document"); |
| 483 | |
} |
| 484 | |
} |
| 485 | 0 | else if (KEWConstants.INITIATE_COMMAND.equals(kualiMaintenanceForm.getCommand())) { |
| 486 | 0 | kualiMaintenanceForm.setReadOnly(false); |
| 487 | 0 | return setupMaintenance(mapping, form, request, response, KRADConstants.MAINTENANCE_NEW_ACTION); |
| 488 | |
} |
| 489 | |
else { |
| 490 | 0 | LOG.error("We should never have gotten to here"); |
| 491 | 0 | throw new IllegalStateException("docHandler called with invalid parameters"); |
| 492 | |
} |
| 493 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 494 | |
} |
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
@Override |
| 500 | |
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 501 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form; |
| 502 | |
|
| 503 | 0 | WebUtils.reuseErrorMapFromPreviousRequest(maintenanceForm); |
| 504 | 0 | maintenanceForm.setDerivedValuesOnForm(request); |
| 505 | |
|
| 506 | 0 | refreshAdHocRoutingWorkgroupLookups(request, maintenanceForm); |
| 507 | 0 | MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 508 | |
|
| 509 | |
|
| 510 | 0 | Map<String, String> requestParams = new HashMap<String, String>(); |
| 511 | 0 | for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) { |
| 512 | 0 | String requestKey = (String) i.nextElement(); |
| 513 | 0 | String requestValue = request.getParameter(requestKey); |
| 514 | 0 | requestParams.put(requestKey, requestValue); |
| 515 | 0 | } |
| 516 | |
|
| 517 | |
|
| 518 | 0 | Collection<PersistableBusinessObject> rawValues = null; |
| 519 | 0 | if (StringUtils.equals(KRADConstants.MULTIPLE_VALUE, maintenanceForm.getRefreshCaller())) { |
| 520 | 0 | String lookupResultsSequenceNumber = maintenanceForm.getLookupResultsSequenceNumber(); |
| 521 | 0 | if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) { |
| 522 | |
|
| 523 | 0 | String lookupResultsBOClassName = maintenanceForm.getLookupResultsBOClassName(); |
| 524 | 0 | Class lookupResultsBOClass = Class.forName(lookupResultsBOClassName); |
| 525 | |
|
| 526 | 0 | rawValues = getLookupResultsService().retrieveSelectedResultBOs(lookupResultsSequenceNumber, lookupResultsBOClass, GlobalVariables.getUserSession().getPerson().getPrincipalId()); |
| 527 | |
} |
| 528 | |
} |
| 529 | |
|
| 530 | 0 | if (rawValues != null) { |
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | 0 | String collectionName = maintenanceForm.getLookedUpCollectionName(); |
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | 0 | document.getNewMaintainableObject().addMultipleValueLookupResults(document, collectionName, rawValues, false, document.getNewMaintainableObject().getBusinessObject()); |
| 550 | 0 | if (LOG.isInfoEnabled()) { |
| 551 | 0 | LOG.info("********************doing editing 3 in refersh()***********************."); |
| 552 | |
} |
| 553 | 0 | boolean isEdit = KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceForm.getMaintenanceAction()); |
| 554 | 0 | boolean isCopy = KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceForm.getMaintenanceAction()); |
| 555 | |
|
| 556 | 0 | if (isEdit || isCopy) { |
| 557 | 0 | document.getOldMaintainableObject().addMultipleValueLookupResults(document, collectionName, rawValues, true, document.getOldMaintainableObject().getBusinessObject()); |
| 558 | 0 | document.getOldMaintainableObject().refresh(maintenanceForm.getRefreshCaller(), requestParams, document); |
| 559 | |
} |
| 560 | |
} |
| 561 | |
|
| 562 | 0 | document.getNewMaintainableObject().refresh(maintenanceForm.getRefreshCaller(), requestParams, document); |
| 563 | |
|
| 564 | |
|
| 565 | 0 | String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); |
| 566 | 0 | if(StringUtils.contains(fullParameter, KRADConstants.CUSTOM_ACTION)){ |
| 567 | 0 | String customAction = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); |
| 568 | 0 | String[] actionValue = new String[1]; |
| 569 | 0 | actionValue[0]= StringUtils.substringAfter(customAction, "."); |
| 570 | 0 | Map<String,String[]> paramMap = request.getParameterMap(); |
| 571 | 0 | paramMap.put(KRADConstants.CUSTOM_ACTION, actionValue); |
| 572 | 0 | doProcessingAfterPost( (KualiMaintenanceForm) form, paramMap ); |
| 573 | |
} |
| 574 | |
|
| 575 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 576 | |
} |
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
protected Map buildKeyMapFromRequest(Maintainable maintainable, HttpServletRequest request) { |
| 583 | 0 | List keyFieldNames = null; |
| 584 | |
|
| 585 | |
|
| 586 | 0 | if (!StringUtils.isBlank(request.getParameter(KRADConstants.OVERRIDE_KEYS))) { |
| 587 | 0 | String[] overrideKeys = request.getParameter(KRADConstants.OVERRIDE_KEYS).split(KRADConstants.FIELD_CONVERSIONS_SEPARATOR); |
| 588 | 0 | keyFieldNames = new ArrayList(); |
| 589 | 0 | for (String overrideKey : overrideKeys) { |
| 590 | 0 | keyFieldNames.add(overrideKey); |
| 591 | |
} |
| 592 | 0 | } |
| 593 | |
else { |
| 594 | 0 | keyFieldNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(maintainable.getBusinessObject().getClass()); |
| 595 | |
} |
| 596 | 0 | return getRequestParameters(keyFieldNames, maintainable, request); |
| 597 | |
} |
| 598 | |
|
| 599 | |
protected Map<String, String> getRequestParameters(List keyFieldNames, Maintainable maintainable, HttpServletRequest request){ |
| 600 | |
|
| 601 | 0 | Map<String, String> requestParameters = new HashMap<String, String>(); |
| 602 | |
|
| 603 | |
|
| 604 | 0 | for (Iterator iter = keyFieldNames.iterator(); iter.hasNext();) { |
| 605 | 0 | String keyPropertyName = (String) iter.next(); |
| 606 | |
|
| 607 | 0 | if (request.getParameter(keyPropertyName) != null) { |
| 608 | 0 | String keyValue = request.getParameter(keyPropertyName); |
| 609 | |
|
| 610 | |
|
| 611 | 0 | if (getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(maintainable.getBoClass(), keyPropertyName)) { |
| 612 | |
try { |
| 613 | 0 | keyValue = StringUtils.removeEnd(keyValue, EncryptionService.ENCRYPTION_POST_PREFIX); |
| 614 | 0 | keyValue = encryptionService.decrypt(keyValue); |
| 615 | |
} |
| 616 | 0 | catch (GeneralSecurityException e) { |
| 617 | 0 | throw new RuntimeException(e); |
| 618 | 0 | } |
| 619 | |
} |
| 620 | |
|
| 621 | |
|
| 622 | 0 | requestParameters.put(keyPropertyName, keyValue); |
| 623 | |
} |
| 624 | 0 | } |
| 625 | |
|
| 626 | 0 | return requestParameters; |
| 627 | |
|
| 628 | |
} |
| 629 | |
|
| 630 | |
|
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
String extractCollectionName(HttpServletRequest request, String methodToCall) { |
| 636 | |
|
| 637 | 0 | String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); |
| 638 | 0 | String collectionName = null; |
| 639 | 0 | if (StringUtils.isNotBlank(parameterName)) { |
| 640 | 0 | collectionName = StringUtils.substringBetween(parameterName, methodToCall + ".", ".("); |
| 641 | |
} |
| 642 | 0 | return collectionName; |
| 643 | |
} |
| 644 | |
|
| 645 | |
Collection extractCollection(PersistableBusinessObject bo, String collectionName) { |
| 646 | |
|
| 647 | 0 | Collection maintCollection = (Collection) ObjectUtils.getPropertyValue(bo, collectionName); |
| 648 | 0 | return maintCollection; |
| 649 | |
} |
| 650 | |
|
| 651 | |
Class extractCollectionClass(String docTypeName, String collectionName) { |
| 652 | 0 | return maintenanceDocumentDictionaryService.getCollectionBusinessObjectClass(docTypeName, collectionName); |
| 653 | |
} |
| 654 | |
|
| 655 | |
|
| 656 | |
|
| 657 | |
|
| 658 | |
public ActionForward addLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 659 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form; |
| 660 | 0 | MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 661 | 0 | Maintainable oldMaintainable = document.getOldMaintainableObject(); |
| 662 | 0 | Maintainable newMaintainable = document.getNewMaintainableObject(); |
| 663 | |
|
| 664 | 0 | String collectionName = extractCollectionName(request, KRADConstants.ADD_LINE_METHOD); |
| 665 | 0 | if (collectionName == null) { |
| 666 | 0 | LOG.error("Unable to get find collection name and class in request."); |
| 667 | 0 | throw new RuntimeException("Unable to get find collection name and class in request."); |
| 668 | |
} |
| 669 | |
|
| 670 | |
|
| 671 | 0 | if ((StringUtils.lastIndexOf(collectionName, "]") + 1) == collectionName.length()) { |
| 672 | 0 | collectionName = StringUtils.substringBeforeLast(collectionName, "["); |
| 673 | |
} |
| 674 | |
|
| 675 | 0 | PersistableBusinessObject bo = newMaintainable.getBusinessObject(); |
| 676 | 0 | Collection maintCollection = extractCollection(bo, collectionName); |
| 677 | 0 | Class collectionClass = extractCollectionClass(((MaintenanceDocument) maintenanceForm.getDocument()).getDocumentHeader().getWorkflowDocument().getDocumentTypeName(), collectionName); |
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | 0 | PersistableBusinessObject addBO = newMaintainable.getNewCollectionLine(collectionName); |
| 683 | 0 | if (LOG.isDebugEnabled()) { |
| 684 | 0 | LOG.debug("obtained addBO from newCollectionLine: " + addBO); |
| 685 | |
} |
| 686 | |
|
| 687 | |
|
| 688 | 0 | getBusinessObjectService().linkUserFields(addBO); |
| 689 | |
|
| 690 | |
|
| 691 | 0 | newMaintainable.processBeforeAddLine(collectionName, collectionClass, addBO); |
| 692 | |
|
| 693 | |
|
| 694 | 0 | boolean rulePassed = false; |
| 695 | 0 | if (LOG.isDebugEnabled()) { |
| 696 | 0 | LOG.debug("about to call AddLineEvent applyRules: document=" + document + "\ncollectionName=" + collectionName + "\nBO=" + addBO); |
| 697 | |
} |
| 698 | 0 | rulePassed = getKualiRuleService().applyRules(new KualiAddLineEvent(document, collectionName, addBO)); |
| 699 | |
|
| 700 | |
|
| 701 | 0 | if (rulePassed) { |
| 702 | 0 | if (LOG.isInfoEnabled()) { |
| 703 | 0 | LOG.info("********************doing editing 4 in addline()***********************."); |
| 704 | |
} |
| 705 | |
|
| 706 | 0 | boolean isEdit = KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceForm.getMaintenanceAction()); |
| 707 | 0 | boolean isCopy = KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceForm.getMaintenanceAction()); |
| 708 | |
|
| 709 | |
|
| 710 | 0 | if (isEdit || isCopy) { |
| 711 | 0 | PersistableBusinessObject oldBo = oldMaintainable.getBusinessObject(); |
| 712 | 0 | Collection oldMaintCollection = (Collection) ObjectUtils.getPropertyValue(oldBo, collectionName); |
| 713 | |
|
| 714 | 0 | if (oldMaintCollection == null) { |
| 715 | 0 | oldMaintCollection = new ArrayList(); |
| 716 | |
} |
| 717 | 0 | if (PersistableBusinessObject.class.isAssignableFrom(collectionClass)) { |
| 718 | 0 | PersistableBusinessObject placeholder = (PersistableBusinessObject) collectionClass.newInstance(); |
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | 0 | placeholder.setNewCollectionRecord(true); |
| 725 | 0 | ((List) oldMaintCollection).add(placeholder); |
| 726 | 0 | } |
| 727 | |
else { |
| 728 | 0 | LOG.warn("Should be a instance of PersistableBusinessObject"); |
| 729 | 0 | ((List) oldMaintCollection).add(collectionClass.newInstance()); |
| 730 | |
} |
| 731 | |
|
| 732 | 0 | ObjectUtils.setObjectProperty(oldBo, collectionName, List.class, oldMaintCollection); |
| 733 | |
} |
| 734 | |
|
| 735 | 0 | newMaintainable.addNewLineToCollection(collectionName); |
| 736 | 0 | int subCollectionIndex = 0; |
| 737 | 0 | for (Object aSubCollection : maintCollection) { |
| 738 | 0 | subCollectionIndex += getSubCollectionIndex(aSubCollection, maintenanceForm.getDocTypeName()); |
| 739 | |
} |
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
} |
| 772 | 0 | doProcessingAfterPost( (KualiMaintenanceForm) form, request ); |
| 773 | |
|
| 774 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 775 | |
} |
| 776 | |
|
| 777 | |
protected int getSubCollectionIndex(Object object, String documentTypeName) { |
| 778 | 0 | int index = 1; |
| 779 | 0 | MaintainableCollectionDefinition theCollectionDefinition = null; |
| 780 | 0 | for (MaintainableCollectionDefinition maintainableCollectionDefinition : maintenanceDocumentDictionaryService.getMaintainableCollections(documentTypeName)) { |
| 781 | 0 | if (maintainableCollectionDefinition.getBusinessObjectClass().equals(object.getClass())) { |
| 782 | |
|
| 783 | 0 | theCollectionDefinition = maintainableCollectionDefinition; |
| 784 | 0 | break; |
| 785 | |
} |
| 786 | |
} |
| 787 | 0 | if (theCollectionDefinition != null) { |
| 788 | 0 | for (MaintainableCollectionDefinition subCollDef : theCollectionDefinition.getMaintainableCollections()) { |
| 789 | 0 | String name = subCollDef.getName(); |
| 790 | 0 | String capitalFirst = name.substring(0, 1).toUpperCase(); |
| 791 | 0 | String methodName = "get" + capitalFirst + name.substring(1); |
| 792 | 0 | List subCollectionList = new ArrayList(); |
| 793 | |
try { |
| 794 | 0 | subCollectionList = (List) object.getClass().getMethod(methodName).invoke(object); |
| 795 | |
} |
| 796 | 0 | catch (InvocationTargetException ite) { |
| 797 | |
|
| 798 | |
} |
| 799 | 0 | catch (IllegalAccessException iae) { |
| 800 | |
|
| 801 | |
} |
| 802 | 0 | catch (NoSuchMethodException nme) { |
| 803 | |
|
| 804 | 0 | } |
| 805 | 0 | index += subCollectionList.size(); |
| 806 | 0 | } |
| 807 | |
} |
| 808 | 0 | return index; |
| 809 | |
} |
| 810 | |
|
| 811 | |
|
| 812 | |
|
| 813 | |
|
| 814 | |
|
| 815 | |
|
| 816 | |
public ActionForward deleteLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 817 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form; |
| 818 | 0 | MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 819 | 0 | Maintainable oldMaintainable = document.getOldMaintainableObject(); |
| 820 | 0 | Maintainable newMaintainable = document.getNewMaintainableObject(); |
| 821 | |
|
| 822 | 0 | String collectionName = extractCollectionName(request, KRADConstants.DELETE_LINE_METHOD); |
| 823 | 0 | if (collectionName == null) { |
| 824 | 0 | LOG.error("Unable to get find collection name in request."); |
| 825 | 0 | throw new RuntimeException("Unable to get find collection class in request."); |
| 826 | |
} |
| 827 | |
|
| 828 | 0 | PersistableBusinessObject bo = newMaintainable.getBusinessObject(); |
| 829 | 0 | Collection maintCollection = extractCollection(bo, collectionName); |
| 830 | 0 | if (collectionName == null) { |
| 831 | 0 | LOG.error("Collection is null in parent business object."); |
| 832 | 0 | throw new RuntimeException("Collection is null in parent business object."); |
| 833 | |
} |
| 834 | |
|
| 835 | 0 | int deleteRecordIndex = getLineToDelete(request); |
| 836 | 0 | if (deleteRecordIndex < 0 || deleteRecordIndex > maintCollection.size() - 1) { |
| 837 | 0 | if (collectionName == null) { |
| 838 | 0 | LOG.error("Invalid index for deletion of collection record: " + deleteRecordIndex); |
| 839 | 0 | throw new RuntimeException("Invalid index for deletion of collection record: " + deleteRecordIndex); |
| 840 | |
} |
| 841 | |
} |
| 842 | |
|
| 843 | 0 | ((List) maintCollection).remove(deleteRecordIndex); |
| 844 | |
|
| 845 | |
|
| 846 | 0 | if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(maintenanceForm.getMaintenanceAction()) || |
| 847 | |
KRADConstants.MAINTENANCE_COPY_ACTION.equals(maintenanceForm.getMaintenanceAction())) { |
| 848 | 0 | bo = oldMaintainable.getBusinessObject(); |
| 849 | 0 | maintCollection = extractCollection(bo, collectionName); |
| 850 | |
|
| 851 | 0 | if (collectionName == null) { |
| 852 | 0 | LOG.error("Collection is null in parent business object."); |
| 853 | 0 | throw new RuntimeException("Collection is null in parent business object."); |
| 854 | |
} |
| 855 | |
|
| 856 | 0 | ((List) maintCollection).remove(deleteRecordIndex); |
| 857 | |
} |
| 858 | |
|
| 859 | |
|
| 860 | |
|
| 861 | |
|
| 862 | |
|
| 863 | |
|
| 864 | |
|
| 865 | |
|
| 866 | |
|
| 867 | |
|
| 868 | |
|
| 869 | |
|
| 870 | |
|
| 871 | |
|
| 872 | |
|
| 873 | |
|
| 874 | |
|
| 875 | |
|
| 876 | |
|
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
|
| 885 | |
|
| 886 | |
|
| 887 | |
|
| 888 | |
|
| 889 | |
|
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | |
|
| 894 | |
|
| 895 | |
|
| 896 | |
|
| 897 | 0 | doProcessingAfterPost( (KualiMaintenanceForm) form, request ); |
| 898 | |
|
| 899 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 900 | |
} |
| 901 | |
|
| 902 | |
|
| 903 | |
|
| 904 | |
|
| 905 | |
public ActionForward toggleInactiveRecordDisplay(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 906 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) form; |
| 907 | 0 | MaintenanceDocument document = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 908 | 0 | Maintainable oldMaintainable = document.getOldMaintainableObject(); |
| 909 | 0 | Maintainable newMaintainable = document.getNewMaintainableObject(); |
| 910 | |
|
| 911 | 0 | String collectionName = extractCollectionName(request, KRADConstants.TOGGLE_INACTIVE_METHOD); |
| 912 | 0 | if (collectionName == null) { |
| 913 | 0 | LOG.error("Unable to get find collection name in request."); |
| 914 | 0 | throw new RuntimeException("Unable to get find collection class in request."); |
| 915 | |
} |
| 916 | |
|
| 917 | 0 | String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE); |
| 918 | 0 | boolean showInactive = Boolean.parseBoolean(StringUtils.substringBetween(parameterName, KRADConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, ".")); |
| 919 | |
|
| 920 | 0 | oldMaintainable.setShowInactiveRecords(collectionName, showInactive); |
| 921 | 0 | newMaintainable.setShowInactiveRecords(collectionName, showInactive); |
| 922 | |
|
| 923 | 0 | return mapping.findForward(RiceConstants.MAPPING_BASIC); |
| 924 | |
} |
| 925 | |
|
| 926 | |
|
| 927 | |
|
| 928 | |
|
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
protected void clearPrimaryKeyFields(MaintenanceDocument document) { |
| 934 | |
|
| 935 | 0 | PersistableBusinessObject bo = document.getNewMaintainableObject().getBusinessObject(); |
| 936 | 0 | List<String> keyFieldNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(bo.getClass()); |
| 937 | |
|
| 938 | 0 | for (String keyFieldName : keyFieldNames) { |
| 939 | |
try { |
| 940 | 0 | ObjectUtils.setObjectProperty(bo, keyFieldName, null); |
| 941 | |
} |
| 942 | 0 | catch (Exception e) { |
| 943 | 0 | LOG.error("Unable to clear primary key field: " + e.getMessage()); |
| 944 | 0 | throw new RuntimeException("Unable to clear primary key field: " + e.getMessage()); |
| 945 | 0 | } |
| 946 | |
} |
| 947 | 0 | } |
| 948 | |
|
| 949 | |
|
| 950 | |
|
| 951 | |
|
| 952 | |
|
| 953 | |
|
| 954 | |
|
| 955 | |
protected void clearUnauthorizedNewFields(MaintenanceDocument document) { |
| 956 | |
|
| 957 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
| 958 | |
|
| 959 | |
|
| 960 | 0 | MaintenanceDocumentAuthorizer documentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(document); |
| 961 | |
|
| 962 | |
|
| 963 | 0 | MaintenanceDocumentRestrictions maintenanceDocumentRestrictions = getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(document, user); |
| 964 | |
|
| 965 | |
|
| 966 | 0 | PersistableBusinessObject newBo = document.getNewMaintainableObject().getBusinessObject(); |
| 967 | |
|
| 968 | 0 | document.getNewMaintainableObject().clearBusinessObjectOfRestrictedValues(maintenanceDocumentRestrictions); |
| 969 | 0 | } |
| 970 | |
|
| 971 | |
|
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
@SuppressWarnings("unchecked") |
| 977 | |
protected void doProcessingAfterPost( KualiForm form, HttpServletRequest request ) { |
| 978 | 0 | MaintenanceDocument document = (MaintenanceDocument) ((KualiMaintenanceForm)form).getDocument(); |
| 979 | 0 | Maintainable maintainable = document.getNewMaintainableObject(); |
| 980 | 0 | PersistableBusinessObject bo = maintainable.getBusinessObject(); |
| 981 | |
|
| 982 | 0 | getBusinessObjectService().linkUserFields(bo); |
| 983 | |
|
| 984 | 0 | maintainable.processAfterPost(document, request.getParameterMap() ); |
| 985 | 0 | } |
| 986 | |
|
| 987 | |
protected void doProcessingAfterPost( KualiForm form, Map<String,String[]> parameters ) { |
| 988 | 0 | MaintenanceDocument document = (MaintenanceDocument) ((KualiMaintenanceForm)form).getDocument(); |
| 989 | 0 | Maintainable maintainable = document.getNewMaintainableObject(); |
| 990 | 0 | PersistableBusinessObject bo = maintainable.getBusinessObject(); |
| 991 | |
|
| 992 | 0 | getBusinessObjectService().linkUserFields(bo); |
| 993 | |
|
| 994 | 0 | maintainable.processAfterPost(document, parameters ); |
| 995 | 0 | } |
| 996 | |
|
| 997 | |
protected void populateAuthorizationFields(KualiDocumentFormBase formBase){ |
| 998 | 0 | super.populateAuthorizationFields(formBase); |
| 999 | |
|
| 1000 | 0 | KualiMaintenanceForm maintenanceForm = (KualiMaintenanceForm) formBase; |
| 1001 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) maintenanceForm.getDocument(); |
| 1002 | 0 | MaintenanceDocumentAuthorizer maintenanceDocumentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(maintenanceDocument); |
| 1003 | 0 | Person user = GlobalVariables.getUserSession().getPerson(); |
| 1004 | 0 | maintenanceForm.setReadOnly(!formBase.getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT)); |
| 1005 | 0 | MaintenanceDocumentRestrictions maintenanceDocumentAuthorizations = getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(maintenanceDocument, user); |
| 1006 | 0 | maintenanceForm.setAuthorizations(maintenanceDocumentAuthorizations); |
| 1007 | 0 | } |
| 1008 | |
|
| 1009 | |
public LookupService getLookupService() { |
| 1010 | 0 | if ( lookupService == null ) { |
| 1011 | 0 | lookupService = KRADServiceLocatorWeb.getLookupService(); |
| 1012 | |
} |
| 1013 | 0 | return this.lookupService; |
| 1014 | |
} |
| 1015 | |
|
| 1016 | |
public LookupResultsService getLookupResultsService() { |
| 1017 | 0 | if ( lookupResultsService == null ) { |
| 1018 | 0 | lookupResultsService = KNSServiceLocator.getLookupResultsService(); |
| 1019 | |
} |
| 1020 | 0 | return this.lookupResultsService; |
| 1021 | |
} |
| 1022 | |
|
| 1023 | |
} |