Coverage Report - org.kuali.rice.kim.inquiry.GroupInquirableImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
GroupInquirableImpl
0%
0/47
0%
0/18
4
 
 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.core.impl.namespace.NamespaceBo;
 20  
 import org.kuali.rice.kim.bo.impl.PermissionImpl;
 21  
 import org.kuali.rice.kim.impl.group.GroupBo;
 22  
 import org.kuali.rice.kim.impl.type.KimTypeBo;
 23  
 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
 24  
 import org.kuali.rice.kim.util.KimConstants;
 25  
 import org.kuali.rice.kns.bo.BusinessObject;
 26  
 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
 27  
 import org.kuali.rice.kns.lookup.HtmlData;
 28  
 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
 29  
 import org.kuali.rice.kns.uif.widget.Inquiry;
 30  
 import org.kuali.rice.kns.util.KNSConstants;
 31  
 import org.kuali.rice.kns.util.ObjectUtils;
 32  
 import org.kuali.rice.kns.util.UrlFactory;
 33  
 
 34  
 import java.util.*;
 35  
 
 36  
 /**
 37  
  * This is a description of what this class does - kellerj don't forget to fill this in.
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class GroupInquirableImpl extends KualiInquirableImpl {
 43  
 
 44  
 
 45  0
         protected final String GROUP_NAME = "name";
 46  0
         protected final String GROUP_ID = "id";
 47  0
         protected final String NAMESPACE_CODE = "namespaceCode";
 48  
         
 49  
         @Override
 50  
         public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry){
 51  
                 
 52  0
                 if(GROUP_NAME.equals(propertyName)){
 53  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 54  0
                         primaryKeys.put(GROUP_ID, GROUP_ID);
 55  0
                         inquiry.buildInquiryLink(dataObject, propertyName, GroupBo.class, primaryKeys);
 56  0
                 } else if(NAMESPACE_CODE.equals(propertyName)){
 57  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 58  0
                         primaryKeys.put(propertyName, "code");
 59  0
                         inquiry.buildInquiryLink(dataObject, propertyName, NamespaceBo.class, primaryKeys);
 60  0
                 } else if("kimTypeInfo.name".equals(propertyName)){
 61  0
                         Map<String, String> primaryKeys = new HashMap<String, String>();
 62  0
                         primaryKeys.put("kimTypeInfo.id", KimConstants.PrimaryKeyConstants.KIM_TYPE_ID);
 63  0
                         inquiry.buildInquiryLink(dataObject, propertyName, KimTypeBo.class, primaryKeys);
 64  
         }
 65  0
         }
 66  
         
 67  
     @Override
 68  
     public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
 69  0
                 if(GROUP_NAME.equals(attributeName)){
 70  0
                         List<String> primaryKeys = new ArrayList<String>();
 71  0
                         primaryKeys.add(GROUP_ID);
 72  0
                     String href = (getInquiryUrlForPrimaryKeys(GroupBo.class, businessObject, primaryKeys, null)).getHref();
 73  0
                     AnchorHtmlData htmlData = new AnchorHtmlData();
 74  0
                     htmlData.setHref(getCustomGroupInquiryHref(href));
 75  0
                         return htmlData;
 76  0
                 } else if(NAMESPACE_CODE.equals(attributeName)){
 77  0
                         List<String> primaryKeys = new ArrayList<String>();
 78  0
                         primaryKeys.add("code");
 79  0
                         NamespaceBo parameterNamespace = new NamespaceBo();
 80  0
                         parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName));
 81  0
                         return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null);
 82  0
                 } else if("kimTypeInfo.name".equals(attributeName)){
 83  0
                         KimTypeBo kimType = new KimTypeBo();
 84  0
                         kimType.setId( ((GroupBo)businessObject).getKimTypeId() );
 85  0
                         return getInquiryUrlForPrimaryKeys(KimTypeBo.class, kimType, Collections.singletonList( KimConstants.PrimaryKeyConstants.KIM_TYPE_ID ), null);
 86  
         }
 87  
                 
 88  0
         return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
 89  
     }
 90  
 
 91  
         public String getCustomGroupInquiryHref(String href){
 92  0
         Properties parameters = new Properties();
 93  0
         String hrefPart = "";
 94  0
                 if (StringUtils.isNotBlank(href) && href.contains("&" + KimConstants.PrimaryKeyConstants.GROUP_ID + "=")) {
 95  0
                         int idx1 = href.indexOf("&"+KimConstants.PrimaryKeyConstants.GROUP_ID+"=");
 96  0
                     int idx2 = href.indexOf("&", idx1+1);
 97  0
                     if (idx2 < 0) {
 98  0
                             idx2 = href.length();
 99  
                     }
 100  0
                 parameters.put(KNSConstants.DISPATCH_REQUEST_PARAMETER, KNSConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY);
 101  0
                 hrefPart = href.substring(idx1, idx2);
 102  
             }
 103  0
                 return UrlFactory.parameterizeUrl(KimCommonUtilsInternal.getKimBasePath()+
 104  
                                 KimConstants.KimUIConstants.KIM_GROUP_INQUIRY_ACTION, parameters)+hrefPart;
 105  
         }
 106  
 
 107  
         /**
 108  
          * This overridden method ...
 109  
          *
 110  
          * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getBusinessObject(java.util.Map)
 111  
          */
 112  
         @SuppressWarnings("unchecked")
 113  
         @Override
 114  
         public BusinessObject getBusinessObject(Map fieldValues) {
 115  0
             BusinessObject bo = super.getBusinessObject(fieldValues);
 116  0
             return bo;
 117  
         }
 118  
 
 119  
 }