Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/api-samples/pom.xml
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>
39 changes: 39 additions & 0 deletions api/api-samples/sample-api-imperative-book/pom.xml
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>
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...");
}
}
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);
}
}
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";
}
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> {
}
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> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "j.k. rowling",
"pageInformation": {
"page": "1",
"size": "1"
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static <O extends BaseServiceResponse> ResponseEntity<List<O>> create(Pag
final ResponseEntity<List<O>> responseEntity;
List<O> pageContent = null;
if (page != null) {
pageContent = page.getResponsesForPage();
pageContent = page.getPageSize() > 0 ? page.getResponsesForPage() : page.getResponses();
}
if (page == null || CollectionUtils.isEmpty(pageContent)) {
responseEntity = new ResponseEntity<>(HttpStatus.NO_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
package io.americanexpress.service.sample.imperativebook.config;

import io.americanexpress.synapse.service.imperative.config.BaseImperativeServiceConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* The type Book service config.
*
* @author Francois Gutt
*/
@Configuration
@ComponentScan("io.americanexpress.service.sample.imperativebook")
public class BookServiceConfig extends BaseImperativeServiceConfig {

}
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 {
}
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 {
}
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;
}
}
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 {
}
Loading