2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aaf.certservice.certification.configuration;
23 import com.fasterxml.jackson.databind.ObjectMapper;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.List;
30 import org.onap.aaf.certservice.certification.CertificationModelFactory;
31 import org.onap.aaf.certservice.certification.configuration.model.CmpServers;
32 import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 class CmpServersConfigLoader {
37 private static final Logger LOGGER = LoggerFactory.getLogger(CertificationModelFactory.class);
39 List<Cmpv2Server> load(String path) {
40 List<Cmpv2Server> result = new ArrayList<>();
42 result = loadConfigFromFile(path).getCmpv2Servers();
43 } catch (FileNotFoundException e) {
44 LOGGER.error("CMP Servers configuration file not found: ", e);
45 } catch (IOException e) {
46 LOGGER.error("Exception occurred during CMP Servers configuration loading: ", e);
51 private CmpServers loadConfigFromFile(String path) throws IOException {
52 ObjectMapper objectMapper = new ObjectMapper();
53 URL resource = getClass().getClassLoader().getResource(path);
54 if (resource == null) {
55 throw new FileNotFoundException();
57 String configFilePath = resource.getFile();
58 return objectMapper.readValue(new File(configFilePath), CmpServers.class);