View Javadoc

1   /*
2    * Copyright 2007-2009 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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.kim.bo.impl.GroupImpl;
20  import org.kuali.rice.kim.bo.types.impl.KimTypeImpl;
21  import org.kuali.rice.kim.util.KimCommonUtils;
22  import org.kuali.rice.kim.util.KimConstants;
23  import org.kuali.rice.kns.bo.BusinessObject;
24  import org.kuali.rice.kns.bo.Namespace;
25  import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
26  import org.kuali.rice.kns.lookup.HtmlData;
27  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
28  import org.kuali.rice.kns.util.KNSConstants;
29  import org.kuali.rice.kns.util.ObjectUtils;
30  import org.kuali.rice.kns.util.UrlFactory;
31  
32  import java.util.*;
33  
34  /**
35   * This is a description of what this class does - kellerj don't forget to fill this in.
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   *
39   */
40  public class GroupInquirableImpl extends KualiInquirableImpl {
41  
42  
43  	protected final String GROUP_NAME = "groupName";
44  	protected final String GROUP_ID = "groupId";
45  	protected final String NAMESPACE_CODE = "namespaceCode";
46  	
47      /**
48       * @see org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject,
49       *      java.lang.String, boolean)
50       */
51      @Override
52      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
53  		if(GROUP_NAME.equals(attributeName)){
54  			List<String> primaryKeys = new ArrayList<String>();
55  			primaryKeys.add(GROUP_ID);
56  		    String href = (getInquiryUrlForPrimaryKeys(GroupImpl.class, businessObject, primaryKeys, null)).getHref();
57  		    AnchorHtmlData htmlData = new AnchorHtmlData();
58  		    htmlData.setHref(getCustomGroupInquiryHref(href));
59  			return htmlData;
60  		} else if(NAMESPACE_CODE.equals(attributeName)){
61  			List<String> primaryKeys = new ArrayList<String>();
62  			primaryKeys.add("code");
63  			Namespace parameterNamespace = new Namespace();
64  			parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
65  			return getInquiryUrlForPrimaryKeys(Namespace.class, parameterNamespace, primaryKeys, null);
66  		} else if("kimTypeInfo.name".equals(attributeName)){
67  			KimTypeImpl kimType = new KimTypeImpl();
68  			kimType.setKimTypeId( ((GroupImpl)businessObject).getKimTypeId() );
69  			return getInquiryUrlForPrimaryKeys(KimTypeImpl.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
70          }
71  		
72          return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
73      }
74  
75  	public String getCustomGroupInquiryHref(String href){
76          Properties parameters = new Properties();
77          String hrefPart = "";
78  		if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) {
79  			int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"=");
80  		    int idx2 = href.indexOf("&", idx1+1);
81  		    if (idx2 < 0) {
82  		    	idx2 = href.length();
83  		    }
84  	        parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);
85  	        hrefPart = href.substring(idx1, idx2);
86  	    }
87  		return UrlFactory.parameterizeUrl(KimCommonUtils.getKimBasePath()+
88  				KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION, parameters)+hrefPart;
89  	}
90  
91  	/**
92  	 * This overridden method ...
93  	 *
94  	 * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map)
95  	 */
96  	@SuppressWarnings("unchecked")
97  	@Override
98  	public BusinessObject getBusinessObject(Map fieldValues) {
99  	    BusinessObject bo = super.getBusinessObject(fieldValues);
100 	    ((GroupImpl)bo).setMemberPersonsAndGroups();
101 	    return bo;
102 	}
103 
104 }