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