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.kuali.rice.coreservice.impl.namespace.NamespaceBo;
019import org.kuali.rice.kim.api.KimConstants;
020import org.kuali.rice.kim.impl.role.RoleBo;
021import org.kuali.rice.kim.impl.type.KimTypeBo;
022import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
023import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
024import org.kuali.rice.kns.lookup.HtmlData;
025import org.kuali.rice.krad.bo.BusinessObject;
026import org.kuali.rice.krad.data.KradDataServiceLocator;
027import org.kuali.rice.krad.uif.widget.Inquiry;
028
029import java.util.ArrayList;
030import java.util.Collections;
031import java.util.HashMap;
032import java.util.List;
033import 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 */
041public 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            String code = (String) KradDataServiceLocator.getDataObjectService().wrap(businessObject).getPropertyValueNullSafe(attributeName);
081                        parameterNamespace.setCode(code);
082                        return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
083                } else if("kimRoleType.name".equals(attributeName)){
084                        KimTypeBo kimType = new KimTypeBo();
085                        kimType.setId( ((RoleBo)businessObject).getKimTypeId() );
086                        return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
087        }
088                
089        return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
090    }
091
092}