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=========================================================
20 package org.onap.aai.schemaservice.query;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.stereotype.Service;
27 import javax.annotation.PostConstruct;
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
33 import java.util.stream.Stream;
36 public class QueryService {
38 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(QueryService.class);
40 private String queryLocation;
42 private String storedQueriesContent;
44 public QueryService(@Value("${schema.query.location}") String queryLocation){
45 this.queryLocation = queryLocation;
49 public void initialize() throws IOException {
51 String fileName = queryLocation + File.separator + "stored-queries.json";
52 LOGGER.debug("Loading the following stored queries file {}", fileName);
54 StringBuilder contentBuilder = new StringBuilder();
56 try(Stream<String> stream = Files.lines(Paths.get(fileName), StandardCharsets.UTF_8)){
57 stream.forEach(s -> contentBuilder.append(s));
60 storedQueriesContent = contentBuilder.toString();
62 LOGGER.trace("Contents of the stored query file {}", storedQueriesContent);
65 public String getStoredQueries(){
66 return storedQueriesContent;