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