Some bug fixes and Minor Chages.
[music.git] / src / main / java / org / onap / music / JerseyConfig.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2019 AT&T Intellectual Property
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music;
24
25 import io.swagger.jaxrs.config.BeanConfig;
26 import io.swagger.jaxrs.listing.ApiListingResource;
27 import io.swagger.jaxrs.listing.SwaggerSerializers;
28
29 import javax.annotation.PostConstruct;
30
31 import org.glassfish.jersey.server.ResourceConfig;
32 import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
33 import org.onap.music.exceptions.MusicExceptionMapper;
34 import org.onap.music.rest.RestMusicDataAPI;
35 import org.onap.music.rest.RestMusicHealthCheckAPI;
36 import org.onap.music.rest.RestMusicLocksAPI; 
37 import org.onap.music.rest.RestMusicQAPI; 
38 import org.onap.music.rest.RestMusicTestAPI; 
39 import org.onap.music.rest.RestMusicVersionAPI;
40 import org.springframework.beans.factory.annotation.Value;
41 import org.springframework.stereotype.Component;
42
43 @Component 
44 public class JerseyConfig extends ResourceConfig {
45
46     @Value("${spring.jersey.application-path:/}") 
47     private String apiPath;
48
49     public JerseyConfig() { 
50         this.registerEndpoints();
51         register(MusicExceptionMapper.class);
52     } 
53
54     @PostConstruct
55     public void init() {
56         this.configureSwagger();
57     }
58
59     private void registerEndpoints() {
60         register(RestMusicDataAPI.class);
61         register(RestMusicLocksAPI.class); 
62         register(RestMusicConditionalAPI.class); 
63         register(RestMusicQAPI.class); 
64         register(RestMusicTestAPI.class); 
65         register(RestMusicVersionAPI.class);
66         register(RestMusicHealthCheckAPI.class);
67     
68     }
69
70     private void configureSwagger() {
71         // Available at localhost:port/swagger.json
72         this.register(ApiListingResource.class);
73         this.register(SwaggerSerializers.class);
74
75         BeanConfig config = new BeanConfig();
76         config.setConfigId("MUSIC");
77         config.setTitle("MUSIC");
78         config.setVersion("v2");
79         config.setContact("Thomas Nelson");
80         config.setSchemes(new String[] {"http", "https"});
81         config.setBasePath("/MUSIC/rest");
82         config.setResourcePackage("org.onap.music");
83         config.setPrettyPrint(true);
84         config.setScan(true);
85     }
86
87 }