2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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=========================================================
20 package org.onap.universalvesadapter.service;
23 import java.net.URISyntaxException;
25 import org.onap.universalvesadapter.configs.DiskRepoConfiguration;
26 import org.onap.universalvesadapter.exception.ConfigFileReadException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.stereotype.Component;
32 import org.springframework.web.client.RestTemplate;
35 * Implementation of {@code ConfigFileService} using disk repository
41 public class DiskRepoConfigFileService implements ConfigFileService {
43 private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
46 private DiskRepoConfiguration diskRepoConfiguration;
48 private RestTemplate restTemplate = new RestTemplate();
50 private URI uri = null;
53 * @see org.onap.universalvesadapter.service.ConfigFileService#readConfigFile(java.lang.String)
56 public String readConfigFile(String fileName) throws ConfigFileReadException {
57 LOGGER.debug("Reading config file for " + fileName);
60 uri = new URI(diskRepoConfiguration.getFileRepositoryUrl()+fileName);
61 LOGGER.debug("Read URI for " + fileName);
62 } catch (URISyntaxException exception) {
63 throw new ConfigFileReadException("Unable to read config file for file "
64 + fileName + "\n Reason : " + exception.getMessage());
67 LOGGER.debug("Calling file repo service for URI" + uri);
68 ResponseEntity<String> fileDataEntity = restTemplate.getForEntity(uri, String.class);
69 LOGGER.debug("Call completed successfully");
70 return fileDataEntity.getBody();