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.Collections;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.coa.identity.OrgReviewRole;
24 import org.kuali.ole.coa.service.OrgReviewRoleService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEKeyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
29 import org.kuali.rice.kns.document.MaintenanceDocument;
30 import org.kuali.rice.kns.maintenance.Maintainable;
31 import org.kuali.rice.kns.web.ui.Field;
32 import org.kuali.rice.kns.web.ui.Row;
33 import org.kuali.rice.kns.web.ui.Section;
34 import org.kuali.rice.krad.bo.BusinessObject;
35 import org.kuali.rice.krad.maintenance.MaintenanceLock;
36 import org.kuali.rice.krad.util.GlobalVariables;
37 import org.kuali.rice.krad.util.KRADConstants;
38
39
40 public class OrgReviewRoleMaintainableImpl extends FinancialSystemMaintainable {
41
42 private transient static OrgReviewRoleService orgReviewRoleService;
43
44 @Override
45 public boolean isExternalBusinessObject(){
46 return true;
47 }
48
49 @Override
50 public List<MaintenanceLock> generateMaintenanceLocks() {
51 return Collections.emptyList();
52 }
53
54 @Override
55 public void prepareBusinessObject(BusinessObject businessObject){
56 OrgReviewRole orr = (OrgReviewRole)businessObject;
57
58
59
60
61
62 if( (KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL.equals(orr.getMethodToCall()) ||
63 KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL.equals(orr.getMethodToCall()))
64 &&
65 (StringUtils.isNotEmpty(orr.getODelMId()) || StringUtils.isNotEmpty(orr.getORMId())) ){
66
67 if(StringUtils.isNotEmpty(orr.getODelMId()) && !orr.isCreateDelegation()){
68 getOrgReviewRoleService().populateOrgReviewRoleFromDelegationMember(orr, orr.getORMId(), orr.getODelMId());
69
70 orr.setDelegate(true);
71 if ( KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL.equals(orr.getMethodToCall()) ) {
72 orr.setDelegationMemberId("");
73 }
74 } else if(StringUtils.isNotEmpty(orr.getORMId())){
75 getOrgReviewRoleService().populateOrgReviewRoleFromRoleMember(orr, orr.getORMId());
76
77 if(orr.isCreateDelegation()) {
78 orr.setDelegate(true);
79 if ( KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL.equals(orr.getMethodToCall()) ) {
80 orr.setDelegationMemberId("");
81 }
82 } else {
83 orr.setDelegate(false);
84 if ( KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL.equals(orr.getMethodToCall()) ) {
85 orr.setRoleMemberId("");
86 }
87 }
88 }
89
90 orr.setORMId("");
91 orr.setODelMId("");
92 }
93 setBusinessObject(orr);
94 }
95
96
97
98
99
100 @Override
101 public void processAfterEdit(MaintenanceDocument document, Map<String,String[]> parameters){
102 super.processAfterEdit(document, parameters);
103 OrgReviewRole orr = (OrgReviewRole)document.getOldMaintainableObject().getBusinessObject();
104 orr.setEdit(true);
105 orr = (OrgReviewRole) document.getNewMaintainableObject().getBusinessObject();
106 orr.setEdit(true);
107 if ( orr.isCreateDelegation() ) {
108 orr.setPerson(null);
109 orr.setRole(null);
110 orr.setGroup(null);
111 }
112 }
113
114 @Override
115 public void processAfterCopy(MaintenanceDocument document, Map<String,String[]> parameters){
116 super.processAfterCopy(document, parameters);
117 OrgReviewRole orr = (OrgReviewRole)document.getOldMaintainableObject().getBusinessObject();
118 if(orr.isDelegate() || orr.isCreateDelegation()) {
119 orr.setDelegationMemberId("");
120 } else {
121 orr.setRoleMemberId("");
122 }
123 orr.setCopy(true);
124 orr = (OrgReviewRole) document.getNewMaintainableObject().getBusinessObject();
125 if(orr.isDelegate() || orr.isCreateDelegation()) {
126 orr.setDelegationMemberId("");
127 } else {
128 orr.setRoleMemberId("");
129 }
130 orr.setCopy(true);
131 }
132
133
134
135
136
137
138
139
140
141 @Override
142 public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
143 List<Section> sections = super.getSections(document, oldMaintainable);
144 OrgReviewRole orr = (OrgReviewRole)document.getNewMaintainableObject().getBusinessObject();
145
146 String closestOrgReviewRoleParentDocumentTypeName = getOrgReviewRoleService().getClosestOrgReviewRoleParentDocumentTypeName(orr.getFinancialSystemDocumentTypeCode());
147 boolean isFSTransDoc = StringUtils.equals( orr.getFinancialSystemDocumentTypeCode(), OLEConstants.COAConstants.FINANCIAL_SYSTEM_TRANSACTIONAL_DOCUMENT)
148 || StringUtils.equals( OLEConstants.COAConstants.FINANCIAL_SYSTEM_TRANSACTIONAL_DOCUMENT, closestOrgReviewRoleParentDocumentTypeName);
149 boolean hasAccountingOrganizationHierarchy = isFSTransDoc || getOrgReviewRoleService().hasAccountingOrganizationHierarchy(orr.getFinancialSystemDocumentTypeCode());
150
151 boolean shouldReviewTypesFieldBeReadOnly = isFSTransDoc
152 || getOrgReviewRoleService().hasOrganizationHierarchy(orr.getFinancialSystemDocumentTypeCode())
153 || (StringUtils.isNotBlank(closestOrgReviewRoleParentDocumentTypeName)
154 && StringUtils.equals(closestOrgReviewRoleParentDocumentTypeName, OLEConstants.COAConstants.FINANCIAL_SYSTEM_COMPLEX_MAINTENANCE_DOCUMENT));
155
156
157
158
159 if(oldMaintainable!=null){
160 if(orr.isCreateRoleMember() || orr.isCopyRoleMember()){
161 for (Section section : sections) {
162 for (Row row : section.getRows()) {
163 for (Field field : row.getFields()) {
164 prepareFieldsForCreateRoleMemberMode(field);
165 prepareFieldsCommon(field, shouldReviewTypesFieldBeReadOnly, hasAccountingOrganizationHierarchy );
166 }
167 }
168 }
169 } else if(orr.isDelegate() && (orr.isCopy() || StringUtils.isBlank( orr.getDelegationMemberId() )) ){
170 for (Section section : sections) {
171 for (Row row : section.getRows()) {
172 for (Field field : row.getFields()) {
173 prepareFieldsForCreateDelegationMode(field);
174 prepareFieldsCommon(field, shouldReviewTypesFieldBeReadOnly, hasAccountingOrganizationHierarchy );
175 }
176 }
177 }
178 } else if(orr.isEditRoleMember()){
179 for (Section section : sections) {
180 for (Row row : section.getRows()) {
181 for (Field field : row.getFields()) {
182 prepareFieldsForEditRoleMember(field);
183 prepareFieldsCommon(field, shouldReviewTypesFieldBeReadOnly, hasAccountingOrganizationHierarchy );
184 }
185 }
186 }
187 } else if(orr.isEditDelegation()){
188 for (Section section : sections) {
189 for (Row row : section.getRows()) {
190 for (Field field : row.getFields()) {
191 prepareFieldsForEditDelegation(field);
192 prepareFieldsCommon(field, shouldReviewTypesFieldBeReadOnly, hasAccountingOrganizationHierarchy );
193 }
194 }
195 }
196 }
197 } else if ( orr.isCreateRoleMember() || orr.isCopyRoleMember() || orr.isEditRoleMember()) {
198
199 for (Section section : sections) {
200 for (Row row : section.getRows()) {
201 for (Field field : row.getFields()) {
202 if(OrgReviewRole.DELEGATION_TYPE_CODE.equals(field.getPropertyName())){
203 field.setFieldType(Field.HIDDEN);
204 }
205 }
206 }
207 }
208 }
209 return sections;
210 }
211
212 protected void prepareFieldsCommon(Field field, boolean shouldReviewTypesFieldBeReadOnly, boolean hasAccountingOrganizationHierarchy){
213 if ( field == null ) {
214 throw new IllegalArgumentException( "The Field parameter may not be null." );
215 }
216
217 if(!shouldReviewTypesFieldBeReadOnly) {
218 return;
219 }
220
221 if(OrgReviewRole.REVIEW_ROLES_INDICATOR_FIELD_NAME.equals(field.getPropertyName())) {
222 field.setReadOnly(true);
223 } else if( !hasAccountingOrganizationHierarchy
224 && (OrgReviewRole.FROM_AMOUNT_FIELD_NAME.equals(field.getPropertyName()) ||
225 OrgReviewRole.TO_AMOUNT_FIELD_NAME.equals(field.getPropertyName()) ||
226 OrgReviewRole.OVERRIDE_CODE_FIELD_NAME.equals(field.getPropertyName()))) {
227 field.setReadOnly(true);
228 }
229 }
230
231 protected void setCommonFieldsToReadOnlyOnEdit( Field field ) {
232 if(OrgReviewRole.CHART_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
233 OrgReviewRole.ORG_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
234 OrgReviewRole.DOC_TYPE_NAME_FIELD_NAME.equals(field.getPropertyName()) ||
235 OrgReviewRole.REVIEW_ROLES_INDICATOR_FIELD_NAME.equals(field.getPropertyName()) ||
236 OrgReviewRole.PRINCIPAL_NAME_FIELD_NAME.equals(field.getPropertyName()) ||
237 OrgReviewRole.ROLE_NAME_FIELD_NAME.equals(field.getPropertyName()) ||
238 OrgReviewRole.ROLE_NAME_FIELD_NAMESPACE_CODE.equals(field.getPropertyName()) ||
239 OrgReviewRole.GROUP_NAME_FIELD_NAME.equals(field.getPropertyName()) ||
240 OrgReviewRole.GROUP_NAME_FIELD_NAMESPACE_CODE.equals(field.getPropertyName())){
241 field.setReadOnly(true);
242 }
243 }
244
245 protected void prepareFieldsForEditRoleMember(Field field){
246 setCommonFieldsToReadOnlyOnEdit(field);
247
248 if(OrgReviewRole.DELEGATION_TYPE_CODE.equals(field.getPropertyName())){
249 field.setFieldType(Field.HIDDEN);
250 }
251 }
252
253 protected void prepareFieldsForEditDelegation(Field field){
254 setCommonFieldsToReadOnlyOnEdit(field);
255 if(OrgReviewRole.ACTION_POLICY_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
256 OrgReviewRole.ACTION_TYPE_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
257 OrgReviewRole.PRIORITY_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
258 OrgReviewRole.FORCE_ACTION_FIELD_NAME.equals(field.getPropertyName())){
259 field.setReadOnly(true);
260 }
261 }
262
263 protected void prepareFieldsForCreateRoleMemberMode(Field field){
264
265 if(OrgReviewRole.DELEGATION_TYPE_CODE.equals(field.getPropertyName())){
266 field.setFieldType(Field.HIDDEN);
267 }
268 }
269
270 protected void prepareFieldsForCreateDelegationMode(Field field){
271
272 if(OrgReviewRole.CHART_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
273 OrgReviewRole.ORG_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
274 OrgReviewRole.DOC_TYPE_NAME_FIELD_NAME.equals(field.getPropertyName()) ||
275 OrgReviewRole.REVIEW_ROLES_INDICATOR_FIELD_NAME.equals(field.getPropertyName()) ||
276 OrgReviewRole.ACTION_POLICY_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
277 OrgReviewRole.ACTION_TYPE_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
278 OrgReviewRole.PRIORITY_CODE_FIELD_NAME.equals(field.getPropertyName()) ||
279 OrgReviewRole.FORCE_ACTION_FIELD_NAME.equals(field.getPropertyName())){
280 field.setReadOnly(true);
281 }
282 }
283
284
285
286
287
288 @Override
289 public void saveBusinessObject() {
290 getOrgReviewRoleService().saveOrgReviewRoleToKim((OrgReviewRole)getBusinessObject());
291 }
292
293 protected OrgReviewRoleService getOrgReviewRoleService(){
294 if(orgReviewRoleService==null){
295 orgReviewRoleService = SpringContext.getBean( OrgReviewRoleService.class );
296 }
297 return orgReviewRoleService;
298 }
299
300 @Override
301 public void refresh(String refreshCaller, Map fieldValues, MaintenanceDocument document) {
302 super.refresh(refreshCaller, fieldValues, document);
303 String docTypeName = ((OrgReviewRole)document.getNewMaintainableObject().getBusinessObject()).getFinancialSystemDocumentTypeCode();
304 if(StringUtils.isNotBlank(docTypeName) &&
305 !getOrgReviewRoleService().isValidDocumentTypeForOrgReview(docTypeName) ){
306
307 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(OLEConstants.MAINTENANCE_NEW_MAINTAINABLE + OrgReviewRole.DOC_TYPE_NAME_FIELD_NAME, OLEKeyConstants.ERROR_DOCUMENT_ORGREVIEW_INVALID_DOCUMENT_TYPE, docTypeName);
308 ((OrgReviewRole)document.getNewMaintainableObject().getBusinessObject()).setFinancialSystemDocumentTypeCode("");
309 }
310 }
311
312 }