View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl1.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sec.businessobject.inquiry;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sec.SecPropertyConstants;
24  import org.kuali.ole.sec.businessobject.SecurityModelDefinition;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
27  import org.kuali.rice.core.api.membership.MemberType;
28  import org.kuali.rice.kim.api.KimConstants;
29  import org.kuali.rice.kim.api.identity.Person;
30  import org.kuali.rice.kim.framework.group.GroupEbo;
31  import org.kuali.rice.kim.framework.role.RoleEbo;
32  import org.kuali.rice.kns.lookup.HtmlData;
33  import org.kuali.rice.krad.bo.BusinessObject;
34  import org.kuali.rice.krad.util.KRADConstants;
35  import org.kuali.rice.krad.util.ObjectUtils;
36  import org.kuali.rice.krad.util.UrlFactory;
37  
38  
39  /**
40   * Sets inquiry for member name based on type
41   */
42  public class SecurityModelMemberInquirable extends KfsInquirableImpl {
43  
44      /**
45       * @see org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String, boolean)
46       */
47      @Override
48      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
49          if (SecPropertyConstants.MEMBER_ID.equals(attributeName)) {
50              Properties parameters = new Properties();
51              parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD);
52  
53              Map<String, String> fieldList = new HashMap<String, String>();
54  
55              String memberId = (String) ObjectUtils.getPropertyValue(businessObject, SecPropertyConstants.MEMBER_ID);
56              String memberTypeCode = (String) ObjectUtils.getPropertyValue(businessObject, SecPropertyConstants.MEMBER_TYPE_CODE);
57  
58              if (StringUtils.isNotBlank(memberId) && StringUtils.isNotBlank(memberTypeCode)) {
59                  if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
60                      parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, RoleEbo.class.getName());
61                      parameters.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId);
62                      fieldList.put(KimConstants.PrimaryKeyConstants.ROLE_ID, memberId.toString());
63                  }
64                  else if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
65                      parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, GroupEbo.class.getName());
66                      parameters.put(KimConstants.PrimaryKeyConstants.GROUP_ID, memberId);
67                      fieldList.put(KimConstants.PrimaryKeyConstants.GROUP_ID, memberId.toString());
68                  }
69                  else {
70                      parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Person.class.getName());
71                      parameters.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, memberId);
72                      fieldList.put(KimConstants.PrimaryKeyConstants.PRINCIPAL_ID, memberId.toString());
73                  }
74  
75                  return getHyperLink(SecurityModelDefinition.class, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters));
76              }
77          }
78  
79          return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
80      }
81  
82  
83  }