Update the license for 2017-2018 license
[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-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
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 package org.onap.aai.util;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.ListIterator;
28
29 import org.onap.aai.introspection.Version;
30 import org.onap.aai.util.swagger.GenerateSwagger;
31
32 import freemarker.template.TemplateException;
33
34 public class AutoGenerateHtml {
35         
36         public static final String DEFAULT_SCHEMA_DIR = "../aai-schema";
37         //if the program is run from aai-common, use this directory as default"
38         public static final String ALT_SCHEMA_DIR = "aai-schema";
39         //used to check to see if program is run from aai-core
40         public static final String DEFAULT_RUN_DIR = "aai-core";
41
42         public static void main(String[] args) throws IOException, TemplateException {
43                 String savedProperty = System.getProperty("aai.generate.version");
44                 List<Version> versionsToGen = Arrays.asList(Version.values());
45                 Collections.sort(versionsToGen);
46                 Collections.reverse(versionsToGen);
47                 ListIterator<Version> versionIterator = versionsToGen.listIterator();
48                 String schemaDir;
49                 if(System.getProperty("user.dir") != null && !System.getProperty("user.dir").contains(DEFAULT_RUN_DIR)) {
50                         schemaDir = ALT_SCHEMA_DIR;
51                 }
52                 else {
53                         schemaDir = DEFAULT_SCHEMA_DIR;
54                 }
55                 while (versionIterator.hasNext()) {
56                         System.setProperty("aai.generate.version", versionIterator.next().toString());   
57                 String yamlFile = schemaDir + "/src/main/resources/aai_swagger_yaml/aai_swagger_" + System.getProperty("aai.generate.version")+ ".yaml";
58                 File swaggerYamlFile = new File(yamlFile);
59                 if(swaggerYamlFile.exists()) {
60                         GenerateSwagger.main(args);
61                 }
62                 }
63                 String versionToGenerate = System.setProperty("aai.generate.version", savedProperty);   
64         }
65 }