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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kim.bo.impl.GroupImpl;
20 import org.kuali.rice.kim.bo.types.impl.KimTypeImpl;
21 import org.kuali.rice.kim.util.KimCommonUtils;
22 import org.kuali.rice.kim.util.KimConstants;
23 import org.kuali.rice.kns.bo.BusinessObject;
24 import org.kuali.rice.kns.bo.Namespace;
25 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
26 import org.kuali.rice.kns.lookup.HtmlData;
27 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
28 import org.kuali.rice.kns.util.KNSConstants;
29 import org.kuali.rice.kns.util.ObjectUtils;
30 import org.kuali.rice.kns.util.UrlFactory;
31
32 import java.util.*;
33
34
35
36
37
38
39
40 public class GroupInquirableImpl extends KualiInquirableImpl {
41
42
43 protected final String GROUP_NAME = "groupName";
44 protected final String GROUP_ID = "groupId";
45 protected final String NAMESPACE_CODE = "namespaceCode";
46
47
48
49
50
51 @Override
52 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
53 if(GROUP_NAME.equals(attributeName)){
54 List<String> primaryKeys = new ArrayList<String>();
55 primaryKeys.add(GROUP_ID);
56 String href = (getInquiryUrlForPrimaryKeys(GroupImpl.class, businessObject, primaryKeys, null)).getHref();
57 AnchorHtmlData htmlData = new AnchorHtmlData();
58 htmlData.setHref(getCustomGroupInquiryHref(href));
59 return htmlData;
60 } else if(NAMESPACE_CODE.equals(attributeName)){
61 List<String> primaryKeys = new ArrayList<String>();
62 primaryKeys.add("code");
63 Namespace parameterNamespace = new Namespace();
64 parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
65 return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null);
66 } else if("kimTypeInfo.name".equals(attributeName)){
67 KimTypeImpl kimType = new KimTypeImpl();
68 kimType.setKimTypeId( ((GroupImpl)businessObject).getKimTypeId() );
69 return getInquiryUrlForPrimaryKeys(KimTypeImpl.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
70 }
71
72 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
73 }
74
75 public String getCustomGroupInquiryHref(String href){
76 Properties parameters = new Properties();
77 String hrefPart = "";
78 if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) {
79 int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"=");
80 int idx2 = href.indexOf("&", idx1+1);
81 if (idx2 < 0) {
82 idx2 = href.length();
83 }
84 parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);
85 hrefPart = href.substring(idx1, idx2);
86 }
87 return UrlFactory.parameterizeUrl(KimCommonUtils.getKimBasePath()+
88 KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION, parameters)+hrefPart;
89 }
90
91
92
93
94
95
96 @SuppressWarnings("unchecked")
97 @Override
98 public BusinessObject getBusinessObject(Map fieldValues) {
99 BusinessObject bo = super.getBusinessObject(fieldValues);
100 ((GroupImpl)bo).setMemberPersonsAndGroups();
101 return bo;
102 }
103
104 }