2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.aai.util;
25 import java.io.IOException;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.ListIterator;
30 import org.onap.aai.setup.SchemaVersion;
31 import org.onap.aai.setup.SchemaVersions;
32 import org.onap.aai.util.swagger.GenerateSwagger;
34 import freemarker.template.TemplateException;
35 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
37 public class AutoGenerateHtml {
39 private static final String AAI_GENERATE_VERSION = "aai.generate.version";
40 public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
41 //if the program is run from aai-common, use this directory as default"
42 public static final String ALT_SCHEMA_DIR = "aai-schema";
43 //used to check to see if program is run from aai-core
44 public static final String DEFAULT_RUN_DIR = "aai-core";
46 public static void main(String[] args) throws IOException, TemplateException {
47 String savedProperty = System.getProperty(AAI_GENERATE_VERSION);
49 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
50 "org.onap.aai.config",
55 SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
57 List<SchemaVersion> versionsToGen = schemaVersions.getVersions();
58 Collections.sort(versionsToGen);
59 Collections.reverse(versionsToGen);
60 ListIterator<SchemaVersion> versionIterator = versionsToGen.listIterator();
62 if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
63 schemaDir = ALT_SCHEMA_DIR;
66 schemaDir = DEFAULT_SCHEMA_DIR;
68 String release = System.getProperty("aai.release", "onap");
69 while (versionIterator.hasNext()) {
70 System.setProperty(AAI_GENERATE_VERSION, versionIterator.next().toString());
71 String yamlFile = schemaDir + "/src/main/resources/" + release + "/aai_swagger_yaml/aai_swagger_" + System.getProperty(AAI_GENERATE_VERSION)+ ".yaml";
72 File swaggerYamlFile = new File(yamlFile);
73 if(swaggerYamlFile.exists()) {
74 GenerateSwagger.schemaVersions = schemaVersions;
75 GenerateSwagger.main(args);
78 System.setProperty(AAI_GENERATE_VERSION, savedProperty);