From ad5181d9e3b82327a3a14564947fe34465f32008 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 27 Dec 2017 15:46:26 +0530 Subject: Fixed sonar issues - OrchestrationProcessFactory Fixed all sonar issues except exception handling Change-Id: Id1ecf35c157be3c1c9c3f5614bd97b5f8c856e5b Issue-ID: SDC-343 Signed-off-by: mojahidi --- .../process/OrchestrationProcessFactory.java | 46 ++++++++++++---------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java index 6200b287a1..64edf86dc7 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -1,15 +1,27 @@ +/* + * 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.sdc.vendorsoftwareproduct.impl.orchestration.process; import org.openecomp.config.api.Configuration; import org.openecomp.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.file.FileUtils; -import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants; - -import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -17,43 +29,37 @@ import java.util.concurrent.ConcurrentHashMap; import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; public class OrchestrationProcessFactory { - private static final String confFile = "config-orchestration.json"; - private static Map processImplMap; + private static final Map PROCESS_IMPL_MAP; + private OrchestrationProcessFactory() { + + } static { Configuration config = ConfigurationManager.lookup(); - processImplMap = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + PROCESS_IMPL_MAP = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, ConfigConstants.PROCESS_IMPL_KEY, ImplementationConfiguration.class)); } public static Optional getInstance(String fileSuffix) { + if (fileSuffix == null) { return Optional.empty(); } - - fileSuffix = fileSuffix.toLowerCase().trim(); - OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(fileSuffix); + String updatedFileSuffix = fileSuffix; + updatedFileSuffix = updatedFileSuffix.toLowerCase().trim(); + OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(updatedFileSuffix); if (onboardingTypesEnum == null) { return Optional.empty(); } try { - return Optional.of(createInstance(processImplMap.get(onboardingTypesEnum.toString()))); + return Optional.of(createInstance(PROCESS_IMPL_MAP.get(onboardingTypesEnum.toString()))); }catch (Exception e){ return Optional.empty(); } } - private static Map getOrchestrationImplMap(){ - try { - return FileUtils.readViaInputStream(confFile, - stream -> JsonUtil.json2Object(stream, Map.class)); - }catch (Exception e){ - return new HashMap<>(); - } - } - private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass) throws Exception { OrchestrationTemplateProcessHandler handler; -- cgit 1.2.3-korg