Skip to content

Commit 85e01b6

Browse files
author
Raja Maragani
committed
DURACI-6696 Implement Subscription rest interface
Implemented rest interface for Subscription with RAML and Swagger Change-Id: I2024511aa1878f5ed44000e51961dbbc29c18bcc
1 parent e845839 commit 85e01b6

21 files changed

+1789
-11
lines changed

pom.xml

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
<artifactId>spring-boot-starter-parent</artifactId>
1111
<version>1.5.2.RELEASE</version>
1212
</parent>
13+
14+
<properties>
15+
<java.version>1.8</java.version>
16+
<plugin-version>0.8.6</plugin-version>
17+
<output-relative-path>src/main/java</output-relative-path>
18+
<raml-path>src/main/resources/public/raml/subscription.raml</raml-path>
19+
<base-package>com.ericsson.ei.controller</base-package>
20+
</properties>
1321

1422
<repositories>
1523
<repository>
@@ -34,6 +42,11 @@
3442
<groupId>org.springframework.boot</groupId>
3543
<artifactId>spring-boot-starter-web</artifactId>
3644
</dependency>
45+
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-security</artifactId>
49+
</dependency>
3750

3851
<dependency>
3952
<groupId>org.springframework.boot</groupId>
@@ -104,7 +117,31 @@
104117
<artifactId>mongo-java-driver</artifactId>
105118
<version>3.4.2</version>
106119
</dependency>
107-
120+
<dependency>
121+
<groupId>joda-time</groupId>
122+
<artifactId>joda-time</artifactId>
123+
</dependency>
124+
<dependency>
125+
<groupId>com.fasterxml.jackson.core</groupId>
126+
<artifactId>jackson-databind</artifactId>
127+
</dependency>
128+
<dependency>
129+
<groupId>commons-lang</groupId>
130+
<artifactId>commons-lang</artifactId>
131+
<version>2.6</version>
132+
</dependency>
133+
<dependency>
134+
<groupId>io.springfox</groupId>
135+
<artifactId>springfox-swagger-ui</artifactId>
136+
<version>2.6.1</version>
137+
<scope>compile</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>io.springfox</groupId>
141+
<artifactId>springfox-swagger2</artifactId>
142+
<version>2.6.1</version>
143+
<scope>compile</scope>
144+
</dependency>
108145
<dependency>
109146
<groupId>org.apache.qpid</groupId>
110147
<artifactId>qpid-broker</artifactId>
@@ -120,17 +157,75 @@
120157
</dependency>
121158

