001/*
002 * Copyright 2010 The Kuali Foundation.
003 * 
004 * Licensed under the Educational Community License, Version 1.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/ecl1.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.ole.sec.businessobject.inquiry;
017
018import java.util.HashMap;
019import java.util.Map;
020import java.util.Properties;
021
022import org.apache.commons.lang.StringUtils;
023import org.kuali.ole.sec.SecPropertyConstants;
024import org.kuali.ole.sec.businessobject.SecurityModelDefinition;
025import org.kuali.ole.sys.OLEConstants;
026import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
027import org.kuali.rice.core.api.membership.MemberType;
028import org.kuali.rice.kim.api.KimConstants;
029import org.kuali.rice.kim.api.identity.Person;
030import org.kuali.rice.kim.framework.group.GroupEbo;
031import org.kuali.rice.kim.framework.role.RoleEbo;
032import org.kuali.rice.kns.lookup.HtmlData;
033import org.kuali.rice.krad.bo.BusinessObject;
034import org.kuali.rice.krad.util.KRADConstants;
035import org.kuali.rice.krad.util.ObjectUtils;
036import org.kuali.rice.krad.util.UrlFactory;
037
038
039/**
040 * Sets inquiry for member name based on type
041 */
042public class SecurityModelMemberInquirable extends KfsInquirableImpl {
043
044    /**
045     * @see org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String, boolean)
046     */
047    @Override
048    public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
049        if (SecPropertyConstants.MEMBER_ID.equals(attributeName)) {
050            Properties parameters = new Properties();
051            parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD);
052
053            Map<String, String> fieldList = new HashMap<String, String>();
054
055            String memberId = (String) ObjectUtils.getPropertyValue(businessObject, SecPropertyConstants.MEMBER_ID);
056            String memberTypeCode = (String) ObjectUtils.getPropertyValue(businessObject, SecPropertyConstants.MEMBER_TYPE_CODE);
057
058            if (StringUtils.isNotBlank(memberId) && StringUtils.isNotBlank(memberTypeCode)) {
059                if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
060                    parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, RoleEbo.class.getName());
061                    parameters.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId);
062                    fieldList.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId.toString());
063                }
064                else if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
065                    parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, GroupEbo.class.getName());
066                    parameters.put(KimConstants.PrimaryKeyConstants.GROUP_ID, memberId);
067                    fieldList.put(KimConstants.PrimaryKeyConstants.GROUP_ID, memberId.toString());
068                }
069                else {
070                    parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Person.class.getName());
071                    parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, memberId);
072                    fieldList.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, memberId.toString());
073                }
074
075                return getHyperLink(SecurityModelDefinition.class, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters));
076            }
077        }
078
079        return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
080    }
081
082
083}