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