View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.kim.inquiry;
17  
18  import org.kuali.rice.coreservice.impl.namespace.NamespaceBo;
19  import org.kuali.rice.kim.api.KimConstants;
20  import org.kuali.rice.kim.impl.role.RoleBo;
21  import org.kuali.rice.kim.impl.type.KimTypeBo;
22  import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl;
23  import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
24  import org.kuali.rice.kns.lookup.HtmlData;
25  import org.kuali.rice.krad.bo.BusinessObject;
26  import org.kuali.rice.krad.data.KradDataServiceLocator;
27  import org.kuali.rice.krad.uif.widget.Inquiry;
28  
29  import java.util.ArrayList;
30  import java.util.Collections;
31  import java.util.HashMap;
32  import java.util.List;
33  import java.util.Map;
34  
35  /**
36   * This is a description of what this class does - bhargavp don't forget to fill this in. 
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   *
40   */
41  public class RoleInquirableImpl extends KualiInquirableImpl {
42  
43  	protected final String ROLE_NAME = "name";
44  	protected final String ROLE_ID = "id";
45  	protected final String NAMESPACE_CODE = "namespaceCode";
46  	
47  	@Override
48  	public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){
49  		if(ROLE_NAME.equals(propertyName)){
50  			Map<String, String> primaryKeys = new HashMap<String, String>();
51  			primaryKeys.put(ROLE_ID, ROLE_ID);
52  			inquiry.buildInquiryLink(dataObject, propertyName, RoleBo.class, primaryKeys);
53  		}else if(NAMESPACE_CODE.equals(propertyName)){
54  			Map<String, String> primaryKeys = new HashMap<String, String>();
55  			primaryKeys.put(propertyName, "code");
56  			inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys);
57  		} else if("kimRoleType.name".equals(propertyName)){
58  			Map<String, String> primaryKeys = new HashMap<String, String>();
59  			primaryKeys.put("kimRoleType.id", KimConstants.PrimaryKeyConstants.KIM_TYPE_ID);
60  			inquiry.buildInquiryLink(dataObject, propertyName, KimTypeBo.class, primaryKeys);
61          }else{
62          	super.buildInquirableLink(dataObject, propertyName, inquiry);
63          }
64  	}
65  	
66      @Override
67      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
68  		if(ROLE_NAME.equals(attributeName)){
69  			List<String> primaryKeys = new ArrayList<String>();
70  			primaryKeys.add(ROLE_ID);
71  		    //((AnchorHtmlData)inqUrl).setHref("../kim/identityManagementRoleDocument.do?methodToCall=inquiry&command=initiate&docTypeName=IdentityManagementRoleDocument"+href.substring(idx1, idx2));
72  		    String href = (getInquiryUrlForPrimaryKeys(RoleBo.class, businessObject, primaryKeys, null)).getHref();
73  		    HtmlData.AnchorHtmlData htmlData = new HtmlData.AnchorHtmlData();
74  		    htmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(href));
75  			return htmlData;
76  		} else if(NAMESPACE_CODE.equals(attributeName)){
77  			List<String> primaryKeys = new ArrayList<String>();
78  			primaryKeys.add("code");
79  			NamespaceBo parameterNamespace = new NamespaceBo();
80              String code = (String) KradDataServiceLocator.getDataObjectService().wrap(businessObject).getPropertyValueNullSafe(attributeName);
81  			parameterNamespace.setCode(code);
82  			return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
83  		} else if("kimRoleType.name".equals(attributeName)){
84  			KimTypeBo kimType = new KimTypeBo();
85  			kimType.setId( ((RoleBo)businessObject).getKimTypeId() );
86  			return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
87          }
88  		
89          return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
90      }
91  
92  }