[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-PDP-REST / src / main / java / org / onap / policy / pdp / rest / config / PDPRestConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
4  * ================================================================================
5  * Copyright (C) 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 package org.onap.policy.pdp.rest.config;
21
22 import javax.servlet.MultipartConfigElement;
23
24 import org.onap.policy.common.logging.eelf.PolicyLogger;
25 import org.onap.policy.pdp.rest.api.controller.PolicyEngineServices;
26 import org.springframework.context.annotation.Bean;
27 import org.springframework.context.annotation.ComponentScan;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
30 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
31 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
32
33 import springfox.documentation.builders.ApiInfoBuilder;
34 import springfox.documentation.builders.PathSelectors;
35 import springfox.documentation.builders.RequestHandlerSelectors;
36 import springfox.documentation.service.ApiInfo;
37 import springfox.documentation.spi.DocumentationType;
38 import springfox.documentation.spring.web.plugins.Docket;
39 import springfox.documentation.swagger2.annotations.EnableSwagger2;
40
41 @Configuration
42 @EnableWebMvc
43 @EnableSwagger2
44 @ComponentScan(basePackageClasses = PolicyEngineServices.class)
45 public class PDPRestConfig extends WebMvcConfigurerAdapter{
46         @Override 
47     public void addResourceHandlers(ResourceHandlerRegistry registry) {
48         registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
49         registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
50     }
51     
52     private ApiInfo apiInfo(){
53         return new ApiInfoBuilder()
54                 .title("Policy Engine REST API")
55                 .description("This API helps to make queries against Policy Engine")
56                 .version("3.0")
57                 .build();
58     }
59     
60     @Bean
61     public Docket policyAPI(){
62         PolicyLogger.info("Setting up Swagger... ");
63         return new Docket(DocumentationType.SWAGGER_2)                
64                 .select()
65                 .apis(RequestHandlerSelectors.basePackage("org.onap.policy.pdp.rest.api"))
66                 .paths(PathSelectors.any())
67                 .build()
68                 .apiInfo(apiInfo());
69     }
70     
71     @Bean
72     public MultipartConfigElement multipartConfigElement(){
73         String location = System.getProperty("java.io.tmpdir");
74         MultipartConfigElement mp = new MultipartConfigElement(location);
75         return mp;
76     }
77 }