001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.kim.inquiry;
017
018 import org.kuali.rice.coreservice.impl.namespace.NamespaceBo;
019 import org.kuali.rice.kim.api.KimConstants;
020 import org.kuali.rice.kim.impl.role.RoleBo;
021 import org.kuali.rice.kim.impl.type.KimTypeBo;
022 import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
023 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
024 import org.kuali.rice.kns.lookup.HtmlData;
025 import org.kuali.rice.krad.bo.BusinessObject;
026 import org.kuali.rice.krad.uif.widget.Inquiry;
027 import org.kuali.rice.krad.util.ObjectUtils;
028
029 import java.util.ArrayList;
030 import java.util.Collections;
031 import java.util.HashMap;
032 import java.util.List;
033 import java.util.Map;
034
035 /**
036 * This is a description of what this class does - bhargavp don't forget to fill this in.
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 *
040 */
041 public class RoleInquirableImpl extends KualiInquirableImpl {
042
043 protected final String ROLE_NAME = "name";
044 protected final String ROLE_ID = "id";
045 protected final String NAMESPACE_CODE = "namespaceCode";
046
047 @Override
048 public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){
049 if(ROLE_NAME.equals(propertyName)){
050 Map<String, String> primaryKeys = new HashMap<String, String>();
051 primaryKeys.put(ROLE_ID, ROLE_ID);
052 inquiry.buildInquiryLink(dataObject, propertyName, RoleBo.class, primaryKeys);
053 }else if(NAMESPACE_CODE.equals(propertyName)){
054 Map<String, String> primaryKeys = new HashMap<String, String>();
055 primaryKeys.put(propertyName, "code");
056 inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys);
057 } else if("kimRoleType.name".equals(propertyName)){
058 Map<String, String> primaryKeys = new HashMap<String, String>();
059 primaryKeys.put("kimRoleType.id", KimConstants.PrimaryKeyConstants.KIM_TYPE_ID);
060 inquiry.buildInquiryLink(dataObject, propertyName, KimTypeBo.class, primaryKeys);
061 }else{
062 super.buildInquirableLink(dataObject, propertyName, inquiry);
063 }
064 }
065
066 @Override
067 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
068 if(ROLE_NAME.equals(attributeName)){
069 List<String> primaryKeys = new ArrayList<String>();
070 primaryKeys.add(ROLE_ID);
071 //((AnchorHtmlData)inqUrl).setHref("../kim/identityManagementRoleDocument.do?methodToCall=inquiry&command=initiate&docTypeName=IdentityManagementRoleDocument"+href.substring(idx1, idx2));
072 String href = (getInquiryUrlForPrimaryKeys(RoleBo.class, businessObject, primaryKeys, null)).getHref();
073 HtmlData.AnchorHtmlData htmlData = new HtmlData.AnchorHtmlData();
074 htmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(href));
075 return htmlData;
076 } else if(NAMESPACE_CODE.equals(attributeName)){
077 List<String> primaryKeys = new ArrayList<String>();
078 primaryKeys.add("code");
079 NamespaceBo parameterNamespace = new NamespaceBo();
080 parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
081 return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
082 } else if("kimRoleType.name".equals(attributeName)){
083 KimTypeBo kimType = new KimTypeBo();
084 kimType.setId( ((RoleBo)businessObject).getKimTypeId() );
085 return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
086 }
087
088 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
089 }
090
091 }