Coverage Report - org.kuali.student.kim.mock.DataProviderForKimEntityInfoImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DataProviderForKimEntityInfoImpl
0%
0/47
0%
0/30
6.6
DataProviderForKimEntityInfoImpl$1
0%
0/1
N/A
6.6
 
 1  
 /**
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 package org.kuali.student.kim.mock;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityAffiliationInfo;
 21  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityInfo;
 22  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityNameInfo;
 23  
 import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo;
 24  
 import org.kuali.rice.kns.datadictionary.validation.DataType;
 25  
 
 26  
 /**
 27  
  * Provides values to compare
 28  
  * @author nwright
 29  
  */
 30  0
 public class DataProviderForKimEntityInfoImpl implements DataProviderForKimEntityInfoInfc {
 31  
 
 32  0
     final static Logger LOG = Logger.getLogger(DataProviderForKimEntityInfoImpl.class);
 33  
 
 34  0
     public DataProviderForKimEntityInfoImpl() {
 35  0
     }
 36  
 
 37  
     @Override
 38  
     public List<Object> getValues(KimEntityInfo obj, String fieldKey) {
 39  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PERSON_FIRST_NAME)) {
 40  0
             List<Object> dvs = new ArrayList();
 41  0
             for (KimEntityNameInfo nameInfo : obj.getNames()) {
 42  0
                 dvs.add(nameInfo.getFirstName());
 43  
             }
 44  0
             return dvs;
 45  
         }
 46  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PERSON_LAST_NAME)) {
 47  0
             List<Object> dvs = new ArrayList();
 48  0
             for (KimEntityNameInfo nameInfo : obj.getNames()) {
 49  0
                 dvs.add(nameInfo.getLastName());
 50  
             }
 51  0
             return dvs;
 52  
         }
 53  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PERSON_MIDDLE_NAME)) {
 54  0
             List<Object> dvs = new ArrayList();
 55  0
             for (KimEntityNameInfo nameInfo : obj.getNames()) {
 56  0
                 dvs.add(nameInfo.getMiddleName());
 57  
             }
 58  0
             return dvs;
 59  
         }
 60  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PRINCIPALS_PRINCIPALNAME)) {
 61  0
             List<Object> dvs = new ArrayList();
 62  0
             for (KimPrincipalInfo prinInfo : obj.getPrincipals()) {
 63  0
                 dvs.add(prinInfo.getPrincipalName());
 64  
             }
 65  0
             return dvs;
 66  
         }
 67  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PRINCIPALS_PRINCIPALID)) {
 68  0
             List<Object> dvs = new ArrayList();
 69  0
             for (KimPrincipalInfo prinInfo : obj.getPrincipals()) {
 70  0
                 dvs.add(prinInfo.getPrincipalId());
 71  
             }
 72  0
             return dvs;
 73  
         }
 74  0
         if (fieldKey.equals(IdentityServiceConstants.KIM_PERSON_AFFILIATION_TYPE_CODE)) {
 75  0
             List<Object> dvs = new ArrayList();
 76  0
             for (KimEntityAffiliationInfo affInfo : obj.getAffiliations()) {
 77  0
                 dvs.add(affInfo.getAffiliationTypeCode());
 78  
             }
 79  0
             return dvs;
 80  
         }
 81  0
         throw new IllegalArgumentException("Search criteria " + fieldKey + " is not supported");
 82  
     }
 83  
 
 84  
     @Override
 85  
     public DataType getDataType(String fieldKey) {
 86  0
         for (String supportedKey : IdentityServiceConstants.SUPPORTED_SEARCH_FIELD_KEYS) {
 87  0
             if (supportedKey.equals(fieldKey)) {
 88  0
                 return DataType.STRING;
 89  
             }
 90  
         }
 91  0
         throw new IllegalArgumentException("Search criteria " + fieldKey + " is not supported");
 92  
     }
 93  
 
 94  
     @Override
 95  
     public boolean supportsField(String fieldKey) {
 96  
         try {
 97  0
             getDataType(fieldKey);
 98  0
             return true;
 99  0
         } catch (IllegalArgumentException ex) {
 100  0
             return false;
 101  
         }
 102  
     }
 103  
 
 104  
     @Override
 105  
     public Object parseValue(String fieldKey, String value) throws IllegalArgumentException {
 106  0
         DataType dt = this.getDataType(fieldKey);
 107  0
         switch (dt) {
 108  
             case STRING:
 109  0
                 return value.toLowerCase();
 110  
             default:
 111  0
                 throw new IllegalArgumentException("Search criteria " + fieldKey + " has a data type that is not supported");
 112  
         }
 113  
 
 114  
     }
 115  
 }