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 public class ResponsibilityInquirableImpl extends RoleMemberInquirableImpl {
51
52 protected final String KIM_RESPONSIBILITY_REQUIRED_ATTRIBUTE_ID = "kimResponsibilityRequiredAttributeId";
53 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 if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){
68 List<String> primaryKeys = new ArrayList<String>();
69 primaryKeys.add(RESPONSIBILITY_ID);
70 return getInquiryUrlForPrimaryKeys(ResponsibilityImpl.class, businessObject, primaryKeys, null);
71 } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){
72 List<String> primaryKeys = new ArrayList<String>();
73 primaryKeys.add("code");
74 Namespace parameterNamespace = new Namespace();
75 parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
76 return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null);
77 } else if(DETAIL_OBJECTS.equals(attributeName)){
78
79 } else if(ASSIGNED_TO_ROLES.equals(attributeName)){
80 return getAssignedRoleInquiryUrl(businessObject);
81 }
82
83 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
84 }
85
86 @SuppressWarnings("unchecked")
87 protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){
88 List<ResponsibilityAttributeDataImpl> responsibilityAttributeData =
89 (List<ResponsibilityAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName);
90 List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
91 List<String> primaryKeys = new ArrayList<String>();
92 primaryKeys.add(ATTRIBUTE_DATA_ID);
93 for(ResponsibilityAttributeDataImpl responsibilityAttributeDataImpl: responsibilityAttributeData){
94 htmlData.add(getInquiryUrlForPrimaryKeys(ResponsibilityAttributeDataImpl.class, responsibilityAttributeDataImpl, primaryKeys,
95 getKimAttributeLabelFromDD(responsibilityAttributeDataImpl.getKimAttribute().getAttributeName())+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+
96 responsibilityAttributeDataImpl.getAttributeValue()));
97 }
98 return new MultipleAnchorHtmlData(htmlData);
99 }
100
101 @SuppressWarnings("unchecked")
102 protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){
103 ResponsibilityImpl responsibility = (ResponsibilityImpl)businessObject;
104 List<RoleImpl> assignedToRoles = responsibility.getAssignedToRoles();
105 List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>();
106 if(assignedToRoles!=null && !assignedToRoles.isEmpty()){
107 List<String> primaryKeys = Collections.singletonList(ROLE_ID);
108 RoleService roleService = KIMServiceLocator.getRoleService();
109 for(RoleImpl roleImpl: assignedToRoles){
110 KimRoleInfo roleInfo = roleService.getRole(roleImpl.getRoleId());
111 AnchorHtmlData inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys,
112 roleInfo.getNamespaceCode()+" "+
113 roleInfo.getRoleName());
114 inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref()));
115 htmlData.add(inquiryHtmlData);
116 }
117 }
118 return new MultipleAnchorHtmlData(htmlData);
119 }
120
121
122
123
124
125
126 @SuppressWarnings("unchecked")
127 @Override
128 public BusinessObject getBusinessObject(Map fieldValues) {
129 Map<String, String> criteria = new HashMap<String, String>();
130 criteria.put("responsibilityId", fieldValues.get("responsibilityId").toString());
131 KimResponsibilityImpl responsibilityImpl = (KimResponsibilityImpl)KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimResponsibilityImpl.class, criteria);
132 return getResponsibilitiesSearchResultsCopy(responsibilityImpl);
133 }
134
135 public ResponsibilityService getResponsibilityService() {
136 if (responsibilityService == null ) {
137 responsibilityService = KIMServiceLocator.getResponsibilityService();
138 }
139 return responsibilityService;
140 }
141
142 @SuppressWarnings("unchecked")
143 private ResponsibilityImpl getResponsibilitiesSearchResultsCopy(KimResponsibilityImpl responsibilitySearchResult){
144 ResponsibilityImpl responsibilitySearchResultCopy = new ResponsibilityImpl();
145 try{
146 PropertyUtils.copyProperties(responsibilitySearchResultCopy, responsibilitySearchResult);
147 } catch(Exception ex){
148
149 ex.printStackTrace();
150 }
151 Map<String, String> criteria = new HashMap<String, String>();
152 criteria.put("responsibilityId", responsibilitySearchResultCopy.getResponsibilityId());
153 List<RoleResponsibilityImpl> roleResponsibilitys =
154 (List<RoleResponsibilityImpl>)KNSServiceLocator.getBusinessObjectService().findMatching(RoleResponsibilityImpl.class, criteria);
155 List<RoleImpl> assignedToRoles = new ArrayList<RoleImpl>();
156 for(RoleResponsibilityImpl roleResponsibilityImpl: roleResponsibilitys){
157 assignedToRoles.add(getRoleImpl(roleResponsibilityImpl.getRoleId()));
158 }
159 responsibilitySearchResultCopy.setAssignedToRoles(assignedToRoles);
160 return responsibilitySearchResultCopy;
161 }
162
163 }