Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-service / src / main / java / org / onap / aai / schemaservice / SchemaServiceApp.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
21 package org.onap.aai.schemaservice;
22
23 import java.util.Map;
24 import java.util.UUID;
25
26 import javax.annotation.PostConstruct;
27 import javax.annotation.PreDestroy;
28
29 import org.onap.aai.aailog.logs.AaiDebugLog;
30 import org.onap.aai.exceptions.AAIException;
31 import org.onap.aai.schemaservice.config.PropertyPasswordConfiguration;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.slf4j.MDC;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.SpringApplication;
37 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
38 import org.springframework.boot.autoconfigure.SpringBootApplication;
39 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
40 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
41 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
42 import org.springframework.context.annotation.ComponentScan;
43 import org.springframework.core.env.Environment;
44 import org.springframework.web.context.request.RequestContextListener;
45
46 @SpringBootApplication
47 // Component Scan provides a way to look for spring beans
48 // It only searches beans in the following packages
49 // Any method annotated with @Bean annotation or any class
50 // with @Component, @Configuration, @Service will be picked up
51 @EnableAutoConfiguration(
52     exclude = {DataSourceAutoConfiguration.class,
53         DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
54 @ComponentScan(basePackages = {"org.onap.aai.schemaservice", "org.onap.aai.aaf"})
55 public class SchemaServiceApp {
56
57     private static final Logger logger = LoggerFactory.getLogger(SchemaServiceApp.class.getName());
58
59     private static final String APP_NAME = "aai-schema-service";
60     private static AaiDebugLog debugLog = new AaiDebugLog();
61     static {
62         debugLog.setupMDC();
63     }
64
65     @Autowired
66     private Environment env;
67
68     public static void main(String[] args) throws AAIException {
69
70         setDefaultProps();
71
72         SpringApplication app = new SpringApplication(SchemaServiceApp.class);
73         app.setLogStartupInfo(false);
74         app.setRegisterShutdownHook(true);
75         app.addInitializers(new PropertyPasswordConfiguration());
76
77         Environment env = app.run(args).getEnvironment();
78
79         logger.debug("Application '{}' is running on {}!",
80             env.getProperty("spring.application.name"), env.getProperty("server.port"));
81
82         logger.debug("SchemaService MicroService Started");
83
84         System.out.println("SchemaService Microservice Started");
85
86     }
87
88     public static void setDefaultProps() {
89
90         if (System.getProperty("file.separator") == null) {
91             System.setProperty("file.separator", "/");
92         }
93
94         String currentDirectory = System.getProperty("user.dir");
95
96         if (System.getProperty("AJSC_HOME") == null) {
97             System.setProperty("AJSC_HOME", ".");
98         }
99
100         if (currentDirectory.contains(APP_NAME)) {
101             if (System.getProperty("BUNDLECONFIG_DIR") == null) {
102                 System.setProperty("BUNDLECONFIG_DIR", "src/main/resources");
103             }
104         } else {
105             if (System.getProperty("BUNDLECONFIG_DIR") == null) {
106                 System.setProperty("BUNDLECONFIG_DIR", "aai-schema-service/src/main/resources");
107             }
108         }
109     }
110
111     @PostConstruct
112     private void init() throws AAIException {
113         System.setProperty("org.onap.aai.serverStarted", "false");
114         setDefaultProps();
115
116         logger.debug("SchemaService initialization started...");
117
118         // Setting this property to allow for encoded slash (/) in the path parameter
119         // This is only needed for tomcat keeping this as temporary
120         System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
121
122         if (env.acceptsProfiles(Profiles.TWO_WAY_SSL)
123             && env.acceptsProfiles(Profiles.ONE_WAY_SSL)) {
124             logger.warn("You have seriously misconfigured your application");
125         }
126
127     }
128
129     @PreDestroy
130     public void cleanup() {
131
132         logger.debug("SchemaService shutting down");
133     }
134 }