1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
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 |
|
|
|
|
| 85.4% |
Uncovered Elements: 7 (48) |
Complexity: 13 |
Complexity Density: 0.42 |
|
31 |
|
public class SearchDispatcherImpl implements SearchDispatcher{ |
32 |
|
final Logger LOG = Logger.getLogger(SearchDispatcherImpl.class); |
33 |
|
|
34 |
|
private List<SearchService> services; |
35 |
|
|
36 |
|
|
37 |
|
private Map<String,SearchService> serviceMap = null; |
38 |
|
|
39 |
|
|
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
6
|
public SearchDispatcherImpl() {... |
42 |
6
|
super(); |
43 |
|
} |
44 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
45 |
1
|
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 |
|
|
54 |
|
} |
55 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
56 |
2
|
public void init(){... |
57 |
2
|
serviceMap = new HashMap<String,SearchService>(); |
58 |
|
|
59 |
|
|
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 |
|
|
81 |
|
@param |
82 |
|
@return |
83 |
|
|
|
|
| 85% |
Uncovered Elements: 3 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
84 |
4
|
public SearchResult dispatchSearch(SearchRequest searchRequest) {... |
85 |
|
|
86 |
|
|
87 |
4
|
if(serviceMap==null){ |
88 |
2
|
init(); |
89 |
|
} |
90 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
6
|
public void setServices(List<SearchService> services) {... |
110 |
6
|
this.services = services; |
111 |
|
} |
112 |
|
} |