1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.inquiry; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.apache.commons.beanutils.PropertyUtils; |
24 | |
import org.kuali.rice.kim.bo.impl.PermissionImpl; |
25 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
26 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
27 | |
import org.kuali.rice.kim.bo.role.impl.KimPermissionImpl; |
28 | |
import org.kuali.rice.kim.bo.role.impl.PermissionAttributeDataImpl; |
29 | |
import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl; |
30 | |
import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl; |
31 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
32 | |
import org.kuali.rice.kim.service.PermissionService; |
33 | |
import org.kuali.rice.kim.service.RoleService; |
34 | |
import org.kuali.rice.kim.util.KimConstants; |
35 | |
import org.kuali.rice.kns.bo.BusinessObject; |
36 | |
import org.kuali.rice.kns.bo.Namespace; |
37 | |
import org.kuali.rice.kns.lookup.HtmlData; |
38 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
39 | |
import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData; |
40 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
41 | |
import org.kuali.rice.kns.util.ObjectUtils; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class PermissionInquirableImpl extends RoleMemberInquirableImpl { |
50 | |
|
51 | |
transient private static PermissionService permissionService; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@Override |
59 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){ |
66 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
67 | 0 | primaryKeys.add(KimConstants.PrimaryKeyConstants.PERMISSION_ID); |
68 | 0 | return getInquiryUrlForPrimaryKeys(PermissionImpl.class, businessObject, primaryKeys, null); |
69 | 0 | } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){ |
70 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
71 | 0 | primaryKeys.add("code"); |
72 | 0 | Namespace parameterNamespace = new Namespace(); |
73 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
74 | 0 | return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null); |
75 | 0 | } else if(DETAIL_OBJECTS.equals(attributeName)){ |
76 | |
|
77 | 0 | } else if(ASSIGNED_TO_ROLES.equals(attributeName)){ |
78 | 0 | return getAssignedRoleInquiryUrl(businessObject); |
79 | |
} |
80 | |
|
81 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
82 | |
} |
83 | |
|
84 | |
protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){ |
85 | 0 | List<PermissionAttributeDataImpl> permissionAttributeData = |
86 | |
(List<PermissionAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName); |
87 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
88 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
89 | 0 | primaryKeys.add(ATTRIBUTE_DATA_ID); |
90 | 0 | for(PermissionAttributeDataImpl permissionAttributeDataImpl: permissionAttributeData){ |
91 | 0 | htmlData.add(getInquiryUrlForPrimaryKeys(PermissionAttributeDataImpl.class, permissionAttributeDataImpl, primaryKeys, |
92 | |
getKimAttributeLabelFromDD(permissionAttributeDataImpl.getKimAttribute().getAttributeName())+ |
93 | |
KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+ |
94 | |
permissionAttributeDataImpl.getAttributeValue())); |
95 | |
} |
96 | 0 | return new MultipleAnchorHtmlData(htmlData); |
97 | |
} |
98 | |
|
99 | |
protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){ |
100 | 0 | PermissionImpl permission = (PermissionImpl)businessObject; |
101 | 0 | List<RoleImpl> assignedToRoles = permission.getAssignedToRoles(); |
102 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
103 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
104 | 0 | primaryKeys.add(ROLE_ID); |
105 | 0 | if(assignedToRoles!=null && !assignedToRoles.isEmpty()){ |
106 | 0 | RoleService roleService = KIMServiceLocator.getRoleService(); |
107 | |
KimRoleInfo roleInfo; |
108 | |
AnchorHtmlData inquiryHtmlData; |
109 | 0 | for(RoleImpl roleImpl: assignedToRoles){ |
110 | 0 | roleInfo = roleService.getRole(roleImpl.getRoleId()); |
111 | 0 | inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys, |
112 | |
roleInfo.getNamespaceCode()+" "+ |
113 | |
roleInfo.getRoleName()); |
114 | 0 | inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref())); |
115 | 0 | inquiryHtmlData.setTarget(AnchorHtmlData.TARGET_BLANK); |
116 | 0 | htmlData.add(inquiryHtmlData); |
117 | |
} |
118 | |
} |
119 | 0 | return new MultipleAnchorHtmlData(htmlData); |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
@SuppressWarnings("unchecked") |
129 | |
@Override |
130 | |
public BusinessObject getBusinessObject(Map fieldValues) { |
131 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
132 | 0 | criteria.put("permissionId", fieldValues.get("permissionId").toString()); |
133 | 0 | KimPermissionImpl permissionImpl = (KimPermissionImpl)KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimPermissionImpl.class, criteria); |
134 | 0 | return getPermissionsSearchResultsCopy(permissionImpl); |
135 | |
} |
136 | |
|
137 | |
public PermissionService getPermissionService() { |
138 | 0 | if (permissionService == null ) { |
139 | 0 | permissionService = KIMServiceLocator.getPermissionService(); |
140 | |
} |
141 | 0 | return permissionService; |
142 | |
} |
143 | |
|
144 | |
private PermissionImpl getPermissionsSearchResultsCopy(KimPermissionImpl permissionSearchResult){ |
145 | 0 | PermissionImpl permissionSearchResultCopy = new PermissionImpl(); |
146 | |
try{ |
147 | 0 | PropertyUtils.copyProperties(permissionSearchResultCopy, permissionSearchResult); |
148 | 0 | } catch(Exception ex){ |
149 | |
|
150 | 0 | ex.printStackTrace(); |
151 | 0 | } |
152 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
153 | 0 | criteria.put("permissionId", permissionSearchResultCopy.getPermissionId()); |
154 | 0 | List<RolePermissionImpl> rolePermissions = |
155 | |
(List<RolePermissionImpl>)KNSServiceLocator.getBusinessObjectService().findMatching(RolePermissionImpl.class, criteria); |
156 | 0 | List<RoleImpl> assignedToRoles = new ArrayList<RoleImpl>(); |
157 | 0 | for(RolePermissionImpl rolePermissionImpl: rolePermissions){ |
158 | 0 | assignedToRoles.add(getRoleImpl(rolePermissionImpl.getRoleId())); |
159 | |
} |
160 | 0 | permissionSearchResultCopy.setAssignedToRoles(assignedToRoles); |
161 | 0 | return permissionSearchResultCopy; |
162 | |
} |
163 | |
|
164 | |
} |