1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.lookup; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
20 | |
import org.kuali.rice.kim.api.type.KimType; |
21 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
22 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
23 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; |
24 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; |
25 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
26 | |
import org.kuali.rice.kim.document.KimTypeAttributesHelper; |
27 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
28 | |
import org.kuali.rice.kim.service.RoleService; |
29 | |
import org.kuali.rice.kim.service.UiDocumentService; |
30 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
31 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
32 | |
import org.kuali.rice.kim.util.KimConstants; |
33 | |
import org.kuali.rice.kns.bo.BusinessObject; |
34 | |
import org.kuali.rice.kns.datadictionary.AttributeDefinition; |
35 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
36 | |
import org.kuali.rice.kns.util.GlobalVariables; |
37 | |
|
38 | |
import java.util.ArrayList; |
39 | |
import java.util.List; |
40 | |
import java.util.Map; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class KimDocumentRoleMemberLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
47 | |
|
48 | |
private static final long serialVersionUID = 1L; |
49 | |
private transient UiDocumentService uiDocumentService; |
50 | |
private transient RoleService roleService; |
51 | |
private transient KimTypeInfoService kimTypeInfoService; |
52 | |
|
53 | |
@SuppressWarnings("unchecked") |
54 | |
protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) { |
55 | 0 | List<KimDocumentRoleMember> searchResults = new ArrayList<KimDocumentRoleMember>(); |
56 | 0 | IdentityManagementRoleDocument roleDocument = (IdentityManagementRoleDocument)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY); |
57 | 0 | if(roleDocument!=null){ |
58 | 0 | String memberId = fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID); |
59 | 0 | String memberTypeCode = fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE); |
60 | 0 | String memberName = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME); |
61 | 0 | String memberNamespaceCode = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE); |
62 | 0 | String activeFromDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE); |
63 | 0 | String activeToDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE); |
64 | 0 | List<KimDocumentRoleMember> currentRoleMembers = roleDocument.getMembers(); |
65 | 0 | if(currentRoleMembers!=null && !currentRoleMembers.isEmpty()){ |
66 | 0 | for(KimDocumentRoleMember currentRoleMember: currentRoleMembers){ |
67 | 0 | if((StringUtils.isEmpty(memberId) || (StringUtils.isNotEmpty(memberId) && memberId.equals(currentRoleMember.getMemberId()))) |
68 | |
&& (StringUtils.isEmpty(memberTypeCode) || (StringUtils.isNotEmpty(memberTypeCode) && memberTypeCode.equals(currentRoleMember.getMemberTypeCode()))) |
69 | |
&& (StringUtils.isEmpty(memberName) || (StringUtils.isNotEmpty(memberName) && memberName.equals(currentRoleMember.getMemberName()))) |
70 | |
&& (StringUtils.isEmpty(memberNamespaceCode) || (StringUtils.isNotEmpty(memberNamespaceCode) && memberNamespaceCode.equals(currentRoleMember.getMemberNamespaceCode()))) |
71 | |
&& (StringUtils.isEmpty(activeFromDate) || (StringUtils.isNotEmpty(activeFromDate) && activeFromDate.equals(currentRoleMember.getActiveFromDate()))) |
72 | |
&& (StringUtils.isEmpty(activeToDate) || (StringUtils.isNotEmpty(activeToDate) && activeToDate.equals(currentRoleMember.getActiveToDate())))){ |
73 | 0 | searchResults.add(currentRoleMember); |
74 | |
} |
75 | |
} |
76 | |
} |
77 | 0 | } else{ |
78 | 0 | searchResults = getUiDocumentService().getRoleMembers(fieldValues); |
79 | |
} |
80 | 0 | if(searchResults!=null){ |
81 | 0 | for(KimDocumentRoleMember roleMember: searchResults) |
82 | 0 | roleMember.setQualifiersToDisplay(getQualifiersToDisplay(roleMember)); |
83 | |
} |
84 | 0 | return searchResults; |
85 | |
} |
86 | |
|
87 | |
public String getQualifiersToDisplay(KimDocumentRoleMember roleMember) { |
88 | 0 | if(roleMember!=null && StringUtils.isNotEmpty(roleMember.getRoleId()) && |
89 | |
roleMember.getQualifiers()!=null && !roleMember.getQualifiers().isEmpty()){ |
90 | 0 | KimRoleInfo roleInfo = getRoleService().getRole(roleMember.getRoleId()); |
91 | 0 | KimType kimType = null; |
92 | 0 | if(roleInfo!=null) |
93 | 0 | kimType = getKimTypeInfoService().getKimType(roleInfo.getKimTypeId()); |
94 | 0 | if(kimType!=null){ |
95 | 0 | KimTypeAttributesHelper attributesHelper = new KimTypeAttributesHelper(kimType); |
96 | 0 | StringBuffer attributesToDisplay = new StringBuffer(); |
97 | |
AttributeDefinition attribDefn; |
98 | 0 | for(KimDocumentRoleQualifier attribute: roleMember.getQualifiers()){ |
99 | 0 | if(attribute.getKimAttribute()!=null){ |
100 | 0 | attribDefn = attributesHelper.getAttributeDefinition(attribute.getKimAttribute().getAttributeName()); |
101 | 0 | attributesToDisplay.append(attribDefn!=null?attribDefn.getLabel():""); |
102 | 0 | attributesToDisplay.append(KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR ); |
103 | 0 | attributesToDisplay.append(attribute.getAttrVal()); |
104 | 0 | attributesToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR); |
105 | |
} |
106 | |
} |
107 | 0 | return KimCommonUtilsInternal.stripEnd(attributesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR); |
108 | |
} |
109 | |
} |
110 | 0 | return ""; |
111 | |
} |
112 | |
|
113 | |
public RoleService getRoleService() { |
114 | 0 | if ( roleService == null ) { |
115 | 0 | roleService = KimApiServiceLocator.getRoleService(); |
116 | |
} |
117 | 0 | return roleService; |
118 | |
} |
119 | |
|
120 | |
public KimTypeInfoService getKimTypeInfoService() { |
121 | 0 | if ( kimTypeInfoService == null ) { |
122 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
123 | |
} |
124 | 0 | return kimTypeInfoService; |
125 | |
} |
126 | |
|
127 | |
public UiDocumentService getUiDocumentService() { |
128 | 0 | if ( uiDocumentService == null ) { |
129 | 0 | uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); |
130 | |
} |
131 | 0 | return uiDocumentService; |
132 | |
} |
133 | |
} |