| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.krad.maintenance.rules; |
| 18 | |
|
| 19 | |
import java.security.GeneralSecurityException; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.Collection; |
| 22 | |
import java.util.Iterator; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.Map; |
| 25 | |
import java.util.Properties; |
| 26 | |
import java.util.Set; |
| 27 | |
|
| 28 | |
import org.apache.commons.collections.CollectionUtils; |
| 29 | |
import org.apache.commons.lang.StringUtils; |
| 30 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 31 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 32 | |
import org.kuali.rice.core.api.datetime.DateTimeService; |
| 33 | |
import org.kuali.rice.core.util.RiceKeyConstants; |
| 34 | |
import org.kuali.rice.core.web.format.Formatter; |
| 35 | |
import org.kuali.rice.kew.api.WorkflowDocument; |
| 36 | |
import org.kuali.rice.kim.api.role.RoleService; |
| 37 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
| 38 | |
import org.kuali.rice.krad.bo.BusinessObject; |
| 39 | |
import org.kuali.rice.krad.bo.GlobalBusinessObject; |
| 40 | |
import org.kuali.rice.krad.bo.Inactivatable; |
| 41 | |
import org.kuali.rice.krad.bo.PersistableBusinessObject; |
| 42 | |
import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata; |
| 43 | |
import org.kuali.rice.krad.document.Document; |
| 44 | |
import org.kuali.rice.krad.document.MaintenanceDocument; |
| 45 | |
import org.kuali.rice.krad.document.authorization.MaintenanceDocumentAuthorizer; |
| 46 | |
import org.kuali.rice.krad.exception.ValidationException; |
| 47 | |
import org.kuali.rice.krad.maintenance.Maintainable; |
| 48 | |
import org.kuali.rice.krad.rule.AddCollectionLineRule; |
| 49 | |
import org.kuali.rice.krad.rule.event.ApproveDocumentEvent; |
| 50 | |
import org.kuali.rice.krad.rules.DocumentRuleBase; |
| 51 | |
import org.kuali.rice.krad.rules.MaintenanceDocumentRule; |
| 52 | |
import org.kuali.rice.krad.service.BusinessObjectAuthorizationService; |
| 53 | |
import org.kuali.rice.krad.service.BusinessObjectDictionaryService; |
| 54 | |
import org.kuali.rice.krad.service.BusinessObjectMetaDataService; |
| 55 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
| 56 | |
import org.kuali.rice.krad.service.DataDictionaryService; |
| 57 | |
import org.kuali.rice.krad.service.DictionaryValidationService; |
| 58 | |
import org.kuali.rice.krad.service.DocumentHelperService; |
| 59 | |
import org.kuali.rice.krad.service.InactivationBlockingDetectionService; |
| 60 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 61 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
| 62 | |
import org.kuali.rice.krad.service.MaintenanceDocumentDictionaryService; |
| 63 | |
import org.kuali.rice.krad.service.PersistenceStructureService; |
| 64 | |
import org.kuali.rice.krad.util.ErrorMessage; |
| 65 | |
import org.kuali.rice.krad.util.ForeignKeyFieldsPopulationState; |
| 66 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 67 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 68 | |
import org.kuali.rice.krad.util.KRADPropertyConstants; |
| 69 | |
import org.kuali.rice.krad.util.MessageMap; |
| 70 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 71 | |
import org.kuali.rice.krad.util.UrlFactory; |
| 72 | |
import org.kuali.rice.krad.workflow.service.WorkflowDocumentService; |
| 73 | |
import org.springframework.util.AutoPopulatingList; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public class MaintenanceDocumentRuleBase extends DocumentRuleBase implements MaintenanceDocumentRule, AddCollectionLineRule { |
| 82 | 0 | protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentRuleBase.class); |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public static final String MAINTAINABLE_ERROR_PREFIX = KRADConstants.MAINTENANCE_NEW_MAINTAINABLE; |
| 89 | |
public static final String DOCUMENT_ERROR_PREFIX = "document."; |
| 90 | |
public static final String MAINTAINABLE_ERROR_PATH = DOCUMENT_ERROR_PREFIX + "newMaintainableObject"; |
| 91 | |
|
| 92 | |
protected PersistenceStructureService persistenceStructureService; |
| 93 | |
protected BusinessObjectMetaDataService businessObjectMetaDataService; |
| 94 | |
protected DataDictionaryService ddService; |
| 95 | |
protected DocumentHelperService documentHelperService; |
| 96 | |
protected BusinessObjectService boService; |
| 97 | |
protected BusinessObjectDictionaryService boDictionaryService; |
| 98 | |
protected DictionaryValidationService dictionaryValidationService; |
| 99 | |
protected ConfigurationService configService; |
| 100 | |
protected MaintenanceDocumentDictionaryService maintDocDictionaryService; |
| 101 | |
protected WorkflowDocumentService workflowDocumentService; |
| 102 | |
protected org.kuali.rice.kim.service.PersonService personService; |
| 103 | |
protected RoleService roleService; |
| 104 | |
protected BusinessObjectAuthorizationService businessObjectAuthorizationService; |
| 105 | |
|
| 106 | |
private Object oldBo; |
| 107 | |
private Object newBo; |
| 108 | |
private Class boClass; |
| 109 | |
|
| 110 | |
protected List priorErrorPath; |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 0 | public MaintenanceDocumentRuleBase() { |
| 118 | |
|
| 119 | 0 | priorErrorPath = new ArrayList(); |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
try { |
| 128 | 0 | this.setPersistenceStructureService(KRADServiceLocator.getPersistenceStructureService()); |
| 129 | 0 | this.setDdService(KRADServiceLocatorWeb.getDataDictionaryService()); |
| 130 | 0 | this.setBusinessObjectMetaDataService(KRADServiceLocatorWeb.getBusinessObjectMetaDataService()); |
| 131 | 0 | this.setBoService(KRADServiceLocator.getBusinessObjectService()); |
| 132 | 0 | this.setBoDictionaryService(KRADServiceLocatorWeb.getBusinessObjectDictionaryService()); |
| 133 | 0 | this.setDictionaryValidationService(KRADServiceLocatorWeb.getDictionaryValidationService()); |
| 134 | 0 | this.setConfigService(KRADServiceLocator.getKualiConfigurationService()); |
| 135 | 0 | this.setDocumentHelperService(KRADServiceLocatorWeb.getDocumentHelperService()); |
| 136 | 0 | this.setMaintDocDictionaryService(KRADServiceLocatorWeb.getMaintenanceDocumentDictionaryService()); |
| 137 | 0 | this.setWorkflowDocumentService(KRADServiceLocatorWeb.getWorkflowDocumentService()); |
| 138 | 0 | this.setPersonService( KimApiServiceLocator.getPersonService() ); |
| 139 | 0 | this.setBusinessObjectAuthorizationService(KRADServiceLocatorWeb.getBusinessObjectAuthorizationService()); |
| 140 | 0 | } catch ( Exception ex ) { |
| 141 | |
|
| 142 | 0 | } |
| 143 | 0 | } |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
@Override |
| 149 | |
public boolean processSaveDocument(Document document) { |
| 150 | |
|
| 151 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document; |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | 0 | clearErrorPath(); |
| 156 | |
|
| 157 | |
|
| 158 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | 0 | if (!isDocumentValidForSave(maintenanceDocument)) { |
| 165 | 0 | resumeErrorPath(); |
| 166 | 0 | return false; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | 0 | processCustomSaveDocumentBusinessRules(maintenanceDocument); |
| 173 | |
|
| 174 | |
|
| 175 | 0 | resumeErrorPath(); |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | 0 | return true; |
| 180 | |
} |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
@Override |
| 186 | |
public boolean processRouteDocument(Document document) { |
| 187 | 0 | LOG.info("processRouteDocument called"); |
| 188 | |
|
| 189 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document; |
| 190 | |
|
| 191 | |
|
| 192 | 0 | MaintenanceDocumentAuthorizer documentAuthorizer = (MaintenanceDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(document); |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | 0 | clearErrorPath(); |
| 197 | |
|
| 198 | |
|
| 199 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
| 200 | |
|
| 201 | |
|
| 202 | 0 | processGlobalSaveDocumentBusinessRules(maintenanceDocument); |
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | 0 | boolean success = true; |
| 207 | |
|
| 208 | 0 | WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); |
| 209 | 0 | if (workflowDocument.isInitiated() || workflowDocument.isSaved()){ |
| 210 | 0 | success &= documentAuthorizer.canCreateOrMaintain((MaintenanceDocument)document, GlobalVariables.getUserSession().getPerson()); |
| 211 | 0 | if (success == false) { |
| 212 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.DOCUMENT_ERRORS, RiceKeyConstants.AUTHORIZATION_ERROR_DOCUMENT, new String[]{GlobalVariables.getUserSession().getPerson().getPrincipalName(), "Create/Maintain", this.getMaintDocDictionaryService().getDocumentTypeName(newBo.getClass())}); |
| 213 | |
} |
| 214 | |
} |
| 215 | |
|
| 216 | 0 | success &= processGlobalRouteDocumentBusinessRules(maintenanceDocument); |
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | 0 | success &= processCustomRouteDocumentBusinessRules(maintenanceDocument); |
| 222 | |
|
| 223 | 0 | success &= processInactivationBlockChecking(maintenanceDocument); |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | 0 | resumeErrorPath(); |
| 228 | |
|
| 229 | 0 | return success; |
| 230 | |
} |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
protected boolean isDocumentInactivatingBusinessObject(MaintenanceDocument maintenanceDocument) { |
| 239 | 0 | if (maintenanceDocument.isEdit()) { |
| 240 | 0 | Class boClass = maintenanceDocument.getNewMaintainableObject().getBoClass(); |
| 241 | |
|
| 242 | 0 | if (boClass != null && Inactivatable.class.isAssignableFrom(boClass)) { |
| 243 | 0 | Inactivatable oldInactivateableBO = (Inactivatable) oldBo; |
| 244 | 0 | Inactivatable newInactivateableBO = (Inactivatable) newBo; |
| 245 | |
|
| 246 | 0 | return oldInactivateableBO.isActive() && !newInactivateableBO.isActive(); |
| 247 | |
} |
| 248 | |
} |
| 249 | 0 | return false; |
| 250 | |
} |
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument) { |
| 259 | 0 | if (isDocumentInactivatingBusinessObject(maintenanceDocument)) { |
| 260 | 0 | Class boClass = maintenanceDocument.getNewMaintainableObject().getBoClass(); |
| 261 | 0 | Set<InactivationBlockingMetadata> inactivationBlockingMetadatas = ddService.getAllInactivationBlockingDefinitions(boClass); |
| 262 | |
|
| 263 | 0 | if (inactivationBlockingMetadatas != null) { |
| 264 | 0 | for (InactivationBlockingMetadata inactivationBlockingMetadata : inactivationBlockingMetadatas) { |
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | 0 | if (!processInactivationBlockChecking(maintenanceDocument, inactivationBlockingMetadata)) { |
| 269 | 0 | return false; |
| 270 | |
} |
| 271 | |
} |
| 272 | |
} |
| 273 | |
} |
| 274 | 0 | return true; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
protected boolean processInactivationBlockChecking(MaintenanceDocument maintenanceDocument, InactivationBlockingMetadata inactivationBlockingMetadata) { |
| 286 | 0 | if(newBo instanceof PersistableBusinessObject) { |
| 287 | 0 | String inactivationBlockingDetectionServiceBeanName = inactivationBlockingMetadata.getInactivationBlockingDetectionServiceBeanName(); |
| 288 | 0 | if (StringUtils.isBlank(inactivationBlockingDetectionServiceBeanName)) { |
| 289 | 0 | inactivationBlockingDetectionServiceBeanName = KRADServiceLocatorWeb.DEFAULT_INACTIVATION_BLOCKING_DETECTION_SERVICE; |
| 290 | |
} |
| 291 | 0 | InactivationBlockingDetectionService inactivationBlockingDetectionService = KRADServiceLocatorWeb |
| 292 | |
.getInactivationBlockingDetectionService(inactivationBlockingDetectionServiceBeanName); |
| 293 | |
|
| 294 | 0 | boolean foundBlockingRecord = inactivationBlockingDetectionService.hasABlockingRecord((PersistableBusinessObject)newBo, inactivationBlockingMetadata); |
| 295 | |
|
| 296 | 0 | if (foundBlockingRecord) { |
| 297 | 0 | putInactivationBlockingErrorOnPage(maintenanceDocument, inactivationBlockingMetadata); |
| 298 | |
} |
| 299 | |
|
| 300 | 0 | return !foundBlockingRecord; |
| 301 | |
} |
| 302 | |
|
| 303 | 0 | return true; |
| 304 | |
} |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
protected void putInactivationBlockingErrorOnPage(MaintenanceDocument document, InactivationBlockingMetadata inactivationBlockingMetadata) { |
| 313 | 0 | if (!persistenceStructureService.hasPrimaryKeyFieldValues(newBo)) { |
| 314 | 0 | throw new RuntimeException("Maintenance document did not have all primary key values filled in."); |
| 315 | |
} |
| 316 | 0 | Properties parameters = new Properties(); |
| 317 | 0 | parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, inactivationBlockingMetadata.getBlockedBusinessObjectClass().getName()); |
| 318 | 0 | parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.METHOD_DISPLAY_ALL_INACTIVATION_BLOCKERS); |
| 319 | |
|
| 320 | 0 | List keys = new ArrayList(); |
| 321 | 0 | if (getPersistenceStructureService().isPersistable(newBo.getClass())) { |
| 322 | 0 | keys = getPersistenceStructureService().listPrimaryKeyFieldNames(newBo.getClass()); |
| 323 | |
} |
| 324 | |
|
| 325 | |
|
| 326 | 0 | String keyName = null; |
| 327 | 0 | for (Iterator iter = keys.iterator(); iter.hasNext();) { |
| 328 | 0 | keyName = (String) iter.next(); |
| 329 | |
|
| 330 | 0 | Object keyValue = null; |
| 331 | 0 | if (keyName != null) { |
| 332 | 0 | keyValue = ObjectUtils.getPropertyValue(newBo, keyName); |
| 333 | |
} |
| 334 | |
|
| 335 | 0 | if (keyValue == null) { |
| 336 | 0 | keyValue = ""; |
| 337 | 0 | } else if (keyValue instanceof java.sql.Date) { |
| 338 | 0 | if (Formatter.findFormatter(keyValue.getClass()) != null) { |
| 339 | 0 | Formatter formatter = Formatter.getFormatter(keyValue.getClass()); |
| 340 | 0 | keyValue = (String) formatter.format(keyValue); |
| 341 | 0 | } |
| 342 | |
} else { |
| 343 | 0 | keyValue = keyValue.toString(); |
| 344 | |
} |
| 345 | |
|
| 346 | |
|
| 347 | 0 | if (businessObjectAuthorizationService.attributeValueNeedsToBeEncryptedOnFormsAndLinks(inactivationBlockingMetadata.getBlockedBusinessObjectClass(), keyName)) { |
| 348 | |
try { |
| 349 | 0 | keyValue = CoreApiServiceLocator.getEncryptionService().encrypt(keyValue); |
| 350 | |
} |
| 351 | 0 | catch (GeneralSecurityException e) { |
| 352 | 0 | LOG.error("Exception while trying to encrypted value for inquiry framework.", e); |
| 353 | 0 | throw new RuntimeException(e); |
| 354 | 0 | } |
| 355 | |
} |
| 356 | |
|
| 357 | 0 | parameters.put(keyName, keyValue); |
| 358 | 0 | } |
| 359 | |
|
| 360 | 0 | String blockingUrl = UrlFactory.parameterizeUrl(KRADConstants.DISPLAY_ALL_INACTIVATION_BLOCKERS_ACTION, parameters); |
| 361 | |
|
| 362 | |
|
| 363 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_INACTIVATION_BLOCKED, blockingUrl); |
| 364 | 0 | } |
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
@Override |
| 370 | |
public boolean processApproveDocument(ApproveDocumentEvent approveEvent) { |
| 371 | |
|
| 372 | 0 | MaintenanceDocument maintenanceDocument = (MaintenanceDocument) approveEvent.getDocument(); |
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | 0 | clearErrorPath(); |
| 377 | |
|
| 378 | |
|
| 379 | 0 | setupBaseConvenienceObjects(maintenanceDocument); |
| 380 | |
|
| 381 | |
|
| 382 | 0 | processGlobalSaveDocumentBusinessRules(maintenanceDocument); |
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | 0 | boolean success = true; |
| 387 | |
|
| 388 | |
|
| 389 | 0 | success &= processGlobalApproveDocumentBusinessRules(maintenanceDocument); |
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | 0 | success &= processCustomApproveDocumentBusinessRules(maintenanceDocument); |
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | 0 | resumeErrorPath(); |
| 399 | |
|
| 400 | 0 | return success; |
| 401 | |
} |
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
protected void putGlobalError(String errorConstant) { |
| 412 | 0 | if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) { |
| 413 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant); |
| 414 | |
} |
| 415 | 0 | } |
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
protected void putGlobalError(String errorConstant, String parameter) { |
| 427 | 0 | if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) { |
| 428 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant, parameter); |
| 429 | |
} |
| 430 | 0 | } |
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
protected void putGlobalError(String errorConstant, String[] parameters) { |
| 442 | 0 | if (!errorAlreadyExists(KRADConstants.DOCUMENT_ERRORS, errorConstant)) { |
| 443 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.DOCUMENT_ERRORS, errorConstant, parameters); |
| 444 | |
} |
| 445 | 0 | } |
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
protected void putFieldError(String propertyName, String errorConstant) { |
| 458 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
| 459 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant); |
| 460 | |
} |
| 461 | 0 | } |
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
protected void putFieldError(String propertyName, String errorConstant, String parameter) { |
| 476 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
| 477 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameter); |
| 478 | |
} |
| 479 | 0 | } |
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
protected void putFieldError(String propertyName, String errorConstant, String[] parameters) { |
| 494 | 0 | if (!errorAlreadyExists(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant)) { |
| 495 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(MAINTAINABLE_ERROR_PREFIX + propertyName, errorConstant, parameters); |
| 496 | |
} |
| 497 | 0 | } |
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
protected void putFieldErrorWithShortLabel(String propertyName, String errorConstant) { |
| 507 | 0 | String shortLabel = ddService.getAttributeShortLabel(boClass, propertyName); |
| 508 | 0 | putFieldError(propertyName, errorConstant, shortLabel); |
| 509 | 0 | } |
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
protected void putDocumentError(String propertyName, String errorConstant, String parameter) { |
| 524 | 0 | if (!errorAlreadyExists(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant)) { |
| 525 | 0 | GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameter); |
| 526 | |
} |
| 527 | 0 | } |
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
protected void putDocumentError(String propertyName, String errorConstant, String[] parameters) { |
| 542 | 0 | GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + propertyName, errorConstant, parameters); |
| 543 | 0 | } |
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
protected boolean errorAlreadyExists(String propertyName, String errorConstant) { |
| 557 | |
|
| 558 | 0 | if (GlobalVariables.getMessageMap().fieldHasMessage(propertyName, errorConstant)) { |
| 559 | 0 | return true; |
| 560 | |
} |
| 561 | |
else { |
| 562 | 0 | return false; |
| 563 | |
} |
| 564 | |
} |
| 565 | |
|
| 566 | |
|
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
|
| 574 | |
protected void putGlobalsError(String propertyName, String errorConstant) { |
| 575 | 0 | if (!errorAlreadyExists(propertyName, errorConstant)) { |
| 576 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant); |
| 577 | |
} |
| 578 | 0 | } |
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
protected void putGlobalsError(String propertyName, String errorConstant, String parameter) { |
| 590 | 0 | if (!errorAlreadyExists(propertyName, errorConstant)) { |
| 591 | 0 | GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(propertyName, errorConstant, parameter); |
| 592 | |
} |
| 593 | 0 | } |
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
protected void clearErrorPath() { |
| 606 | |
|
| 607 | |
|
| 608 | 0 | priorErrorPath.addAll(GlobalVariables.getMessageMap().getErrorPath()); |
| 609 | |
|
| 610 | |
|
| 611 | 0 | GlobalVariables.getMessageMap().getErrorPath().clear(); |
| 612 | |
|
| 613 | 0 | } |
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
protected void resumeErrorPath() { |
| 625 | |
|
| 626 | |
|
| 627 | 0 | GlobalVariables.getMessageMap().getErrorPath().addAll(priorErrorPath); |
| 628 | 0 | } |
| 629 | |
|
| 630 | |
|
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
|
| 636 | |
|
| 637 | |
protected boolean dataDictionaryValidate(MaintenanceDocument document) { |
| 638 | 0 | LOG.debug("MaintenanceDocument validation beginning"); |
| 639 | |
|
| 640 | |
|
| 641 | |
|
| 642 | 0 | GlobalVariables.getMessageMap().addToErrorPath("document.newMaintainableObject"); |
| 643 | |
|
| 644 | |
|
| 645 | 0 | Maintainable newMaintainable = document.getNewMaintainableObject(); |
| 646 | 0 | if (newMaintainable == null) { |
| 647 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject"); |
| 648 | 0 | throw new ValidationException("Maintainable object from Maintenance Document '" |
| 649 | |
+ document.getDocumentTitle() + "' is null, unable to proceed."); |
| 650 | |
} |
| 651 | |
|
| 652 | |
|
| 653 | 0 | Object dataObject = newMaintainable.getDataObject(); |
| 654 | 0 | if (dataObject == null) { |
| 655 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject."); |
| 656 | 0 | throw new ValidationException("Maintainable's component business object is null."); |
| 657 | |
} |
| 658 | |
|
| 659 | |
|
| 660 | |
|
| 661 | 0 | if(newBo instanceof PersistableBusinessObject && |
| 662 | |
CollectionUtils.isNotEmpty(maintDocDictionaryService.getMaintainableSections(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()))) { |
| 663 | |
|
| 664 | 0 | BusinessObject businessObject = (BusinessObject)newBo; |
| 665 | |
|
| 666 | |
|
| 667 | 0 | maintDocDictionaryService.validateMaintenanceRequiredFields(document); |
| 668 | |
|
| 669 | |
|
| 670 | 0 | maintDocDictionaryService.validateMaintainableCollectionsForDuplicateEntries(document); |
| 671 | |
|
| 672 | |
|
| 673 | 0 | dictionaryValidationService.validateBusinessObjectOnMaintenanceDocument(businessObject, |
| 674 | |
document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 675 | |
|
| 676 | |
|
| 677 | 0 | dictionaryValidationService.validateDefaultExistenceChecks(businessObject); |
| 678 | 0 | } |
| 679 | |
else { |
| 680 | 0 | GlobalVariables.getMessageMap().addToErrorPath("dataObject"); |
| 681 | |
|
| 682 | 0 | dictionaryValidationService.validate(newBo); |
| 683 | |
|
| 684 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("dataObject"); |
| 685 | |
} |
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | 0 | GlobalVariables.getMessageMap().removeFromErrorPath("document.newMaintainableObject"); |
| 690 | |
|
| 691 | 0 | LOG.debug("MaintenanceDocument validation ending"); |
| 692 | 0 | return true; |
| 693 | |
} |
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
|
| 711 | |
protected boolean primaryKeyCheck(MaintenanceDocument document) { |
| 712 | |
|
| 713 | |
|
| 714 | 0 | boolean success = true; |
| 715 | 0 | Class<?> boClass = document.getNewMaintainableObject().getBoClass(); |
| 716 | |
|
| 717 | 0 | Object oldBo = document.getOldMaintainableObject().getDataObject(); |
| 718 | 0 | Object newBo = document.getNewMaintainableObject().getDataObject(); |
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | 0 | if (newBo instanceof GlobalBusinessObject) { |
| 726 | 0 | return success; |
| 727 | |
} |
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | 0 | if (document.isEdit()) { |
| 732 | 0 | if (!businessObjectMetaDataService.equalsByPrimaryKeys(oldBo, newBo)) { |
| 733 | |
|
| 734 | 0 | putDocumentError(KRADConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PRIMARY_KEYS_CHANGED_ON_EDIT, getHumanReadablePrimaryKeyFieldNames(boClass)); |
| 735 | 0 | success &= false; |
| 736 | |
} |
| 737 | |
} |
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | 0 | else if (document.isNew()) { |
| 742 | |
|
| 743 | |
|
| 744 | 0 | if(newBo instanceof PersistableBusinessObject) { |
| 745 | |
|
| 746 | |
|
| 747 | 0 | Map<String, ?> newPkFields = businessObjectMetaDataService.getPrimaryKeyFieldValues(newBo); |
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | 0 | PersistableBusinessObject testBo = boService.findByPrimaryKey(boClass.asSubclass(PersistableBusinessObject.class), newPkFields); |
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | 0 | if (testBo != null) { |
| 760 | 0 | putDocumentError(KRADConstants.DOCUMENT_ERRORS, RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_KEYS_ALREADY_EXIST_ON_CREATE_NEW, getHumanReadablePrimaryKeyFieldNames(boClass)); |
| 761 | 0 | success &= false; |
| 762 | |
} |
| 763 | |
} |
| 764 | |
} |
| 765 | |
|
| 766 | 0 | return success; |
| 767 | |
} |
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
protected String getHumanReadablePrimaryKeyFieldNames(Class<?> boClass) { |
| 777 | |
|
| 778 | 0 | String delim = ""; |
| 779 | 0 | StringBuffer pkFieldNames = new StringBuffer(); |
| 780 | |
|
| 781 | |
|
| 782 | 0 | List<String> pkFields = businessObjectMetaDataService.listPrimaryKeyFieldNames(boClass); |
| 783 | 0 | for (Iterator<String> iter = pkFields.iterator(); iter.hasNext();) { |
| 784 | 0 | String pkFieldName = (String) iter.next(); |
| 785 | |
|
| 786 | |
|
| 787 | |
|
| 788 | 0 | String humanReadableFieldName = ddService.getAttributeLabel(boClass, pkFieldName); |
| 789 | |
|
| 790 | |
|
| 791 | 0 | pkFieldNames.append(delim + humanReadableFieldName); |
| 792 | |
|
| 793 | |
|
| 794 | 0 | if (delim.equalsIgnoreCase("")) { |
| 795 | 0 | delim = ", "; |
| 796 | |
} |
| 797 | 0 | } |
| 798 | |
|
| 799 | 0 | return pkFieldNames.toString(); |
| 800 | |
} |
| 801 | |
|
| 802 | |
|
| 803 | |
|
| 804 | |
|
| 805 | |
|
| 806 | |
|
| 807 | |
|
| 808 | |
|
| 809 | |
|
| 810 | |
|
| 811 | |
|
| 812 | |
protected boolean processGlobalApproveDocumentBusinessRules(MaintenanceDocument document) { |
| 813 | 0 | return true; |
| 814 | |
} |
| 815 | |
|
| 816 | |
|
| 817 | |
|
| 818 | |
|
| 819 | |
|
| 820 | |
|
| 821 | |
|
| 822 | |
|
| 823 | |
|
| 824 | |
|
| 825 | |
|
| 826 | |
|
| 827 | |
protected boolean processGlobalRouteDocumentBusinessRules(MaintenanceDocument document) { |
| 828 | |
|
| 829 | 0 | boolean success = true; |
| 830 | |
|
| 831 | |
|
| 832 | 0 | success &= checkEmptyDocumentField(KRADPropertyConstants.DOCUMENT_HEADER + "." + KRADPropertyConstants.DOCUMENT_DESCRIPTION, document.getDocumentHeader().getDocumentDescription(), "Description"); |
| 833 | |
|
| 834 | 0 | return success; |
| 835 | |
} |
| 836 | |
|
| 837 | |
|
| 838 | |
|
| 839 | |
|
| 840 | |
|
| 841 | |
|
| 842 | |
|
| 843 | |
|
| 844 | |
|
| 845 | |
|
| 846 | |
|
| 847 | |
|
| 848 | |
|
| 849 | |
|
| 850 | |
|
| 851 | |
|
| 852 | |
protected boolean processGlobalSaveDocumentBusinessRules(MaintenanceDocument document) { |
| 853 | |
|
| 854 | |
|
| 855 | 0 | boolean success = true; |
| 856 | |
|
| 857 | |
|
| 858 | 0 | primaryKeyCheck(document); |
| 859 | |
|
| 860 | |
|
| 861 | |
|
| 862 | 0 | this.dataDictionaryValidate(document); |
| 863 | |
|
| 864 | 0 | return success; |
| 865 | |
} |
| 866 | |
|
| 867 | |
|
| 868 | |
|
| 869 | |
|
| 870 | |
|
| 871 | |
|
| 872 | |
|
| 873 | |
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { |
| 874 | 0 | return true; |
| 875 | |
} |
| 876 | |
|
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) { |
| 885 | 0 | return true; |
| 886 | |
} |
| 887 | |
|
| 888 | |
|
| 889 | |
|
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | |
|
| 894 | |
protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) { |
| 895 | 0 | return true; |
| 896 | |
} |
| 897 | |
|
| 898 | |
|
| 899 | |
|
| 900 | |
|
| 901 | |
|
| 902 | |
|
| 903 | |
|
| 904 | |
|
| 905 | |
|
| 906 | |
|
| 907 | |
|
| 908 | |
|
| 909 | |
|
| 910 | |
|
| 911 | |
|
| 912 | |
protected boolean isDocumentValidForSave(MaintenanceDocument maintenanceDocument) { |
| 913 | |
|
| 914 | 0 | boolean success = true; |
| 915 | |
|
| 916 | 0 | success &= super.isDocumentOverviewValid(maintenanceDocument); |
| 917 | 0 | success &= validateDocumentStructure((Document) maintenanceDocument); |
| 918 | 0 | success &= validateMaintenanceDocument(maintenanceDocument); |
| 919 | 0 | success &= validateGlobalBusinessObjectPersistable(maintenanceDocument); |
| 920 | 0 | return success; |
| 921 | |
} |
| 922 | |
|
| 923 | |
|
| 924 | |
|
| 925 | |
|
| 926 | |
|
| 927 | |
|
| 928 | |
|
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
protected boolean validateDocumentStructure(Document document) { |
| 934 | 0 | boolean success = true; |
| 935 | |
|
| 936 | |
|
| 937 | 0 | String documentHeaderId = document.getDocumentNumber(); |
| 938 | 0 | if (documentHeaderId == null || StringUtils.isEmpty(documentHeaderId)) { |
| 939 | 0 | throw new ValidationException("Document has no document number, unable to proceed."); |
| 940 | |
} |
| 941 | |
|
| 942 | 0 | return success; |
| 943 | |
} |
| 944 | |
|
| 945 | |
|
| 946 | |
|
| 947 | |
|
| 948 | |
|
| 949 | |
|
| 950 | |
|
| 951 | |
|
| 952 | |
|
| 953 | |
|
| 954 | |
|
| 955 | |
|
| 956 | |
protected boolean validateMaintenanceDocument(MaintenanceDocument maintenanceDocument) { |
| 957 | 0 | boolean success = true; |
| 958 | 0 | Maintainable newMaintainable = maintenanceDocument.getNewMaintainableObject(); |
| 959 | |
|
| 960 | |
|
| 961 | 0 | if (newMaintainable == null) { |
| 962 | 0 | throw new ValidationException("Maintainable object from Maintenance Document '" + maintenanceDocument.getDocumentTitle() + "' is null, unable to proceed."); |
| 963 | |
} |
| 964 | |
|
| 965 | |
|
| 966 | 0 | if (newMaintainable.getDataObject() == null) { |
| 967 | 0 | throw new ValidationException("Maintainable's component data object is null."); |
| 968 | |
} |
| 969 | |
|
| 970 | 0 | return success; |
| 971 | |
} |
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
|
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
protected boolean validateGlobalBusinessObjectPersistable(MaintenanceDocument document) { |
| 985 | 0 | boolean success = true; |
| 986 | |
|
| 987 | 0 | if (document.getNewMaintainableObject() == null) { |
| 988 | 0 | return success; |
| 989 | |
} |
| 990 | 0 | if (document.getNewMaintainableObject().getDataObject() == null) { |
| 991 | 0 | return success; |
| 992 | |
} |
| 993 | 0 | if (!(document.getNewMaintainableObject().getDataObject() instanceof GlobalBusinessObject)) { |
| 994 | 0 | return success; |
| 995 | |
} |
| 996 | |
|
| 997 | 0 | PersistableBusinessObject bo = (PersistableBusinessObject) document.getNewMaintainableObject().getDataObject(); |
| 998 | 0 | GlobalBusinessObject gbo = (GlobalBusinessObject) bo; |
| 999 | 0 | return gbo.isPersistable(); |
| 1000 | |
} |
| 1001 | |
|
| 1002 | |
|
| 1003 | |
|
| 1004 | |
|
| 1005 | |
|
| 1006 | |
|
| 1007 | |
|
| 1008 | |
|
| 1009 | |
|
| 1010 | |
|
| 1011 | |
|
| 1012 | |
|
| 1013 | |
protected boolean isCorrectMaintenanceClass(MaintenanceDocument document, Class clazz) { |
| 1014 | |
|
| 1015 | |
|
| 1016 | 0 | if (document == null || clazz == null) { |
| 1017 | 0 | throw new IllegalArgumentException("Null arguments were passed in."); |
| 1018 | |
} |
| 1019 | |
|
| 1020 | |
|
| 1021 | 0 | if (clazz.toString().equals(document.getNewMaintainableObject().getBoClass().toString())) { |
| 1022 | 0 | return true; |
| 1023 | |
} |
| 1024 | |
else { |
| 1025 | 0 | return false; |
| 1026 | |
} |
| 1027 | |
} |
| 1028 | |
|
| 1029 | |
|
| 1030 | |
|
| 1031 | |
|
| 1032 | |
|
| 1033 | |
|
| 1034 | |
|
| 1035 | |
|
| 1036 | |
|
| 1037 | |
|
| 1038 | |
|
| 1039 | |
|
| 1040 | |
|
| 1041 | |
|
| 1042 | |
protected boolean checkEmptyBOField(String propertyName, Object valueToTest, String parameter) { |
| 1043 | |
|
| 1044 | 0 | boolean success = true; |
| 1045 | |
|
| 1046 | 0 | success = checkEmptyValue(valueToTest); |
| 1047 | |
|
| 1048 | |
|
| 1049 | 0 | if (!success) { |
| 1050 | 0 | putFieldError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter); |
| 1051 | |
} |
| 1052 | |
|
| 1053 | 0 | return success; |
| 1054 | |
} |
| 1055 | |
|
| 1056 | |
|
| 1057 | |
|
| 1058 | |
|
| 1059 | |
|
| 1060 | |
|
| 1061 | |
|
| 1062 | |
|
| 1063 | |
|
| 1064 | |
|
| 1065 | |
|
| 1066 | |
|
| 1067 | |
|
| 1068 | |
|
| 1069 | |
protected boolean checkEmptyDocumentField(String propertyName, Object valueToTest, String parameter) { |
| 1070 | 0 | boolean success = true; |
| 1071 | 0 | success = checkEmptyValue(valueToTest); |
| 1072 | 0 | if (!success) { |
| 1073 | 0 | putDocumentError(propertyName, RiceKeyConstants.ERROR_REQUIRED, parameter); |
| 1074 | |
} |
| 1075 | 0 | return success; |
| 1076 | |
} |
| 1077 | |
|
| 1078 | |
|
| 1079 | |
|
| 1080 | |
|
| 1081 | |
|
| 1082 | |
|
| 1083 | |
|
| 1084 | |
|
| 1085 | |
|
| 1086 | |
|
| 1087 | |
|
| 1088 | |
|
| 1089 | |
protected boolean checkEmptyValue(Object valueToTest) { |
| 1090 | 0 | boolean success = true; |
| 1091 | |
|
| 1092 | |
|
| 1093 | 0 | if (valueToTest == null) { |
| 1094 | 0 | success = false; |
| 1095 | |
} |
| 1096 | |
else { |
| 1097 | |
|
| 1098 | 0 | if (valueToTest instanceof String) { |
| 1099 | 0 | if (StringUtils.isBlank((String) valueToTest)) { |
| 1100 | 0 | success = false; |
| 1101 | |
} |
| 1102 | |
} |
| 1103 | |
} |
| 1104 | |
|
| 1105 | 0 | return success; |
| 1106 | |
} |
| 1107 | |
|
| 1108 | |
|
| 1109 | |
|
| 1110 | |
|
| 1111 | |
|
| 1112 | |
|
| 1113 | |
|
| 1114 | |
protected void showErrorMap() { |
| 1115 | |
|
| 1116 | 0 | if (GlobalVariables.getMessageMap().hasNoErrors()) { |
| 1117 | 0 | return; |
| 1118 | |
} |
| 1119 | |
|
| 1120 | 0 | for (Iterator i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext();) { |
| 1121 | 0 | Map.Entry e = (Map.Entry) i.next(); |
| 1122 | |
|
| 1123 | 0 | AutoPopulatingList errorList = (AutoPopulatingList) e.getValue(); |
| 1124 | 0 | for (Iterator j = errorList.iterator(); j.hasNext();) { |
| 1125 | 0 | ErrorMessage em = (ErrorMessage) j.next(); |
| 1126 | |
|
| 1127 | 0 | if (em.getMessageParameters() == null) { |
| 1128 | 0 | LOG.error(e.getKey().toString() + " = " + em.getErrorKey()); |
| 1129 | |
} |
| 1130 | |
else { |
| 1131 | 0 | LOG.error(e.getKey().toString() + " = " + em.getErrorKey() + " : " + em.getMessageParameters().toString()); |
| 1132 | |
} |
| 1133 | 0 | } |
| 1134 | 0 | } |
| 1135 | |
|
| 1136 | 0 | } |
| 1137 | |
|
| 1138 | |
|
| 1139 | |
|
| 1140 | |
|
| 1141 | |
public void setupBaseConvenienceObjects(MaintenanceDocument document) { |
| 1142 | |
|
| 1143 | |
|
| 1144 | 0 | oldBo = document.getOldMaintainableObject().getDataObject(); |
| 1145 | 0 | if (oldBo != null && oldBo instanceof PersistableBusinessObject) { |
| 1146 | 0 | ((PersistableBusinessObject)oldBo).refreshNonUpdateableReferences(); |
| 1147 | |
} |
| 1148 | |
|
| 1149 | |
|
| 1150 | 0 | newBo = document.getNewMaintainableObject().getDataObject(); |
| 1151 | 0 | if(newBo instanceof PersistableBusinessObject) { |
| 1152 | 0 | ((PersistableBusinessObject)newBo).refreshNonUpdateableReferences(); |
| 1153 | |
} |
| 1154 | |
|
| 1155 | 0 | boClass = document.getNewMaintainableObject().getBoClass(); |
| 1156 | |
|
| 1157 | |
|
| 1158 | 0 | setupConvenienceObjects(); |
| 1159 | 0 | } |
| 1160 | |
|
| 1161 | |
public void setupConvenienceObjects() { |
| 1162 | |
|
| 1163 | 0 | } |
| 1164 | |
|
| 1165 | |
|
| 1166 | |
|
| 1167 | |
|
| 1168 | |
|
| 1169 | |
|
| 1170 | |
|
| 1171 | |
|
| 1172 | |
|
| 1173 | |
|
| 1174 | |
|
| 1175 | |
|
| 1176 | |
|
| 1177 | |
protected boolean checkForPartiallyFilledOutReferenceForeignKeys(String referenceName) { |
| 1178 | 0 | boolean success = true; |
| 1179 | |
|
| 1180 | 0 | if (newBo instanceof PersistableBusinessObject) { |
| 1181 | |
ForeignKeyFieldsPopulationState fkFieldsState; |
| 1182 | 0 | fkFieldsState = persistenceStructureService.getForeignKeyFieldsPopulationState( |
| 1183 | |
(PersistableBusinessObject) newBo, referenceName); |
| 1184 | |
|
| 1185 | |
|
| 1186 | 0 | if (fkFieldsState.isAnyFieldsPopulated() && !fkFieldsState.isAllFieldsPopulated()) { |
| 1187 | 0 | success = false; |
| 1188 | |
|
| 1189 | |
|
| 1190 | |
|
| 1191 | |
|
| 1192 | 0 | List fKeys = new ArrayList(persistenceStructureService.getForeignKeysForReference( |
| 1193 | |
newBo.getClass().asSubclass(PersistableBusinessObject.class), referenceName).keySet()); |
| 1194 | 0 | String fKeysReadable = consolidateFieldNames(fKeys, ", ").toString(); |
| 1195 | |
|
| 1196 | |
|
| 1197 | 0 | for (Iterator iter = fkFieldsState.getUnpopulatedFieldNames().iterator(); iter.hasNext();) { |
| 1198 | 0 | String fieldName = (String) iter.next(); |
| 1199 | |
|
| 1200 | |
|
| 1201 | 0 | String fieldNameReadable = ddService.getAttributeLabel(newBo.getClass(), fieldName); |
| 1202 | |
|
| 1203 | |
|
| 1204 | 0 | putFieldError(fieldName, |
| 1205 | |
RiceKeyConstants.ERROR_DOCUMENT_MAINTENANCE_PARTIALLY_FILLED_OUT_REF_FKEYS, new String[]{ |
| 1206 | |
fieldNameReadable, fKeysReadable}); |
| 1207 | 0 | } |
| 1208 | |
} |
| 1209 | |
} |
| 1210 | |
|
| 1211 | 0 | return success; |
| 1212 | |
} |
| 1213 | |
|
| 1214 | |
|
| 1215 | |
|
| 1216 | |
|
| 1217 | |
|
| 1218 | |
|
| 1219 | |
|
| 1220 | |
|
| 1221 | |
|
| 1222 | |
protected StringBuffer consolidateFieldNames(List fieldNames, String delimiter) { |
| 1223 | |
|
| 1224 | 0 | StringBuffer sb = new StringBuffer(); |
| 1225 | |
|
| 1226 | |
|
| 1227 | 0 | boolean firstPass = true; |
| 1228 | 0 | String delim = ""; |
| 1229 | |
|
| 1230 | |
|
| 1231 | 0 | for (Iterator iter = fieldNames.iterator(); iter.hasNext();) { |
| 1232 | 0 | String fieldName = (String) iter.next(); |
| 1233 | |
|
| 1234 | |
|
| 1235 | |
|
| 1236 | 0 | sb.append(delim + ddService.getAttributeLabel(newBo.getClass(), fieldName)); |
| 1237 | |
|
| 1238 | |
|
| 1239 | 0 | if (firstPass) { |
| 1240 | 0 | delim = delimiter; |
| 1241 | 0 | firstPass = false; |
| 1242 | |
} |
| 1243 | 0 | } |
| 1244 | |
|
| 1245 | 0 | return sb; |
| 1246 | |
} |
| 1247 | |
|
| 1248 | |
|
| 1249 | |
|
| 1250 | |
|
| 1251 | |
|
| 1252 | |
|
| 1253 | |
|
| 1254 | |
|
| 1255 | |
|
| 1256 | |
|
| 1257 | |
|
| 1258 | |
protected String getFieldLabel(String fieldName) { |
| 1259 | 0 | return ddService.getAttributeLabel(newBo.getClass(), fieldName) + "(" + ddService.getAttributeShortLabel(newBo.getClass(), fieldName) + ")"; |
| 1260 | |
} |
| 1261 | |
|
| 1262 | |
|
| 1263 | |
|
| 1264 | |
|
| 1265 | |
|
| 1266 | |
|
| 1267 | |
|
| 1268 | |
|
| 1269 | |
|
| 1270 | |
|
| 1271 | |
|
| 1272 | |
|
| 1273 | |
protected String getFieldLabel(Class boClass, String fieldName) { |
| 1274 | 0 | return ddService.getAttributeLabel(boClass, fieldName) + "(" + ddService.getAttributeShortLabel(boClass, fieldName) + ")"; |
| 1275 | |
} |
| 1276 | |
|
| 1277 | |
|
| 1278 | |
|
| 1279 | |
|
| 1280 | |
|
| 1281 | |
|
| 1282 | |
protected final BusinessObjectDictionaryService getBoDictionaryService() { |
| 1283 | 0 | return boDictionaryService; |
| 1284 | |
} |
| 1285 | |
|
| 1286 | |
|
| 1287 | |
|
| 1288 | |
|
| 1289 | |
|
| 1290 | |
|
| 1291 | |
public final void setBoDictionaryService(BusinessObjectDictionaryService boDictionaryService) { |
| 1292 | 0 | this.boDictionaryService = boDictionaryService; |
| 1293 | 0 | } |
| 1294 | |
|
| 1295 | |
|
| 1296 | |
|
| 1297 | |
|
| 1298 | |
|
| 1299 | |
|
| 1300 | |
protected final BusinessObjectService getBoService() { |
| 1301 | 0 | return boService; |
| 1302 | |
} |
| 1303 | |
|
| 1304 | |
|
| 1305 | |
|
| 1306 | |
|
| 1307 | |
|
| 1308 | |
|
| 1309 | |
public final void setBoService(BusinessObjectService boService) { |
| 1310 | 0 | this.boService = boService; |
| 1311 | 0 | } |
| 1312 | |
|
| 1313 | |
|
| 1314 | |
|
| 1315 | |
|
| 1316 | |
|
| 1317 | |
|
| 1318 | |
protected final ConfigurationService getConfigService() { |
| 1319 | 0 | return configService; |
| 1320 | |
} |
| 1321 | |
|
| 1322 | |
|
| 1323 | |
|
| 1324 | |
|
| 1325 | |
|
| 1326 | |
|
| 1327 | |
public final void setConfigService(ConfigurationService configService) { |
| 1328 | 0 | this.configService = configService; |
| 1329 | 0 | } |
| 1330 | |
|
| 1331 | |
|
| 1332 | |
|
| 1333 | |
|
| 1334 | |
|
| 1335 | |
|
| 1336 | |
protected final DataDictionaryService getDdService() { |
| 1337 | 0 | return ddService; |
| 1338 | |
} |
| 1339 | |
|
| 1340 | |
|
| 1341 | |
|
| 1342 | |
|
| 1343 | |
|
| 1344 | |
|
| 1345 | |
public final void setDdService(DataDictionaryService ddService) { |
| 1346 | 0 | this.ddService = ddService; |
| 1347 | 0 | } |
| 1348 | |
|
| 1349 | |
|
| 1350 | |
|
| 1351 | |
|
| 1352 | |
|
| 1353 | |
|
| 1354 | |
protected final DictionaryValidationService getDictionaryValidationService() { |
| 1355 | 0 | return dictionaryValidationService; |
| 1356 | |
} |
| 1357 | |
|
| 1358 | |
|
| 1359 | |
|
| 1360 | |
|
| 1361 | |
|
| 1362 | |
|
| 1363 | |
public final void setDictionaryValidationService(DictionaryValidationService dictionaryValidationService) { |
| 1364 | 0 | this.dictionaryValidationService = dictionaryValidationService; |
| 1365 | 0 | } |
| 1366 | |
|
| 1367 | |
|
| 1368 | |
|
| 1369 | |
|
| 1370 | |
|
| 1371 | |
|
| 1372 | |
protected final MaintenanceDocumentDictionaryService getMaintDocDictionaryService() { |
| 1373 | 0 | return maintDocDictionaryService; |
| 1374 | |
} |
| 1375 | |
|
| 1376 | |
|
| 1377 | |
|
| 1378 | |
|
| 1379 | |
|
| 1380 | |
|
| 1381 | |
public final void setMaintDocDictionaryService(MaintenanceDocumentDictionaryService maintDocDictionaryService) { |
| 1382 | 0 | this.maintDocDictionaryService = maintDocDictionaryService; |
| 1383 | 0 | } |
| 1384 | |
|
| 1385 | |
|
| 1386 | |
|
| 1387 | |
|
| 1388 | |
|
| 1389 | |
|
| 1390 | |
protected final Object getNewBo() { |
| 1391 | 0 | return newBo; |
| 1392 | |
} |
| 1393 | |
|
| 1394 | |
protected void setNewBo(Object newBo) { |
| 1395 | 0 | this.newBo = newBo; |
| 1396 | 0 | } |
| 1397 | |
|
| 1398 | |
|
| 1399 | |
|
| 1400 | |
|
| 1401 | |
|
| 1402 | |
|
| 1403 | |
protected final Object getOldBo() { |
| 1404 | 0 | return oldBo; |
| 1405 | |
} |
| 1406 | |
|
| 1407 | |
|
| 1408 | |
|
| 1409 | |
|
| 1410 | |
|
| 1411 | |
|
| 1412 | |
protected final BusinessObjectMetaDataService getBusinessObjectMetaDataService() { |
| 1413 | 0 | return businessObjectMetaDataService; |
| 1414 | |
} |
| 1415 | |
|
| 1416 | |
|
| 1417 | |
|
| 1418 | |
|
| 1419 | |
|
| 1420 | |
|
| 1421 | |
public final void setBusinessObjectMetaDataService(BusinessObjectMetaDataService businessObjectMetaDataService) { |
| 1422 | 0 | this.businessObjectMetaDataService = businessObjectMetaDataService; |
| 1423 | 0 | } |
| 1424 | |
|
| 1425 | |
|
| 1426 | |
|
| 1427 | |
|
| 1428 | |
|
| 1429 | |
|
| 1430 | |
protected final PersistenceStructureService getPersistenceStructureService() { |
| 1431 | 0 | return persistenceStructureService; |
| 1432 | |
} |
| 1433 | |
|
| 1434 | |
|
| 1435 | |
|
| 1436 | |
|
| 1437 | |
|
| 1438 | |
|
| 1439 | |
public final void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) { |
| 1440 | 0 | this.persistenceStructureService = persistenceStructureService; |
| 1441 | 0 | } |
| 1442 | |
|
| 1443 | |
|
| 1444 | |
|
| 1445 | |
|
| 1446 | |
|
| 1447 | |
|
| 1448 | |
public WorkflowDocumentService getWorkflowDocumentService() { |
| 1449 | 0 | return workflowDocumentService; |
| 1450 | |
} |
| 1451 | |
|
| 1452 | |
|
| 1453 | |
|
| 1454 | |
|
| 1455 | |
|
| 1456 | |
|
| 1457 | |
public void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) { |
| 1458 | 0 | this.workflowDocumentService = workflowDocumentService; |
| 1459 | 0 | } |
| 1460 | |
|
| 1461 | |
public boolean processAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) { |
| 1462 | 0 | LOG.debug("processAddCollectionLineBusinessRules"); |
| 1463 | |
|
| 1464 | |
|
| 1465 | 0 | setupBaseConvenienceObjects(document); |
| 1466 | |
|
| 1467 | |
|
| 1468 | 0 | this.validateMaintenanceDocument( document ); |
| 1469 | |
|
| 1470 | 0 | boolean success = true; |
| 1471 | 0 | MessageMap map = GlobalVariables.getMessageMap(); |
| 1472 | 0 | int errorCount = map.getErrorCount(); |
| 1473 | 0 | map.addToErrorPath( MAINTAINABLE_ERROR_PATH ); |
| 1474 | 0 | if ( LOG.isDebugEnabled() ) { |
| 1475 | 0 | LOG.debug( "processAddCollectionLineBusinessRules - BO: " + bo ); |
| 1476 | 0 | LOG.debug( "Before Validate: " + map ); |
| 1477 | |
} |
| 1478 | |
|
| 1479 | 0 | getMaintDocDictionaryService().validateMaintainableCollectionsAddLineRequiredFields( document, document.getNewMaintainableObject().getBusinessObject(), collectionName ); |
| 1480 | 0 | String errorPath = KRADConstants.MAINTENANCE_ADD_PREFIX + collectionName; |
| 1481 | 0 | map.addToErrorPath( errorPath ); |
| 1482 | |
|
| 1483 | 0 | getDictionaryValidationService().validateBusinessObject( bo, false ); |
| 1484 | 0 | success &= map.getErrorCount() == errorCount; |
| 1485 | 0 | success &= dictionaryValidationService.validateDefaultExistenceChecksForNewCollectionItem(document.getNewMaintainableObject().getBusinessObject(), bo, collectionName); |
| 1486 | 0 | success &= validateDuplicateIdentifierInDataDictionary(document, collectionName, bo); |
| 1487 | 0 | success &= processCustomAddCollectionLineBusinessRules( document, collectionName, bo ); |
| 1488 | |
|
| 1489 | 0 | map.removeFromErrorPath( errorPath ); |
| 1490 | 0 | map.removeFromErrorPath( MAINTAINABLE_ERROR_PATH ); |
| 1491 | 0 | if ( LOG.isDebugEnabled() ) { |
| 1492 | 0 | LOG.debug( "After Validate: " + map ); |
| 1493 | 0 | LOG.debug( "processAddCollectionLineBusinessRules returning: " + success ); |
| 1494 | |
} |
| 1495 | |
|
| 1496 | 0 | return success; |
| 1497 | |
} |
| 1498 | |
|
| 1499 | |
|
| 1500 | |
|
| 1501 | |
|
| 1502 | |
|
| 1503 | |
|
| 1504 | |
|
| 1505 | |
|
| 1506 | |
|
| 1507 | |
|
| 1508 | |
|
| 1509 | |
|
| 1510 | |
|
| 1511 | |
protected boolean validateDuplicateIdentifierInDataDictionary(MaintenanceDocument document, String collectionName, PersistableBusinessObject bo) { |
| 1512 | 0 | boolean valid = true; |
| 1513 | 0 | PersistableBusinessObject maintBo = document.getNewMaintainableObject().getBusinessObject(); |
| 1514 | 0 | Collection maintCollection = (Collection) ObjectUtils.getPropertyValue(maintBo, collectionName); |
| 1515 | 0 | List<String> duplicateIdentifier = document.getNewMaintainableObject().getDuplicateIdentifierFieldsFromDataDictionary(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(), collectionName); |
| 1516 | 0 | if (duplicateIdentifier.size()>0) { |
| 1517 | 0 | List<String> existingIdentifierString = document.getNewMaintainableObject().getMultiValueIdentifierList(maintCollection, duplicateIdentifier); |
| 1518 | 0 | if (document.getNewMaintainableObject().hasBusinessObjectExisted(bo, existingIdentifierString, duplicateIdentifier)) { |
| 1519 | 0 | valid = false; |
| 1520 | 0 | GlobalVariables.getMessageMap().putError(duplicateIdentifier.get(0), RiceKeyConstants.ERROR_DUPLICATE_ELEMENT, "entries in ", document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName()); |
| 1521 | |
} |
| 1522 | |
} |
| 1523 | 0 | return valid; |
| 1524 | |
} |
| 1525 | |
|
| 1526 | |
public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject line) { |
| 1527 | 0 | return true; |
| 1528 | |
} |
| 1529 | |
|
| 1530 | |
public org.kuali.rice.kim.service.PersonService getPersonService() { |
| 1531 | 0 | return personService; |
| 1532 | |
} |
| 1533 | |
|
| 1534 | |
public void setPersonService(org.kuali.rice.kim.service.PersonService personService) { |
| 1535 | 0 | this.personService = personService; |
| 1536 | 0 | } |
| 1537 | |
|
| 1538 | |
public DateTimeService getDateTimeService() { |
| 1539 | 0 | return CoreApiServiceLocator.getDateTimeService(); |
| 1540 | |
} |
| 1541 | |
|
| 1542 | |
|
| 1543 | |
|
| 1544 | |
|
| 1545 | |
public DocumentHelperService getDocumentHelperService() { |
| 1546 | 0 | return this.documentHelperService; |
| 1547 | |
} |
| 1548 | |
|
| 1549 | |
|
| 1550 | |
|
| 1551 | |
|
| 1552 | |
public void setDocumentHelperService(DocumentHelperService documentHelperService) { |
| 1553 | 0 | this.documentHelperService = documentHelperService; |
| 1554 | 0 | } |
| 1555 | |
|
| 1556 | |
|
| 1557 | |
|
| 1558 | |
|
| 1559 | |
public BusinessObjectAuthorizationService getBusinessObjectAuthorizationService() { |
| 1560 | 0 | return this.businessObjectAuthorizationService; |
| 1561 | |
} |
| 1562 | |
|
| 1563 | |
|
| 1564 | |
|
| 1565 | |
|
| 1566 | |
public void setBusinessObjectAuthorizationService( |
| 1567 | |
BusinessObjectAuthorizationService businessObjectAuthorizationService) { |
| 1568 | 0 | this.businessObjectAuthorizationService = businessObjectAuthorizationService; |
| 1569 | 0 | } |
| 1570 | |
|
| 1571 | |
protected RoleService getRoleService(){ |
| 1572 | 0 | if(this.roleService==null){ |
| 1573 | 0 | this.roleService = KimApiServiceLocator.getRoleService(); |
| 1574 | |
} |
| 1575 | 0 | return this.roleService; |
| 1576 | |
} |
| 1577 | |
|
| 1578 | |
} |
| 1579 | |
|