diff options
author | 2018-05-23 11:21:11 +0300 | |
---|---|---|
committer | 2018-05-23 11:30:13 +0300 | |
commit | 3e4c18770957b55e2f80da32c3a32caa908f1386 (patch) | |
tree | 8a94c656300e75e38febfe9826ad36fc54fe14f5 /dcaedt_catalog/commons/src/main | |
parent | da9db1b89e8c9199da4791a2ccd26d1628120a08 (diff) |
Upgrade dt-be-main
Update sources for dcae-dt-be-main to latest version
Change-Id: I3d58a2dc32611c0ca90f1c97e1294a17d5748623
Issue-ID: SDC-1359
Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'dcaedt_catalog/commons/src/main')
5 files changed, 42 insertions, 88 deletions
diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Futures.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Futures.java index ffaf42b..a405932 100644 --- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Futures.java +++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Futures.java @@ -8,9 +8,6 @@ import java.util.concurrent.CountDownLatch; import java.util.function.Function; import org.onap.sdc.common.onaplog.OnapLoggerDebug; -import org.onap.sdc.common.onaplog.OnapLoggerError; -import org.onap.sdc.dcae.catalog.commons.Future; -import org.onap.sdc.dcae.catalog.commons.FutureHandler; import org.onap.sdc.common.onaplog.Enums.LogLevel; @@ -196,16 +193,13 @@ public class Futures<T> { return this; } } - - /** */ + public static class Accumulator<T> extends BasicFuture<List<T>> implements Future<List<T>> { - protected List<Future<T>> futures = new LinkedList<Future<T>>(); - //protected List<T> results = new LinkedList<T>(); - protected BasicHandler<T> handler = null; + protected List<Future<T>> futures = new LinkedList<Future<T>>(); + protected BasicHandler<T> accumulatorHandler = null; - private static OnapLoggerError errLogger = OnapLoggerError.getInstance(); private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); public Accumulator() { @@ -228,7 +222,7 @@ public class Futures<T> { public Future<List<T>> accumulate() { this.futures = Collections.unmodifiableList(this.futures); - this.handler = new BasicHandler<T>(new CountDownLatch(this.futures.size())) { + this.accumulatorHandler = new BasicHandler<T>(new CountDownLatch(this.futures.size())) { protected void process(Future<T> theResult) { if (theResult.failed()) { Accumulator.this.cause = theResult.cause(); @@ -246,7 +240,7 @@ public class Futures<T> { } }; futures.stream() - .forEach(f -> f.setHandler(this.handler)); + .forEach(f -> f.setHandler(this.accumulatorHandler)); return this; } diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxies.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxies.java index 8983599..0b13def 100644 --- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxies.java +++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxies.java @@ -19,10 +19,6 @@ public class Proxies { public static <T> T build(Map theData, Class<T> theType) { return builder.build(new JSONObject(theData), theType); } - - public static <T> T build(Map theData, Map theContextData, Class<T> theType) { - return builder.build(new JSONObject(theData), theContextData, theType); - } public static <T> T build(JSONObject theData, Class<T> theType) { return builder.build(theData, theType); diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java index d368886..bdce9c3 100644 --- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java +++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java @@ -1,30 +1,14 @@ package org.onap.sdc.dcae.catalog.commons; import java.util.List; -import java.util.LinkedList; -import java.util.Map; -import java.util.Collections; - -import java.util.stream.Collectors; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; - -import java.lang.reflect.Type; import java.lang.reflect.Method; -import java.lang.reflect.Array; import java.lang.reflect.Constructor; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; - import java.lang.invoke.MethodHandles; -import com.google.common.reflect.Invokable; -import org.onap.sdc.dcae.catalog.commons.Proxy; -import org.onap.sdc.dcae.catalog.commons.ProxyBuilder; import com.google.common.reflect.AbstractInvocationHandler; import org.apache.commons.beanutils.ConvertUtils; @@ -37,13 +21,13 @@ public class Proxy extends AbstractInvocationHandler { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - public static @interface DataMap { + public @interface DataMap { - public String map() default ""; + String map() default ""; - public boolean proxy() default false; + boolean proxy() default false; - public Class elementType() default Void.class; + Class elementType() default Void.class; } @@ -51,12 +35,10 @@ public class Proxy extends AbstractInvocationHandler { static { try { - lookupHandleConstructor = - MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, - int.class); + lookupHandleConstructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class); if (!lookupHandleConstructor.isAccessible()) { - lookupHandleConstructor.setAccessible(true); + lookupHandleConstructor.setAccessible(true); } } catch (Exception x) { @@ -64,7 +46,6 @@ public class Proxy extends AbstractInvocationHandler { } } - private JSONObject data; private ProxyBuilder builder; @@ -81,11 +62,9 @@ public class Proxy extends AbstractInvocationHandler { return this.builder; } - protected Object handleInvocation( - Object theProxy,Method theMethod,Object[] theArgs) - throws Throwable { + protected Object handleInvocation(Object theProxy,Method theMethod,Object[] theArgs) throws Throwable { if (theMethod.isDefault()) { - final Class<?> declaringClass = theMethod.getDeclaringClass(); + final Class<?> declaringClass = theMethod.getDeclaringClass(); return lookupHandleConstructor .newInstance(declaringClass, MethodHandles.Lookup.PRIVATE) @@ -96,28 +75,35 @@ public class Proxy extends AbstractInvocationHandler { String key = theMethod.getName(); - Proxy.DataMap dataMap = (Proxy.DataMap)theMethod.getAnnotation(Proxy.DataMap.class); + Proxy.DataMap dataMap = theMethod.getAnnotation(Proxy.DataMap.class); if (dataMap != null) { String dataKey = dataMap.map(); - if (dataKey != null && !"".equals(dataKey)) + if (!"".equals(dataKey)) { key = dataKey; + } } //this is ugly, can this be done through an extension mechanism such as plugging in functions? - if ( builder.hasExtension(key) ) + if ( builder.hasExtension(key) ) { return this.builder.extension(key).apply(this, theArgs); + } //we give priority to the context (because of the 'catalog' property issue in catalog service) but //how natural is this? Object val = this.builder.context(key); - if (val == null) + if (val == null) { val = this.data.opt(key); + } - if (val == null) + if (val == null) { return null; + } + return getProxies(theMethod, dataMap, val); + } -//as we create proxies here we should store them back in the 'data' so that we do not do it again -//can we always 'recognize' them? + private Object getProxies(Method theMethod, DataMap dataMap, Object val) throws InstantiationException, IllegalAccessException { + //as we create proxies here we should store them back in the 'data' so that we do not do it again + //can we always 'recognize' them? if (val instanceof String && String.class != theMethod.getReturnType()) { //??This will yield a POJO .. @@ -128,7 +114,7 @@ public class Proxy extends AbstractInvocationHandler { return builder.build((JSONObject)val, theMethod.getReturnType()); } } - else if (val instanceof JSONArray&& dataMap != null && + else if (val instanceof JSONArray && dataMap != null && dataMap.proxy() && List.class.isAssignableFrom(theMethod.getReturnType())) { diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ProxyBuilder.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ProxyBuilder.java index e3a422a..8b6e6d1 100644 --- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ProxyBuilder.java +++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ProxyBuilder.java @@ -21,40 +21,18 @@ public class ProxyBuilder { public ProxyBuilder() { } -/* - public <T> T build(Map theData, Class<T> theType) { - return build(theData, this.context, theType); - } - - public <T> T build(Map theData, Map theContextData, Class<T> theType) { - return (T)java.lang.reflect.Proxy.newProxyInstance( - ProxyBuilder.class.getClassLoader(), - new Class[] { theType }, - new Proxy(theData, this)); - } -*/ + public <T> T build(Map theData, Class<T> theType) { return build(new JSONObject(theData), theType); } - - public <T> T build(Map theData, Map theContextData, Class<T> theType) { - return build(new JSONObject(theData), theContextData, theType); - } public <T> T build(JSONObject theData, Class<T> theType) { - return build(theData, this.context, theType); - } - - public <T> T build(JSONObject theData, Map theContextData, Class<T> theType) { return (T)java.lang.reflect.Proxy.newProxyInstance( - ProxyBuilder.class.getClassLoader(), - new Class[] { theType }, - new Proxy(theData, this)); + ProxyBuilder.class.getClassLoader(), + new Class[] { theType }, + new Proxy(theData, this)); } - - - public ProxyBuilder withConverter(final Function<Object, ?> theConverter, Class theType) { ConvertUtils.register(new Converter() { public Object convert(Class theToType, Object theValue) { diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java index 3493cb1..f6ea6ad 100644 --- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java +++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java @@ -138,26 +138,26 @@ public class Recycler { } } String type = (String)theSpec.get("type"); - if (value != null && type != null) { + if (value != null && type != null && !"string".equals(type)) { value = getValueByType(value, type); } return value; } private Object getValueByType(Object value, String type) { - Object returnValue = null; + try { if ("map".equals(type) && !(value instanceof Map)) { - returnValue = new ObjectMapper().readValue(value.toString(), new TypeReference<Map>(){}); + return new ObjectMapper().readValue(value.toString(), new TypeReference<Map>(){}); } - else if ("list".equals(type) && !(value instanceof List)) { - returnValue = new ObjectMapper().readValue(value.toString(), new TypeReference<List>(){}); + if ("list".equals(type) && !(value instanceof List)) { + return new ObjectMapper().readValue(value.toString(), new TypeReference<List>(){}); } - else if ("integer".equals(type) && (value instanceof String)) { - returnValue = Integer.valueOf((String)value); + if ("integer".equals(type) && (value instanceof String)) { + return Integer.valueOf((String)value); } - else if ("float".equals(type) && (value instanceof String)) { - returnValue = Double.valueOf((String)value); //double because that's how the yaml parser would encode it + if ("float".equals(type) && (value instanceof String)) { + return Double.valueOf((String)value); //double because that's how the yaml parser would encode it } } catch (NumberFormatException nfx) { @@ -166,7 +166,7 @@ public class Recycler { catch (IOException iox) { debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Failed to process {} representation of a collection: {}", value.getClass().getName(), iox); } - return returnValue; + return value; } /* */ |