Clover Coverage Report - KS Common UI 1.1.1-SNAPSHOT
Coverage timestamp: Wed Apr 20 2011 05:05:15 EST
../../../../../../../img/srcFileCovDistChart0.png 17% of files have more coverage
22   94   13   3.67
10   58   0.59   6
6     2.17  
1    
 
  SearchDispatchRpcGwtServlet       Line # 28 22 0% 13 38 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
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    private ConcurrentHashMap<SearchRequest, SearchResult> cache = new ConcurrentHashMap<SearchRequest, SearchResult>();
37   
 
38  0 toggle public SearchDispatchRpcGwtServlet() {
39  0 super();
40    }
41   
42    /**
43    * Delegates to the service responsible for the given search type key
44    *
45    * @param searchRequest
46    * @return The searchResult from the delegated search or null
47    * @throws MissingParameterException
48    */
 
49  0 toggle @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  0 toggle @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  0 toggle 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    }
84    }
85    }
86   
 
87  0 toggle public void setSearchDispatcher(SearchDispatcher searchDispatcher) {
88  0 this.searchDispatcher = searchDispatcher;
89    }
90   
 
91  0 toggle public void setIdTranslatorFilter(IdTranslatorFilter idTranslatorFilter) {
92  0 this.idTranslatorFilter = idTranslatorFilter;
93    }
94    }