From da5dfcd1a354807d13849c7f4ead535ccfa722fa Mon Sep 17 00:00:00 2001 From: avigaffa Date: Sun, 31 Dec 2017 15:07:39 +0200 Subject: Fixing sonar Exception Handling Change-Id: I04eb047973a3f5c07dd9dc410cb13af974e8ded1 Issue-ID: SDC-810 Signed-off-by: avigaffa Signed-off-by: vempo --- .../openecomp/core/impl/ToscaConverterUtil.java | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java') diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java index d34d46796d..802827e343 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterUtil.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2017 European Support Limited + * + * 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. + */ + package org.openecomp.core.impl; import org.apache.commons.collections4.CollectionUtils; @@ -17,18 +33,23 @@ import java.util.stream.Collectors; import java.util.stream.Stream; public class ToscaConverterUtil { + private static final String SET = "set"; private static final String DEFAULT = "default"; private static final String DEFAULT_CAPITAL = "Default"; - private static Set defaultValueKeys; + private static final Set DEFAULT_VALUE_KEYS; - private static Logger LOGGER = LoggerFactory.getLogger(ToscaConverterUtil.class.getName()); + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaConverterUtil.class); static { - defaultValueKeys = + DEFAULT_VALUE_KEYS = Stream.of(DEFAULT, DEFAULT_CAPITAL).collect(Collectors.toSet()); } + private ToscaConverterUtil() { + // static utility methods only, prevent instantiation + } + public static Optional createObjectFromClass(String objectId, Object objectCandidate, Class classToCreate) { @@ -42,7 +63,8 @@ public class ToscaConverterUtil { } private static Optional createObjectUsingSetters(Object objectCandidate, - Class classToCreate) throws Exception { + Class classToCreate) + throws ReflectiveOperationException { if (Objects.isNull(objectCandidate) || !(objectCandidate instanceof Map)) { return Optional.empty(); @@ -91,7 +113,7 @@ public class ToscaConverterUtil { private static Object getDefaultParameterValue(Map entryValue) { Object defaultValue = null; Set keys = new HashSet<>(entryValue.keySet()); - keys.retainAll(defaultValueKeys); + keys.retainAll(DEFAULT_VALUE_KEYS); if (CollectionUtils.isNotEmpty(keys)) { defaultValue = entryValue.get(keys.iterator().next()); -- cgit 1.2.3-korg