Sync the latest code changes
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / AutoGenerateHtml.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.util;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.ListIterator;
30
31 import org.onap.aai.introspection.Version;
32 import org.onap.aai.util.swagger.GenerateSwagger;
33
34 import freemarker.template.TemplateException;
35
36 public class AutoGenerateHtml {
37         
38         public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
39         //if the program is run from aai-common, use this directory as default"
40         public static final String ALT_SCHEMA_DIR = "aai-schema";
41         //used to check to see if program is run from aai-core
42         public static final String DEFAULT_RUN_DIR = "aai-core";
43
44         public static void main(String[] args) throws IOException, TemplateException {
45                 String savedProperty = System.getProperty("aai.generate.version");
46                 List<Version> versionsToGen = Arrays.asList(Version.values());
47                 Collections.sort(versionsToGen);
48                 Collections.reverse(versionsToGen);
49                 ListIterator<Version> versionIterator = versionsToGen.listIterator();
50                 String schemaDir;
51                 if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
52                         schemaDir = ALT_SCHEMA_DIR;
53                 }
54                 else {
55                         schemaDir = DEFAULT_SCHEMA_DIR;
56                 }
57                 while (versionIterator.hasNext()) {
58                         System.setProperty("aai.generate.version", versionIterator.next().toString());   
59                 String yamlFile = schemaDir + "/src/main/resources/aai_swagger_yaml/aai_swagger_" + System.getProperty("aai.generate.version")+ ".yaml";
60                 File swaggerYamlFile = new File(yamlFile);
61                 if(swaggerYamlFile.exists()) {
62                         GenerateSwagger.main(args);
63                 }
64                 }
65                 String versionToGenerate = System.setProperty("aai.generate.version", savedProperty);   
66         }
67 }