122159
</dependencies>
123-
124-
<properties>
125-
<java.version>1.8</java.version>
126-
</properties>
127-
128160
<build>
129161
<plugins>
130162
<plugin>
131163
<groupId>org.springframework.boot</groupId>
132164
<artifactId>spring-boot-maven-plugin</artifactId>
133165
</plugin>
166+
167+
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
168+
from raml -->
169+
<plugin>
170+
<groupId>com.phoenixnap.oss</groupId>
171+
<artifactId>springmvc-raml-plugin</artifactId>
172+
<version>${plugin-version}</version>
173+
<configuration>
174+
<!-- path to raml file -->
175+
<ramlPath>${raml-path}</ramlPath>
176+
<!-- output of generated code -->
177+
<outputRelativePath>${output-relative-path}</outputRelativePath>
178+
<addTimestampFolder>false</addTimestampFolder>
179+
<!-- package for generated sources -->
180+
<basePackage>${base-package}</basePackage>
181+
<baseUri>/</baseUri>
182+
<seperateMethodsByContentType>false</seperateMethodsByContentType>
183+
<useJackson1xCompatibility>false</useJackson1xCompatibility>
184+
</configuration>
185+
</plugin>
186+
<!-- Required to build the executable jar file -->
187+
<plugin>
188+
<groupId>org.springframework.boot</groupId>
189+
<artifactId>spring-boot-maven-plugin</artifactId>
190+
<configuration>
191+
<classifier>exec</classifier>
192+
</configuration>
193+
</plugin>
194+
<!-- required for adding generated sources -->
195+
<plugin>
196+
<groupId>org.codehaus.mojo</groupId>
197+
<artifactId>build-helper-maven-plugin</artifactId>
198+
<executions>
199+
<execution>
200+
<phase>generate-sources</phase>
201+
<goals>
202+
<goal>add-source</goal>
203+
</goals>
204+
<configuration>
205+
<sources>
206+
<!-- where to find the generated sources -->
207+
<source>${output-relative-path}</source>
208+
</sources>
209+
</configuration>
210+
</execution>
211+
</executions>
212+
</plugin>
213+
<plugin>
214+
<groupId>com.phoenixnap.oss</groupId>
215+
<artifactId>springmvc-raml-plugin</artifactId>
216+
<configuration>
217+
<rule>com.phoenixnap.oss.ramlapisync.generation.rules.Spring4ControllerInterfaceRule</rule>
218+
</configuration>
219+
<executions>
220+
<execution>
221+
<id>generate-springmvc-controllers</id>
222+
<phase>generate-sources</phase>
223+
<goals>
224+
<goal>generate-springmvc-endpoints</goal>
225+
</goals>
226+
</execution>
227+
</executions>
228+
</plugin>
134229
</plugins>
135230
</build>
136231
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/***********************************************************************
2+
* *
3+
* Copyright Ericsson AB 2017 *
4+
* *
5+
* No part of this software may be reproduced in any form without the *
6+
* written permission of the copyright owner. *
7+
* *
8+
***********************************************************************/
9+
10+
package com.ericsson.ei;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
13+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
14+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
15+
16+
@Configuration
17+
@EnableWebSecurity
18+
public class EnpointSecurity extends WebSecurityConfigurerAdapter {
19+
20+
@Override
21+
protected void configure(HttpSecurity http) throws Exception {
22+
http.csrf().disable();
23+
24+
}
25+
26+
27+
28+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/***********************************************************************
2+
* *
3+
* Copyright Ericsson AB 2017 *
4+
* *
5+
* No part of this software may be reproduced in any form without the *
6+
* written permission of the copyright owner. *
7+
* *
8+
***********************************************************************/
9+
10+
package com.ericsson.ei.config;
11+
12+
import org.springframework.context.annotation.Bean;
13+
import org.springframework.context.annotation.Configuration;
14+
15+
import springfox.documentation.builders.PathSelectors;
16+
import springfox.documentation.builders.RequestHandlerSelectors;
17+
import springfox.documentation.service.ApiInfo;
18+
import springfox.documentation.spi.DocumentationType;
19+
import springfox.documentation.spring.web.plugins.Docket;
20+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
21+
22+
@Configuration
23+
@EnableSwagger2
24+
public class SwaggerConfig {
25+
@Bean
26+
public Docket productApi() {
27+
return new Docket(DocumentationType.SWAGGER_2)
28+
.select()
29+
.apis(RequestHandlerSelectors.basePackage("com.ericsson.ei.controller"))
30+
.paths(PathSelectors.any())
31+
.build()
32+
.apiInfo(metaData());
33+
}
34+
@SuppressWarnings("deprecation")
35+
private ApiInfo metaData() {
36+
ApiInfo apiInfo = new ApiInfo(
37+
"Subscription REST API",
38+
"Subscription REST API to store and retrive the subscription.",
39+
"1.0",
40+
"Terms of service","",
41+
"Apache License Version 2.0",
42+
"https://www.apache.org/licenses/LICENSE-2.0");
43+
return apiInfo;
44+
}
45+
}
Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,69 @@
1+
12
package com.ericsson.ei.controller;
23

4+
import java.util.List;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.PathVariable;
37
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
49
import org.springframework.web.bind.annotation.RestController;
510

11+
12+
/**
13+
* Provides interaction with Subscription resource
14+
* (Generated with springmvc-raml-parser v.0.8.6)
15+
*
16+
*/
617
@RestController
7-
public class SubscriptionController {
18+
@RequestMapping(value = "/subscriptions", produces = "application/json")
19+
public interface SubscriptionController {
20+
21+
22+
/**
23+
* List the names of all subscriptions
24+
*
25+
*/
26+
@RequestMapping(value = "", method = RequestMethod.GET)
27+
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptions();
28+
29+
/**
30+
* Takes the subscription rules, the name for subscription and the user name of the person registering this subscription and saves the subscription in subscription database. The name needs to be unique.
31+
*
32+
*/
33+
@RequestMapping(value = "", method = RequestMethod.POST)
34+
public ResponseEntity<?> createSubscription(
35+
@javax.validation.Valid
36+
@org.springframework.web.bind.annotation.RequestBody
37+
com.ericsson.ei.controller.model.Subscription subscription);
38+
39+
/**
40+
* Returns the subscription rules for given subscription name.
41+
*
42+
*/
43+
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
44+
public ResponseEntity<com.ericsson.ei.controller.model.Subscription> getSubscriptionById(
45+
@PathVariable
46+
String subscriptionName);
47+
48+
/**
49+
* Modify an existing Subscription.
50+
*
51+
*/
52+
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.PUT)
53+
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> updateSubscriptionById(
54+
@PathVariable
55+
String subscriptionName,
56+
@javax.validation.Valid
57+
@org.springframework.web.bind.annotation.RequestBody
58+
com.ericsson.ei.controller.model.Subscription subscription);
859

9-
@RequestMapping("/listSubscriptions")
10-
public String[] listSubscriptions() {
11-
return new String[1];
60+
/**
61+
* Removes the subscription from the database.
62+
*
63+
*/
64+
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.DELETE)
65+
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> deleteSubscriptionById(
66+
@PathVariable
67+
String subscriptionName);
1268

13-
}
1469
}

0 commit comments

Comments
 (0)