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