001    /*
002     * Copyright 2011 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.kfs.sec.businessobject.inquiry;
017    
018    import java.util.HashMap;
019    import java.util.Map;
020    import java.util.Properties;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.kfs.pdp.businessobject.PayeeACHAccount;
024    import org.kuali.kfs.sec.SecPropertyConstants;
025    import org.kuali.kfs.sys.KFSConstants;
026    import org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl;
027    import org.kuali.rice.kim.bo.Person;
028    import org.kuali.rice.kim.bo.impl.GroupImpl;
029    import org.kuali.rice.kim.bo.impl.RoleImpl;
030    import org.kuali.rice.kim.util.KimConstants;
031    import org.kuali.rice.kns.bo.BusinessObject;
032    import org.kuali.rice.kns.lookup.HtmlData;
033    import org.kuali.rice.kns.util.KNSConstants;
034    import org.kuali.rice.kns.util.KualiInteger;
035    import org.kuali.rice.kns.util.ObjectUtils;
036    import org.kuali.rice.kns.util.UrlFactory;
037    
038    
039    /**
040     * Sets inquiry for member name based on type
041     */
042    public class SecurityModelMemberInquirable extends KfsInquirableImpl {
043    
044        /**
045         * @see org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.kns.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(KNSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.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 (KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)) {
060                        parameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, RoleImpl.class.getName());
061                        parameters.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId);
062                        fieldList.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId.toString());
063                    }
064                    else if (KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)) {
065                        parameters.put(KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, GroupImpl.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(KNSConstants.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(PayeeACHAccount.class, fieldList, UrlFactory.parameterizeUrl(KNSConstants.INQUIRY_ACTION, parameters));
076                }
077            }
078    
079            return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
080        }
081    
082    
083    }