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.Collections; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.apache.commons.beanutils.PropertyUtils; |
25 | |
import org.kuali.rice.kim.bo.impl.ResponsibilityImpl; |
26 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
27 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
28 | |
import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl; |
29 | |
import org.kuali.rice.kim.bo.role.impl.ResponsibilityAttributeDataImpl; |
30 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl; |
31 | |
import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl; |
32 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
33 | |
import org.kuali.rice.kim.service.ResponsibilityService; |
34 | |
import org.kuali.rice.kim.service.RoleService; |
35 | |
import org.kuali.rice.kim.util.KimConstants; |
36 | |
import org.kuali.rice.kns.bo.BusinessObject; |
37 | |
import org.kuali.rice.kns.bo.Namespace; |
38 | |
import org.kuali.rice.kns.lookup.HtmlData; |
39 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
40 | |
import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData; |
41 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
42 | |
import org.kuali.rice.kns.util.ObjectUtils; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class ResponsibilityInquirableImpl extends RoleMemberInquirableImpl { |
51 | |
|
52 | 0 | protected final String KIM_RESPONSIBILITY_REQUIRED_ATTRIBUTE_ID = "kimResponsibilityRequiredAttributeId"; |
53 | 0 | protected final String RESPONSIBILITY_ID = "responsibilityId"; |
54 | |
transient private static ResponsibilityService responsibilityService; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
@Override |
61 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 0 | if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){ |
68 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
69 | 0 | primaryKeys.add(RESPONSIBILITY_ID); |
70 | 0 | return getInquiryUrlForPrimaryKeys(ResponsibilityImpl.class, businessObject, primaryKeys, null); |
71 | 0 | } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){ |
72 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
73 | 0 | primaryKeys.add("code"); |
74 | 0 | Namespace parameterNamespace = new Namespace(); |
75 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
76 | 0 | return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null); |
77 | 0 | } else if(DETAIL_OBJECTS.equals(attributeName)){ |
78 | |
|
79 | 0 | } else if(ASSIGNED_TO_ROLES.equals(attributeName)){ |
80 | 0 | return getAssignedRoleInquiryUrl(businessObject); |
81 | |
} |
82 | |
|
83 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
84 | |
} |
85 | |
|
86 | |
@SuppressWarnings("unchecked") |
87 | |
protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){ |
88 | 0 | List<ResponsibilityAttributeDataImpl> responsibilityAttributeData = |
89 | |
(List<ResponsibilityAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName); |
90 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
91 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
92 | 0 | primaryKeys.add(ATTRIBUTE_DATA_ID); |
93 | 0 | for(ResponsibilityAttributeDataImpl responsibilityAttributeDataImpl: responsibilityAttributeData){ |
94 | 0 | htmlData.add(getInquiryUrlForPrimaryKeys(ResponsibilityAttributeDataImpl.class, responsibilityAttributeDataImpl, primaryKeys, |
95 | |
getKimAttributeLabelFromDD(responsibilityAttributeDataImpl.getKimAttribute().getAttributeName())+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+ |
96 | |
responsibilityAttributeDataImpl.getAttributeValue())); |
97 | |
} |
98 | 0 | return new MultipleAnchorHtmlData(htmlData); |
99 | |
} |
100 | |
|
101 | |
@SuppressWarnings("unchecked") |
102 | |
protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){ |
103 | 0 | ResponsibilityImpl responsibility = (ResponsibilityImpl)businessObject; |
104 | 0 | List<RoleImpl> assignedToRoles = responsibility.getAssignedToRoles(); |
105 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
106 | 0 | if(assignedToRoles!=null && !assignedToRoles.isEmpty()){ |
107 | 0 | List<String> primaryKeys = Collections.singletonList(ROLE_ID); |
108 | 0 | RoleService roleService = KIMServiceLocator.getRoleService(); |
109 | 0 | for(RoleImpl roleImpl: assignedToRoles){ |
110 | 0 | KimRoleInfo roleInfo = roleService.getRole(roleImpl.getRoleId()); |
111 | 0 | AnchorHtmlData inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys, |
112 | |
roleInfo.getNamespaceCode()+" "+ |
113 | |
roleInfo.getRoleName()); |
114 | 0 | inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref())); |
115 | 0 | htmlData.add(inquiryHtmlData); |
116 | 0 | } |
117 | |
} |
118 | 0 | return new MultipleAnchorHtmlData(htmlData); |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@SuppressWarnings("unchecked") |
127 | |
@Override |
128 | |
public BusinessObject getBusinessObject(Map fieldValues) { |
129 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
130 | 0 | criteria.put("responsibilityId", fieldValues.get("responsibilityId").toString()); |
131 | 0 | KimResponsibilityImpl responsibilityImpl = (KimResponsibilityImpl)KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimResponsibilityImpl.class, criteria); |
132 | 0 | return getResponsibilitiesSearchResultsCopy(responsibilityImpl); |
133 | |
} |
134 | |
|
135 | |
public ResponsibilityService getResponsibilityService() { |
136 | 0 | if (responsibilityService == null ) { |
137 | 0 | responsibilityService = KIMServiceLocator.getResponsibilityService(); |
138 | |
} |
139 | 0 | return responsibilityService; |
140 | |
} |
141 | |
|
142 | |
@SuppressWarnings("unchecked") |
143 | |
private ResponsibilityImpl getResponsibilitiesSearchResultsCopy(KimResponsibilityImpl responsibilitySearchResult){ |
144 | 0 | ResponsibilityImpl responsibilitySearchResultCopy = new ResponsibilityImpl(); |
145 | |
try{ |
146 | 0 | PropertyUtils.copyProperties(responsibilitySearchResultCopy, responsibilitySearchResult); |
147 | 0 | } catch(Exception ex){ |
148 | |
|
149 | 0 | ex.printStackTrace(); |
150 | 0 | } |
151 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
152 | 0 | criteria.put("responsibilityId", responsibilitySearchResultCopy.getResponsibilityId()); |
153 | 0 | List<RoleResponsibilityImpl> roleResponsibilitys = |
154 | |
(List<RoleResponsibilityImpl>)KNSServiceLocator.getBusinessObjectService().findMatching(RoleResponsibilityImpl.class, criteria); |
155 | 0 | List<RoleImpl> assignedToRoles = new ArrayList<RoleImpl>(); |
156 | 0 | for(RoleResponsibilityImpl roleResponsibilityImpl: roleResponsibilitys){ |
157 | 0 | assignedToRoles.add(getRoleImpl(roleResponsibilityImpl.getRoleId())); |
158 | |
} |
159 | 0 | responsibilitySearchResultCopy.setAssignedToRoles(assignedToRoles); |
160 | 0 | return responsibilitySearchResultCopy; |
161 | |
} |
162 | |
|
163 | |
} |