1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapPropertyConstants;
19 import org.kuali.ole.module.purap.businessobject.ReceivingAddress;
20 import org.kuali.ole.sys.OLEPropertyConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.ole.sys.service.PostalCodeValidationService;
23 import org.kuali.rice.kns.document.MaintenanceDocument;
24 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 public class ReceivingAddressRule extends MaintenanceDocumentRuleBase {
28
29 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
30 LOG.info("processCustomApproveDocumentBusinessRules called");
31 this.setupConvenienceObjects();
32 boolean success = this.validateAddress(document);
33 return success && super.processCustomApproveDocumentBusinessRules(document);
34 }
35
36 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
37 LOG.info("processCustomRouteDocumentBusinessRules called");
38 this.setupConvenienceObjects();
39 boolean success = this.validateAddress(document);
40 return success && super.processCustomRouteDocumentBusinessRules(document);
41 }
42
43 protected boolean validateAddress(MaintenanceDocument document) {
44 ReceivingAddress newReceivingAddress = (ReceivingAddress) document.getNewMaintainableObject().getBusinessObject();
45 GlobalVariables.getMessageMap().clearErrorPath();
46 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT);
47 boolean valid = SpringContext.getBean(PostalCodeValidationService.class).validateAddress(newReceivingAddress.getReceivingCountryCode(), newReceivingAddress.getReceivingStateCode(), newReceivingAddress.getReceivingPostalCode(), PurapPropertyConstants.RECEIVING_ADDRESS_STATE, PurapPropertyConstants.RECEIVING_ADDRESS_POSTAL_CODE);
48 GlobalVariables.getMessageMap().clearErrorPath();
49 return valid;
50 }
51
52 }