1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.server.gwt; |
17 | |
|
18 | |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
19 | |
import org.kuali.student.common.ui.client.service.SearchRpcService; |
20 | |
import org.kuali.student.core.assembly.transform.IdTranslatorFilter; |
21 | |
import org.kuali.student.core.exceptions.MissingParameterException; |
22 | |
import org.kuali.student.core.search.dto.*; |
23 | |
import org.kuali.student.core.search.service.SearchDispatcher; |
24 | |
|
25 | |
import java.util.List; |
26 | |
import java.util.concurrent.ConcurrentHashMap; |
27 | |
|
28 | |
public class SearchDispatchRpcGwtServlet extends RemoteServiceServlet implements SearchRpcService { |
29 | |
|
30 | |
private static final long serialVersionUID = 1L; |
31 | |
|
32 | |
private IdTranslatorFilter idTranslatorFilter; |
33 | |
|
34 | |
private SearchDispatcher searchDispatcher; |
35 | |
|
36 | 0 | private ConcurrentHashMap<SearchRequest, SearchResult> cache = new ConcurrentHashMap<SearchRequest, SearchResult>(); |
37 | |
|
38 | |
public SearchDispatchRpcGwtServlet() { |
39 | 0 | super(); |
40 | 0 | } |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
public SearchResult search(SearchRequest searchRequest) { |
51 | 0 | SearchResult searchResult = searchDispatcher.dispatchSearch(searchRequest); |
52 | 0 | List<SearchParam> params = searchRequest.getParams(); |
53 | 0 | if(params != null && params.size() > 0){ |
54 | 0 | SearchParam firstParam = params.get(0); |
55 | 0 | if(firstParam.getKey().equals("lu.queryParam.cluVersionIndId")){ |
56 | 0 | doIdTranslation(searchResult); |
57 | |
|
58 | |
} |
59 | |
} |
60 | 0 | return searchResult; |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public SearchResult cachingSearch(SearchRequest searchRequest) { |
65 | 0 | if(cache.containsKey(searchRequest)){ |
66 | 0 | return cache.get(searchRequest); |
67 | |
} |
68 | 0 | SearchResult searchResult = search(searchRequest); |
69 | 0 | cache.putIfAbsent(searchRequest, searchResult); |
70 | 0 | return searchResult; |
71 | |
} |
72 | |
|
73 | |
private void doIdTranslation(SearchResult searchResult) { |
74 | 0 | for (SearchResultRow searchResultRow : searchResult.getRows()) { |
75 | 0 | for (SearchResultCell searchResultCell : searchResultRow.getCells()) { |
76 | 0 | String value = searchResultCell.getValue(); |
77 | 0 | if (value != null && value.startsWith("kuali.atp")) { |
78 | 0 | String newValue = idTranslatorFilter.getTranslationForAtp(value); |
79 | 0 | if (newValue != null) { |
80 | 0 | searchResultCell.setValue(newValue); |
81 | |
} |
82 | |
} |
83 | 0 | } |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
public void setSearchDispatcher(SearchDispatcher searchDispatcher) { |
88 | 0 | this.searchDispatcher = searchDispatcher; |
89 | 0 | } |
90 | |
|
91 | |
public void setIdTranslatorFilter(IdTranslatorFilter idTranslatorFilter) { |
92 | 0 | this.idTranslatorFilter = idTranslatorFilter; |
93 | 0 | } |
94 | |
} |