1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
import org.apache.commons.beanutils.PropertyUtils; |
19 | |
import org.kuali.rice.core.impl.namespace.NamespaceBo; |
20 | |
import org.kuali.rice.kim.api.KimConstants; |
21 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityService; |
22 | |
import org.kuali.rice.kim.api.role.Role; |
23 | |
import org.kuali.rice.kim.api.role.RoleService; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.kim.impl.role.RoleBo; |
26 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityBo; |
27 | |
import org.kuali.rice.kim.inquiry.RoleMemberInquirableImpl; |
28 | |
import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl; |
29 | |
import org.kuali.rice.kns.lookup.HtmlData; |
30 | |
import org.kuali.rice.krad.bo.BusinessObject; |
31 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
32 | |
import org.kuali.rice.krad.uif.widget.Inquiry; |
33 | |
import org.kuali.rice.krad.util.ObjectUtils; |
34 | |
|
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collections; |
37 | |
import java.util.HashMap; |
38 | |
import java.util.List; |
39 | |
import java.util.Map; |
40 | |
|
41 | 0 | public class ResponsibilityInquirableImpl extends RoleMemberInquirableImpl { |
42 | |
|
43 | 0 | protected final String KIM_RESPONSIBILITY_REQUIRED_ATTRIBUTE_ID = "kimResponsibilityRequiredAttributeId"; |
44 | 0 | protected final String RESPONSIBILITY_ID = "id"; |
45 | |
transient private static ResponsibilityService responsibilityService; |
46 | |
|
47 | |
@Override |
48 | |
public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){ |
49 | |
|
50 | 0 | if(NAME.equals(propertyName) || NAME_TO_DISPLAY.equals(propertyName)){ |
51 | 0 | Map<String, String> primaryKeys = new HashMap<String, String>(); |
52 | 0 | primaryKeys.put(RESPONSIBILITY_ID, RESPONSIBILITY_ID); |
53 | 0 | inquiry.buildInquiryLink(dataObject, propertyName, UberResponsibilityBo.class, primaryKeys); |
54 | 0 | } else if(NAMESPACE_CODE.equals(propertyName) || TEMPLATE_NAMESPACE_CODE.equals(propertyName)){ |
55 | 0 | Map<String, String> primaryKeys = new HashMap<String, String>(); |
56 | 0 | primaryKeys.put(propertyName, "code"); |
57 | 0 | inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys); |
58 | 0 | } else if(DETAIL_OBJECTS.equals(propertyName)){ |
59 | |
|
60 | 0 | super.buildInquirableLink(dataObject, propertyName, inquiry); |
61 | 0 | } else if(ASSIGNED_TO_ROLES.equals(propertyName)){ |
62 | |
|
63 | 0 | super.buildInquirableLink(dataObject, propertyName, inquiry); |
64 | |
}else{ |
65 | 0 | super.buildInquirableLink(dataObject, propertyName, inquiry); |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
@Override |
70 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){ |
77 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
78 | 0 | primaryKeys.add(RESPONSIBILITY_ID); |
79 | 0 | return getInquiryUrlForPrimaryKeys(UberResponsibilityBo.class, businessObject, primaryKeys, null); |
80 | 0 | } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){ |
81 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
82 | 0 | primaryKeys.add("code"); |
83 | 0 | NamespaceBo parameterNamespace = new NamespaceBo(); |
84 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
85 | 0 | return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null); |
86 | 0 | } else if(DETAIL_OBJECTS.equals(attributeName)){ |
87 | |
|
88 | 0 | } else if(ASSIGNED_TO_ROLES.equals(attributeName)){ |
89 | 0 | return getAssignedRoleInquiryUrl(businessObject); |
90 | |
} |
91 | |
|
92 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
93 | |
} |
94 | |
|
95 | |
@SuppressWarnings("unchecked") |
96 | |
protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){ |
97 | 0 | List<ResponsibilityAttributeBo> responsibilityAttributeData = |
98 | |
(List<ResponsibilityAttributeBo>)ObjectUtils.getPropertyValue(businessObject, attributeName); |
99 | 0 | List<HtmlData.AnchorHtmlData> htmlData = new ArrayList<HtmlData.AnchorHtmlData>(); |
100 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
101 | 0 | primaryKeys.add(ATTRIBUTE_DATA_ID); |
102 | 0 | for(ResponsibilityAttributeBo responsibilityAttributeDataImpl: responsibilityAttributeData){ |
103 | 0 | htmlData.add(getInquiryUrlForPrimaryKeys(ResponsibilityAttributeBo.class, responsibilityAttributeDataImpl, primaryKeys, |
104 | |
getKimAttributeLabelFromDD(responsibilityAttributeDataImpl.getKimAttribute().getAttributeName())+ KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+ |
105 | |
responsibilityAttributeDataImpl.getAttributeValue())); |
106 | |
} |
107 | 0 | return new HtmlData.MultipleAnchorHtmlData(htmlData); |
108 | |
} |
109 | |
|
110 | |
@SuppressWarnings("unchecked") |
111 | |
protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){ |
112 | 0 | UberResponsibilityBo responsibility = (UberResponsibilityBo)businessObject; |
113 | 0 | List<RoleBo> assignedToRoles = responsibility.getAssignedToRoles(); |
114 | 0 | List<HtmlData.AnchorHtmlData> htmlData = new ArrayList<HtmlData.AnchorHtmlData>(); |
115 | 0 | if(assignedToRoles!=null && !assignedToRoles.isEmpty()){ |
116 | 0 | List<String> primaryKeys = Collections.singletonList(ROLE_ID); |
117 | 0 | RoleService roleService = KimApiServiceLocator.getRoleService(); |
118 | 0 | for(RoleBo roleImpl: assignedToRoles){ |
119 | 0 | Role role = roleService.getRole(roleImpl.getId()); |
120 | 0 | HtmlData.AnchorHtmlData inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleBo.class, role, primaryKeys, |
121 | |
role.getNamespaceCode()+" "+ |
122 | |
role.getName()); |
123 | 0 | inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref())); |
124 | 0 | htmlData.add(inquiryHtmlData); |
125 | 0 | } |
126 | |
} |
127 | 0 | return new HtmlData.MultipleAnchorHtmlData(htmlData); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public Object retrieveDataObject(Map fieldValues){ |
132 | 0 | return getBusinessObject(fieldValues); |
133 | |
} |
134 | |
|
135 | |
@SuppressWarnings("unchecked") |
136 | |
@Override |
137 | |
public BusinessObject getBusinessObject(Map fieldValues) { |
138 | 0 | ResponsibilityBo responsibilityImpl |
139 | |
= KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(ResponsibilityBo.class, Collections.singletonMap( |
140 | |
"id", fieldValues.get("id").toString())); |
141 | 0 | return getResponsibilitiesSearchResultsCopy(responsibilityImpl); |
142 | |
} |
143 | |
|
144 | |
public ResponsibilityService getResponsibilityService() { |
145 | 0 | if (responsibilityService == null ) { |
146 | 0 | responsibilityService = KimApiServiceLocator.getResponsibilityService(); |
147 | |
} |
148 | 0 | return responsibilityService; |
149 | |
} |
150 | |
|
151 | |
@SuppressWarnings("unchecked") |
152 | |
private ResponsibilityBo getResponsibilitiesSearchResultsCopy(ResponsibilityBo responsibilitySearchResult){ |
153 | 0 | UberResponsibilityBo responsibilitySearchResultCopy = new UberResponsibilityBo(); |
154 | |
try{ |
155 | 0 | PropertyUtils.copyProperties(responsibilitySearchResultCopy, responsibilitySearchResult); |
156 | 0 | } catch(Exception ex){ |
157 | 0 | throw new RuntimeException(ex); |
158 | 0 | } |
159 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
160 | 0 | criteria.put("responsibilityId", responsibilitySearchResultCopy.getId()); |
161 | 0 | List<RoleResponsibilityBo> roleResponsibilitys = |
162 | |
(List<RoleResponsibilityBo>) KRADServiceLocator.getBusinessObjectService().findMatching(RoleResponsibilityBo.class, criteria); |
163 | 0 | List<RoleBo> assignedToRoles = new ArrayList<RoleBo>(); |
164 | 0 | for(RoleResponsibilityBo roleResponsibilityImpl: roleResponsibilitys){ |
165 | 0 | assignedToRoles.add(getRoleImpl(roleResponsibilityImpl.getRoleId())); |
166 | |
} |
167 | 0 | responsibilitySearchResultCopy.setAssignedToRoles(assignedToRoles); |
168 | 0 | return responsibilitySearchResultCopy; |
169 | |
} |
170 | |
|
171 | |
} |