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 | 0 | public class GroupInquirableImpl extends KualiInquirableImpl { |
41 | |
|
42 | |
|
43 | 0 | protected final String GROUP_NAME = "groupName"; |
44 | 0 | protected final String GROUP_ID = "groupId"; |
45 | 0 | protected final String NAMESPACE_CODE = "namespaceCode"; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Override |
52 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
53 | 0 | if(GROUP_NAME.equals(attributeName)){ |
54 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
55 | 0 | primaryKeys.add(GROUP_ID); |
56 | 0 | String href = (getInquiryUrlForPrimaryKeys(GroupImpl.class, businessObject, primaryKeys, null)).getHref(); |
57 | 0 | AnchorHtmlData htmlData = new AnchorHtmlData(); |
58 | 0 | htmlData.setHref(getCustomGroupInquiryHref(href)); |
59 | 0 | return htmlData; |
60 | 0 | } else if(NAMESPACE_CODE.equals(attributeName)){ |
61 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
62 | 0 | primaryKeys.add("code"); |
63 | 0 | Namespace parameterNamespace = new Namespace(); |
64 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
65 | 0 | return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null); |
66 | 0 | } else if("kimTypeInfo.name".equals(attributeName)){ |
67 | 0 | KimTypeImpl kimType = new KimTypeImpl(); |
68 | 0 | kimType.setKimTypeId( ((GroupImpl)businessObject).getKimTypeId() ); |
69 | 0 | return getInquiryUrlForPrimaryKeys(KimTypeImpl.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null); |
70 | |
} |
71 | |
|
72 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
73 | |
} |
74 | |
|
75 | |
public String getCustomGroupInquiryHref(String href){ |
76 | 0 | Properties parameters = new Properties(); |
77 | 0 | String hrefPart = ""; |
78 | 0 | if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) { |
79 | 0 | int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"="); |
80 | 0 | int idx2 = href.indexOf("&", idx1+1); |
81 | 0 | if (idx2 < 0) { |
82 | 0 | idx2 = href.length(); |
83 | |
} |
84 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
85 | 0 | hrefPart = href.substring(idx1, idx2); |
86 | |
} |
87 | 0 | 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 | 0 | BusinessObject bo = super.getBusinessObject(fieldValues); |
100 | 0 | ((GroupImpl)bo).setMemberPersonsAndGroups(); |
101 | 0 | return bo; |
102 | |
} |
103 | |
|
104 | |
} |