001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.inquiry; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.coreservice.impl.namespace.NamespaceBo; 020import org.kuali.rice.kim.api.KimConstants; 021import org.kuali.rice.kim.impl.group.GroupBo; 022import org.kuali.rice.kim.impl.type.KimTypeBo; 023import org.kuali.rice.kim.util.KimCommonUtilsInternal; 024import org.kuali.rice.kns.inquiry.KualiInquirableImpl; 025import org.kuali.rice.kns.lookup.HtmlData; 026import org.kuali.rice.krad.bo.BusinessObject; 027import org.kuali.rice.krad.data.KradDataServiceLocator; 028import org.kuali.rice.krad.uif.widget.Inquiry; 029import org.kuali.rice.krad.util.KRADConstants; 030import org.kuali.rice.krad.util.UrlFactory; 031 032import java.util.ArrayList; 033import java.util.Collections; 034import java.util.HashMap; 035import java.util.List; 036import java.util.Map; 037import java.util.Properties; 038 039/** 040 * This is a description of what this class does - kellerj don't forget to fill this in. 041 * 042 * @author Kuali Rice Team (rice.collab@kuali.org) 043 * 044 */ 045public class GroupInquirableImpl extends KualiInquirableImpl { 046 047 048 protected final String GROUP_NAME = "name"; 049 protected final String GROUP_ID = "id"; 050 protected final String NAMESPACE_CODE = "namespaceCode"; 051 052 @Override 053 public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){ 054 055 if(GROUP_NAME.equals(propertyName)){ 056 Map<String, String> primaryKeys = new HashMap<String, String>(); 057 primaryKeys.put(GROUP_ID, GROUP_ID); 058 inquiry.buildInquiryLink(dataObject, propertyName, GroupBo.class, primaryKeys); 059 } else if(NAMESPACE_CODE.equals(propertyName)){ 060 Map<String, String> primaryKeys = new HashMap<String, String>(); 061 primaryKeys.put(propertyName, "code"); 062 inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys); 063 } else if("kimTypeInfo.name".equals(propertyName)){ 064 Map<String, String> primaryKeys = new HashMap<String, String>(); 065 primaryKeys.put("kimTypeInfo.id", KimConstants.PrimaryKeyConstants.KIM_TYPE_ID); 066 inquiry.buildInquiryLink(dataObject, propertyName, KimTypeBo.class, primaryKeys); 067 } 068 } 069 070 @Override 071 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { 072 if(GROUP_NAME.equals(attributeName)){ 073 List<String> primaryKeys = new ArrayList<String>(); 074 primaryKeys.add(GROUP_ID); 075 String href = (getInquiryUrlForPrimaryKeys(GroupBo.class, businessObject, primaryKeys, null)).getHref(); 076 HtmlData.AnchorHtmlData htmlData = new HtmlData.AnchorHtmlData(); 077 htmlData.setHref(getCustomGroupInquiryHref(href)); 078 return htmlData; 079 } else if(NAMESPACE_CODE.equals(attributeName)){ 080 List<String> primaryKeys = new ArrayList<String>(); 081 primaryKeys.add("code"); 082 String code = (String) KradDataServiceLocator.getDataObjectService().wrap(businessObject).getPropertyValueNullSafe(attributeName); 083 NamespaceBo parameterNamespace = new NamespaceBo(); 084 parameterNamespace.setCode(code); 085 return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null); 086 } else if("kimTypeInfo.name".equals(attributeName)){ 087 KimTypeBo kimType = new KimTypeBo(); 088 kimType.setId( ((GroupBo)businessObject).getKimTypeId() ); 089 return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null); 090 } 091 092 return super.getInquiryUrl(businessObject, attributeName, forceInquiry); 093 } 094 095 public String getCustomGroupInquiryHref(String href){ 096 Properties parameters = new Properties(); 097 String hrefPart = ""; 098 if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) { 099 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 * This overridden method ... 113 * 114 * @see org.kuali.rice.krad.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map) 115 */ 116 @SuppressWarnings("unchecked") 117 @Override 118 public BusinessObject getBusinessObject(Map fieldValues) { 119 BusinessObject bo = super.getBusinessObject(fieldValues); 120 return bo; 121 } 122 123}