1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.identity;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.Date;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.kuali.ole.coa.businessobject.Chart;
27 import org.kuali.ole.coa.businessobject.Organization;
28 import org.kuali.ole.coa.service.ChartService;
29 import org.kuali.ole.coa.service.OrgReviewRoleService;
30 import org.kuali.ole.coa.service.OrganizationService;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.OLEPropertyConstants;
33 import org.kuali.ole.sys.context.SpringContext;
34 import org.kuali.ole.sys.identity.OleKimAttributes;
35 import org.kuali.rice.core.api.config.property.ConfigurationService;
36 import org.kuali.rice.core.api.criteria.PredicateUtils;
37 import org.kuali.rice.core.api.criteria.QueryByCriteria;
38 import org.kuali.rice.core.api.delegation.DelegationType;
39 import org.kuali.rice.core.api.membership.MemberType;
40 import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
41 import org.kuali.rice.core.api.util.type.KualiDecimal;
42 import org.kuali.rice.kew.api.action.ActionType;
43 import org.kuali.rice.kew.api.doctype.DocumentTypeService;
44 import org.kuali.rice.kew.doctype.bo.DocumentType;
45 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
46 import org.kuali.rice.kim.api.KimConstants;
47 import org.kuali.rice.kim.api.common.delegate.DelegateMemberContract;
48 import org.kuali.rice.kim.api.identity.Person;
49 import org.kuali.rice.kim.api.role.Role;
50 import org.kuali.rice.kim.api.role.RoleMember;
51 import org.kuali.rice.kim.api.role.RoleMemberContract;
52 import org.kuali.rice.kim.api.role.RoleMemberQueryResults;
53 import org.kuali.rice.kim.api.role.RoleResponsibilityAction;
54 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
55 import org.kuali.rice.kim.api.type.KimType;
56 import org.kuali.rice.kim.api.type.KimTypeAttribute;
57 import org.kuali.rice.kim.framework.group.GroupEbo;
58 import org.kuali.rice.kim.framework.role.RoleEbo;
59 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
60 import org.kuali.rice.krad.service.KualiModuleService;
61 import org.kuali.rice.krad.service.ModuleService;
62 import org.kuali.rice.krad.util.KRADConstants;
63
64
65
66
67 public class OrgReviewRole extends PersistableBusinessObjectBase implements MutableInactivatable {
68
69 public static final String CACHE_NAME = OLEConstants.APPLICATION_NAMESPACE_CODE + "/" + "OrgReviewRole";
70
71 protected static final String ORR_INQUIRY_TITLE_PROPERTY = "message.inquiry.org.review.role.title";
72 protected static String INQUIRY_TITLE_VALUE = null;
73
74 private static transient OrgReviewRoleService orgReviewRoleService;
75 private static transient OrganizationService organizationService;
76 private static transient ChartService chartService;
77
78
79 protected String organizationTypeCode = "99";
80 private static final long serialVersionUID = 1L;
81
82 public static final String REVIEW_ROLES_INDICATOR_FIELD_NAME = "reviewRolesIndicator";
83 public static final String ROLE_NAME_FIELD_NAMESPACE_CODE = "roleMemberRoleNamespaceCode";
84 public static final String ROLE_NAME_FIELD_NAME = "roleMemberRoleName";
85 public static final String GROUP_NAME_FIELD_NAMESPACE_CODE = "groupMemberGroupNamespaceCode";
86 public static final String GROUP_NAME_FIELD_NAME = "groupMemberGroupName";
87 public static final String PRINCIPAL_NAME_FIELD_NAME = "principalMemberPrincipalName";
88 public static final String CHART_CODE_FIELD_NAME = OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE;
89 public static final String ORG_CODE_FIELD_NAME = OLEPropertyConstants.ORGANIZATION_CODE;
90 public static final String DOC_TYPE_NAME_FIELD_NAME = "financialSystemDocumentTypeCode";
91 public static final String DELEGATE_FIELD_NAME = "delegate";
92 public static final String DELEGATION_TYPE_CODE = "delegationTypeCode";
93 public static final String FROM_AMOUNT_FIELD_NAME = "fromAmount";
94 public static final String TO_AMOUNT_FIELD_NAME = "toAmount";
95 public static final String OVERRIDE_CODE_FIELD_NAME = OLEPropertyConstants.OVERRIDE_CODE;
96 public static final String ACTION_TYPE_CODE_FIELD_NAME = "actionTypeCode";
97 public static final String PRIORITY_CODE_FIELD_NAME = "priorityNumber";
98 public static final String ACTION_POLICY_CODE_FIELD_NAME = "actionPolicyCode";
99 public static final String FORCE_ACTION_FIELD_NAME = "forceAction";
100 public static final String ACTIVE_FROM_DATE = "activeFromDate";
101 public static final String ACTIVE_TO_DATE = "activeToDate";
102
103 public static final String ORIGINAL_DELEGATION_MEMBER_ID_TO_MODIFY = "ODelMId";
104 public static final String ORIGINAL_ROLE_MEMBER_ID_TO_MODIFY = "ORMId";
105
106 public static final String NEW_DELEGATION_ID_KEY_VALUE = "New";
107
108 protected String methodToCall;
109 protected String kimTypeId;
110
111 protected String orgReviewRoleMemberId;
112 protected Chart chart;
113 protected Organization organization;
114 protected boolean edit;
115 protected boolean copy;
116
117 protected RoleEbo role;
118 protected GroupEbo group;
119 protected Person person;
120
121 protected List<OleKimDocumentAttributeData> attributes = new ArrayList<OleKimDocumentAttributeData>();
122 protected List<RoleResponsibilityAction> roleRspActions = new ArrayList<RoleResponsibilityAction>();
123
124
125 protected String roleMemberRoleId;
126 protected String roleMemberRoleNamespaceCode;
127 protected String roleMemberRoleName;
128
129 protected String groupMemberGroupId;
130 protected String groupMemberGroupNamespaceCode;
131 protected String groupMemberGroupName;
132
133 protected String principalMemberPrincipalId;
134 protected String principalMemberPrincipalName;
135 protected String principalMemberName;
136
137
138 protected String roleId;
139 protected String namespaceCode;
140 protected String roleName;
141
142
143 protected String memberTypeCode;
144
145
146 protected String delegationTypeCode;
147
148 protected String delegationMemberId;
149 protected String roleMemberId;
150
151 protected String oDelMId;
152 protected String oRMId;
153
154 protected String financialSystemDocumentTypeCode;
155 protected DocumentTypeEBO financialSystemDocumentType;
156 protected List<String> roleNamesToConsider;
157 protected String reviewRolesIndicator;
158
159 protected String actionTypeCode;
160 protected String priorityNumber;
161 protected String actionPolicyCode;
162 protected boolean forceAction;
163 protected String chartOfAccountsCode;
164 protected String organizationCode;
165 protected KualiDecimal fromAmount;
166 protected KualiDecimal toAmount;
167 protected String overrideCode;
168 protected boolean active = true;
169 protected boolean delegate;
170
171 protected Date activeFromDate;
172 protected Date activeToDate;
173
174
175
176
177
178 @Override
179 public boolean isActive() {
180 return active;
181 }
182
183
184
185
186 @Override
187 public void setActive(boolean active) {
188 this.active = active;
189 }
190
191
192
193
194 public boolean isDelegate() {
195 return delegate;
196 }
197
198
199
200
201 public void setDelegate(boolean delegate) {
202 this.delegate = delegate;
203 }
204
205
206
207
208 public Chart getChart() {
209 if (StringUtils.isBlank(getChartOfAccountsCode())) {
210 chart = null;
211 }
212 else {
213 if (chart == null || !StringUtils.equals(getChartOfAccountsCode(), chart.getChartOfAccountsCode())) {
214 chart = getChartService().getByPrimaryId(getChartOfAccountsCode());
215 }
216 }
217 return chart;
218 }
219
220
221
222
223 public String getGroupMemberGroupId() {
224 if ( StringUtils.isBlank(groupMemberGroupId) ) {
225 if ( StringUtils.isNotBlank(groupMemberGroupNamespaceCode) && StringUtils.isNotBlank(groupMemberGroupName) ) {
226 getGroup();
227 }
228 }
229 return groupMemberGroupId;
230 }
231
232
233
234
235 public void setGroupMemberGroupId(String groupMemberGroupId) {
236 this.groupMemberGroupId = groupMemberGroupId;
237 }
238
239
240
241
242 public String getGroupMemberGroupName() {
243 return groupMemberGroupName;
244 }
245
246
247
248
249 public void setGroupMemberGroupName(String groupMemberGroupName) {
250 this.groupMemberGroupName = groupMemberGroupName;
251 }
252
253
254
255
256 public String getGroupMemberGroupNamespaceCode() {
257 return groupMemberGroupNamespaceCode;
258 }
259
260
261
262
263 public void setGroupMemberGroupNamespaceCode(String groupMemberGroupNamespaceCode) {
264 this.groupMemberGroupNamespaceCode = groupMemberGroupNamespaceCode;
265 }
266
267
268
269
270 public String getPrincipalMemberPrincipalId() {
271 if ( StringUtils.isBlank(principalMemberPrincipalId) ) {
272 if ( StringUtils.isNotBlank(principalMemberPrincipalName) ) {
273 getPerson();
274 }
275 }
276 return principalMemberPrincipalId;
277 }
278
279
280
281
282 public void setPrincipalMemberPrincipalId(String principalMemberPrincipalId) {
283 this.principalMemberPrincipalId = principalMemberPrincipalId;
284 }
285
286
287
288
289 public String getPrincipalMemberPrincipalName() {
290 if ( StringUtils.isBlank(principalMemberPrincipalName) ) {
291 getPerson();
292 }
293 return principalMemberPrincipalName;
294 }
295
296 public String getPrincipalMemberName() {
297 if ( StringUtils.isBlank(principalMemberName) ) {
298 getPerson();
299 }
300 return principalMemberName;
301 }
302
303
304
305
306
307 public void setPrincipalMemberPrincipalName(String principalMemberPrincipalName) {
308 this.principalMemberPrincipalName = principalMemberPrincipalName;
309 }
310
311
312
313
314 public String getRoleMemberRoleId() {
315 if ( StringUtils.isBlank(roleMemberRoleId) ) {
316 if ( StringUtils.isNotBlank(roleMemberRoleName) && StringUtils.isNotBlank(roleMemberRoleName) ) {
317 getRole();
318 }
319 }
320 return roleMemberRoleId;
321 }
322
323
324
325
326 public void setRoleMemberRoleId(String roleMemberRoleId) {
327 this.roleMemberRoleId = roleMemberRoleId;
328 }
329
330
331
332
333 public String getRoleMemberRoleName() {
334 return roleMemberRoleName;
335 }
336
337
338
339
340 public void setRoleMemberRoleName(String roleMemberRoleName) {
341 this.roleMemberRoleName = roleMemberRoleName;
342 }
343
344
345
346
347 public String getRoleMemberRoleNamespaceCode() {
348 return roleMemberRoleNamespaceCode;
349 }
350
351
352
353
354 public void setRoleMemberRoleNamespaceCode(String roleMemberRoleNamespaceCode) {
355 this.roleMemberRoleNamespaceCode = roleMemberRoleNamespaceCode;
356 }
357
358
359
360
361 public Organization getOrganization() {
362 if (StringUtils.isBlank(getChartOfAccountsCode()) || StringUtils.isBlank(getOrganizationCode())) {
363 organization = null;
364 }
365 else {
366 if (organization == null || !StringUtils.equals(getChartOfAccountsCode(), chart.getChartOfAccountsCode())
367 || !StringUtils.equals(getOrganizationCode(), organization.getOrganizationCode())) {
368 organization = getOrganizationService().getByPrimaryIdWithCaching(getChartOfAccountsCode(),
369 getOrganizationCode());
370 }
371 }
372 return organization;
373 }
374
375
376
377
378
379 public String getOverrideCode() {
380 return this.overrideCode;
381 }
382
383
384
385
386 public void setOverrideCode(String overrideCode) {
387 this.overrideCode = overrideCode;
388 }
389
390
391
392
393
394 public KualiDecimal getFromAmount() {
395 return fromAmount;
396 }
397
398 public String getFromAmountStr() {
399 return fromAmount==null?null:fromAmount.toString();
400 }
401
402
403
404
405
406 public void setFromAmount(KualiDecimal fromAmount) {
407 this.fromAmount = fromAmount;
408 }
409
410 public void setFromAmount(String fromAmount) {
411 if (StringUtils.isNotEmpty(fromAmount) && StringUtils.isNumeric(fromAmount)) {
412 this.fromAmount = new KualiDecimal(fromAmount);
413 }
414 else {
415 this.fromAmount = null;
416 }
417 }
418
419
420
421
422
423 public KualiDecimal getToAmount() {
424 return toAmount;
425 }
426
427 public String getToAmountStr() {
428 return toAmount==null?null:toAmount.toString();
429 }
430
431
432
433
434
435 public void setToAmount(KualiDecimal toAmount) {
436 this.toAmount = toAmount;
437 }
438
439 public void setToAmount(String toAmount) {
440 if (StringUtils.isNotEmpty(toAmount) && StringUtils.isNumeric(toAmount)) {
441 this.toAmount = new KualiDecimal(toAmount);
442 }
443 else {
444 this.toAmount = null;
445 }
446 }
447
448
449
450
451
452 public Date getActiveFromDate() {
453 return activeFromDate;
454 }
455
456
457
458
459 public void setActiveFromDate(java.util.Date activeFromDate) {
460 this.activeFromDate = activeFromDate;
461 }
462
463
464
465
466
467 public Date getActiveToDate() {
468 return activeToDate;
469 }
470
471
472
473
474 public void setActiveToDate(java.util.Date activeToDate) {
475 this.activeToDate = activeToDate;
476 }
477
478
479
480
481
482 public String getOrgReviewRoleMemberId() {
483 return orgReviewRoleMemberId;
484 }
485
486
487
488
489 public void setOrgReviewRoleMemberId(String orgReviewRoleMemberId) {
490 this.orgReviewRoleMemberId = orgReviewRoleMemberId;
491 }
492
493 @Override
494 public void refresh() {}
495
496
497
498
499
500 public DocumentTypeEBO getFinancialSystemDocumentType() {
501 if ( StringUtils.isBlank( financialSystemDocumentTypeCode ) ) {
502 financialSystemDocumentType = null;
503 } else {
504 if ( financialSystemDocumentType == null || !StringUtils.equals(financialSystemDocumentTypeCode, financialSystemDocumentType.getName() ) ) {
505 org.kuali.rice.kew.api.doctype.DocumentType temp = SpringContext.getBean(DocumentTypeService.class).getDocumentTypeByName(financialSystemDocumentTypeCode);
506 if ( temp != null ) {
507 financialSystemDocumentType = DocumentType.from( temp );
508 } else {
509 financialSystemDocumentType = null;
510 }
511 }
512 }
513 return financialSystemDocumentType;
514 }
515
516
517
518
519
520 public String getFinancialSystemDocumentTypeCode() {
521 return financialSystemDocumentTypeCode;
522 }
523
524
525
526
527 public void setFinancialSystemDocumentTypeCode(String financialSystemDocumentTypeCode) {
528 boolean isChanged = !StringUtils.equals(this.financialSystemDocumentTypeCode, financialSystemDocumentTypeCode);
529 this.financialSystemDocumentTypeCode = financialSystemDocumentTypeCode;
530 setRoleNamesAndReviewIndicator(isChanged);
531 }
532
533 private void setRoleNamesAndReviewIndicator(boolean hasFinancialSystemDocumentTypeCodeChanged){
534 if(hasFinancialSystemDocumentTypeCodeChanged){
535
536 if(StringUtils.isNotBlank(getRoleId()) && StringUtils.isNotBlank(getRoleName())){
537 setRoleNamesToConsider(Collections.singletonList(getRoleName()));
538 } else {
539 setRoleNamesToConsider();
540 }
541 if(isBothReviewRolesIndicator()) {
542 setReviewRolesIndicatorOnDocTypeChange(OLEConstants.COAConstants.ORG_REVIEW_ROLE_ORG_ACC_BOTH_CODE);
543 } else if(isAccountingOrgReviewRoleIndicator()) {
544 setReviewRolesIndicatorOnDocTypeChange(OLEConstants.COAConstants.ORG_REVIEW_ROLE_ORG_ACC_ONLY_CODE);
545 } else if(isOrgReviewRoleIndicator()) {
546 setReviewRolesIndicatorOnDocTypeChange(OLEConstants.COAConstants.ORG_REVIEW_ROLE_ORG_ONLY_CODE);
547 }
548 }
549 }
550
551
552
553
554
555 public void setFinancialSystemDocumentType(DocumentTypeEBO financialSystemDocumentType) {
556 this.financialSystemDocumentType = financialSystemDocumentType;
557 }
558
559
560
561
562 public String getDelegationTypeCode() {
563 return delegationTypeCode;
564 }
565
566 public String getDelegationTypeCodeDescription() {
567 if ( getDelegationType() != null ) {
568 return getDelegationType().getLabel();
569 }
570 return "";
571 }
572
573 public DelegationType getDelegationType() {
574 return DelegationType.parseCode(delegationTypeCode);
575 }
576
577
578
579
580
581 public void setDelegationTypeCode(String delegationTypeCode) {
582 this.delegationTypeCode = delegationTypeCode;
583 }
584
585
586
587
588
589 public String getMemberTypeCodeDescription() {
590 return KimConstants.KimUIConstants.KIM_MEMBER_TYPES_MAP.get(memberTypeCode);
591 }
592
593
594
595
596 public void setMemberTypeCode(String memberTypeCode) {
597 this.memberTypeCode = memberTypeCode;
598 }
599
600
601
602
603 public void setAttributes(List<OleKimDocumentAttributeData> attributes) {
604 this.attributes = attributes;
605 }
606
607 public List<OleKimDocumentAttributeData> getAttributes() {
608 return attributes;
609 }
610
611 public String getAttributeValue(String attributeName){
612 OleKimDocumentAttributeData attributeData = getAttribute(attributeName);
613 return attributeData==null?"":attributeData.getAttrVal();
614 }
615
616 protected OleKimDocumentAttributeData getAttribute(String attributeName){
617 if(StringUtils.isNotBlank(attributeName)) {
618 for(OleKimDocumentAttributeData attribute: attributes){
619 if( attribute.getKimAttribute()!=null
620 && StringUtils.equals(attribute.getKimAttribute().getAttributeName(),attributeName)){
621 return attribute;
622 }
623 }
624 }
625 return null;
626 }
627
628
629
630
631
632 public String getChartOfAccountsCode() {
633 return this.chartOfAccountsCode;
634 }
635
636
637
638
639 public String getOrganizationCode() {
640 return this.organizationCode;
641 }
642
643
644
645
646 public void setOrganizationCode(String organizationCode) {
647 this.organizationCode = organizationCode;
648 }
649
650
651
652
653 public void setChartOfAccountsCode(String chartOfAccountsCode) {
654 this.chartOfAccountsCode = chartOfAccountsCode;
655 }
656
657
658
659
660 public List<String> getRoleNamesToConsider() {
661 if(roleNamesToConsider==null && getFinancialSystemDocumentTypeCode()!=null) {
662 setRoleNamesToConsider();
663 }
664 return roleNamesToConsider;
665 }
666 public void setRoleNamesToConsider(List<String> narrowedDownRoleNames) {
667 roleNamesToConsider = new ArrayList<String>( narrowedDownRoleNames );
668 }
669
670
671
672
673 public void setRoleNamesToConsider() {
674 roleNamesToConsider = getOrgReviewRoleService().getRolesToConsider(getFinancialSystemDocumentTypeCode());
675 }
676
677
678
679
680 public boolean isAccountingOrgReviewRoleIndicator() {
681 return getRoleNamesToConsider()!=null &&
682 getRoleNamesToConsider().contains(OLEConstants.SysKimApiConstants.ACCOUNTING_REVIEWER_ROLE_NAME);
683 }
684
685
686
687
688 public boolean isBothReviewRolesIndicator() {
689 return getRoleNamesToConsider()!=null &&
690 getRoleNamesToConsider().contains(OLEConstants.SysKimApiConstants.ORGANIZATION_REVIEWER_ROLE_NAME) &&
691 getRoleNamesToConsider().contains(OLEConstants.SysKimApiConstants.ACCOUNTING_REVIEWER_ROLE_NAME);
692 }
693
694
695
696
697 public boolean isOrgReviewRoleIndicator() {
698 return getRoleNamesToConsider()!=null &&
699 getRoleNamesToConsider().contains(OLEConstants.SysKimApiConstants.ORGANIZATION_REVIEWER_ROLE_NAME);
700 }
701
702
703
704
705 public String getActionTypeCode() {
706 return actionTypeCode;
707 }
708
709 public String getActionTypeCodeToDisplay() {
710 if(roleRspActions==null || roleRspActions.isEmpty()) {
711 return "";
712 }
713 return roleRspActions.get(0).getActionTypeCode();
714 }
715
716
717
718
719
720
721
722 public String getActionTypeCodeDescription() {
723 ActionType at = ActionType.fromCode(getActionTypeCodeToDisplay(), true);
724 return (at==null)?"":at.getLabel();
725 }
726
727
728
729
730
731 public void setActionTypeCode(String actionTypeCode) {
732 this.actionTypeCode = actionTypeCode;
733 }
734
735
736
737
738 public String getPriorityNumber() {
739 return priorityNumber;
740 }
741
742 public String getPriorityNumberToDisplay() {
743 if(roleRspActions==null || roleRspActions.isEmpty() ) {
744 return "";
745 }
746 return roleRspActions.get(0).getPriorityNumber()==null?"":roleRspActions.get(0).getPriorityNumber()+"";
747 }
748
749
750
751
752
753 public void setPriorityNumber(String priorityNumber) {
754 this.priorityNumber = priorityNumber;
755 }
756
757
758
759
760 public String getActionPolicyCode() {
761 return actionPolicyCode;
762 }
763
764
765
766
767 public void setActionPolicyCode(String actionPolicyCode) {
768 this.actionPolicyCode = actionPolicyCode;
769 }
770
771
772
773
774 public boolean isForceAction() {
775 return forceAction;
776 }
777
778
779
780
781 public void setForceAction(boolean forceAction) {
782 this.forceAction = forceAction;
783 }
784
785
786
787
788
789 public String getRoleId() {
790 return roleId;
791 }
792
793
794
795
796 public void setRoleId(String roleId) {
797 Role roleInfo = KimApiServiceLocator.getRoleService().getRole(roleId);
798 if ( roleInfo != null ) {
799 setNamespaceCode(roleInfo.getNamespaceCode());
800 setRoleName(roleInfo.getName());
801 setKimTypeId(roleInfo.getKimTypeId());
802 }
803 this.roleId = roleId;
804 }
805
806
807
808
809 public String getReviewRolesIndicator() {
810 return reviewRolesIndicator;
811 }
812
813
814
815
816 public void setReviewRolesIndicator(String reviewRolesIndicator) {
817 this.reviewRolesIndicator = reviewRolesIndicator;
818 }
819
820
821
822
823 private void setReviewRolesIndicatorOnDocTypeChange(String reviewRolesIndicator) {
824 this.reviewRolesIndicator = reviewRolesIndicator;
825 }
826
827
828 public boolean hasRole(){
829 getRole();
830 return StringUtils.isNotBlank(roleMemberRoleName);
831 }
832
833 public boolean hasGroup(){
834 getGroup();
835 return StringUtils.isNotBlank(groupMemberGroupName);
836 }
837
838 public boolean hasPrincipal(){
839 getPerson();
840 return StringUtils.isNotBlank(principalMemberPrincipalName);
841 }
842
843 public boolean hasAnyMember(){
844 return hasRole() || hasGroup() || hasPrincipal();
845 }
846
847 public void setRoleMember( RoleMemberContract roleMember ) {
848 memberTypeCode = roleMember.getType().getCode();
849 if(MemberType.ROLE.equals(roleMember.getType())){
850 roleMemberRoleId = roleMember.getMemberId();
851 roleMemberRoleNamespaceCode = roleMember.getMemberNamespaceCode();
852 roleMemberRoleName = roleMember.getMemberName();
853 } else if(MemberType.GROUP.equals(roleMember.getType())){
854 groupMemberGroupId = roleMember.getMemberId();
855 groupMemberGroupNamespaceCode = roleMember.getMemberNamespaceCode();
856 groupMemberGroupName = roleMember.getMemberName();
857 } else if(MemberType.PRINCIPAL.equals(roleMember.getType())){
858 principalMemberPrincipalId = roleMember.getMemberId();
859 principalMemberPrincipalName = roleMember.getMemberName();
860 }
861
862 if ( roleMember.getActiveFromDate() != null ) {
863 setActiveFromDate(roleMember.getActiveFromDate().toDate());
864 } else {
865 setActiveFromDate( null );
866 }
867 if ( roleMember.getActiveToDate() != null ) {
868 setActiveToDate(roleMember.getActiveToDate().toDate());
869 } else {
870 setActiveToDate( null );
871 }
872 setActive(roleMember.isActive());
873
874 setRoleMemberId(roleMember.getId());
875 setDelegate(false);
876 setRoleId(roleMember.getRoleId());
877
878 setRoleRspActions(KimApiServiceLocator.getRoleService().getRoleMemberResponsibilityActions(roleMember.getId()));
879
880 extractAttributesFromMap(roleMember.getAttributes());
881 }
882
883 public void extractAttributesFromMap( Map<String,String> attributes ) {
884 setAttributes(getAttributeSetAsQualifierList(attributes));
885
886
887 setChartOfAccountsCode(getAttributeValue(OleKimAttributes.CHART_OF_ACCOUNTS_CODE));
888 setOrganizationCode(getAttributeValue(OleKimAttributes.ORGANIZATION_CODE));
889 setOverrideCode(getAttributeValue(OleKimAttributes.ACCOUNTING_LINE_OVERRIDE_CODE));
890 setFromAmount(getAttributeValue(OleKimAttributes.FROM_AMOUNT));
891 setToAmount(getAttributeValue(OleKimAttributes.TO_AMOUNT));
892 setFinancialSystemDocumentTypeCode(getAttributeValue(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME));
893 }
894
895 public void setDelegateMember( RoleMemberContract roleMember, DelegateMemberContract delegateMember ) {
896 if ( roleMember == null ) {
897 roleMember = getRoleMemberFromKimRoleService( delegateMember.getRoleMemberId() );
898 }
899 setRoleId( roleMember.getRoleId() );
900 memberTypeCode = delegateMember.getType().getCode();
901 if(MemberType.ROLE.equals(delegateMember.getType())){
902 roleMemberRoleId = delegateMember.getMemberId();
903 getRole();
904 } else if(MemberType.GROUP.equals(delegateMember.getType())){
905 groupMemberGroupId = delegateMember.getMemberId();
906 getGroup();
907 } else if(MemberType.PRINCIPAL.equals(delegateMember.getType())){
908 principalMemberPrincipalId = delegateMember.getMemberId();
909 getPerson();
910 }
911
912 if ( delegateMember.getActiveFromDate() != null ) {
913 setActiveFromDate(delegateMember.getActiveFromDate().toDate());
914 }
915 if ( delegateMember.getActiveToDate() != null ) {
916 setActiveToDate(delegateMember.getActiveToDate().toDate());
917 }
918 setActive(delegateMember.isActive());
919 setDelegate(true);
920 setDelegationMemberId(delegateMember.getDelegationMemberId());
921 setRoleMemberId(roleMember.getId());
922
923 extractAttributesFromMap(delegateMember.getAttributes());
924 }
925
926 protected RoleMember getRoleMemberFromKimRoleService( String roleMemberId ) {
927 RoleMemberQueryResults roleMembers = KimApiServiceLocator.getRoleService().findRoleMembers(QueryByCriteria.Builder.fromPredicates( PredicateUtils.convertMapToPredicate(Collections.singletonMap(KimConstants.PrimaryKeyConstants.ID, roleMemberId))));
928 if ( roleMembers == null || roleMembers.getResults() == null || roleMembers.getResults().isEmpty() ) {
929 throw new IllegalArgumentException( "Unknown role member ID passed in - nothing returned from KIM RoleService: " + roleMemberId );
930 }
931 return roleMembers.getResults().get(0);
932 }
933
934 public String getMemberId() {
935 if(MemberType.ROLE.getCode().equals(memberTypeCode)){
936 return getRoleMemberRoleId();
937 } else if(MemberType.GROUP.getCode().equals(memberTypeCode)){
938 return getGroupMemberGroupId();
939 } else if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)){
940 return getPrincipalMemberPrincipalId();
941 }
942 return "";
943 }
944
945 public String getMemberName() {
946 if(MemberType.ROLE.getCode().equals(memberTypeCode)){
947 return getRoleMemberRoleName();
948 } else if(MemberType.GROUP.getCode().equals(memberTypeCode)){
949 return getGroupMemberGroupName();
950 } else if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)){
951 return getPrincipalMemberName();
952 }
953 return "";
954 }
955
956 public String getMemberNamespaceCode() {
957 if(MemberType.ROLE.getCode().equals(memberTypeCode)){
958 return getRoleMemberRoleNamespaceCode();
959 } else if(MemberType.GROUP.getCode().equals(memberTypeCode)){
960 return getGroupMemberGroupNamespaceCode();
961 } else if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)){
962 return "";
963 }
964 return "";
965 }
966
967 public String getMemberFieldName(){
968 if(MemberType.ROLE.equals(getMemberType())) {
969 return ROLE_NAME_FIELD_NAME;
970 } else if(MemberType.GROUP.equals(getMemberType())) {
971 return GROUP_NAME_FIELD_NAME;
972 } else if(MemberType.PRINCIPAL.equals(getMemberType())) {
973 return PRINCIPAL_NAME_FIELD_NAME;
974 }
975 return null;
976 }
977
978
979
980
981
982 public String getMemberTypeCode() {
983 return memberTypeCode;
984 }
985
986 public MemberType getMemberType() {
987 if ( StringUtils.isBlank(memberTypeCode) ) {
988 return null;
989 }
990 return MemberType.fromCode(memberTypeCode);
991 }
992
993
994
995
996
997 public GroupEbo getGroup() {
998 if ( (group == null || !StringUtils.equals(group.getId(), groupMemberGroupId)) && StringUtils.isNotBlank(groupMemberGroupId) ) {
999 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(GroupEbo.class);
1000 if ( moduleService != null ) {
1001 Map<String,Object> keys = new HashMap<String, Object>(1);
1002 keys.put(KimConstants.PrimaryKeyConstants.ID, groupMemberGroupId);
1003 group = moduleService.getExternalizableBusinessObject(GroupEbo.class, keys);
1004 groupMemberGroupNamespaceCode = group.getNamespaceCode();
1005 groupMemberGroupName = group.getName();
1006 } else {
1007 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
1008 }
1009 } else if ( StringUtils.isNotBlank(groupMemberGroupName) ) {
1010 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(GroupEbo.class);
1011 if ( moduleService != null ) {
1012
1013 if ( StringUtils.isNotBlank(groupMemberGroupNamespaceCode) ) {
1014 Map<String,Object> keys = new HashMap<String, Object>(2);
1015 keys.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, groupMemberGroupNamespaceCode);
1016 keys.put(KimConstants.UniqueKeyConstants.GROUP_NAME, groupMemberGroupName);
1017 List<GroupEbo> groups = moduleService.getExternalizableBusinessObjectsList(GroupEbo.class, keys);
1018
1019 if ( groups != null && !groups.isEmpty() ) {
1020 group = groups.get(0);
1021 groupMemberGroupId = group.getId();
1022 } else {
1023 group = null;
1024 groupMemberGroupId = "";
1025 }
1026 } else {
1027 Map<String,Object> keys = new HashMap<String, Object>(1);
1028 keys.put(KimConstants.UniqueKeyConstants.GROUP_NAME, groupMemberGroupName);
1029 List<GroupEbo> groups = moduleService.getExternalizableBusinessObjectsList(GroupEbo.class, keys);
1030
1031 if ( groups != null && groups.size() == 1 ) {
1032 group = groups.get(0);
1033 groupMemberGroupId = group.getId();
1034 groupMemberGroupNamespaceCode = group.getNamespaceCode();
1035 } else {
1036 group = null;
1037 groupMemberGroupId = "";
1038 }
1039 }
1040 } else {
1041 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
1042 }
1043 } else {
1044 group = null;
1045 }
1046 return group;
1047 }
1048
1049
1050
1051
1052 public void setGroup(GroupEbo group) {
1053 this.group = group;
1054 if ( group != null ) {
1055 groupMemberGroupNamespaceCode = group.getNamespaceCode();
1056 groupMemberGroupName = group.getName();
1057 groupMemberGroupId = group.getId();
1058 } else {
1059 groupMemberGroupNamespaceCode = "";
1060 groupMemberGroupName = "";
1061 groupMemberGroupId = "";
1062 }
1063 }
1064
1065
1066
1067
1068 public Person getPerson() {
1069 if( (StringUtils.isNotEmpty(principalMemberPrincipalId)
1070 || StringUtils.isNotEmpty(principalMemberPrincipalName))
1071 &&
1072 (person==null || !StringUtils.equals(person.getPrincipalId(), principalMemberPrincipalId) ) ) {
1073 if ( StringUtils.isNotEmpty(principalMemberPrincipalId) ) {
1074 person = KimApiServiceLocator.getPersonService().getPerson(principalMemberPrincipalId);
1075 } else if ( StringUtils.isNotEmpty(principalMemberPrincipalName) ) {
1076 person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalMemberPrincipalName);
1077 } else {
1078 person = null;
1079 }
1080 if ( person != null ) {
1081 principalMemberPrincipalId = person.getPrincipalId();
1082 principalMemberPrincipalName = person.getPrincipalName();
1083 principalMemberName = person.getName();
1084 } else {
1085 principalMemberPrincipalId = "";
1086 principalMemberName = "";
1087 }
1088 }
1089 return person;
1090 }
1091
1092
1093
1094
1095 public void setPerson(Person person) {
1096 this.person = person;
1097 if ( person != null ) {
1098 principalMemberPrincipalName = person.getPrincipalName();
1099 principalMemberPrincipalId = person.getPrincipalId();
1100 principalMemberName = person.getName();
1101 } else {
1102 principalMemberPrincipalId = "";
1103 principalMemberPrincipalName = "";
1104 principalMemberName = "";
1105 }
1106 }
1107
1108
1109
1110
1111
1112 public RoleEbo getRole() {
1113 if ( (role == null || !StringUtils.equals(role.getId(), roleMemberRoleId)) && StringUtils.isNotBlank(roleMemberRoleId) ) {
1114 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(RoleEbo.class);
1115 if ( moduleService != null ) {
1116 Map<String,Object> keys = new HashMap<String, Object>(1);
1117 keys.put(KimConstants.PrimaryKeyConstants.ROLE_ID, roleMemberRoleId);
1118 role = moduleService.getExternalizableBusinessObject(RoleEbo.class, keys);
1119 roleMemberRoleNamespaceCode = role.getNamespaceCode();
1120 roleMemberRoleName = role.getName();
1121 } else {
1122 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
1123 }
1124 } else if ( StringUtils.isNotBlank(roleMemberRoleName) ) {
1125 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(RoleEbo.class);
1126 if ( moduleService != null ) {
1127
1128 if ( StringUtils.isNotBlank(roleMemberRoleNamespaceCode) ) {
1129 Map<String,Object> keys = new HashMap<String, Object>(2);
1130 keys.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, roleMemberRoleNamespaceCode);
1131 keys.put(KimConstants.UniqueKeyConstants.NAME, roleMemberRoleName);
1132 List<RoleEbo> roles = moduleService.getExternalizableBusinessObjectsList(RoleEbo.class, keys);
1133
1134 if ( roles != null && !roles.isEmpty() ) {
1135 role = roles.get(0);
1136 roleMemberRoleId = role.getId();
1137 } else {
1138 role = null;
1139 roleMemberRoleId = "";
1140 }
1141 } else {
1142 Map<String,Object> keys = new HashMap<String, Object>(1);
1143 keys.put(KimConstants.UniqueKeyConstants.NAME, roleMemberRoleName);
1144 List<RoleEbo> roles = moduleService.getExternalizableBusinessObjectsList(RoleEbo.class, keys);
1145
1146 if ( roles != null && roles.size() == 1 ) {
1147 role = roles.get(0);
1148 roleMemberRoleId = role.getId();
1149 roleMemberRoleNamespaceCode = role.getNamespaceCode();
1150 } else {
1151 role = null;
1152 roleMemberRoleId = "";
1153 }
1154 }
1155 } else {
1156 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
1157 }
1158 } else {
1159 role = null;
1160 }
1161 return role;
1162 }
1163
1164 public void setRole( RoleEbo role ) {
1165 this.role = role;
1166 if ( role != null ) {
1167 roleMemberRoleNamespaceCode = role.getNamespaceCode();
1168 roleMemberRoleName = role.getName();
1169 roleMemberRoleId = role.getId();
1170 } else {
1171 roleMemberRoleNamespaceCode = "";
1172 roleMemberRoleName = "";
1173 roleMemberRoleId = "";
1174 }
1175 }
1176
1177
1178
1179
1180
1181 public boolean isCopy() {
1182 return copy || KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL.equalsIgnoreCase(methodToCall);
1183 }
1184
1185
1186
1187
1188 public void setCopy(boolean copy) {
1189 this.copy = copy;
1190 }
1191
1192
1193
1194
1195 public boolean isEdit() {
1196 return edit || KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL.equalsIgnoreCase(methodToCall);
1197 }
1198
1199
1200
1201
1202 public void setEdit(boolean edit) {
1203 this.edit = edit;
1204 }
1205
1206
1207
1208
1209 public String getODelMId() {
1210 return oDelMId;
1211 }
1212
1213
1214
1215
1216 public void setODelMId(String delMId) {
1217 oDelMId = delMId;
1218 }
1219
1220
1221
1222
1223 public String getORMId() {
1224 return oRMId;
1225 }
1226
1227
1228
1229
1230 public void setORMId(String id) {
1231 oRMId = id;
1232 }
1233
1234
1235
1236
1237 public String getDelegationMemberId() {
1238 return delegationMemberId;
1239 }
1240
1241
1242
1243
1244 public void setDelegationMemberId(String delegationMemberId) {
1245 this.delegationMemberId = delegationMemberId;
1246 }
1247
1248
1249
1250
1251 public String getRoleMemberId() {
1252 return roleMemberId;
1253 }
1254
1255
1256
1257
1258 public void setRoleMemberId(String roleMemberId) {
1259 this.roleMemberId = roleMemberId;
1260 }
1261
1262
1263
1264
1265 public String getMethodToCall() {
1266 return methodToCall;
1267 }
1268
1269
1270
1271
1272 public void setMethodToCall(String methodToCall) {
1273 this.methodToCall = methodToCall;
1274 }
1275
1276 public boolean isEditDelegation(){
1277 return isEdit() && isDelegate();
1278 }
1279
1280 public boolean isEditRoleMember(){
1281 return isEdit() && !isDelegate();
1282 }
1283
1284 public boolean isCopyDelegation(){
1285 return isCopy() && isDelegate();
1286 }
1287
1288 public boolean isCopyRoleMember(){
1289 return isCopy() && !isDelegate();
1290 }
1291
1292 public boolean isCreateDelegation(){
1293 return NEW_DELEGATION_ID_KEY_VALUE.equals(getODelMId()) || (isEditDelegation() && StringUtils.isBlank(getDelegationMemberId()));
1294 }
1295
1296 public boolean isCreateRoleMember(){
1297 return StringUtils.isEmpty(methodToCall);
1298 }
1299
1300 public String getOrganizationTypeCode() {
1301 return "99";
1302 }
1303 public void setOrganizationTypeCode(String organizationTypeCode) {
1304 }
1305 public String getRoleName() {
1306 return roleName;
1307 }
1308 public void setRoleName(String roleName) {
1309 this.roleName = roleName;
1310 setRoleNamesToConsider( Collections.singletonList(roleName) );
1311 }
1312 public String getNamespaceCode() {
1313 return namespaceCode;
1314 }
1315 public void setNamespaceCode(String namespaceCode) {
1316 this.namespaceCode = namespaceCode;
1317 }
1318
1319 @Override
1320 public Long getVersionNumber(){
1321 return 1L;
1322 }
1323
1324 public String getKimTypeId() {
1325 return kimTypeId;
1326 }
1327 public void setKimTypeId(String kimTypeId) {
1328 this.kimTypeId = kimTypeId;
1329 }
1330
1331 public Map<String,String> getQualifierAsAttributeSet(List<OleKimDocumentAttributeData> qualifiers) {
1332 Map<String,String> m = new HashMap<String,String>();
1333 for(OleKimDocumentAttributeData data: qualifiers){
1334 m.put(data.getKimAttribute().getAttributeName(), data.getAttrVal());
1335 }
1336 return m;
1337 }
1338
1339 public List<OleKimDocumentAttributeData> getAttributeSetAsQualifierList( Map<String,String> qualifiers) {
1340 KimType kimTypeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId);
1341 List<OleKimDocumentAttributeData> attributesList = new ArrayList<OleKimDocumentAttributeData>();
1342 OleKimDocumentAttributeData attribData;
1343 for(String key: qualifiers.keySet()){
1344 KimTypeAttribute attribInfo = kimTypeInfo.getAttributeDefinitionByName(key);
1345 attribData = new OleKimDocumentAttributeData();
1346 attribData.setKimAttribute(attribInfo.getKimAttribute());
1347 attribData.setKimTypId(kimTypeInfo.getId());
1348 attribData.setKimAttrDefnId(attribInfo.getId());
1349
1350 attribData.setAttrVal(qualifiers.get(key));
1351 attributesList.add(attribData);
1352 }
1353 return attributesList;
1354 }
1355
1356
1357
1358
1359 public List<RoleResponsibilityAction> getRoleRspActions() {
1360 if ( roleRspActions == null ) {
1361 roleRspActions = new ArrayList<RoleResponsibilityAction>(1);
1362 }
1363 return roleRspActions;
1364 }
1365
1366
1367
1368
1369 public void setRoleRspActions(List<RoleResponsibilityAction> roleRspActions) {
1370 this.roleRspActions = roleRspActions;
1371 }
1372
1373 public String getOrgReviewRoleInquiryTitle() {
1374 if ( INQUIRY_TITLE_VALUE == null ) {
1375 INQUIRY_TITLE_VALUE = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(ORR_INQUIRY_TITLE_PROPERTY);
1376 }
1377 return INQUIRY_TITLE_VALUE;
1378 }
1379
1380 @Override
1381 public void refreshNonUpdateableReferences() {
1382
1383 }
1384
1385 @Override
1386 public void refreshReferenceObject(String referenceObjectName) {
1387
1388 }
1389
1390 protected static OrgReviewRoleService getOrgReviewRoleService() {
1391 if ( orgReviewRoleService == null ) {
1392 orgReviewRoleService = SpringContext.getBean(OrgReviewRoleService.class);
1393 }
1394 return orgReviewRoleService;
1395 }
1396
1397 protected static ChartService getChartService() {
1398 if (chartService == null) {
1399 chartService = SpringContext.getBean(ChartService.class);
1400 }
1401 return chartService;
1402 }
1403
1404 protected static OrganizationService getOrganizationService() {
1405 if (organizationService == null) {
1406 organizationService = SpringContext.getBean(OrganizationService.class);
1407 }
1408 return organizationService;
1409 }
1410 }