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 private ConcurrentHashMap<SearchRequest, SearchResult> cache = new ConcurrentHashMap<SearchRequest, SearchResult>();
38
39 public SearchDispatchRpcGwtServlet() {
40 super();
41 }
42
43
44
45
46
47
48
49
50 @Override
51 public SearchResult search(SearchRequest searchRequest) {
52 SearchResult searchResult = searchDispatcher.dispatchSearch(searchRequest);
53 List<SearchParam> params = searchRequest.getParams();
54 if(params != null && params.size() > 0){
55 SearchParam firstParam = params.get(0);
56 if(firstParam.getKey().equals("lu.queryParam.cluVersionIndId")){
57 doIdTranslation(searchResult);
58
59 }
60 }
61 return searchResult;
62 }
63
64 @Override
65 public SearchResult cachingSearch(SearchRequest searchRequest) {
66 if(cache.containsKey(searchRequest)){
67 return cache.get(searchRequest);
68 }
69 SearchResult searchResult = search(searchRequest);
70 cache.putIfAbsent(searchRequest, searchResult);
71 return searchResult;
72 }
73
74 private void doIdTranslation(SearchResult searchResult) {
75 for (SearchResultRow searchResultRow : searchResult.getRows()) {
76 for (SearchResultCell searchResultCell : searchResultRow.getCells()) {
77 String value = searchResultCell.getValue();
78 if (value != null && value.startsWith("kuali.atp")) {
79 String newValue = idTranslatorFilter.getTranslationForAtp(value);
80 if (newValue != null) {
81 searchResultCell.setValue(newValue);
82 }
83 }
84 }
85 }
86 }
87
88 public void setSearchDispatcher(SearchDispatcher searchDispatcher) {
89 this.searchDispatcher = searchDispatcher;
90 }
91
92 public void setIdTranslatorFilter(IdTranslatorFilter idTranslatorFilter) {
93 this.idTranslatorFilter = idTranslatorFilter;
94 }
95 }