Coverage Report - org.kuali.student.datadictionary.DataDictionaryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryServiceImpl
75%
18/24
66%
4/6
1.5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.student.datadictionary;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.util.ArrayList;
 20  
 import java.util.LinkedHashMap;
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 import org.kuali.rice.kns.datadictionary.DataObjectEntry;
 24  
 import org.kuali.student.common.util.constants.CommonServiceConstants;
 25  
 import org.kuali.student.datadictionary.dto.DictionaryEntryInfo;
 26  
 import org.kuali.student.datadictionary.service.DataDictionaryService;
 27  
 import org.kuali.student.r2.common.dto.ContextInfo;
 28  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 29  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 30  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 31  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 32  
 import org.springframework.context.ApplicationContext;
 33  
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 34  
 
 35  
 /**
 36  
  * Dictionary Service implementation that reads the dictionary from the spring beans and feeds
 37  
  * both the Student dictionary and the RICE dictionary
 38  
  *
 39  
  * @author nwright
 40  
  */
 41  
 public class DataDictionaryServiceImpl implements DataDictionaryService, RiceDataDictionaryServiceInfc {
 42  
 
 43  1
     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DataDictionaryServiceImpl.class);
 44  
     private String serviceNamespaceSuffix;
 45  
     private Map<String, DictionaryEntryInfo> studMap;
 46  
     private Map<String, DataObjectEntry> riceMap;
 47  
 
 48  15
     public DataDictionaryServiceImpl() {
 49  15
     }
 50  
 
 51  
     public String getServiceNamespaceSuffix() {
 52  0
         return serviceNamespaceSuffix;
 53  
     }
 54  
 
 55  
     public void setServiceNamespaceSuffix(String serviceNamespaceSuffix) {
 56  10
         this.serviceNamespaceSuffix = serviceNamespaceSuffix;
 57  10
     }
 58  
 
 59  
 
 60  
     public void setDictionaryLocations(List<String> locations) throws IOException {
 61  10
         studMap = new LinkedHashMap<String, DictionaryEntryInfo>();
 62  10
         riceMap = new LinkedHashMap<String, DataObjectEntry>();
 63  10
         for (String location : locations) {
 64  35
             ApplicationContext ac = new ClassPathXmlApplicationContext(location);
 65  35
             Map<String, DataObjectEntry> beansOfType =
 66  
                     (Map<String, DataObjectEntry>) ac.getBeansOfType(DataObjectEntry.class);
 67  35
             for (DataObjectEntry entry : beansOfType.values()) {
 68  35
                 LOG.debug(entry.getObjectClass());
 69  35
                 riceMap.put(entry.getFullClassName(), entry);
 70  35
                 studMap.put(calcRefObjectURI (entry.getObjectClass()), new Rice2StudentDictionaryEntryConverter().convert(entry));
 71  
             }
 72  35
         }
 73  10
     }
 74  
 
 75  
     private String calcRefObjectURI (Class<?> objectClass) {
 76  35
      return CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + this.serviceNamespaceSuffix + "/" + objectClass.getSimpleName();
 77  
     }
 78  
 
 79  
     @Override
 80  
     public DictionaryEntryInfo getDataDictionaryEntry(String entryKey, ContextInfo context)
 81  
             throws OperationFailedException,
 82  
             MissingParameterException,
 83  
             PermissionDeniedException,
 84  
             DoesNotExistException {
 85  0
         DictionaryEntryInfo entry = studMap.get(entryKey);
 86  0
         if (entry == null) {
 87  0
             throw new DoesNotExistException(entryKey);
 88  
         }
 89  0
         return entry;
 90  
     }
 91  
 
 92  
     @Override
 93  
     public List<String> getDataDictionaryEntryKeys(ContextInfo context)
 94  
             throws OperationFailedException,
 95  
             MissingParameterException,
 96  
             PermissionDeniedException {
 97  0
         return new ArrayList(studMap.keySet());
 98  
     }
 99  
 
 100  
     @Override
 101  
     public DataObjectEntry getDataObjectEntry(String entryKey) {
 102  8
         return riceMap.get(entryKey);
 103  
     }
 104  
 }