1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import org.kuali.ole.coa.businessobject.ObjectConsolidation;
19 import org.kuali.ole.coa.businessobject.ObjectLevel;
20 import org.kuali.ole.coa.service.ChartService;
21 import org.kuali.ole.coa.service.ObjectCodeService;
22 import org.kuali.ole.coa.service.ObjectLevelService;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.kns.document.MaintenanceDocument;
26 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
27
28
29
30
31 public class ObjectConsRule extends MaintenanceDocumentRuleBase {
32
33 protected static ChartService chartService;
34 protected static ObjectLevelService objectLevelService;
35 protected static ObjectCodeService objectCodeService;
36
37
38
39
40
41
42 public ObjectConsRule() {
43 if (chartService == null) {
44 objectLevelService = SpringContext.getBean(ObjectLevelService.class);
45 objectCodeService = SpringContext.getBean(ObjectCodeService.class);
46 chartService = SpringContext.getBean(ChartService.class);
47 }
48 }
49
50
51
52
53
54
55
56
57
58 @Override
59 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
60 ObjectConsolidation objConsolidation = (ObjectConsolidation) getNewBo();
61
62 checkObjLevelCode(objConsolidation);
63 return true;
64 }
65
66
67
68
69
70
71
72
73
74 @Override
75 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
76 boolean success = true;
77 ObjectConsolidation objConsolidation = (ObjectConsolidation) getNewBo();
78
79 success &= checkObjLevelCode(objConsolidation);
80 return success;
81 }
82
83
84
85
86
87
88
89
90 protected boolean checkObjLevelCode(ObjectConsolidation objConsolidation) {
91 boolean success = true;
92
93 ObjectLevel objLevel = objectLevelService.getByPrimaryId(objConsolidation.getChartOfAccountsCode(), objConsolidation.getFinConsolidationObjectCode());
94 if (objLevel != null) {
95 success = false;
96 putFieldError("finConsolidationObjectCode", OLEKeyConstants.ERROR_DOCUMENT_OBJCONSMAINT_ALREADY_EXISTS_AS_OBJLEVEL);
97 }
98 return success;
99 }
100 }