| 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.GroupImpl; |
| 21 | |
import org.kuali.rice.kim.bo.types.impl.KimTypeImpl; |
| 22 | |
import org.kuali.rice.kim.util.KimCommonUtilsInternal; |
| 23 | |
import org.kuali.rice.kim.util.KimConstants; |
| 24 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 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 | |
@Override |
| 48 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
| 49 | 0 | if(GROUP_NAME.equals(attributeName)){ |
| 50 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
| 51 | 0 | primaryKeys.add(GROUP_ID); |
| 52 | 0 | String href = (getInquiryUrlForPrimaryKeys(GroupImpl.class, businessObject, primaryKeys, null)).getHref(); |
| 53 | 0 | AnchorHtmlData htmlData = new AnchorHtmlData(); |
| 54 | 0 | htmlData.setHref(getCustomGroupInquiryHref(href)); |
| 55 | 0 | return htmlData; |
| 56 | 0 | } else if(NAMESPACE_CODE.equals(attributeName)){ |
| 57 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
| 58 | 0 | primaryKeys.add("code"); |
| 59 | 0 | NamespaceBo parameterNamespace = new NamespaceBo(); |
| 60 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
| 61 | 0 | return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null); |
| 62 | 0 | } else if("kimTypeInfo.name".equals(attributeName)){ |
| 63 | 0 | KimTypeImpl kimType = new KimTypeImpl(); |
| 64 | 0 | kimType.setKimTypeId( ((GroupImpl)businessObject).getKimTypeId() ); |
| 65 | 0 | return getInquiryUrlForPrimaryKeys(KimTypeImpl.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null); |
| 66 | |
} |
| 67 | |
|
| 68 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
| 69 | |
} |
| 70 | |
|
| 71 | |
public String getCustomGroupInquiryHref(String href){ |
| 72 | 0 | Properties parameters = new Properties(); |
| 73 | 0 | String hrefPart = ""; |
| 74 | 0 | if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) { |
| 75 | 0 | int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"="); |
| 76 | 0 | int idx2 = href.indexOf("&", idx1+1); |
| 77 | 0 | if (idx2 < 0) { |
| 78 | 0 | idx2 = href.length(); |
| 79 | |
} |
| 80 | 0 | parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY); |
| 81 | 0 | hrefPart = href.substring(idx1, idx2); |
| 82 | |
} |
| 83 | 0 | return UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+ |
| 84 | |
KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION, parameters)+hrefPart; |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
@SuppressWarnings("unchecked") |
| 93 | |
@Override |
| 94 | |
public BusinessObject getBusinessObject(Map fieldValues) { |
| 95 | 0 | BusinessObject bo = super.getBusinessObject(fieldValues); |
| 96 | 0 | ((GroupImpl)bo).setMemberPersonsAndGroups(); |
| 97 | 0 | return bo; |
| 98 | |
} |
| 99 | |
|
| 100 | |
} |