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.KimConstants; |
20 | |
import org.kuali.rice.kim.api.role.Role; |
21 | |
import org.kuali.rice.kim.api.role.RoleService; |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
23 | |
import org.kuali.rice.kim.api.type.KimAttributeField; |
24 | |
import org.kuali.rice.kim.api.type.KimType; |
25 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
26 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; |
27 | |
import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; |
28 | |
import org.kuali.rice.kim.document.IdentityManagementRoleDocument; |
29 | |
import org.kuali.rice.kim.impl.KIMPropertyConstants; |
30 | |
import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper; |
31 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
32 | |
import org.kuali.rice.kim.service.UiDocumentService; |
33 | |
import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; |
34 | |
import org.kuali.rice.krad.bo.BusinessObject; |
35 | |
import org.kuali.rice.krad.util.GlobalVariables; |
36 | |
|
37 | |
import java.util.ArrayList; |
38 | |
import java.util.List; |
39 | |
import java.util.Map; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class KimDocumentRoleMemberLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { |
45 | |
|
46 | |
private static final long serialVersionUID = 1L; |
47 | |
private transient UiDocumentService uiDocumentService; |
48 | |
private transient RoleService roleService; |
49 | |
private transient KimTypeInfoService kimTypeInfoService; |
50 | |
|
51 | |
@SuppressWarnings("unchecked") |
52 | |
protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) { |
53 | 0 | List<KimDocumentRoleMember> searchResults = new ArrayList<KimDocumentRoleMember>(); |
54 | 0 | IdentityManagementRoleDocument roleDocument = (IdentityManagementRoleDocument) GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY); |
55 | 0 | if (roleDocument != null) { |
56 | 0 | String memberId = fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID); |
57 | 0 | String memberTypeCode = fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE); |
58 | 0 | String memberName = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME); |
59 | 0 | String memberNamespaceCode = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE); |
60 | 0 | String activeFromDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE); |
61 | 0 | String activeToDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE); |
62 | 0 | List<KimDocumentRoleMember> currentRoleMembers = roleDocument.getMembers(); |
63 | 0 | if (currentRoleMembers != null && !currentRoleMembers.isEmpty()) { |
64 | 0 | for (KimDocumentRoleMember currentRoleMember : currentRoleMembers) { |
65 | 0 | if ((StringUtils.isEmpty(memberId) || (StringUtils.isNotEmpty(memberId) && memberId.equals(currentRoleMember.getMemberId()))) |
66 | |
&& (StringUtils.isEmpty(memberTypeCode) || (StringUtils.isNotEmpty(memberTypeCode) && memberTypeCode.equals(currentRoleMember.getMemberTypeCode()))) |
67 | |
&& (StringUtils.isEmpty(memberName) || (StringUtils.isNotEmpty(memberName) && memberName.equals(currentRoleMember.getMemberName()))) |
68 | |
&& (StringUtils.isEmpty(memberNamespaceCode) || (StringUtils.isNotEmpty(memberNamespaceCode) && memberNamespaceCode.equals(currentRoleMember.getMemberNamespaceCode()))) |
69 | |
&& (StringUtils.isEmpty(activeFromDate) || (StringUtils.isNotEmpty(activeFromDate) && activeFromDate.equals(currentRoleMember.getActiveFromDate()))) |
70 | |
&& (StringUtils.isEmpty(activeToDate) || (StringUtils.isNotEmpty(activeToDate) && activeToDate.equals(currentRoleMember.getActiveToDate())))) { |
71 | 0 | searchResults.add(currentRoleMember); |
72 | |
} |
73 | |
} |
74 | |
} |
75 | 0 | } else { |
76 | 0 | searchResults = getUiDocumentService().getRoleMembers(fieldValues); |
77 | |
} |
78 | 0 | if (searchResults != null) { |
79 | 0 | for (KimDocumentRoleMember roleMember : searchResults) { |
80 | 0 | roleMember.setQualifiersToDisplay(getQualifiersToDisplay(roleMember)); |
81 | |
} |
82 | |
} |
83 | 0 | return searchResults; |
84 | |
} |
85 | |
|
86 | |
public String getQualifiersToDisplay(KimDocumentRoleMember roleMember) { |
87 | 0 | if (roleMember != null && StringUtils.isNotEmpty(roleMember.getRoleId()) && |
88 | |
roleMember.getQualifiers() != null && !roleMember.getQualifiers().isEmpty()) { |
89 | 0 | Role role = getRoleService().getRole(roleMember.getRoleId()); |
90 | 0 | KimType kimType = null; |
91 | 0 | if (role != null) { |
92 | 0 | kimType = getKimTypeInfoService().getKimType(role.getKimTypeId()); |
93 | |
} |
94 | 0 | if (kimType != null) { |
95 | 0 | KimTypeAttributesHelper attributesHelper = new KimTypeAttributesHelper(kimType); |
96 | 0 | StringBuffer attributesToDisplay = new StringBuffer(); |
97 | |
KimAttributeField 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.getAttributeField().getLongLabel() : ""); |
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 stripEnd(attributesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR); |
108 | |
} |
109 | |
} |
110 | 0 | return ""; |
111 | |
} |
112 | |
|
113 | |
private static String stripEnd(String toStripFrom, String toStrip){ |
114 | |
String stripped; |
115 | 0 | if(toStripFrom==null) return null; |
116 | 0 | if(toStrip==null) return toStripFrom; |
117 | 0 | if(toStrip.length() > toStripFrom.length()) return toStripFrom; |
118 | 0 | if(toStripFrom.endsWith(toStrip)){ |
119 | 0 | StringBuffer buffer = new StringBuffer(toStripFrom); |
120 | 0 | buffer.delete(buffer.length()-toStrip.length(), buffer.length()); |
121 | 0 | stripped = buffer.toString(); |
122 | 0 | } else stripped = toStripFrom; |
123 | 0 | return stripped; |
124 | |
} |
125 | |
|
126 | |
public RoleService getRoleService() { |
127 | 0 | if (roleService == null) { |
128 | 0 | roleService = KimApiServiceLocator.getRoleService(); |
129 | |
} |
130 | 0 | return roleService; |
131 | |
} |
132 | |
|
133 | |
public KimTypeInfoService getKimTypeInfoService() { |
134 | 0 | if (kimTypeInfoService == null) { |
135 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
136 | |
} |
137 | 0 | return kimTypeInfoService; |
138 | |
} |
139 | |
|
140 | |
public UiDocumentService getUiDocumentService() { |
141 | 0 | if (uiDocumentService == null) { |
142 | 0 | uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); |
143 | |
} |
144 | 0 | return uiDocumentService; |
145 | |
} |
146 | |
} |