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