| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.maintenance; |
| 17 | |
|
| 18 | |
import org.apache.commons.beanutils.PropertyUtils; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.encryption.EncryptionService; |
| 21 | |
import org.kuali.rice.core.api.services.CoreApiServiceLocator; |
| 22 | |
import org.kuali.rice.core.web.format.FormatException; |
| 23 | |
import org.kuali.rice.kim.bo.Person; |
| 24 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 25 | |
import org.kuali.rice.kns.authorization.FieldRestriction; |
| 26 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 27 | |
import org.kuali.rice.kns.bo.BusinessObjectRelationship; |
| 28 | |
import org.kuali.rice.kns.bo.DocumentHeader; |
| 29 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
| 30 | |
import org.kuali.rice.kns.datadictionary.*; |
| 31 | |
import org.kuali.rice.kns.datadictionary.exception.UnknownBusinessClassAttributeException; |
| 32 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
| 33 | |
import org.kuali.rice.kns.document.MaintenanceLock; |
| 34 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationController; |
| 35 | |
import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions; |
| 36 | |
import org.kuali.rice.kns.exception.PessimisticLockingException; |
| 37 | |
import org.kuali.rice.kns.lookup.LookupUtils; |
| 38 | |
import org.kuali.rice.kns.lookup.valuefinder.ValueFinder; |
| 39 | |
import org.kuali.rice.kns.service.*; |
| 40 | |
import org.kuali.rice.kns.util.*; |
| 41 | |
import org.kuali.rice.kns.web.ui.Section; |
| 42 | |
import org.kuali.rice.kns.web.ui.SectionBridge; |
| 43 | |
|
| 44 | |
import java.beans.PropertyDescriptor; |
| 45 | |
import java.io.Serializable; |
| 46 | |
import java.lang.reflect.InvocationTargetException; |
| 47 | |
import java.security.GeneralSecurityException; |
| 48 | |
import java.util.*; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
public class KualiMaintainableImpl implements Maintainable, Serializable { |
| 54 | |
private static final long serialVersionUID = 4814145799502207182L; |
| 55 | |
|
| 56 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiMaintainableImpl.class); |
| 57 | |
|
| 58 | |
protected String documentNumber; |
| 59 | |
protected PersistableBusinessObject businessObject; |
| 60 | |
protected Class<? extends PersistableBusinessObject> boClass; |
| 61 | |
protected String maintenanceAction; |
| 62 | |
|
| 63 | 0 | protected Map<String, PersistableBusinessObject> newCollectionLines = new HashMap<String, PersistableBusinessObject>(); |
| 64 | 0 | protected Map<String, Boolean> inactiveRecordDisplay = new HashMap<String, Boolean>(); |
| 65 | |
|
| 66 | |
protected String docTypeName; |
| 67 | |
|
| 68 | |
protected static PersistenceStructureService persistenceStructureService; |
| 69 | |
|
| 70 | |
protected static MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
| 71 | |
protected static DataDictionaryService dataDictionaryService; |
| 72 | |
protected static BusinessObjectService businessObjectService; |
| 73 | |
protected static BusinessObjectDictionaryService businessObjectDictionaryService; |
| 74 | |
protected static EncryptionService encryptionService; |
| 75 | |
protected static org.kuali.rice.kim.service.PersonService personService; |
| 76 | |
protected static BusinessObjectMetaDataService businessObjectMetaDataService; |
| 77 | |
protected static BusinessObjectAuthorizationService businessObjectAuthorizationService; |
| 78 | |
protected static MaintenanceDocumentService maintenanceDocumentService; |
| 79 | |
protected static DocumentHelperService documentHelperService; |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 0 | public KualiMaintainableImpl() { |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public KualiMaintainableImpl(PersistableBusinessObject businessObject) { |
| 93 | 0 | this(); |
| 94 | 0 | this.businessObject = businessObject; |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
public void setupNewFromExisting(MaintenanceDocument document, Map<String, String[]> parameters) { |
| 98 | |
|
| 99 | 0 | } |
| 100 | |
|
| 101 | |
public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) { |
| 102 | |
|
| 103 | 0 | } |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public String getDocumentTitle(MaintenanceDocument document) { |
| 111 | |
|
| 112 | 0 | return ""; |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
public List<MaintenanceLock> generateMaintenanceLocks() { |
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | 0 | List<MaintenanceLock> maintenanceLocks = new ArrayList<MaintenanceLock>(); |
| 126 | 0 | StringBuffer lockRepresentation = new StringBuffer(boClass.getName()); |
| 127 | 0 | lockRepresentation.append(KNSConstants.Maintenance.AFTER_CLASS_DELIM); |
| 128 | |
|
| 129 | 0 | PersistableBusinessObject bo = getBusinessObject(); |
| 130 | 0 | List keyFieldNames = getMaintenanceDocumentDictionaryService().getLockingKeys(getDocumentTypeName()); |
| 131 | |
|
| 132 | 0 | for (Iterator i = keyFieldNames.iterator(); i.hasNext();) { |
| 133 | 0 | String fieldName = (String) i.next(); |
| 134 | 0 | Object fieldValue = ObjectUtils.getPropertyValue(bo, fieldName); |
| 135 | 0 | if (fieldValue == null) { |
| 136 | 0 | fieldValue = ""; |
| 137 | |
} |
| 138 | |
|
| 139 | |
|
| 140 | 0 | if (getBusinessObjectAuthorizationService().attributeValueNeedsToBeEncryptedOnFormsAndLinks(boClass, fieldName)) { |
| 141 | |
try { |
| 142 | 0 | fieldValue = getEncryptionService().encrypt(fieldValue); |
| 143 | 0 | } catch (GeneralSecurityException e) { |
| 144 | 0 | LOG.error("Unable to encrypt secure field for locking representation " + e.getMessage()); |
| 145 | 0 | throw new RuntimeException("Unable to encrypt secure field for locking representation " + e.getMessage()); |
| 146 | 0 | } |
| 147 | |
} |
| 148 | |
|
| 149 | 0 | lockRepresentation.append(fieldName); |
| 150 | 0 | lockRepresentation.append(KNSConstants.Maintenance.AFTER_FIELDNAME_DELIM); |
| 151 | 0 | lockRepresentation.append(String.valueOf(fieldValue)); |
| 152 | 0 | if (i.hasNext()) { |
| 153 | 0 | lockRepresentation.append(KNSConstants.Maintenance.AFTER_VALUE_DELIM); |
| 154 | |
} |
| 155 | 0 | } |
| 156 | |
|
| 157 | 0 | MaintenanceLock maintenanceLock = new MaintenanceLock(); |
| 158 | 0 | maintenanceLock.setDocumentNumber(documentNumber); |
| 159 | 0 | maintenanceLock.setLockingRepresentation(lockRepresentation.toString()); |
| 160 | 0 | maintenanceLocks.add(maintenanceLock); |
| 161 | 0 | return maintenanceLocks; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
@SuppressWarnings("unchecked") |
| 168 | |
public Map populateBusinessObject(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) { |
| 169 | 0 | fieldValues = decryptEncryptedData(fieldValues, maintenanceDocument, methodToCall); |
| 170 | 0 | Map newFieldValues = null; |
| 171 | 0 | newFieldValues = getPersonService().resolvePrincipalNamesToPrincipalIds(getBusinessObject(), fieldValues); |
| 172 | |
|
| 173 | 0 | Map cachedValues = FieldUtils.populateBusinessObjectFromMap(getBusinessObject(), newFieldValues); |
| 174 | 0 | performForceUpperCase(newFieldValues); |
| 175 | |
|
| 176 | 0 | return cachedValues; |
| 177 | |
} |
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
protected Map<String, String> decryptEncryptedData(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) { |
| 188 | |
try { |
| 189 | 0 | MaintenanceDocumentRestrictions auths = getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(maintenanceDocument, GlobalVariables.getUserSession().getPerson()); |
| 190 | 0 | for (Iterator<String> iter = fieldValues.keySet().iterator(); iter.hasNext();) { |
| 191 | 0 | String fieldName = iter.next(); |
| 192 | 0 | String fieldValue = (String) fieldValues.get(fieldName); |
| 193 | |
|
| 194 | 0 | if (fieldValue != null && !"".equals(fieldValue) && fieldValue.endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) { |
| 195 | 0 | if (shouldFieldBeEncrypted(maintenanceDocument, fieldName, auths, methodToCall)) { |
| 196 | 0 | String encryptedValue = fieldValue; |
| 197 | |
|
| 198 | |
|
| 199 | 0 | encryptedValue = StringUtils.stripEnd(encryptedValue, EncryptionService.ENCRYPTION_POST_PREFIX); |
| 200 | 0 | String decryptedValue = getEncryptionService().decrypt(encryptedValue); |
| 201 | |
|
| 202 | 0 | fieldValues.put(fieldName, decryptedValue); |
| 203 | 0 | } else |
| 204 | 0 | throw new RuntimeException( |
| 205 | |
"The field value for field name " + fieldName + " should not be encrypted."); |
| 206 | 0 | } else if (fieldValue != null && !"".equals(fieldValue) && shouldFieldBeEncrypted(maintenanceDocument, fieldName, auths, methodToCall)) |
| 207 | 0 | throw new RuntimeException( |
| 208 | |
"The field value for field name " + fieldName + " should be encrypted."); |
| 209 | 0 | } |
| 210 | 0 | } catch (GeneralSecurityException e) { |
| 211 | 0 | throw new RuntimeException("Unable to decrypt secure data: " + e.getMessage()); |
| 212 | 0 | } |
| 213 | |
|
| 214 | 0 | return fieldValues; |
| 215 | |
} |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
protected boolean shouldFieldBeEncrypted(MaintenanceDocument maintenanceDocument, String fieldName, MaintenanceDocumentRestrictions auths, String methodToCall) { |
| 232 | 0 | if ("refresh".equals(methodToCall) && fieldName != null) { |
| 233 | 0 | fieldName = fieldName.replaceAll("\\[[0-9]*+\\]", ""); |
| 234 | 0 | fieldName = fieldName.replaceAll("^add\\.", ""); |
| 235 | 0 | Map<String, AttributeSecurity> fieldNameToAttributeSecurityMap = MaintenanceUtils.retrievePropertyPathToAttributeSecurityMappings(getDocumentTypeName()); |
| 236 | 0 | AttributeSecurity attributeSecurity = fieldNameToAttributeSecurityMap.get(fieldName); |
| 237 | 0 | return attributeSecurity != null && attributeSecurity.hasRestrictionThatRemovesValueFromUI(); |
| 238 | |
} else { |
| 239 | 0 | return false; |
| 240 | |
} |
| 241 | |
} |
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
| 250 | 0 | List<Section> sections = new ArrayList<Section>(); |
| 251 | 0 | sections.addAll(getCoreSections(document, oldMaintainable)); |
| 252 | |
|
| 253 | 0 | return sections; |
| 254 | |
} |
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
public List<Section> getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
| 265 | 0 | List<Section> sections = new ArrayList<Section>(); |
| 266 | 0 | MaintenanceDocumentRestrictions maintenanceRestrictions = getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(document, GlobalVariables.getUserSession().getPerson()); |
| 267 | |
|
| 268 | 0 | MaintenanceDocumentPresentationController maintenanceDocumentPresentationController = (MaintenanceDocumentPresentationController) getDocumentHelperService() |
| 269 | |
.getDocumentPresentationController(document); |
| 270 | 0 | Set<String> conditionallyRequiredFields = maintenanceDocumentPresentationController.getConditionallyRequiredPropertyNames(document); |
| 271 | |
|
| 272 | 0 | List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 273 | |
try { |
| 274 | |
|
| 275 | 0 | for (Iterator iter = sectionDefinitions.iterator(); iter.hasNext();) { |
| 276 | 0 | MaintainableSectionDefinition maintSectionDef = (MaintainableSectionDefinition) iter.next(); |
| 277 | |
|
| 278 | 0 | List<String> displayedFieldNames = new ArrayList<String>(); |
| 279 | 0 | if (!maintenanceRestrictions.isHiddenSectionId(maintSectionDef.getId())) { |
| 280 | |
|
| 281 | 0 | for (Iterator iter2 = maintSectionDef.getMaintainableItems().iterator(); iter2.hasNext();) { |
| 282 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) iter2.next(); |
| 283 | 0 | if (item instanceof MaintainableFieldDefinition) { |
| 284 | 0 | displayedFieldNames.add(((MaintainableFieldDefinition) item).getName()); |
| 285 | |
} |
| 286 | 0 | } |
| 287 | |
|
| 288 | 0 | Section section = SectionBridge.toSection(maintSectionDef, getBusinessObject(), this, oldMaintainable, getMaintenanceAction(), displayedFieldNames, conditionallyRequiredFields); |
| 289 | 0 | if (maintenanceRestrictions.isReadOnlySectionId(maintSectionDef.getId())) { |
| 290 | 0 | section.setReadOnly(true); |
| 291 | |
} |
| 292 | |
|
| 293 | |
|
| 294 | 0 | sections.add(section); |
| 295 | |
} |
| 296 | |
|
| 297 | 0 | } |
| 298 | |
|
| 299 | 0 | } catch (InstantiationException e) { |
| 300 | 0 | LOG.error("Unable to create instance of object class" + e.getMessage()); |
| 301 | 0 | throw new RuntimeException("Unable to create instance of object class" + e.getMessage()); |
| 302 | 0 | } catch (IllegalAccessException e) { |
| 303 | 0 | LOG.error("Unable to create instance of object class" + e.getMessage()); |
| 304 | 0 | throw new RuntimeException("Unable to create instance of object class" + e.getMessage()); |
| 305 | 0 | } |
| 306 | |
|
| 307 | 0 | return sections; |
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
public void saveBusinessObject() { |
| 314 | 0 | getBusinessObjectService().linkAndSave(businessObject); |
| 315 | 0 | } |
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
public String getMaintainableTitle() { |
| 321 | 0 | return getMaintenanceDocumentDictionaryService().getMaintenanceLabel(getDocumentTypeName()); |
| 322 | |
} |
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
public boolean isBoNotesEnabled() { |
| 328 | 0 | return getBusinessObjectDictionaryService().areNotesSupported(this.boClass); |
| 329 | |
} |
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
public void refresh(String refreshCaller, Map fieldValues, MaintenanceDocument document) { |
| 336 | 0 | String referencesToRefresh = (String) fieldValues.get(KNSConstants.REFERENCES_TO_REFRESH); |
| 337 | 0 | refreshReferences(referencesToRefresh); |
| 338 | 0 | } |
| 339 | |
|
| 340 | |
|
| 341 | |
protected void refreshReferences(String referencesToRefresh) { |
| 342 | 0 | PersistenceStructureService persistenceStructureService = getPersistenceStructureService(); |
| 343 | 0 | if (StringUtils.isNotBlank(referencesToRefresh)) { |
| 344 | 0 | String[] references = StringUtils.split(referencesToRefresh, KNSConstants.REFERENCES_TO_REFRESH_SEPARATOR); |
| 345 | 0 | for (String reference : references) { |
| 346 | 0 | if (StringUtils.isNotBlank(reference)) { |
| 347 | 0 | if (reference.startsWith(KNSConstants.ADD_PREFIX + ".")) { |
| 348 | |
|
| 349 | 0 | reference = reference.substring(KNSConstants.ADD_PREFIX.length() + 1); |
| 350 | |
|
| 351 | 0 | String boToRefreshName = StringUtils.substringBeforeLast(reference, "."); |
| 352 | 0 | String propertyToRefresh = StringUtils.substringAfterLast(reference, "."); |
| 353 | 0 | if (StringUtils.isNotBlank(propertyToRefresh)) { |
| 354 | 0 | PersistableBusinessObject addlineBO = getNewCollectionLine(boToRefreshName); |
| 355 | 0 | Class addlineBOClass = addlineBO.getClass(); |
| 356 | 0 | if (LOG.isDebugEnabled()) { |
| 357 | 0 | LOG.debug("Refresh this \"new\"/add object for the collections: " + reference); |
| 358 | |
} |
| 359 | 0 | if (persistenceStructureService.hasReference(addlineBOClass, propertyToRefresh) || |
| 360 | |
persistenceStructureService.hasCollection(addlineBOClass, propertyToRefresh)) { |
| 361 | 0 | addlineBO.refreshReferenceObject(propertyToRefresh); |
| 362 | |
} else { |
| 363 | 0 | if (getDataDictionaryService().hasRelationship(addlineBOClass.getName(), propertyToRefresh)) { |
| 364 | |
|
| 365 | 0 | Object possibleBO = ObjectUtils.getPropertyValue(addlineBO, propertyToRefresh); |
| 366 | 0 | if (possibleBO != null && possibleBO instanceof PersistableBusinessObject) { |
| 367 | 0 | ((PersistableBusinessObject) possibleBO).refresh(); |
| 368 | |
} |
| 369 | |
} |
| 370 | |
} |
| 371 | 0 | } else { |
| 372 | 0 | LOG.error("Error: unable to refresh this \"new\"/add object for the collections: " + reference); |
| 373 | |
} |
| 374 | 0 | } else if (ObjectUtils.isNestedAttribute(reference)) { |
| 375 | 0 | Object nestedObject = ObjectUtils.getNestedValue(getBusinessObject(), ObjectUtils.getNestedAttributePrefix(reference)); |
| 376 | 0 | if (nestedObject instanceof Collection) { |
| 377 | |
|
| 378 | |
|
| 379 | 0 | } else if (nestedObject instanceof PersistableBusinessObject) { |
| 380 | 0 | String propertyToRefresh = ObjectUtils.getNestedAttributePrimitive(reference); |
| 381 | 0 | if (persistenceStructureService.hasReference(nestedObject.getClass(), propertyToRefresh) || |
| 382 | |
persistenceStructureService.hasCollection(nestedObject.getClass(), propertyToRefresh)) { |
| 383 | 0 | if (LOG.isDebugEnabled()) { |
| 384 | 0 | LOG.debug("Refeshing " + ObjectUtils.getNestedAttributePrefix(reference) + " " + ObjectUtils.getNestedAttributePrimitive(reference)); |
| 385 | |
} |
| 386 | 0 | ((PersistableBusinessObject) nestedObject).refreshReferenceObject(propertyToRefresh); |
| 387 | |
} else { |
| 388 | |
|
| 389 | 0 | Object possibleBO = ObjectUtils.getPropertyValue(nestedObject, propertyToRefresh); |
| 390 | 0 | if (possibleBO != null && possibleBO instanceof PersistableBusinessObject) { |
| 391 | 0 | if (getDataDictionaryService().hasRelationship(possibleBO.getClass().getName(), propertyToRefresh)) { |
| 392 | 0 | ((PersistableBusinessObject) possibleBO).refresh(); |
| 393 | |
} |
| 394 | |
} |
| 395 | |
} |
| 396 | 0 | } else { |
| 397 | 0 | LOG.warn("Expected that a referenceToRefresh (" + reference + ") would be a PersistableBusinessObject or Collection, but instead, it was of class " + nestedObject.getClass().getName()); |
| 398 | |
} |
| 399 | 0 | } else { |
| 400 | 0 | if (LOG.isDebugEnabled()) { |
| 401 | 0 | LOG.debug("Refreshing " + reference); |
| 402 | |
} |
| 403 | 0 | if (persistenceStructureService.hasReference(boClass, reference) || |
| 404 | |
persistenceStructureService.hasCollection(boClass, reference)) { |
| 405 | 0 | getBusinessObject().refreshReferenceObject(reference); |
| 406 | |
} else { |
| 407 | 0 | if (getDataDictionaryService().hasRelationship(getBusinessObject().getClass().getName(), reference)) { |
| 408 | |
|
| 409 | 0 | Object possibleRelationship = ObjectUtils.getPropertyValue(getBusinessObject(), reference); |
| 410 | 0 | if (possibleRelationship != null) { |
| 411 | 0 | if (possibleRelationship instanceof PersistableBusinessObject) { |
| 412 | 0 | ((PersistableBusinessObject) possibleRelationship).refresh(); |
| 413 | 0 | } else if (possibleRelationship instanceof Collection) { |
| 414 | |
|
| 415 | |
|
| 416 | |
} else { |
| 417 | 0 | LOG.warn("Expected that a referenceToRefresh (" + reference + |
| 418 | |
") would be a PersistableBusinessObject or Collection, but instead, it was of class " + |
| 419 | |
possibleRelationship.getClass().getName()); |
| 420 | |
} |
| 421 | |
} |
| 422 | |
} |
| 423 | |
} |
| 424 | |
} |
| 425 | |
} |
| 426 | |
} |
| 427 | |
} |
| 428 | 0 | } |
| 429 | |
|
| 430 | |
|
| 431 | |
public void addMultipleValueLookupResults(MaintenanceDocument document, String collectionName, Collection<PersistableBusinessObject> rawValues, boolean needsBlank, PersistableBusinessObject bo) { |
| 432 | 0 | Collection maintCollection = (Collection) ObjectUtils.getPropertyValue(bo, collectionName); |
| 433 | 0 | String docTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentType(); |
| 434 | |
|
| 435 | 0 | List<String> duplicateIdentifierFieldsFromDataDictionary = getDuplicateIdentifierFieldsFromDataDictionary(docTypeName, collectionName); |
| 436 | |
|
| 437 | 0 | List<String> existingIdentifierList = getMultiValueIdentifierList(maintCollection, duplicateIdentifierFieldsFromDataDictionary); |
| 438 | |
|
| 439 | 0 | Class collectionClass = getMaintenanceDocumentDictionaryService().getCollectionBusinessObjectClass(docTypeName, collectionName); |
| 440 | |
|
| 441 | 0 | List<MaintainableSectionDefinition> sections = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 442 | 0 | Map<String, String> template = MaintenanceUtils.generateMultipleValueLookupBOTemplate(sections, collectionName); |
| 443 | |
try { |
| 444 | 0 | for (PersistableBusinessObject nextBo : rawValues) { |
| 445 | |
PersistableBusinessObject templatedBo; |
| 446 | 0 | if (needsBlank) { |
| 447 | 0 | templatedBo = (PersistableBusinessObject) collectionClass.newInstance(); |
| 448 | |
} else { |
| 449 | |
|
| 450 | |
try { |
| 451 | 0 | ModuleService moduleService = KNSServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(collectionClass); |
| 452 | 0 | if (moduleService != null && moduleService.isExternalizable(collectionClass)) |
| 453 | 0 | templatedBo = (PersistableBusinessObject) moduleService.createNewObjectFromExternalizableClass(collectionClass); |
| 454 | |
else |
| 455 | 0 | templatedBo = (PersistableBusinessObject) collectionClass.newInstance(); |
| 456 | 0 | } catch (Exception e) { |
| 457 | 0 | throw new RuntimeException("Cannot instantiate " + collectionClass.getName(), e); |
| 458 | 0 | } |
| 459 | |
|
| 460 | 0 | setNewCollectionLineDefaultValues(collectionName, templatedBo); |
| 461 | |
|
| 462 | 0 | ObjectUtils.createHybridBusinessObject(templatedBo, nextBo, template); |
| 463 | |
|
| 464 | 0 | prepareBusinessObjectForAdditionFromMultipleValueLookup(collectionName, templatedBo); |
| 465 | |
} |
| 466 | 0 | templatedBo.setNewCollectionRecord(true); |
| 467 | |
|
| 468 | 0 | if (!hasBusinessObjectExisted(templatedBo, existingIdentifierList, duplicateIdentifierFieldsFromDataDictionary)) { |
| 469 | 0 | maintCollection.add(templatedBo); |
| 470 | |
|
| 471 | |
} |
| 472 | 0 | } |
| 473 | 0 | } catch (Exception e) { |
| 474 | 0 | LOG.error("Unable to add multiple value lookup results " + e.getMessage()); |
| 475 | 0 | throw new RuntimeException("Unable to add multiple value lookup results " + e.getMessage()); |
| 476 | 0 | } |
| 477 | 0 | } |
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
public List<String> getDuplicateIdentifierFieldsFromDataDictionary(String docTypeName, String collectionName) { |
| 489 | 0 | List<String> duplicateIdentifierFieldNames = new ArrayList<String>(); |
| 490 | 0 | MaintainableCollectionDefinition collDef = getMaintenanceDocumentDictionaryService().getMaintainableCollection(docTypeName, collectionName); |
| 491 | 0 | Collection<MaintainableFieldDefinition> fieldDef = collDef.getDuplicateIdentificationFields(); |
| 492 | 0 | for (MaintainableFieldDefinition eachFieldDef : fieldDef) { |
| 493 | 0 | duplicateIdentifierFieldNames.add(eachFieldDef.getName()); |
| 494 | |
} |
| 495 | 0 | return duplicateIdentifierFieldNames; |
| 496 | |
} |
| 497 | |
|
| 498 | |
|
| 499 | |
public List<String> getMultiValueIdentifierList(Collection maintCollection, List<String> duplicateIdentifierFields) { |
| 500 | 0 | List<String> identifierList = new ArrayList<String>(); |
| 501 | 0 | for (PersistableBusinessObject bo : (Collection<PersistableBusinessObject>) maintCollection) { |
| 502 | 0 | String uniqueIdentifier = new String(); |
| 503 | 0 | for (String identifierField : duplicateIdentifierFields) { |
| 504 | 0 | uniqueIdentifier = uniqueIdentifier + identifierField + "-" + ObjectUtils.getPropertyValue(bo, identifierField); |
| 505 | |
} |
| 506 | 0 | if (StringUtils.isNotEmpty(uniqueIdentifier)) { |
| 507 | 0 | identifierList.add(uniqueIdentifier); |
| 508 | |
} |
| 509 | 0 | } |
| 510 | 0 | return identifierList; |
| 511 | |
} |
| 512 | |
|
| 513 | |
public boolean hasBusinessObjectExisted(BusinessObject bo, List<String> existingIdentifierList, List<String> duplicateIdentifierFields) { |
| 514 | 0 | String uniqueIdentifier = new String(); |
| 515 | 0 | for (String identifierField : duplicateIdentifierFields) { |
| 516 | 0 | uniqueIdentifier = uniqueIdentifier + identifierField + "-" + ObjectUtils.getPropertyValue(bo, identifierField); |
| 517 | |
} |
| 518 | 0 | if (existingIdentifierList.contains(uniqueIdentifier)) { |
| 519 | 0 | return true; |
| 520 | |
} else { |
| 521 | 0 | return false; |
| 522 | |
} |
| 523 | |
} |
| 524 | |
|
| 525 | |
public void prepareBusinessObjectForAdditionFromMultipleValueLookup(String collectionName, BusinessObject bo) { |
| 526 | |
|
| 527 | 0 | } |
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
public void prepareForSave() { |
| 533 | 0 | } |
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
public void processAfterRetrieve() { |
| 539 | 0 | } |
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
public void processAfterCopy(MaintenanceDocument document, Map<String, String[]> parameters) { |
| 547 | |
try { |
| 548 | 0 | ObjectUtils.setObjectPropertyDeep(businessObject, KNSPropertyConstants.NEW_COLLECTION_RECORD, boolean.class, true, 2); |
| 549 | 0 | } catch (Exception e) { |
| 550 | 0 | LOG.error("unable to set newCollectionRecord property: " + e.getMessage(), e); |
| 551 | 0 | throw new RuntimeException("unable to set newCollectionRecord property: " + e.getMessage(), e); |
| 552 | 0 | } |
| 553 | 0 | } |
| 554 | |
|
| 555 | |
|
| 556 | |
|
| 557 | |
|
| 558 | |
public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> parameters) { |
| 559 | 0 | } |
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
public void processAfterNew(MaintenanceDocument document, Map<String, String[]> parameters) { |
| 565 | 0 | } |
| 566 | |
|
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
protected String getDocumentTypeName() { |
| 571 | 0 | return getMaintenanceDocumentDictionaryService().getDocumentTypeName(boClass); |
| 572 | |
} |
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
public PersistableBusinessObject getBusinessObject() { |
| 578 | 0 | return businessObject; |
| 579 | |
} |
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
public void setBusinessObject(PersistableBusinessObject businessObject) { |
| 585 | 0 | this.businessObject = businessObject; |
| 586 | 0 | } |
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
public Class<? extends PersistableBusinessObject> getBoClass() { |
| 593 | 0 | return boClass; |
| 594 | |
} |
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
public void setBoClass(Class<? extends PersistableBusinessObject> boClass) { |
| 601 | 0 | this.boClass = boClass; |
| 602 | 0 | this.docTypeName = getDocumentTypeName(); |
| 603 | 0 | } |
| 604 | |
|
| 605 | |
|
| 606 | |
|
| 607 | |
|
| 608 | |
public String getMaintenanceAction() { |
| 609 | 0 | return maintenanceAction; |
| 610 | |
} |
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
public void setMaintenanceAction(String maintenanceAction) { |
| 616 | 0 | this.maintenanceAction = maintenanceAction; |
| 617 | 0 | } |
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
public void setGenerateDefaultValues(String docTypeName) { |
| 624 | 0 | List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 625 | 0 | Map defaultValues = new HashMap(); |
| 626 | |
|
| 627 | |
try { |
| 628 | |
|
| 629 | 0 | for (Iterator iter = sectionDefinitions.iterator(); iter.hasNext();) { |
| 630 | |
|
| 631 | 0 | MaintainableSectionDefinition maintSectionDef = (MaintainableSectionDefinition) iter.next(); |
| 632 | 0 | Collection maintItems = maintSectionDef.getMaintainableItems(); |
| 633 | 0 | for (Iterator iterator = maintItems.iterator(); iterator.hasNext();) { |
| 634 | 0 | MaintainableItemDefinition item = (MaintainableItemDefinition) iterator.next(); |
| 635 | |
|
| 636 | 0 | if (item instanceof MaintainableFieldDefinition) { |
| 637 | 0 | MaintainableFieldDefinition maintainableFieldDefinition = (MaintainableFieldDefinition) item; |
| 638 | |
|
| 639 | 0 | String defaultValue = maintainableFieldDefinition.getDefaultValue(); |
| 640 | 0 | if (defaultValue != null) { |
| 641 | 0 | if (defaultValue.equals("true")) { |
| 642 | 0 | defaultValue = "Yes"; |
| 643 | 0 | } else if (defaultValue.equals("false")) { |
| 644 | 0 | defaultValue = "No"; |
| 645 | |
} |
| 646 | |
} |
| 647 | |
|
| 648 | 0 | Class defaultValueFinderClass = maintainableFieldDefinition.getDefaultValueFinderClass(); |
| 649 | 0 | if (defaultValueFinderClass != null) { |
| 650 | 0 | defaultValue = ((ValueFinder) defaultValueFinderClass.newInstance()).getValue(); |
| 651 | |
|
| 652 | |
} |
| 653 | 0 | if (defaultValue != null) { |
| 654 | 0 | defaultValues.put(item.getName(), defaultValue); |
| 655 | |
} |
| 656 | |
} |
| 657 | 0 | } |
| 658 | 0 | } |
| 659 | 0 | Map cachedValues = FieldUtils.populateBusinessObjectFromMap(getBusinessObject(), defaultValues); |
| 660 | 0 | } catch (Exception e) { |
| 661 | 0 | LOG.error("Unable to set default value " + e.getMessage(), e); |
| 662 | 0 | throw new RuntimeException("Unable to set default value" + e.getMessage(), e); |
| 663 | 0 | } |
| 664 | |
|
| 665 | 0 | } |
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
public void setGenerateBlankRequiredValues(String docTypeName) { |
| 672 | |
try { |
| 673 | 0 | List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 674 | 0 | Map<String, String> defaultValues = new HashMap<String, String>(); |
| 675 | |
|
| 676 | 0 | for (MaintainableSectionDefinition maintSectionDef : sectionDefinitions) { |
| 677 | 0 | for (MaintainableItemDefinition item : maintSectionDef.getMaintainableItems()) { |
| 678 | 0 | if (item instanceof MaintainableFieldDefinition) { |
| 679 | 0 | MaintainableFieldDefinition maintainableFieldDefinition = (MaintainableFieldDefinition) item; |
| 680 | 0 | if (maintainableFieldDefinition.isRequired() |
| 681 | |
&& maintainableFieldDefinition.isUnconditionallyReadOnly()) { |
| 682 | 0 | Object currPropVal = ObjectUtils.getPropertyValue(this.getBusinessObject(), item.getName()); |
| 683 | 0 | if (currPropVal == null |
| 684 | |
|| (currPropVal instanceof String && StringUtils.isBlank((String) currPropVal)) |
| 685 | |
) { |
| 686 | 0 | Class<? extends ValueFinder> defaultValueFinderClass = maintainableFieldDefinition.getDefaultValueFinderClass(); |
| 687 | 0 | if (defaultValueFinderClass != null) { |
| 688 | 0 | String defaultValue = defaultValueFinderClass.newInstance().getValue(); |
| 689 | 0 | if (defaultValue != null) { |
| 690 | 0 | defaultValues.put(item.getName(), defaultValue); |
| 691 | |
} |
| 692 | |
} |
| 693 | |
} |
| 694 | |
} |
| 695 | 0 | } |
| 696 | |
} |
| 697 | |
} |
| 698 | 0 | FieldUtils.populateBusinessObjectFromMap(getBusinessObject(), defaultValues); |
| 699 | 0 | } catch (Exception e) { |
| 700 | 0 | LOG.error("Unable to set blank required value " + e.getMessage(), e); |
| 701 | 0 | throw new RuntimeException("Unable to set blank required value" + e.getMessage(), e); |
| 702 | 0 | } |
| 703 | 0 | } |
| 704 | |
|
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
|
| 711 | |
public final void setDocumentNumber(String documentNumber) { |
| 712 | 0 | this.documentNumber = documentNumber; |
| 713 | 0 | } |
| 714 | |
|
| 715 | |
@Deprecated |
| 716 | |
public void processAfterAddLine(String colName, Class colClass) { |
| 717 | 0 | } |
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
public void processBeforeAddLine(String colName, Class colClass, BusinessObject addBO) { |
| 723 | 0 | } |
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
public boolean getShowInactiveRecords(String collectionName) { |
| 729 | 0 | return InactiveRecordsHidingUtils.getShowInactiveRecords(inactiveRecordDisplay, collectionName); |
| 730 | |
} |
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
public void setShowInactiveRecords(String collectionName, boolean showInactive) { |
| 736 | 0 | InactiveRecordsHidingUtils.setShowInactiveRecords(inactiveRecordDisplay, collectionName, showInactive); |
| 737 | 0 | } |
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
public Map<String, Boolean> getInactiveRecordDisplay() { |
| 743 | 0 | return inactiveRecordDisplay; |
| 744 | |
} |
| 745 | |
|
| 746 | |
public void addNewLineToCollection(String collectionName) { |
| 747 | |
|
| 748 | 0 | if (LOG.isDebugEnabled()) { |
| 749 | 0 | LOG.debug("addNewLineToCollection( " + collectionName + " )"); |
| 750 | |
} |
| 751 | |
|
| 752 | 0 | PersistableBusinessObject addLine = newCollectionLines.get(collectionName); |
| 753 | 0 | if (addLine != null) { |
| 754 | |
|
| 755 | 0 | addLine.setNewCollectionRecord(true); |
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | 0 | Collection maintCollection = (Collection) ObjectUtils.getPropertyValue(getBusinessObject(), collectionName); |
| 761 | |
|
| 762 | 0 | maintCollection.add(addLine); |
| 763 | |
|
| 764 | |
|
| 765 | 0 | String referencesToRefresh = LookupUtils.convertReferencesToSelectCollectionToString(getAllRefreshableReferences(getBusinessObject().getClass())); |
| 766 | 0 | if (LOG.isInfoEnabled()) { |
| 767 | 0 | LOG.info("References to refresh for adding line to collection " + collectionName + ": " + referencesToRefresh); |
| 768 | |
} |
| 769 | 0 | refreshReferences(referencesToRefresh); |
| 770 | |
} |
| 771 | |
|
| 772 | 0 | initNewCollectionLine(collectionName); |
| 773 | |
|
| 774 | 0 | } |
| 775 | |
|
| 776 | |
public PersistableBusinessObject getNewCollectionLine(String collectionName) { |
| 777 | 0 | if (LOG.isDebugEnabled()) { |
| 778 | |
|
| 779 | 0 | LOG.debug("newCollectionLines: " + newCollectionLines); |
| 780 | |
} |
| 781 | 0 | PersistableBusinessObject addLine = newCollectionLines.get(collectionName); |
| 782 | 0 | if (addLine == null) { |
| 783 | 0 | addLine = initNewCollectionLine(collectionName); |
| 784 | |
} |
| 785 | 0 | return addLine; |
| 786 | |
} |
| 787 | |
|
| 788 | |
public PersistableBusinessObject initNewCollectionLine(String collectionName) { |
| 789 | 0 | if (LOG.isDebugEnabled()) { |
| 790 | 0 | LOG.debug("initNewCollectionLine( " + collectionName + " )"); |
| 791 | |
} |
| 792 | |
|
| 793 | |
|
| 794 | |
|
| 795 | |
|
| 796 | |
PersistableBusinessObject addLine; |
| 797 | |
try { |
| 798 | 0 | addLine = (PersistableBusinessObject) getMaintenanceDocumentDictionaryService().getCollectionBusinessObjectClass(docTypeName, collectionName).newInstance(); |
| 799 | 0 | } catch (Exception ex) { |
| 800 | 0 | LOG.error("unable to instantiate new collection line", ex); |
| 801 | 0 | throw new RuntimeException("unable to instantiate new collection line", ex); |
| 802 | 0 | } |
| 803 | |
|
| 804 | 0 | newCollectionLines.put(collectionName, addLine); |
| 805 | |
|
| 806 | |
|
| 807 | 0 | setNewCollectionLineDefaultValues(collectionName, addLine); |
| 808 | 0 | return addLine; |
| 809 | |
} |
| 810 | |
|
| 811 | |
|
| 812 | |
|
| 813 | |
|
| 814 | |
|
| 815 | |
public Map<String, String> populateNewCollectionLines(Map<String, String> fieldValues, MaintenanceDocument maintenanceDocument, String methodToCall) { |
| 816 | 0 | if (LOG.isDebugEnabled()) { |
| 817 | 0 | LOG.debug("populateNewCollectionLines: " + fieldValues); |
| 818 | |
} |
| 819 | 0 | fieldValues = decryptEncryptedData(fieldValues, maintenanceDocument, methodToCall); |
| 820 | |
|
| 821 | 0 | Map<String, String> cachedValues = new HashMap<String, String>(); |
| 822 | |
|
| 823 | |
|
| 824 | 0 | List<MaintainableCollectionDefinition> collections = |
| 825 | |
getMaintenanceDocumentDictionaryService().getMaintainableCollections(docTypeName); |
| 826 | |
|
| 827 | 0 | for (MaintainableCollectionDefinition coll : collections) { |
| 828 | |
|
| 829 | 0 | String collName = coll.getName(); |
| 830 | 0 | if (LOG.isDebugEnabled()) { |
| 831 | 0 | LOG.debug("checking for collection: " + collName); |
| 832 | |
} |
| 833 | |
|
| 834 | 0 | Map<String, String> collectionValues = new HashMap<String, String>(); |
| 835 | 0 | Map<String, String> subCollectionValues = new HashMap<String, String>(); |
| 836 | |
|
| 837 | 0 | for (Map.Entry<String, String> entry : fieldValues.entrySet()) { |
| 838 | 0 | String key = entry.getKey(); |
| 839 | 0 | if (key.startsWith(collName)) { |
| 840 | 0 | String subStrKey = key.substring(collName.length() + 1); |
| 841 | |
|
| 842 | 0 | if (key.contains("[")) { |
| 843 | |
|
| 844 | |
|
| 845 | |
|
| 846 | |
|
| 847 | 0 | subCollectionValues.put(key, entry.getValue()); |
| 848 | |
} else { |
| 849 | 0 | collectionValues.put(subStrKey, entry.getValue()); |
| 850 | |
} |
| 851 | |
} |
| 852 | 0 | } |
| 853 | |
|
| 854 | 0 | if (LOG.isDebugEnabled()) { |
| 855 | 0 | LOG.debug("values for collection: " + collectionValues); |
| 856 | |
} |
| 857 | 0 | cachedValues.putAll(FieldUtils.populateBusinessObjectFromMap(getNewCollectionLine(collName), collectionValues, KNSConstants.MAINTENANCE_ADD_PREFIX + collName + ".")); |
| 858 | 0 | performFieldForceUpperCase(getNewCollectionLine(collName), collectionValues); |
| 859 | |
|
| 860 | 0 | cachedValues.putAll(populateNewSubCollectionLines(coll, subCollectionValues)); |
| 861 | 0 | } |
| 862 | |
|
| 863 | |
|
| 864 | 0 | return cachedValues; |
| 865 | |
} |
| 866 | |
|
| 867 | |
|
| 868 | |
|
| 869 | |
|
| 870 | |
|
| 871 | |
protected Map populateNewSubCollectionLines(MaintainableCollectionDefinition parentCollection, Map fieldValues) { |
| 872 | 0 | if (LOG.isDebugEnabled()) { |
| 873 | 0 | LOG.debug("populateNewSubCollectionLines: " + fieldValues); |
| 874 | |
} |
| 875 | 0 | Map cachedValues = new HashMap(); |
| 876 | |
|
| 877 | 0 | for (MaintainableCollectionDefinition coll : parentCollection.getMaintainableCollections()) { |
| 878 | |
|
| 879 | 0 | String collName = coll.getName(); |
| 880 | |
|
| 881 | |
|
| 882 | 0 | if (LOG.isDebugEnabled()) { |
| 883 | 0 | LOG.debug("checking for sub collection: " + collName); |
| 884 | |
} |
| 885 | 0 | Map<String, String> parents = new HashMap<String, String>(); |
| 886 | |
|
| 887 | 0 | for (Object entry : fieldValues.entrySet()) { |
| 888 | 0 | String key = (String) ((Map.Entry) entry).getKey(); |
| 889 | 0 | if (key.contains(collName)) { |
| 890 | 0 | parents.put(StringUtils.substringBefore(key, "."), ""); |
| 891 | |
} |
| 892 | 0 | } |
| 893 | |
|
| 894 | 0 | for (String parent : parents.keySet()) { |
| 895 | |
|
| 896 | 0 | Map<String, Object> collectionValues = new HashMap<String, Object>(); |
| 897 | |
|
| 898 | 0 | for (Object entry : fieldValues.entrySet()) { |
| 899 | 0 | String key = (String) ((Map.Entry) entry).getKey(); |
| 900 | 0 | if (key.contains(parent)) { |
| 901 | 0 | String substr = StringUtils.substringAfterLast(key, "."); |
| 902 | 0 | collectionValues.put(substr, ((Map.Entry) entry).getValue()); |
| 903 | |
} |
| 904 | 0 | } |
| 905 | |
|
| 906 | 0 | if (LOG.isDebugEnabled()) { |
| 907 | 0 | LOG.debug("values for sub collection: " + collectionValues); |
| 908 | |
} |
| 909 | 0 | GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.MAINTENANCE_ADD_PREFIX + parent + "." + collName); |
| 910 | 0 | cachedValues.putAll(FieldUtils.populateBusinessObjectFromMap(getNewCollectionLine(parent + "." + collName), collectionValues, KNSConstants.MAINTENANCE_ADD_PREFIX + parent + "." + collName + ".")); |
| 911 | 0 | performFieldForceUpperCase(getNewCollectionLine(parent + "." + collName), collectionValues); |
| 912 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.MAINTENANCE_ADD_PREFIX + parent + "." + collName); |
| 913 | 0 | } |
| 914 | |
|
| 915 | 0 | cachedValues.putAll(populateNewSubCollectionLines(coll, fieldValues)); |
| 916 | 0 | } |
| 917 | |
|
| 918 | 0 | return cachedValues; |
| 919 | |
} |
| 920 | |
|
| 921 | |
|
| 922 | |
public Collection<String> getAffectedReferencesFromLookup(BusinessObject baseBO, String attributeName, String collectionPrefix) { |
| 923 | 0 | PersistenceStructureService pss = getPersistenceStructureService(); |
| 924 | 0 | String nestedBOPrefix = ""; |
| 925 | 0 | if (ObjectUtils.isNestedAttribute(attributeName)) { |
| 926 | |
|
| 927 | 0 | nestedBOPrefix = ObjectUtils.getNestedAttributePrefix(attributeName); |
| 928 | |
|
| 929 | |
|
| 930 | 0 | Class reference = ObjectUtils.getPropertyType(baseBO, nestedBOPrefix, pss); |
| 931 | 0 | if (!(PersistableBusinessObject.class.isAssignableFrom(reference))) { |
| 932 | 0 | return new ArrayList<String>(); |
| 933 | |
} |
| 934 | |
|
| 935 | |
try { |
| 936 | 0 | baseBO = (PersistableBusinessObject) reference.newInstance(); |
| 937 | 0 | } catch (InstantiationException e) { |
| 938 | 0 | LOG.error(e); |
| 939 | 0 | } catch (IllegalAccessException e) { |
| 940 | 0 | LOG.error(e); |
| 941 | 0 | } |
| 942 | 0 | attributeName = ObjectUtils.getNestedAttributePrimitive(attributeName); |
| 943 | |
} |
| 944 | |
|
| 945 | 0 | if (baseBO == null) { |
| 946 | 0 | return new ArrayList<String>(); |
| 947 | |
} |
| 948 | |
|
| 949 | 0 | Map<String, Class> referenceNameToClassFromPSS = LookupUtils.getPrimitiveReference(baseBO, attributeName); |
| 950 | 0 | if (referenceNameToClassFromPSS.size() > 1) { |
| 951 | 0 | LOG.error("LookupUtils.getPrimitiveReference return results should only have at most one element"); |
| 952 | |
} |
| 953 | |
|
| 954 | 0 | BusinessObjectMetaDataService businessObjectMetaDataService = getBusinessObjectMetaDataService(); |
| 955 | 0 | BusinessObjectRelationship relationship = businessObjectMetaDataService.getBusinessObjectRelationship(baseBO, attributeName); |
| 956 | 0 | if (relationship == null) { |
| 957 | 0 | return new ArrayList<String>(); |
| 958 | |
} |
| 959 | |
|
| 960 | 0 | Map<String, String> fkToPkMappings = relationship.getParentToChildReferences(); |
| 961 | |
|
| 962 | 0 | Collection<String> affectedReferences = generateAllAffectedReferences(baseBO.getClass(), fkToPkMappings, nestedBOPrefix, collectionPrefix); |
| 963 | 0 | if (LOG.isDebugEnabled()) { |
| 964 | 0 | LOG.debug("References affected by a lookup on BO attribute \"" + collectionPrefix + nestedBOPrefix + "." + attributeName + ": " + affectedReferences); |
| 965 | |
} |
| 966 | |
|
| 967 | 0 | return affectedReferences; |
| 968 | |
} |
| 969 | |
|
| 970 | |
protected boolean isRelationshipRefreshable(Class boClass, String relationshipName) { |
| 971 | 0 | if (getPersistenceStructureService().isPersistable(boClass)) { |
| 972 | 0 | if (getPersistenceStructureService().hasCollection(boClass, relationshipName)) { |
| 973 | 0 | return !getPersistenceStructureService().isCollectionUpdatable(boClass, relationshipName); |
| 974 | 0 | } else if (getPersistenceStructureService().hasReference(boClass, relationshipName)) { |
| 975 | 0 | return !getPersistenceStructureService().isReferenceUpdatable(boClass, relationshipName); |
| 976 | |
} |
| 977 | |
|
| 978 | |
} |
| 979 | |
|
| 980 | 0 | return true; |
| 981 | |
} |
| 982 | |
|
| 983 | |
protected Collection<String> generateAllAffectedReferences(Class boClass, |
| 984 | |
Map<String, String> fkToPkMappings, String nestedBOPrefix, String collectionPrefix) { |
| 985 | 0 | Set<String> allAffectedReferences = new HashSet<String>(); |
| 986 | 0 | DataDictionaryService dataDictionaryService = getDataDictionaryService(); |
| 987 | 0 | PersistenceStructureService pss = getPersistenceStructureService(); |
| 988 | |
|
| 989 | 0 | collectionPrefix = StringUtils.isBlank(collectionPrefix) ? "" : collectionPrefix; |
| 990 | |
|
| 991 | |
|
| 992 | 0 | Collection<String> attributeReferenceFKAttributes = fkToPkMappings.keySet(); |
| 993 | |
|
| 994 | |
|
| 995 | |
|
| 996 | |
|
| 997 | |
|
| 998 | 0 | for (String fkAttribute : attributeReferenceFKAttributes) { |
| 999 | 0 | for (String affectedReference : pss.getReferencesForForeignKey(boClass, fkAttribute).keySet()) { |
| 1000 | 0 | if (isRelationshipRefreshable(boClass, affectedReference)) { |
| 1001 | 0 | if (StringUtils.isBlank(nestedBOPrefix)) { |
| 1002 | 0 | allAffectedReferences.add(collectionPrefix + affectedReference); |
| 1003 | |
} else { |
| 1004 | 0 | allAffectedReferences.add(collectionPrefix + nestedBOPrefix + "." + affectedReference); |
| 1005 | |
} |
| 1006 | |
} |
| 1007 | |
} |
| 1008 | |
} |
| 1009 | |
|
| 1010 | |
|
| 1011 | 0 | for (String collectionName : pss.listCollectionObjectTypes(boClass).keySet()) { |
| 1012 | 0 | if (isRelationshipRefreshable(boClass, collectionName)) { |
| 1013 | 0 | Map<String, String> keyMappingsForCollection = pss.getInverseForeignKeysForCollection(boClass, collectionName); |
| 1014 | 0 | for (String collectionForeignKey : keyMappingsForCollection.keySet()) { |
| 1015 | 0 | if (attributeReferenceFKAttributes.contains(collectionForeignKey)) { |
| 1016 | 0 | if (StringUtils.isBlank(nestedBOPrefix)) { |
| 1017 | 0 | allAffectedReferences.add(collectionPrefix + collectionName); |
| 1018 | |
} else { |
| 1019 | 0 | allAffectedReferences.add(collectionPrefix + nestedBOPrefix + "." + collectionName); |
| 1020 | |
} |
| 1021 | |
} |
| 1022 | |
} |
| 1023 | 0 | } |
| 1024 | |
} |
| 1025 | |
|
| 1026 | |
|
| 1027 | 0 | List<String> ddDefinedRelationships = dataDictionaryService.getRelationshipNames(boClass.getName()); |
| 1028 | 0 | for (String ddRelationship : ddDefinedRelationships) { |
| 1029 | |
|
| 1030 | 0 | Map<String, String> referencePKtoFKmappings = dataDictionaryService.getRelationshipAttributeMap(boClass.getName(), ddRelationship); |
| 1031 | 0 | for (String sourceAttribute : referencePKtoFKmappings.values()) { |
| 1032 | |
|
| 1033 | 0 | if (attributeReferenceFKAttributes.contains(sourceAttribute)) { |
| 1034 | 0 | for (String affectedReference : dataDictionaryService.getRelationshipEntriesForSourceAttribute(boClass.getName(), sourceAttribute)) { |
| 1035 | 0 | if (isRelationshipRefreshable(boClass, ddRelationship)) { |
| 1036 | 0 | if (StringUtils.isBlank(nestedBOPrefix)) { |
| 1037 | 0 | allAffectedReferences.add(affectedReference); |
| 1038 | |
} else { |
| 1039 | 0 | allAffectedReferences.add(nestedBOPrefix + "." + affectedReference); |
| 1040 | |
} |
| 1041 | |
} |
| 1042 | |
} |
| 1043 | |
} |
| 1044 | |
} |
| 1045 | 0 | } |
| 1046 | 0 | return allAffectedReferences; |
| 1047 | |
} |
| 1048 | |
|
| 1049 | |
protected Collection<String> getAllRefreshableReferences(Class boClass) { |
| 1050 | 0 | HashSet<String> references = new HashSet<String>(); |
| 1051 | 0 | for (String referenceName : getPersistenceStructureService().listReferenceObjectFields(boClass).keySet()) { |
| 1052 | 0 | if (isRelationshipRefreshable(boClass, referenceName)) { |
| 1053 | 0 | references.add(referenceName); |
| 1054 | |
} |
| 1055 | |
} |
| 1056 | 0 | for (String collectionName : getPersistenceStructureService().listCollectionObjectTypes(boClass).keySet()) { |
| 1057 | 0 | if (isRelationshipRefreshable(boClass, collectionName)) { |
| 1058 | 0 | references.add(collectionName); |
| 1059 | |
} |
| 1060 | |
} |
| 1061 | 0 | for (String relationshipName : getDataDictionaryService().getRelationshipNames(boClass.getName())) { |
| 1062 | 0 | if (isRelationshipRefreshable(boClass, relationshipName)) { |
| 1063 | 0 | references.add(relationshipName); |
| 1064 | |
} |
| 1065 | |
} |
| 1066 | 0 | return references; |
| 1067 | |
} |
| 1068 | |
|
| 1069 | |
protected void setNewCollectionLineDefaultValues(String collectionName, PersistableBusinessObject addLine) { |
| 1070 | 0 | PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(addLine); |
| 1071 | 0 | for (int i = 0; i < descriptors.length; ++i) { |
| 1072 | 0 | PropertyDescriptor propertyDescriptor = descriptors[i]; |
| 1073 | |
|
| 1074 | 0 | String fieldName = propertyDescriptor.getName(); |
| 1075 | 0 | Class propertyType = propertyDescriptor.getPropertyType(); |
| 1076 | 0 | String value = getMaintenanceDocumentDictionaryService().getCollectionFieldDefaultValue(docTypeName, collectionName, fieldName); |
| 1077 | |
|
| 1078 | 0 | if (value != null) { |
| 1079 | |
try { |
| 1080 | 0 | ObjectUtils.setObjectProperty(addLine, fieldName, propertyType, value); |
| 1081 | 0 | } catch (Exception ex) { |
| 1082 | 0 | LOG.error("Unable to set default property of collection object: " |
| 1083 | |
+ "\nobject: " |
| 1084 | |
+ addLine |
| 1085 | |
+ "\nfieldName=" + fieldName |
| 1086 | |
+ "\npropertyType=" + propertyType |
| 1087 | |
+ "\nvalue=" + value, ex); |
| 1088 | 0 | } |
| 1089 | |
} |
| 1090 | |
|
| 1091 | |
} |
| 1092 | 0 | } |
| 1093 | |
|
| 1094 | |
public void doRouteStatusChange(DocumentHeader documentHeader) { |
| 1095 | 0 | } |
| 1096 | |
|
| 1097 | |
public List<Long> getWorkflowEngineDocumentIdsToLock() { |
| 1098 | 0 | return null; |
| 1099 | |
} |
| 1100 | |
|
| 1101 | |
public static PersistenceStructureService getPersistenceStructureService() { |
| 1102 | 0 | if (persistenceStructureService == null) { |
| 1103 | 0 | persistenceStructureService = KNSServiceLocator.getPersistenceStructureService(); |
| 1104 | |
} |
| 1105 | 0 | return persistenceStructureService; |
| 1106 | |
} |
| 1107 | |
|
| 1108 | |
public static MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
| 1109 | 0 | if (maintenanceDocumentDictionaryService == null) { |
| 1110 | 0 | maintenanceDocumentDictionaryService = KNSServiceLocatorWeb.getMaintenanceDocumentDictionaryService(); |
| 1111 | |
} |
| 1112 | 0 | return maintenanceDocumentDictionaryService; |
| 1113 | |
} |
| 1114 | |
|
| 1115 | |
public static DataDictionaryService getDataDictionaryService() { |
| 1116 | 0 | if (dataDictionaryService == null) { |
| 1117 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
| 1118 | |
} |
| 1119 | 0 | return dataDictionaryService; |
| 1120 | |
} |
| 1121 | |
|
| 1122 | |
public static BusinessObjectService getBusinessObjectService() { |
| 1123 | 0 | if (businessObjectService == null) { |
| 1124 | 0 | businessObjectService = KNSServiceLocator.getBusinessObjectService(); |
| 1125 | |
} |
| 1126 | 0 | return businessObjectService; |
| 1127 | |
} |
| 1128 | |
|
| 1129 | |
public static BusinessObjectDictionaryService getBusinessObjectDictionaryService() { |
| 1130 | 0 | if (businessObjectDictionaryService == null) { |
| 1131 | 0 | businessObjectDictionaryService = KNSServiceLocatorWeb.getBusinessObjectDictionaryService(); |
| 1132 | |
} |
| 1133 | 0 | return businessObjectDictionaryService; |
| 1134 | |
} |
| 1135 | |
|
| 1136 | |
public static EncryptionService getEncryptionService() { |
| 1137 | 0 | if (encryptionService == null) { |
| 1138 | 0 | encryptionService = CoreApiServiceLocator.getEncryptionService(); |
| 1139 | |
} |
| 1140 | 0 | return encryptionService; |
| 1141 | |
} |
| 1142 | |
|
| 1143 | |
public static org.kuali.rice.kim.service.PersonService getPersonService() { |
| 1144 | 0 | if (personService == null) { |
| 1145 | 0 | personService = KIMServiceLocator.getPersonService(); |
| 1146 | |
} |
| 1147 | 0 | return personService; |
| 1148 | |
} |
| 1149 | |
|
| 1150 | |
public static BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
| 1151 | 0 | if (businessObjectMetaDataService == null) { |
| 1152 | 0 | businessObjectMetaDataService = KNSServiceLocatorWeb.getBusinessObjectMetaDataService(); |
| 1153 | |
} |
| 1154 | 0 | return businessObjectMetaDataService; |
| 1155 | |
} |
| 1156 | |
|
| 1157 | |
public static BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
| 1158 | 0 | if (businessObjectAuthorizationService == null) { |
| 1159 | 0 | businessObjectAuthorizationService = KNSServiceLocatorWeb.getBusinessObjectAuthorizationService(); |
| 1160 | |
} |
| 1161 | 0 | return businessObjectAuthorizationService; |
| 1162 | |
} |
| 1163 | |
|
| 1164 | |
public static MaintenanceDocumentService getMaintenanceDocumentService() { |
| 1165 | 0 | if (maintenanceDocumentService == null) { |
| 1166 | 0 | maintenanceDocumentService = KNSServiceLocatorWeb.getMaintenanceDocumentService(); |
| 1167 | |
} |
| 1168 | 0 | return maintenanceDocumentService; |
| 1169 | |
} |
| 1170 | |
|
| 1171 | |
public static DocumentHelperService getDocumentHelperService() { |
| 1172 | 0 | if (documentHelperService == null) { |
| 1173 | 0 | documentHelperService = KNSServiceLocatorWeb.getDocumentHelperService(); |
| 1174 | |
} |
| 1175 | 0 | return documentHelperService; |
| 1176 | |
} |
| 1177 | |
|
| 1178 | |
|
| 1179 | |
|
| 1180 | |
|
| 1181 | |
public void clearBusinessObjectOfRestrictedValues(MaintenanceDocumentRestrictions maintenanceDocumentRestrictions) { |
| 1182 | 0 | List<MaintainableSectionDefinition> sections = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 1183 | 0 | for (MaintainableSectionDefinition sectionDefinition : sections) { |
| 1184 | 0 | for (MaintainableItemDefinition itemDefinition : sectionDefinition.getMaintainableItems()) { |
| 1185 | 0 | if (itemDefinition instanceof MaintainableFieldDefinition) { |
| 1186 | 0 | clearFieldRestrictedValues("", businessObject, (MaintainableFieldDefinition) itemDefinition, maintenanceDocumentRestrictions); |
| 1187 | 0 | } else if (itemDefinition instanceof MaintainableCollectionDefinition) { |
| 1188 | 0 | clearCollectionRestrictedValues("", businessObject, (MaintainableCollectionDefinition) itemDefinition, maintenanceDocumentRestrictions); |
| 1189 | |
} |
| 1190 | |
} |
| 1191 | |
} |
| 1192 | 0 | } |
| 1193 | |
|
| 1194 | |
protected void clearCollectionRestrictedValues(String fieldNamePrefix, BusinessObject businessObject, MaintainableCollectionDefinition collectionDefinition, MaintenanceDocumentRestrictions maintenanceDocumentRestrictions) { |
| 1195 | 0 | String collectionName = fieldNamePrefix + collectionDefinition.getName(); |
| 1196 | 0 | Collection<BusinessObject> collection = (Collection<BusinessObject>) ObjectUtils.getPropertyValue(businessObject, collectionDefinition.getName()); |
| 1197 | |
|
| 1198 | 0 | if (collection != null) { |
| 1199 | 0 | int i = 0; |
| 1200 | |
|
| 1201 | 0 | for (BusinessObject collectionItem : collection) { |
| 1202 | 0 | String collectionItemNamePrefix = collectionName + "[" + i + "]."; |
| 1203 | 0 | for (MaintainableCollectionDefinition subCollectionDefinition : collectionDefinition.getMaintainableCollections()) { |
| 1204 | 0 | clearCollectionRestrictedValues(collectionItemNamePrefix, collectionItem, subCollectionDefinition, maintenanceDocumentRestrictions); |
| 1205 | |
} |
| 1206 | 0 | for (MaintainableFieldDefinition fieldDefinition : collectionDefinition.getMaintainableFields()) { |
| 1207 | 0 | clearFieldRestrictedValues(collectionItemNamePrefix, collectionItem, fieldDefinition, maintenanceDocumentRestrictions); |
| 1208 | |
} |
| 1209 | 0 | i++; |
| 1210 | 0 | } |
| 1211 | |
} |
| 1212 | 0 | } |
| 1213 | |
|
| 1214 | |
protected void clearFieldRestrictedValues(String fieldNamePrefix, BusinessObject businessObject, MaintainableFieldDefinition fieldDefinition, MaintenanceDocumentRestrictions maintenanceDocumentRestrictions) { |
| 1215 | 0 | String fieldName = fieldNamePrefix + fieldDefinition.getName(); |
| 1216 | |
|
| 1217 | 0 | FieldRestriction fieldRestriction = maintenanceDocumentRestrictions.getFieldRestriction(fieldName); |
| 1218 | 0 | if (fieldRestriction.isRestricted()) { |
| 1219 | 0 | String defaultValue = null; |
| 1220 | 0 | if (StringUtils.isNotBlank(fieldDefinition.getDefaultValue())) { |
| 1221 | 0 | defaultValue = fieldDefinition.getDefaultValue(); |
| 1222 | 0 | } else if (fieldDefinition.getDefaultValueFinderClass() != null) { |
| 1223 | |
try { |
| 1224 | 0 | defaultValue = ((ValueFinder) fieldDefinition.getDefaultValueFinderClass().newInstance()).getValue(); |
| 1225 | 0 | } catch (Exception e) { |
| 1226 | 0 | defaultValue = null; |
| 1227 | 0 | LOG.error("Error trying to instantiate ValueFinder or to determine ValueFinder for doc type: " + docTypeName + " field name " + fieldDefinition.getName() + " with field prefix: " + fieldNamePrefix, e); |
| 1228 | 0 | } |
| 1229 | |
} |
| 1230 | |
try { |
| 1231 | 0 | ObjectUtils.setObjectProperty(businessObject, fieldDefinition.getName(), defaultValue); |
| 1232 | 0 | } catch (Exception e) { |
| 1233 | |
|
| 1234 | 0 | LOG.error("Unable to clear maintenance document values for field name: " + fieldName + " default value: " + defaultValue, e); |
| 1235 | 0 | throw new RuntimeException("Unable to clear maintenance document values for field name: " + fieldName, e); |
| 1236 | 0 | } |
| 1237 | |
} |
| 1238 | 0 | } |
| 1239 | |
|
| 1240 | |
protected void performForceUpperCase(Map fieldValues) { |
| 1241 | 0 | List<MaintainableSectionDefinition> sections = getMaintenanceDocumentDictionaryService().getMaintainableSections(docTypeName); |
| 1242 | 0 | for (MaintainableSectionDefinition sectionDefinition : sections) { |
| 1243 | 0 | for (MaintainableItemDefinition itemDefinition : sectionDefinition.getMaintainableItems()) { |
| 1244 | 0 | if (itemDefinition instanceof MaintainableFieldDefinition) { |
| 1245 | 0 | performFieldForceUpperCase("", businessObject, (MaintainableFieldDefinition) itemDefinition, fieldValues); |
| 1246 | 0 | } else if (itemDefinition instanceof MaintainableCollectionDefinition) { |
| 1247 | 0 | performCollectionForceUpperCase("", businessObject, (MaintainableCollectionDefinition) itemDefinition, fieldValues); |
| 1248 | |
|
| 1249 | |
} |
| 1250 | |
} |
| 1251 | |
} |
| 1252 | 0 | } |
| 1253 | |
|
| 1254 | |
protected void performFieldForceUpperCase(String fieldNamePrefix, BusinessObject bo, MaintainableFieldDefinition fieldDefinition, Map fieldValues) { |
| 1255 | 0 | MessageMap errorMap = GlobalVariables.getMessageMap(); |
| 1256 | 0 | String fieldName = fieldDefinition.getName(); |
| 1257 | 0 | String mapKey = fieldNamePrefix + fieldName; |
| 1258 | 0 | if (fieldValues != null && fieldValues.get(mapKey) != null) { |
| 1259 | 0 | if (PropertyUtils.isWriteable(bo, fieldName) && ObjectUtils.getNestedValue(bo, fieldName) != null) { |
| 1260 | |
|
| 1261 | |
try { |
| 1262 | 0 | Class type = ObjectUtils.easyGetPropertyType(bo, fieldName); |
| 1263 | |
|
| 1264 | 0 | Class businessObjectClass = bo.getClass(); |
| 1265 | 0 | boolean upperCase = false; |
| 1266 | |
try { |
| 1267 | 0 | upperCase = getDataDictionaryService().getAttributeForceUppercase(businessObjectClass, fieldName); |
| 1268 | 0 | } catch (UnknownBusinessClassAttributeException t) { |
| 1269 | 0 | boolean catchme = true; |
| 1270 | |
|
| 1271 | 0 | } |
| 1272 | |
|
| 1273 | 0 | Object fieldValue = ObjectUtils.getNestedValue(bo, fieldName); |
| 1274 | |
|
| 1275 | 0 | if (upperCase && fieldValue instanceof String) { |
| 1276 | 0 | fieldValue = ((String) fieldValue).toUpperCase(); |
| 1277 | |
} |
| 1278 | 0 | ObjectUtils.setObjectProperty(bo, fieldName, type, fieldValue); |
| 1279 | 0 | } catch (FormatException e) { |
| 1280 | 0 | errorMap.putError(fieldName, e.getErrorKey(), e.getErrorArgs()); |
| 1281 | 0 | } catch (IllegalAccessException e) { |
| 1282 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1283 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1284 | 0 | } catch (InvocationTargetException e) { |
| 1285 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1286 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1287 | 0 | } catch (NoSuchMethodException e) { |
| 1288 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1289 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1290 | 0 | } |
| 1291 | |
} |
| 1292 | |
} |
| 1293 | 0 | } |
| 1294 | |
|
| 1295 | |
protected void performCollectionForceUpperCase(String fieldNamePrefix, BusinessObject bo, MaintainableCollectionDefinition collectionDefinition, Map fieldValues) { |
| 1296 | 0 | String collectionName = fieldNamePrefix + collectionDefinition.getName(); |
| 1297 | 0 | Collection<BusinessObject> collection = (Collection<BusinessObject>) ObjectUtils.getPropertyValue(bo, collectionDefinition.getName()); |
| 1298 | 0 | if (collection != null) { |
| 1299 | 0 | int i = 0; |
| 1300 | |
|
| 1301 | 0 | for (BusinessObject collectionItem : collection) { |
| 1302 | 0 | String collectionItemNamePrefix = collectionName + "[" + i + "]."; |
| 1303 | |
|
| 1304 | 0 | for (MaintainableFieldDefinition fieldDefinition : collectionDefinition.getMaintainableFields()) { |
| 1305 | 0 | performFieldForceUpperCase(collectionItemNamePrefix, collectionItem, fieldDefinition, fieldValues); |
| 1306 | |
} |
| 1307 | 0 | for (MaintainableCollectionDefinition subCollectionDefinition : collectionDefinition.getMaintainableCollections()) { |
| 1308 | 0 | performCollectionForceUpperCase(collectionItemNamePrefix, collectionItem, subCollectionDefinition, fieldValues); |
| 1309 | |
} |
| 1310 | 0 | i++; |
| 1311 | 0 | } |
| 1312 | |
} |
| 1313 | 0 | } |
| 1314 | |
|
| 1315 | |
protected void performFieldForceUpperCase(BusinessObject bo, Map fieldValues) { |
| 1316 | 0 | MessageMap errorMap = GlobalVariables.getMessageMap(); |
| 1317 | |
|
| 1318 | |
try { |
| 1319 | 0 | for (Iterator iter = fieldValues.keySet().iterator(); iter.hasNext();) { |
| 1320 | 0 | String propertyName = (String) iter.next(); |
| 1321 | |
|
| 1322 | 0 | if (PropertyUtils.isWriteable(bo, propertyName) && fieldValues.get(propertyName) != null) { |
| 1323 | |
|
| 1324 | 0 | Class type = ObjectUtils.easyGetPropertyType(bo, propertyName); |
| 1325 | |
try { |
| 1326 | |
|
| 1327 | |
|
| 1328 | 0 | Class businessObjectClass = bo.getClass(); |
| 1329 | 0 | boolean upperCase = false; |
| 1330 | |
try { |
| 1331 | 0 | upperCase = getDataDictionaryService().getAttributeForceUppercase(businessObjectClass, propertyName); |
| 1332 | 0 | } catch (UnknownBusinessClassAttributeException t) { |
| 1333 | 0 | boolean catchme = true; |
| 1334 | |
|
| 1335 | 0 | } |
| 1336 | |
|
| 1337 | 0 | Object fieldValue = fieldValues.get(propertyName); |
| 1338 | |
|
| 1339 | 0 | if (upperCase && fieldValue instanceof String) { |
| 1340 | 0 | fieldValue = ((String) fieldValue).toUpperCase(); |
| 1341 | |
} |
| 1342 | 0 | ObjectUtils.setObjectProperty(bo, propertyName, type, fieldValue); |
| 1343 | 0 | } catch (FormatException e) { |
| 1344 | 0 | errorMap.putError(propertyName, e.getErrorKey(), e.getErrorArgs()); |
| 1345 | 0 | } |
| 1346 | |
} |
| 1347 | 0 | } |
| 1348 | 0 | } catch (IllegalAccessException e) { |
| 1349 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1350 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1351 | 0 | } catch (InvocationTargetException e) { |
| 1352 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1353 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1354 | 0 | } catch (NoSuchMethodException e) { |
| 1355 | 0 | LOG.error("unable to populate business object" + e.getMessage()); |
| 1356 | 0 | throw new RuntimeException(e.getMessage(), e); |
| 1357 | 0 | } |
| 1358 | |
|
| 1359 | 0 | } |
| 1360 | |
|
| 1361 | |
|
| 1362 | |
|
| 1363 | |
|
| 1364 | |
|
| 1365 | |
|
| 1366 | |
|
| 1367 | |
public boolean isExternalBusinessObject() { |
| 1368 | 0 | return false; |
| 1369 | |
} |
| 1370 | |
|
| 1371 | |
|
| 1372 | |
|
| 1373 | |
|
| 1374 | |
public void prepareBusinessObject(BusinessObject businessObject) { |
| 1375 | |
|
| 1376 | 0 | } |
| 1377 | |
|
| 1378 | |
|
| 1379 | |
|
| 1380 | |
|
| 1381 | |
public String getLockingDocumentId() { |
| 1382 | 0 | return getMaintenanceDocumentService().getLockingDocumentId(this, documentNumber); |
| 1383 | |
} |
| 1384 | |
|
| 1385 | |
|
| 1386 | |
|
| 1387 | |
|
| 1388 | |
|
| 1389 | |
|
| 1390 | |
|
| 1391 | |
public boolean useCustomLockDescriptors() { |
| 1392 | 0 | return false; |
| 1393 | |
} |
| 1394 | |
|
| 1395 | |
|
| 1396 | |
|
| 1397 | |
|
| 1398 | |
|
| 1399 | |
|
| 1400 | |
|
| 1401 | |
public String getCustomLockDescriptor(Person user) { |
| 1402 | 0 | throw new PessimisticLockingException("The Maintainable for document " + documentNumber + |
| 1403 | |
" is using pessimistic locking with custom lock descriptors, but the Maintainable has not overriden the getCustomLockDescriptor method"); |
| 1404 | |
} |
| 1405 | |
|
| 1406 | |
|
| 1407 | |
public void deleteBusinessObject() { |
| 1408 | 0 | if (businessObject == null) |
| 1409 | 0 | return; |
| 1410 | |
|
| 1411 | 0 | KNSServiceLocator.getBusinessObjectService().delete(businessObject); |
| 1412 | 0 | businessObject = null; |
| 1413 | 0 | } |
| 1414 | |
|
| 1415 | |
public boolean isOldBusinessObjectInDocument() { |
| 1416 | 0 | boolean isOldBusinessObjectInExistence = false; |
| 1417 | 0 | if (getBusinessObject() == null) { |
| 1418 | 0 | isOldBusinessObjectInExistence = false; |
| 1419 | |
} else { |
| 1420 | 0 | if (KNSServiceLocator.getPersistenceStructureService().isPersistable(getBusinessObject().getClass())) { |
| 1421 | 0 | isOldBusinessObjectInExistence = KNSServiceLocator.getPersistenceStructureService().hasPrimaryKeyFieldValues(getBusinessObject()); |
| 1422 | |
} |
| 1423 | |
} |
| 1424 | 0 | return isOldBusinessObjectInExistence; |
| 1425 | |
|
| 1426 | |
} |
| 1427 | |
} |