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.setup;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.restclient.RestClient;
25 import org.onap.aai.restclient.RestClientFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.core.io.Resource;
29 import org.springframework.http.HttpHeaders;
30 import org.springframework.http.MediaType;
31 import org.springframework.http.ResponseEntity;
33 import javax.ws.rs.HttpMethod;
38 * <b>AAIConfigTranslator</b> is responsible for looking at the schema files and
39 * edge files based on the available versions Also has the ability to exclude
40 * them based on the node.exclusion.pattern
42 public class SchemaServiceTranslator extends Translator {
44 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SchemaServiceTranslator.class);
46 private static final String SchemaServiceClientType = "schema.service";
48 @Value("${schema.service.nodes.endpoint}")
49 private String nodeSchemaUri;
51 @Value("${schema.service.edges.endpoint}")
52 private String edgeSchemaUri;
55 private RestClientFactory restClientFactory;
57 public SchemaServiceTranslator(SchemaVersions schemaVersions) {
58 super(schemaVersions);
64 * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
68 public List<InputStream> getVersionNodeStream(SchemaVersion version) throws IOException {
70 List<InputStream> inputStreams = new ArrayList<>();
72 String uri = nodeSchemaUri + version.toString();
73 Map<String, String> headersMap = new HashMap<>();
75 headersMap.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML.toString());
76 headersMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML.toString());
77 RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType);
78 ResponseEntity<Resource> schemaResponse = restClient.getGetResource(content, uri,
80 LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode());
81 inputStreams.add(schemaResponse.getBody().getInputStream());
86 public List<String> getJsonPayload(SchemaVersion version) throws IOException {
88 * Call Schema MS to get versions using RestTemplate
90 List<String> inputStreams = new ArrayList<>();
92 String uri = edgeSchemaUri + version.toString();
93 Map<String, String> headersMap = new HashMap<>();
95 RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType);
97 ResponseEntity<String> schemaResponse = restClient.getGetRequest(content, uri,
99 LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode());
100 inputStreams.add(schemaResponse.getBody());