1 package org.kuali.student.r2.common.class1.search;
2
3 import org.kuali.student.r2.common.dto.ContextInfo;
4 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
5 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
6 import org.kuali.student.r2.common.exceptions.MissingParameterException;
7 import org.kuali.student.r2.common.exceptions.OperationFailedException;
8 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
9 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
10 import org.kuali.student.r2.core.search.dto.SearchParamInfo;
11 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
12 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
13 import org.kuali.student.r2.core.search.service.SearchService;
14
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21
22
23
24
25
26
27 public class SearchServiceMockImpl implements SearchService {
28
29
30
31
32 private Map<String, SearchResultInfo> searchResults = new HashMap<String, SearchResultInfo>();
33
34 @Override
35 public List<TypeInfo> getSearchTypes(ContextInfo contextInfo)
36 throws InvalidParameterException, MissingParameterException, OperationFailedException {
37 return null;
38 }
39
40 @Override
41 public TypeInfo getSearchType(String searchTypeKey, ContextInfo contextInfo)
42 throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException {
43 return null;
44 }
45
46 @Override
47 public SearchResultInfo search(SearchRequestInfo searchRequestInfo, ContextInfo contextInfo)
48 throws MissingParameterException, InvalidParameterException, OperationFailedException, PermissionDeniedException {
49 String searchResultsKey = makeSearchResultsKey(searchRequestInfo);
50 return searchResults.get(searchResultsKey);
51 }
52
53
54
55
56
57
58 public void addSearchResult(SearchRequestInfo searchRequestInfo, SearchResultInfo searchResultInfo) {
59 String key = makeSearchResultsKey(searchRequestInfo);
60 searchResults.put(key, searchResultInfo);
61 }
62
63
64
65
66
67
68
69 private String makeSearchResultsKey(SearchRequestInfo searchRequestInfo) {
70 List<String> paramsAndValues = new ArrayList<String>();
71
72 for (SearchParamInfo param : searchRequestInfo.getParams()) {
73 paramsAndValues.add(param.getKey() + "" + param.getValues().toString());
74 }
75
76 Collections.sort(paramsAndValues);
77 return String.format("%s%s", searchRequestInfo.getSearchKey(), paramsAndValues);
78 }
79 }