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