Browse code

BM-14182 Feat: when opening a content table on a search folder, redirect to the right folder (the first one...)

Thomas Cataldo authored on 06/02/2019 16:59:09
Showing 2 changed files
... ...
@@ -22,7 +22,6 @@ import java.util.LinkedList;
22 22
 import java.util.List;
23 23
 
24 24
 import org.vertx.java.core.MultiMap;
25
-import org.vertx.java.core.http.CaseInsensitiveMultiMap;
26 25
 import org.vertx.java.core.http.HttpHeaders;
27 26
 
28 27
 import net.bluemind.core.api.BMVersion;
... ...
@@ -78,7 +77,7 @@ public class BasicClientProxy<S, T> {
78 77
 	}
79 78
 
80 79
 	private MultiMap defaultHeaders(String sessionId) {
81
-		MultiMap headers = new CaseInsensitiveMultiMap();
80
+		MultiMap headers = RestHeaders.newMultimap();
82 81
 		if (sessionId != null) {
83 82
 			headers.add(HEADER_API_KEY, sessionId);
84 83
 		}
... ...
@@ -22,12 +22,12 @@ import java.lang.annotation.Annotation;
22 22
 import java.lang.reflect.InvocationHandler;
23 23
 import java.lang.reflect.Method;
24 24
 import java.lang.reflect.Proxy;
25
-import java.lang.reflect.Type;
26 25
 import java.util.ArrayList;
27 26
 import java.util.HashMap;
28 27
 import java.util.List;
29 28
 import java.util.Map;
30 29
 import java.util.concurrent.CompletableFuture;
30
+import java.util.concurrent.ConcurrentHashMap;
31 31
 import java.util.concurrent.ExecutionException;
32 32
 import java.util.regex.Matcher;
33 33
 import java.util.regex.Pattern;
... ...
@@ -41,8 +41,6 @@ import org.vertx.java.core.MultiMap;
41 41
 import org.vertx.java.core.http.CaseInsensitiveMultiMap;
42 42
 import org.vertx.java.core.http.HttpHeaders;
43 43
 
44
-import com.google.common.cache.Cache;
45
-import com.google.common.cache.CacheBuilder;
46 44
 import com.google.common.escape.Escaper;
47 45
 import com.google.common.net.PercentEscaper;
48 46
 
... ...
@@ -112,7 +110,6 @@ public class ClientProxyGenerator<S, T> {
112 110
 					PatternBinding binding = new PatternBinding(pathComponents);
113 111
 
114 112
 					MethodCallBuilder callBuilder = new MethodCallBuilder(method.httpMethodName, params, binding,
115
-							method.interfaceMethod.getGenericReturnType(), method.interfaceMethod.getReturnType(),
116 113
 							method.produces, DefaultResponseCodecs.codec(method.interfaceMethod.getGenericReturnType(),
117 114
 									method.produces[0]));
118 115
 
... ...
@@ -376,19 +373,15 @@ public class ClientProxyGenerator<S, T> {
376 373
 
377 374
 		private PatternBinding binding;
378 375
 		private List<Parameter> params;
379
-		private Type returnType;
380
-		private final Class<?> returnClass;
381 376
 		private String methodName;
382 377
 		private String mimeType;
383 378
 		private ResponseCodec<?> responseCodec;
384 379
 
385
-		public MethodCallBuilder(String httpMethodName, List<Parameter> params, PatternBinding binding, Type returnType,
386
-				Class<?> returnClass, String[] produces, ResponseCodec<?> responseCodec) {
380
+		public MethodCallBuilder(String httpMethodName, List<Parameter> params, PatternBinding binding,
381
+				String[] produces, ResponseCodec<?> responseCodec) {
387 382
 			this.methodName = httpMethodName;
388 383
 			this.params = params;
389
-			this.returnType = returnType;
390 384
 			this.binding = binding;
391
-			this.returnClass = returnClass;
392 385
 			this.mimeType = produces[0];
393 386
 			this.responseCodec = responseCodec;
394 387
 		}
... ...
@@ -423,12 +416,14 @@ public class ClientProxyGenerator<S, T> {
423 416
 		Map<String, String> pathParams = new HashMap<>();
424 417
 	}
425 418
 
426
-	private final static Cache<Class<?>, ClientProxyGenerator<?, ?>> cached = CacheBuilder.newBuilder().maximumSize(512)
427
-			.build();
419
+	private final static Map<Class<?>, ClientProxyGenerator<?, ?>> cached = new ConcurrentHashMap<>();
428 420
 
429 421
 	@SuppressWarnings("unchecked")
430 422
 	public static <S, T> ClientProxyGenerator<S, T> generator(Class<S> api, Class<T> asyncApi) {
431
-
423
+		ClientProxyGenerator<S, T> cachedGen = (ClientProxyGenerator<S, T>) cached.get(api);
424
+		if (cachedGen != null) {
425
+			return cachedGen;
426
+		}
432 427
 		if (asyncApi == null) {
433 428
 			try {
434 429
 				asyncApi = (Class<T>) Class.forName(api.getCanonicalName() + "Async", false, api.getClassLoader());
... ...
@@ -438,13 +433,8 @@ public class ClientProxyGenerator<S, T> {
438 433
 			}
439 434
 		}
440 435
 
441
-		Class<T> fAsyncApi = asyncApi;
442
-		try {
443
-			return (ClientProxyGenerator<S, T>) cached.get(api, () -> {
444
-				return new ClientProxyGenerator<>(api, fAsyncApi);
445
-			});
446
-		} catch (ExecutionException e) {
447
-			return new ClientProxyGenerator<>(api, asyncApi);
448
-		}
436
+		cachedGen = new ClientProxyGenerator<>(api, asyncApi);
437
+		cached.put(api, cachedGen);
438
+		return cachedGen;
449 439
 	}
450 440
 }