2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-18 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.google.gson.FieldNamingPolicy;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
25 import org.onap.aai.restclient.RestClient;
26 import org.onap.aai.restclient.RestClientFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Value;
29 import org.springframework.http.ResponseEntity;
31 import javax.annotation.PostConstruct;
32 import java.util.HashMap;
33 import java.util.List;
36 public class SchemaVersionsBean {
38 private String SCHEMA_SERVICE = "schema-service";
39 private SchemaServiceVersions schemaVersions;
41 @Value("${schema.service.versions.endpoint}")
42 private String versionsUri;
45 private RestClientFactory restClientFactory;
48 public void initialize() {
49 //Call SchemaService to get versions
50 retrieveAllSchemaVersions();
53 public void retrieveAllSchemaVersions() {
55 Call Schema MS to get versions using RestTemplate
58 Map<String, String> headersMap = new HashMap<>();
59 RestClient restClient = restClientFactory
60 .getRestClient(SCHEMA_SERVICE);
62 ResponseEntity<String> schemaResponse = restClient.getGetRequest( content, versionsUri, headersMap);
63 Gson gson = new GsonBuilder()
64 .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES)
66 schemaVersions = gson.fromJson(schemaResponse.getBody(), SchemaServiceVersions.class);
67 schemaVersions.initializeFromSchemaService();
71 public SchemaServiceVersions getSchemaVersions() {
72 return schemaVersions;
75 public void setSchemaVersions(SchemaServiceVersions schemaVersions) {
76 this.schemaVersions = schemaVersions;
79 public List<SchemaVersion> getVersions() {
80 return getSchemaVersions().getVersions();