2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. 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.aai.schemaservice.query;
24 import java.io.IOException;
25 import java.nio.charset.StandardCharsets;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.stream.Stream;
30 import javax.annotation.PostConstruct;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.stereotype.Service;
38 public class QueryService {
40 private static final Logger LOGGER = LoggerFactory.getLogger(QueryService.class);
42 private String queryLocation;
44 private String storedQueriesContent;
46 public QueryService(@Value("${schema.query.location}") String queryLocation) {
47 this.queryLocation = queryLocation;
51 public void initialize() throws IOException {
53 String fileName = queryLocation + File.separator + "stored-queries.json";
54 LOGGER.debug("Loading the following stored queries file {}", fileName);
56 StringBuilder contentBuilder = new StringBuilder();
58 try (Stream<String> stream = Files.lines(Paths.get(fileName), StandardCharsets.UTF_8)) {
59 stream.forEach(s -> contentBuilder.append(s));
62 storedQueriesContent = contentBuilder.toString();
64 LOGGER.trace("Contents of the stored query file {}", storedQueriesContent);
67 public String getStoredQueries() {
68 return storedQueriesContent;