Clover Coverage Report - Kuali Student 1.2-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Mar 3 2011 04:02:59 EST
../../../../../../../img/srcFileCovDistChart9.png 30% of files have more coverage
31   112   13   6.2
12   72   0.42   5
5     2.6  
1    
 
  SearchDispatcherImpl       Line # 31 31 0% 13 7 85.4% 0.8541667
 
  (2)
 
1    /**
2    * Copyright 2010 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   
16    package org.kuali.student.common.search.service.impl;
17   
18    import java.util.ArrayList;
19    import java.util.HashMap;
20    import java.util.List;
21    import java.util.Map;
22   
23    import org.apache.log4j.Logger;
24    import org.kuali.student.common.exceptions.OperationFailedException;
25    import org.kuali.student.common.search.dto.SearchRequest;
26    import org.kuali.student.common.search.dto.SearchResult;
27    import org.kuali.student.common.search.dto.SearchTypeInfo;
28    import org.kuali.student.common.search.service.SearchDispatcher;
29    import org.kuali.student.common.search.service.SearchService;
30   
 
31    public class SearchDispatcherImpl implements SearchDispatcher{
32    final Logger LOG = Logger.getLogger(SearchDispatcherImpl.class);
33   
34    private List<SearchService> services;
35   
36    //Map of search key->service
37    private Map<String,SearchService> serviceMap = null;
38   
39   
40   
 
41  6 toggle public SearchDispatcherImpl() {
42  6 super();
43    }
44   
 
45  1 toggle public SearchDispatcherImpl(SearchService... services){
46  1 super();
47  1 this.services = new ArrayList<SearchService>();
48  1 if(services!=null){
49  1 for(SearchService service:services){
50  1 this.services.add(service);
51    }
52    }
53    // init();
54    }
55   
 
56  2 toggle public void init(){
57  2 serviceMap = new HashMap<String,SearchService>();
58   
59    //Look through each service, grab it's search keys and add them to the map
60  2 for(SearchService service:services){
61  2 if(null==service){
62  0 LOG.warn("Null service passed to SearchDelegator");
63    }else{
64  2 try {
65  2 List<SearchTypeInfo> searchTypes = service.getSearchTypes();
66  2 if(searchTypes!=null){
67  1 for(SearchTypeInfo searchType:searchTypes){
68  3 serviceMap.put(searchType.getKey(),service);
69    }
70    }
71    } catch (OperationFailedException e) {
72  0 LOG.warn("Error getting searchTypes",e);
73    }
74    }
75    }
76    }
77   
78   
79    /**
80    * Delegates to the service responsible for the given search type key
81    * @param searchRequest
82    * @return The searchResult from the delegated search or null
83    */
 
84  4 toggle public SearchResult dispatchSearch(SearchRequest searchRequest) {
85    //Lazy Load service map. THis might cause synchronization issues?
86    //Needed because of circular bean dependencies... dispatch->serviceImpl->searchMgr->crossSvcMgr->dispatch
87  4 if(serviceMap==null){
88  2 init();
89    }
90    //Lookup which service to call for given search key and do the search
91  4 if(searchRequest != null){
92  4 String searchKey = searchRequest.getSearchKey();
93  4 SearchService searchService = serviceMap.get(searchKey);
94  4 if(searchService != null){
95  2 SearchResult searchResult;
96  2 try {
97  2 searchResult = searchService.search(searchRequest);
98    } catch (Exception e) {
99  0 LOG.warn("Error invoking search",e);
100  0 return null;
101    }
102  2 return searchResult;
103    }
104  2 LOG.error("Error Dispatching, Search Service not found for search key:"+searchRequest.getSearchKey());
105    }
106  2 return null;
107    }
108   
 
109  6 toggle public void setServices(List<SearchService> services) {
110  6 this.services = services;
111    }
112    }