| 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 java.lang.ref.SoftReference; |
| 19 |
|
import java.util.Collections; |
| 20 |
|
import java.util.LinkedHashMap; |
| 21 |
|
import java.util.List; |
| 22 |
|
import java.util.Map; |
| 23 |
|
import java.util.Map.Entry; |
| 24 |
|
|
| 25 |
|
import org.kuali.student.common.assembly.transform.IdTranslatorFilter; |
| 26 |
|
import org.kuali.student.common.exceptions.MissingParameterException; |
| 27 |
|
import org.kuali.student.common.search.dto.SearchParam; |
| 28 |
|
import org.kuali.student.common.search.dto.SearchRequest; |
| 29 |
|
import org.kuali.student.common.search.dto.SearchResult; |
| 30 |
|
import org.kuali.student.common.search.dto.SearchResultCell; |
| 31 |
|
import org.kuali.student.common.search.dto.SearchResultRow; |
| 32 |
|
import org.kuali.student.common.search.service.SearchDispatcher; |
| 33 |
|
import org.kuali.student.common.ui.client.service.SearchRpcService; |
| 34 |
|
import org.springframework.beans.factory.InitializingBean; |
| 35 |
|
|
| 36 |
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 21 |
Complexity Density: 0.64 |
|
| 38 |
|
public class SearchDispatchRpcGwtServlet extends RemoteServiceServlet implements SearchRpcService, InitializingBean { |
| 39 |
|
|
| 40 |
|
private static final long serialVersionUID = 1L; |
| 41 |
|
|
| 42 |
|
private IdTranslatorFilter idTranslatorFilter; |
| 43 |
|
|
| 44 |
|
private SearchDispatcher searchDispatcher; |
| 45 |
|
|
| 46 |
|
protected boolean cachingEnabled = false; |
| 47 |
|
protected int searchCacheMaxSize = 20; |
| 48 |
|
protected int searchCacheMaxAgeSeconds = 90; |
| 49 |
|
protected Map<String,MaxAgeSoftReference<SearchResult>> searchCache; |
| 50 |
|
|
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0
|
public SearchDispatchRpcGwtServlet() {... |
| 53 |
0
|
super(); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
@param |
| 60 |
|
@return |
| 61 |
|
@throws |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 63 |
0
|
@Override... |
| 64 |
|
public SearchResult search(SearchRequest searchRequest) { |
| 65 |
0
|
SearchResult searchResult = searchDispatcher.dispatchSearch(searchRequest); |
| 66 |
0
|
List<SearchParam> params = searchRequest.getParams(); |
| 67 |
0
|
if(params != null && params.size() > 0){ |
| 68 |
0
|
SearchParam firstParam = params.get(0); |
| 69 |
0
|
if(firstParam.getKey().equals("lu.queryParam.cluVersionIndId")){ |
| 70 |
0
|
doIdTranslation(searchResult); |
| 71 |
|
} |
| 72 |
|
} |
| 73 |
0
|
return searchResult; |
| 74 |
|
} |
| 75 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 76 |
0
|
@Override... |
| 77 |
|
public SearchResult cachingSearch(SearchRequest searchRequest) { |
| 78 |
0
|
String cacheKey = searchRequest.toString(); |
| 79 |
0
|
if(cachingEnabled){ |
| 80 |
|
|
| 81 |
|
|
| 82 |
0
|
MaxAgeSoftReference<SearchResult> ref = searchCache.get(cacheKey); |
| 83 |
0
|
if ( ref != null ) { |
| 84 |
0
|
SearchResult cachedSearchResult = ref.get(); |
| 85 |
0
|
if(cachedSearchResult!=null){ |
| 86 |
0
|
return cachedSearchResult; |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
0
|
SearchResult searchResult = search(searchRequest); |
| 93 |
|
|
| 94 |
0
|
if(cachingEnabled){ |
| 95 |
|
|
| 96 |
0
|
searchCache.put(cacheKey, new MaxAgeSoftReference<SearchResult>( searchCacheMaxAgeSeconds, searchResult) ); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
0
|
return searchResult; |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 102 |
0
|
private void doIdTranslation(SearchResult searchResult) {... |
| 103 |
0
|
for (SearchResultRow searchResultRow : searchResult.getRows()) { |
| 104 |
0
|
for (SearchResultCell searchResultCell : searchResultRow.getCells()) { |
| 105 |
0
|
String value = searchResultCell.getValue(); |
| 106 |
0
|
if (value != null && value.startsWith("kuali.atp")) { |
| 107 |
0
|
String newValue = idTranslatorFilter.getTranslationForAtp(value); |
| 108 |
0
|
if (newValue != null) { |
| 109 |
0
|
searchResultCell.setValue(newValue); |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
} |
| 115 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 116 |
0
|
@Override... |
| 117 |
|
public void afterPropertiesSet() throws Exception { |
| 118 |
0
|
if(cachingEnabled){ |
| 119 |
0
|
searchCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<SearchResult>>( searchCacheMaxSize ) ); |
| 120 |
|
} |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
0
|
public void setSearchDispatcher(SearchDispatcher searchDispatcher) {... |
| 124 |
0
|
this.searchDispatcher = searchDispatcher; |
| 125 |
|
} |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
0
|
public void setIdTranslatorFilter(IdTranslatorFilter idTranslatorFilter) {... |
| 128 |
0
|
this.idTranslatorFilter = idTranslatorFilter; |
| 129 |
|
} |
| 130 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 131 |
0
|
public void setCachingEnabled(boolean cachingEnabled) {... |
| 132 |
0
|
this.cachingEnabled = cachingEnabled; |
| 133 |
|
} |
| 134 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 135 |
0
|
public void setSearchCacheMaxSize(int searchCacheMaxSize) {... |
| 136 |
0
|
this.searchCacheMaxSize = searchCacheMaxSize; |
| 137 |
|
} |
| 138 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
0
|
public void setSearchCacheMaxAgeSeconds(int searchCacheMaxAgeSeconds) {... |
| 140 |
0
|
this.searchCacheMaxAgeSeconds = searchCacheMaxAgeSeconds; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 1 |
|
| 150 |
|
public class MaxAgeSoftReference<T> extends SoftReference<T> { |
| 151 |
|
|
| 152 |
|
private long expires; |
| 153 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 154 |
0
|
public MaxAgeSoftReference(long expires, T referent) {... |
| 155 |
0
|
super(referent); |
| 156 |
0
|
this.expires = System.currentTimeMillis() + expires * 1000; |
| 157 |
|
} |
| 158 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 159 |
0
|
public boolean isValid() {... |
| 160 |
0
|
return System.currentTimeMillis() < expires; |
| 161 |
|
} |
| 162 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 163 |
0
|
public T get() { ... |
| 164 |
0
|
return isValid() ? super.get() : null; |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
@author |
| 172 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 173 |
|
public class MaxSizeMap<K,V> extends LinkedHashMap<K,V> { |
| 174 |
|
private static final long serialVersionUID = -5354227348838839919L; |
| 175 |
|
|
| 176 |
|
private int maxSize; |
| 177 |
|
|
| 178 |
|
|
| 179 |
|
@param |
| 180 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 181 |
0
|
public MaxSizeMap( int maxSize ) {... |
| 182 |
0
|
this( maxSize, false ); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
@param |
| 186 |
|
@param |
| 187 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 188 |
0
|
public MaxSizeMap( int maxSize, boolean accessOrder ) {... |
| 189 |
0
|
super( maxSize / 2, 0.75f, accessOrder ); |
| 190 |
0
|
this.maxSize = maxSize; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
@see |
| 195 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 196 |
0
|
@Override... |
| 197 |
|
protected boolean removeEldestEntry(Entry<K,V> eldest) { |
| 198 |
0
|
return size() > maxSize; |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
} |
| 202 |
|
} |