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.coreservice.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.data.KradDataServiceLocator;
28 import org.kuali.rice.krad.uif.widget.Inquiry;
29 import org.kuali.rice.krad.util.KRADConstants;
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 String code = (String) KradDataServiceLocator.getDataObjectService().wrap(businessObject).getPropertyValueNullSafe(attributeName);
83 NamespaceBo parameterNamespace = new NamespaceBo();
84 parameterNamespace.setCode(code);
85 return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
86 } else if("kimTypeInfo.name".equals(attributeName)){
87 KimTypeBo kimType = new KimTypeBo();
88 kimType.setId( ((GroupBo)businessObject).getKimTypeId() );
89 return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
90 }
91
92 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
93 }
94
95 public String getCustomGroupInquiryHref(String href){
96 Properties parameters = new Properties();
97 String hrefPart = "";
98 if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) {
99 int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"=");
100 int idx2 = href.indexOf("&", idx1+1);
101 if (idx2 < 0) {
102 idx2 = href.length();
103 }
104 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);
105 hrefPart = href.substring(idx1, idx2);
106 }
107 return UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+
108 KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION, parameters)+hrefPart;
109 }
110
111
112
113
114
115
116 @SuppressWarnings("unchecked")
117 @Override
118 public BusinessObject getBusinessObject(Map fieldValues) {
119 BusinessObject bo = super.getBusinessObject(fieldValues);
120 return bo;
121 }
122
123 }