Update to Apex jmx files
[policy/apex-pdp.git] / plugins / plugins-context / plugins-context-schema / plugins-context-schema-avro / src / main / java / org / onap / policy / apex / plugins / context / schema / avro / AvroObjectMapperFactory.java
index a48ca80..4a4d92d 100644 (file)
@@ -1,19 +1,20 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
@@ -23,7 +24,6 @@ package org.onap.policy.apex.plugins.context.schema.avro;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-
 import org.apache.avro.Schema;
 import org.onap.policy.apex.context.ContextRuntimeException;
 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -70,14 +70,14 @@ public class AvroObjectMapperFactory {
      * @return the avro object mapper
      */
     public AvroObjectMapper get(final AxKey userKey, final Schema incomingSchema) {
-        Schema schema = incomingSchema;
-        boolean isnullable = false;
+        var schema = incomingSchema;
+        var isnullable = false;
         if (Schema.Type.UNION.equals(schema.getType())) {
 
             final List<Schema> types = schema.getTypes();
-            // TODO: properly support UNIONS
+
             // currently only support unions with 2 types, one of which is NULL
-            final Schema nullschema = Schema.create(Schema.Type.NULL);
+            final var nullschema = Schema.create(Schema.Type.NULL);
             if (types.size() != 2 || !types.contains(nullschema)) {
                 final String resultSting = userKey.getId()
                         + ": Apex currently only supports UNION schemas with 2 options, one must be NULL";
@@ -91,14 +91,15 @@ public class AvroObjectMapperFactory {
                 schema = types.get(1);
             }
             if (Schema.Type.NULL.equals(schema.getType())) {
-                final String resultSting = userKey.getId()
-                        + ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION";
+                final String resultSting =
+                        userKey.getId() + ": Apex currently only supports UNION schema2 with 2 options, "
+                                + "only one can be NULL, and the other cannot be another UNION";
                 LOGGER.warn(resultSting);
                 throw new ContextRuntimeException(resultSting);
             }
         }
 
-        final Schema.Type avroType = schema.getType();
+        final var avroType = schema.getType();
 
         // Check that there is a definition for the mapper for this type
         if (!AVRO_OBJECT_MAPPER_MAP.containsKey(avroType) || AVRO_OBJECT_MAPPER_MAP.get(avroType) == null) {
@@ -111,7 +112,7 @@ public class AvroObjectMapperFactory {
         // Create a mapper
         AvroObjectMapper avroObjectMapper;
         try {
-            avroObjectMapper = AVRO_OBJECT_MAPPER_MAP.get(avroType).newInstance();
+            avroObjectMapper = AVRO_OBJECT_MAPPER_MAP.get(avroType).getDeclaredConstructor().newInstance();
             if (isnullable) {
                 avroObjectMapper = new AvroNullableMapper(avroObjectMapper);
             }