-
Notifications
You must be signed in to change notification settings - Fork 23
Feature/get poly imperative controller #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tisla1080
wants to merge
5
commits into
develop
Choose a base branch
from
feature/get-poly-imperative-controller
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e7243b
feat: BaseGetPolyImperativeRestController
tisla1080 9c7bf4c
feat: sample api for read poly and get poly controller / service testing
tisla1080 52bb4d9
feat: add example read poly request with page information
tisla1080 34f5ca4
style: new line eof
tisla1080 792e58a
style: new line eof
tisla1080 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2020 American Express Travel Related Services Company, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| in compliance with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License | ||
| is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| or implied. See the License for the specific language governing permissions and limitations under | ||
| the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>api</artifactId> | ||
| <version>0.4.10-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>api-samples</artifactId> | ||
| <packaging>pom</packaging> | ||
|
|
||
| <!--Modules--> | ||
| <modules> | ||
| <module>sample-api-imperative-book</module> | ||
| </modules> | ||
|
|
||
| </project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2020 American Express Travel Related Services Company, Inc. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| in compliance with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License | ||
| is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| or implied. See the License for the specific language governing permissions and limitations under | ||
| the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <parent> | ||
| <artifactId>api-samples</artifactId> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <version>0.4.10-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>sample-api-imperative-book</artifactId> | ||
|
|
||
| <!-- Dependencies --> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>synapse-api-rest-imperative</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>sample-service-imperative-book</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
30 changes: 30 additions & 0 deletions
30
.../main/java/io/americanexpress/synapse/api/rest/sample/imperativebook/BookApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package io.americanexpress.synapse.api.rest.sample.imperativebook; | ||
|
|
||
| import org.slf4j.ext.XLogger; | ||
| import org.slf4j.ext.XLoggerFactory; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| /** | ||
| * {@code BookApplication} starts the Spring Boot Application for the book rest sample. | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| @SpringBootApplication() | ||
| public class BookApplication { | ||
|
|
||
| /** | ||
| * The logger. | ||
| */ | ||
| private static final XLogger LOGGER = XLoggerFactory.getXLogger(BookApplication.class); | ||
|
|
||
| /** | ||
| * Runs the application. | ||
| * | ||
| * @param args the var args | ||
| */ | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(BookApplication.class, args); | ||
| LOGGER.info("Rest Book Imperative Sample Application is up and running..."); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
.../java/io/americanexpress/synapse/api/rest/sample/imperativebook/config/BookApiConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package io.americanexpress.synapse.api.rest.sample.imperativebook.config; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.americanexpress.service.sample.imperativebook.config.BookServiceConfig; | ||
| import io.americanexpress.synapse.api.rest.imperative.config.BaseApiImperativeRestConfig; | ||
| import io.americanexpress.synapse.api.rest.imperative.interceptor.MetricInterceptor; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| /** | ||
| * {@code BookApiConfig} sets configuration for the Book API. | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| @Configuration | ||
| @Import(BookServiceConfig.class) | ||
| @ComponentScan("io.americanexpress.synapse.api.rest.sample.imperativebook") | ||
| public class BookApiConfig extends BaseApiImperativeRestConfig { | ||
|
|
||
| /** | ||
| * Constructor taking in objectMapper & metricInterceptor. | ||
| * | ||
| * @param defaultObjectMapper the default object mapper | ||
| * @param interceptor the metric interceptor | ||
| */ | ||
| public BookApiConfig(ObjectMapper defaultObjectMapper, MetricInterceptor interceptor) { | ||
| super(defaultObjectMapper, interceptor); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...n/java/io/americanexpress/synapse/api/rest/sample/imperativebook/config/BookEndpoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package io.americanexpress.synapse.api.rest.sample.imperativebook.config; | ||
|
|
||
| /** | ||
| * {@code BookEndpoint} sets the endpoints for this API. | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class BookEndpoint { | ||
|
|
||
| /** | ||
| * Private constructor for class with constants. | ||
| */ | ||
| private BookEndpoint() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Books resource for all endpoints in this API. | ||
| */ | ||
| public static final String BOOK_ENDPOINT = "/books"; | ||
| } |
19 changes: 19 additions & 0 deletions
19
...ricanexpress/synapse/api/rest/sample/imperativebook/controller/GetPolyBookController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.americanexpress.synapse.api.rest.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.GetPolyBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.GetPolyBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.GetPolyBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseGetPolyImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.synapse.api.rest.sample.imperativebook.config.BookEndpoint.BOOK_ENDPOINT; | ||
|
|
||
| /** | ||
| * {@code GetPolyBookController} gets multiple book resources by a path variable. | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| @RestController | ||
| @RequestMapping(BOOK_ENDPOINT) | ||
| public class GetPolyBookController extends BaseGetPolyImperativeRestController<GetPolyBookServiceRequest, GetPolyBookServiceResponse, GetPolyBookService> { | ||
| } |
19 changes: 19 additions & 0 deletions
19
...icanexpress/synapse/api/rest/sample/imperativebook/controller/ReadPolyBookController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.americanexpress.synapse.api.rest.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.ReadPolyBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.ReadPolyBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.ReadPolyBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseReadPolyImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.synapse.api.rest.sample.imperativebook.config.BookEndpoint.BOOK_ENDPOINT; | ||
|
|
||
| /** | ||
| * {@code ReadPolyBookController} reads multiple book resources with specific criteria | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| @RestController | ||
| @RequestMapping(BOOK_ENDPOINT) | ||
| public class ReadPolyBookController extends BaseReadPolyImperativeRestController<ReadPolyBookServiceRequest, ReadPolyBookServiceResponse, ReadPolyBookService> { | ||
| } |
7 changes: 7 additions & 0 deletions
7
...samples/sample-api-imperative-book/src/test/resources/read-poly-book-service-request.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "author": "j.k. rowling", | ||
| "pageInformation": { | ||
| "page": "1", | ||
| "size": "1" | ||
| } | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
...anexpress/synapse/api/rest/imperative/controller/BaseGetPolyImperativeRestController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package io.americanexpress.synapse.api.rest.imperative.controller; | ||
|
|
||
| import io.americanexpress.synapse.api.rest.imperative.controller.helpers.PolyResponseEntityCreator; | ||
| import io.americanexpress.synapse.service.imperative.model.BaseServiceRequest; | ||
| import io.americanexpress.synapse.service.imperative.model.BaseServiceResponse; | ||
| import io.americanexpress.synapse.service.imperative.model.PageResponse; | ||
| import io.americanexpress.synapse.service.imperative.service.BaseService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestHeader; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * {@code BaseGetPolyImperativeRestController} class specifies the prototypes for listening for requests from the consumer | ||
| * to Read (GET) a resource. This Controller expects no request and a list of objects as response, hence, "Poly" in the name. | ||
| * | ||
| * @param <I> an object extending {@link BaseServiceRequest} | ||
| * @param <O> an object extending {@link BaseServiceResponse} | ||
| * @param <S> an object extending {@link BaseService} | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class BaseGetPolyImperativeRestController< | ||
| I extends BaseServiceRequest, | ||
| O extends BaseServiceResponse, | ||
| S extends BaseService<I, PageResponse<O>> | ||
| > extends BaseController<S> { | ||
|
|
||
| /** | ||
| * Get a list of multiple resources from the back end service. | ||
| * | ||
| * @param httpHeaders containing the HTTP headers from the consumer | ||
| * @param serviceRequest body from the consumer | ||
| * @return a list of resources from the back end service | ||
| */ | ||
| @Operation(summary = "Read operation based on path.", description = "Read a collection of resources based on request criteria.") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = "200", description = "Ok"), | ||
| @ApiResponse(responseCode = "204", description = "No Content"), | ||
| @ApiResponse(responseCode = "400", description = "Bad Request"), | ||
| @ApiResponse(responseCode = "401", description = "Unauthorized"), | ||
| @ApiResponse(responseCode = "403", description = "Forbidden"), | ||
| @ApiResponse(responseCode = "404", description = "Not Found") | ||
| }) | ||
| @GetMapping | ||
| public ResponseEntity<List<O>> read(@RequestHeader HttpHeaders httpHeaders, I serviceRequest) { | ||
| logger.entry(serviceRequest); | ||
|
|
||
| final PageResponse<O> page = service.execute(serviceRequest); | ||
| final ResponseEntity<List<O>> responseEntity = PolyResponseEntityCreator.create(page); | ||
|
|
||
| logger.exit(responseEntity); | ||
| return responseEntity; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ava/io/americanexpress/service/sample/imperativebook/model/GetPolyBookServiceRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.americanexpress.service.sample.imperativebook.model; | ||
|
|
||
| import io.americanexpress.synapse.service.imperative.model.BaseServiceRequest; | ||
|
|
||
| /** | ||
| * {@code GetPolyBookServiceRequest} class is the request model for {@link io.americanexpress.service.sample.imperativebook.service.GetPolyBookService} | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class GetPolyBookServiceRequest extends BaseBook implements BaseServiceRequest { | ||
| } |
11 changes: 11 additions & 0 deletions
11
...va/io/americanexpress/service/sample/imperativebook/model/GetPolyBookServiceResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.americanexpress.service.sample.imperativebook.model; | ||
|
|
||
| import io.americanexpress.synapse.service.imperative.model.BaseServiceResponse; | ||
|
|
||
| /** | ||
| * {@code GetPolyBookServiceResponse} class is the response model for {@link io.americanexpress.service.sample.imperativebook.service.GetPolyBookService} | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class GetPolyBookServiceResponse extends BaseBook implements BaseServiceResponse { | ||
| } |
34 changes: 34 additions & 0 deletions
34
...va/io/americanexpress/service/sample/imperativebook/model/ReadPolyBookServiceRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package io.americanexpress.service.sample.imperativebook.model; | ||
|
|
||
| import io.americanexpress.synapse.service.imperative.model.BasePaginatedServiceRequest; | ||
|
|
||
| /** | ||
| * {@code ReadPolyBookServiceRequest} class is the request model for {@link io.americanexpress.service.sample.imperativebook.service.ReadPolyBookService} | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class ReadPolyBookServiceRequest extends BasePaginatedServiceRequest { | ||
|
|
||
| /** | ||
| * Author of the book. | ||
| */ | ||
| private String author; | ||
|
|
||
| /** | ||
| * Get the author of the book. | ||
| * | ||
| * @return the author of the book | ||
| */ | ||
| public String getAuthor() { | ||
| return author; | ||
| } | ||
|
|
||
| /** | ||
| * Set the author of the book. | ||
| * | ||
| * @param author the author of the book | ||
| */ | ||
| public void setAuthor(String author) { | ||
| this.author = author; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...a/io/americanexpress/service/sample/imperativebook/model/ReadPolyBookServiceResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.americanexpress.service.sample.imperativebook.model; | ||
|
|
||
| import io.americanexpress.synapse.service.imperative.model.BaseServiceResponse; | ||
|
|
||
| /** | ||
| * {@code ReadPolyBookServiceResponse} class is the request model for {@link io.americanexpress.service.sample.imperativebook.service.ReadPolyBookService} | ||
| * | ||
| * @author Tanvir Islam | ||
| */ | ||
| public class ReadPolyBookServiceResponse extends BaseBook implements BaseServiceResponse { | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.