Coverage Report - org.kuali.student.common.ui.server.gwt.SearchDispatchRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchDispatchRpcGwtServlet
0%
0/28
0%
0/18
2.667
 
 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  
 
 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  
      * Delegates to the service responsible for the given search type key
 45  
      *
 46  
      * @param searchRequest
 47  
      * @return The searchResult from the delegated search or null
 48  
      * @throws MissingParameterException
 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  
 }