/*-
* ============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=========================================================
*/
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;
* @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";
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) {
// 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);
}