1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.coa.businessobject.AccountDelegate;
27 import org.kuali.ole.coa.businessobject.AccountDelegateGlobal;
28 import org.kuali.ole.coa.businessobject.AccountDelegateGlobalDetail;
29 import org.kuali.ole.coa.businessobject.AccountDelegateModel;
30 import org.kuali.ole.coa.businessobject.AccountDelegateModelDetail;
31 import org.kuali.ole.coa.businessobject.AccountGlobalDetail;
32 import org.kuali.ole.coa.service.AccountDelegateService;
33 import org.kuali.ole.sys.OLEConstants;
34 import org.kuali.ole.sys.context.SpringContext;
35 import org.kuali.ole.sys.document.FinancialSystemGlobalMaintainable;
36 import org.kuali.rice.kns.document.MaintenanceDocument;
37 import org.kuali.rice.krad.bo.PersistableBusinessObject;
38 import org.kuali.rice.krad.maintenance.MaintenanceLock;
39 import org.kuali.rice.krad.service.BusinessObjectService;
40 import org.kuali.rice.krad.util.ObjectUtils;
41
42
43
44
45
46
47
48 public class AccountDelegateGlobalMaintainableImpl extends FinancialSystemGlobalMaintainable {
49 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountDelegateGlobalMaintainableImpl.class);
50
51
52
53
54
55
56 @Override
57 public void setupNewFromExisting( MaintenanceDocument document, Map<String,String[]> parameters ) {
58 super.setupNewFromExisting( document, parameters );
59
60 AccountDelegateGlobal globalDelegate = (AccountDelegateGlobal) this.getBusinessObject();
61 globalDelegate.setVersionNumber(1L);
62 this.setBusinessObject(globalDelegate);
63
64
65 if (!StringUtils.isBlank(globalDelegate.getModelName()) && !StringUtils.isBlank(globalDelegate.getModelChartOfAccountsCode()) && !StringUtils.isBlank(globalDelegate.getModelOrganizationCode())) {
66 Map pkMap = new HashMap();
67 pkMap.put("accountDelegateModelName", globalDelegate.getModelName());
68 pkMap.put("chartOfAccountsCode", globalDelegate.getModelChartOfAccountsCode());
69 pkMap.put("organizationCode", globalDelegate.getModelOrganizationCode());
70
71 AccountDelegateModel globalDelegateTemplate = (AccountDelegateModel) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(AccountDelegateModel.class, pkMap);
72 if (globalDelegateTemplate != null) {
73
74
75 for (AccountDelegateModelDetail model : globalDelegateTemplate.getAccountDelegateModelDetails()) {
76 if (model.isActive()) {
77 AccountDelegateGlobalDetail newDelegate = new AccountDelegateGlobalDetail(model);
78
79 newDelegate.setNewCollectionRecord(true);
80 globalDelegate.getDelegateGlobals().add(newDelegate);
81 }
82 }
83 }
84 }
85 }
86
87 @Override
88 public String getLockingDocumentId() {
89 String lock = super.getLockingDocumentId();
90 if (StringUtils.isNotBlank(lock))
91 return lock;
92 else {
93 AccountDelegateService accountDelegateService = SpringContext.getBean(AccountDelegateService.class);
94 lock = accountDelegateService.getLockingDocumentId(this, getDocumentNumber());
95 return lock;
96 }
97 }
98
99
100
101
102
103
104
105 @Override
106 public List<MaintenanceLock> generateMaintenanceLocks() {
107
108 List<MaintenanceLock> maintenanceLocks = new ArrayList();
109 AccountDelegateGlobal delegateGlobal = (AccountDelegateGlobal) getBusinessObject();
110
111
112 Set<String> lockingRepresentations = new HashSet<String>();
113
114 MaintenanceLock maintenanceLock;
115 if (ObjectUtils.isNotNull(delegateGlobal)) {
116 for (AccountGlobalDetail accountGlobalDetail : delegateGlobal.getAccountGlobalDetails()) {
117 for (AccountDelegateGlobalDetail delegateGlobalDetail : delegateGlobal.getDelegateGlobals()) {
118 StringBuilder lockRep = new StringBuilder();
119 lockRep.append(AccountDelegate.class.getName());
120 lockRep.append(OLEConstants.Maintenance.AFTER_CLASS_DELIM);
121 lockRep.append("chartOfAccountsCode");
122 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
123 lockRep.append(accountGlobalDetail.getChartOfAccountsCode());
124 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
125 lockRep.append("accountNumber");
126 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
127 lockRep.append(accountGlobalDetail.getAccountNumber());
128 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
129 lockRep.append("financialDocumentTypeCode");
130 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
131 lockRep.append(delegateGlobalDetail.getFinancialDocumentTypeCode());
132 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
133 lockRep.append("accountDelegateSystemId");
134 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
135 lockRep.append(delegateGlobalDetail.getAccountDelegateUniversalId());
136
137
138
139
140 if (!lockingRepresentations.contains(lockRep.toString())) {
141 maintenanceLock = new MaintenanceLock();
142 maintenanceLock.setDocumentNumber(delegateGlobal.getDocumentNumber());
143 maintenanceLock.setLockingRepresentation(lockRep.toString());
144 maintenanceLocks.add(maintenanceLock);
145 lockingRepresentations.add(lockRep.toString());
146 }
147
148 lockRep = new StringBuilder();
149 lockRep.append(AccountDelegate.class.getName());
150 lockRep.append(OLEConstants.Maintenance.AFTER_CLASS_DELIM);
151 lockRep.append("chartOfAccountsCode");
152 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
153 lockRep.append(accountGlobalDetail.getChartOfAccountsCode());
154 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
155 lockRep.append("accountNumber");
156 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
157 lockRep.append(accountGlobalDetail.getAccountNumber());
158 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
159 lockRep.append("financialDocumentTypeCode");
160 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
161 lockRep.append(delegateGlobalDetail.getFinancialDocumentTypeCode());
162 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
163 lockRep.append("accountsDelegatePrmrtIndicator");
164 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
165 lockRep.append("true");
166
167 if (!lockingRepresentations.contains(lockRep.toString())) {
168 maintenanceLock = new MaintenanceLock();
169 maintenanceLock.setDocumentNumber(delegateGlobal.getDocumentNumber());
170 maintenanceLock.setLockingRepresentation(lockRep.toString());
171 maintenanceLocks.add(maintenanceLock);
172 lockingRepresentations.add(lockRep.toString());
173 }
174
175 lockRep = new StringBuilder();
176 lockRep.append(AccountDelegateGlobal.class.getName());
177 lockRep.append(OLEConstants.Maintenance.AFTER_CLASS_DELIM);
178 lockRep.append("chartOfAccountsCode");
179 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
180 lockRep.append(accountGlobalDetail.getChartOfAccountsCode());
181 lockRep.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
182 lockRep.append("accountNumber");
183 lockRep.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
184 lockRep.append(accountGlobalDetail.getAccountNumber());
185
186 if (!lockingRepresentations.contains(lockRep.toString())) {
187 maintenanceLock = new MaintenanceLock();
188 maintenanceLock.setDocumentNumber(delegateGlobal.getDocumentNumber());
189 maintenanceLock.setLockingRepresentation(lockRep.toString());
190 maintenanceLocks.add(maintenanceLock);
191 lockingRepresentations.add(lockRep.toString());
192 }
193 }
194 }
195 }
196 return maintenanceLocks;
197 }
198
199 @Override
200 public Class<? extends PersistableBusinessObject> getPrimaryEditedBusinessObjectClass() {
201 return AccountDelegate.class;
202 }
203
204
205
206
207
208
209 @Override
210 public void saveBusinessObject() {
211 final AccountDelegateGlobal accountDelegateGlobal = (AccountDelegateGlobal)this.getBusinessObject();
212 final AccountDelegateService accountDelegateService = SpringContext.getBean(AccountDelegateService.class);
213
214 accountDelegateService.saveInactivationsForGlobalMaintenanceDocument(accountDelegateGlobal.generateDeactivationsToPersist());
215 accountDelegateService.saveChangesForGlobalMaintenanceDocument(accountDelegateGlobal.generateGlobalChangesToPersist());
216
217 accountDelegateService.updateDelegationRole();
218 }
219 }