Skip to content
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

feat(services): service cleanup #220

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.americanexpress.service.book.rest.model.CreateBookResponse;
import io.americanexpress.service.book.rest.service.CreateBookService;
import io.americanexpress.synapse.service.rest.controller.BaseCreateController;
import io.americanexpress.synapse.service.rest.controller.helpers.CreateResponseEntityCreator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.americanexpress.service.book.rest.model.ReadBookResponse;
import io.americanexpress.service.book.rest.service.ReadBookService;
import io.americanexpress.synapse.service.rest.controller.BaseReadMonoController;
import io.americanexpress.synapse.service.rest.controller.helpers.MonoResponseEntityCreator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down
21 changes: 21 additions & 0 deletions service/synapse-service-graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# synapse-service-graphql

## Description

This synapse module is the framework module used to expose GraphQL APIs. It provides several out-of-the-box
functionalities like:
- An open to extension GraphQLServiceConfig configuration mapping different GraphQLScalarType.

## Usage
- To utilize this module, add the following dependency to the pom.xml file:
```xml
<dependency>
<groupId>com.americanexpress</groupId>
<artifactId>synapse-service-graphql</artifactId>
<version>0.3.8-SNAPSHOT</version>
</dependency>
```
Or add the following to the build.gradle file:
```kotlin
implementation 'io.americanexpress.synapse:synapse-service-graphql:0.3.8-SNAPSHOT'
```
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private ReactiveResponseCreator() {
* @param element to be set in the response
* @return the reactive response
*/
public static final <T> CompletableFuture<T> create(T element) {
public static <T> CompletableFuture<T> create(T element) {
return Mono.fromSupplier(() -> element).toFuture();
}

Expand All @@ -48,7 +48,7 @@ public static final <T> CompletableFuture<T> create(T element) {
* @param elements to be set in the response
* @return the reactive response
*/
public static final <T> CompletableFuture<List<T>> create(List<T> elements) {
public static <T> CompletableFuture<List<T>> create(List<T> elements) {
return Flux.fromIterable(elements)
.collectList()
.toFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ private ConnectionCursorUtil() {

/**
* Get the {@link ConnectionCursor} from this cursor.
* @param cursor the cursor
* @param uuid the uuid
* @return the {@link ConnectionCursor}
*/
public static final ConnectionCursor from(UUID uuid) {
public static ConnectionCursor from(UUID uuid) {
return new DefaultConnectionCursor(UUIDUtil.toString(uuid));
}

Expand All @@ -49,7 +49,7 @@ public static final ConnectionCursor from(UUID uuid) {
* @param edges the edges
* @return the start cursor
*/
public static final <T> ConnectionCursor getStartCursor(List<Edge<T>> edges) {
public static <T> ConnectionCursor getStartCursor(List<Edge<T>> edges) {
return edges.isEmpty() ? null : edges.get(0).getCursor();
}

Expand All @@ -58,7 +58,7 @@ public static final <T> ConnectionCursor getStartCursor(List<Edge<T>> edges) {
* @param edges the edges
* @return the end cursor
*/
public static final <T> ConnectionCursor getEndCursor(List<Edge<T>> edges) {
public static <T> ConnectionCursor getEndCursor(List<Edge<T>> edges) {
return edges.isEmpty() ? null : edges.get(edges.size() - 1).getCursor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private ConnectionUtil() {
* @param after the opaque cursor
* @return the {@link Connection}
*/
public static final <T extends UniversallyUniqueIdentifiable> Connection<T> create(List<T> elements, long first, String after) {
public static <T extends UniversallyUniqueIdentifiable> Connection<T> create(List<T> elements, long first, String after) {

// Get the limit of this stream which is either the number of elements
// specified by "first"; otherwise the full elements size
Expand All @@ -59,7 +59,7 @@ public static final <T extends UniversallyUniqueIdentifiable> Connection<T> crea
.limit(limit)
.map(element -> new DefaultEdge<>(element, ConnectionCursorUtil.from(element.getId())))
.collect(Collectors.toList());

// Create the page information for the connection
ConnectionCursor startCursor = ConnectionCursorUtil.getStartCursor(edges);
ConnectionCursor endCursor = ConnectionCursorUtil.getEndCursor(edges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private UUIDUtil() {
* @param uuid to be converted
* @return a Base64 encoded {@link String}
*/
public static final String toString(UUID uuid) {
public static String toString(UUID uuid) {
return Base64.getEncoder().encodeToString(uuid.toString().getBytes());
}

Expand All @@ -45,7 +45,7 @@ public static final String toString(UUID uuid) {
* @param text to be converted
* @return a Base64 decoded {@link UUID}
*/
public static final UUID toUUID(String text) {
public static UUID toUUID(String text) {
return UUID.fromString(new String(Base64.getDecoder().decode(text)));
}
}
17 changes: 15 additions & 2 deletions service/synapse-service-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@

## Usage
- To utilize this module, add the following dependency to the pom.xml file:
```
```xml
<dependency>
<groupId>com.americanexpress</groupId>
<artifactId>synapse-service-rest</artifactId>
<version>0.3.8-SNAPSHOT</version>
</dependency>
```
Or add the following to the build.gradle file:
```kotlin
implementation 'io.americanexpress.synapse:synapse-service-rest:0.3.8-SNAPSHOT'
```
implementation 'io.americanexpress.synapse:synapse-service-rest:0.2.1!!'
- Have a configuration class that import or extends `ServiceRestConfig`.
- Create controller and service class that extend the crud controller and service base on your need.
- For ex:
```java
public class CreateBookController extends BaseCreateController<CreateBookRequest, CreateBookResponse, CreateBookService>{}
public class CreateBookService extends BaseCreateService<CreateBookRequest, CreateBookResponse>{}
```

## Examples
Examples of utilizing the synapse-service-rest module can be found in the following modules:
- sample-service-reactive-cassandra-book
- sample-service-rest-book
- sample-service-rest-cassandra-book
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.core.env.Environment;

/**
* {@code ObservabilityConfig} class sets the configuration setting up Tanzu Wavefront.
* {@code BaseObservabilityConfig} class sets the configuration setting up Tanzu Wavefront.
* The service utilizing this config must set the properties defined in this class configure Tanzu Wavefront.
*
* @author Gabriel Jimenez
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -70,8 +71,9 @@ public ServiceRestConfig(ObjectMapper defaultObjectMapper, MetricInterceptor int
*/
@Bean
public MappingJackson2HttpMessageConverter jsonMessageConverter() {
final MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(getObjectMapper());
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter(defaultObjectMapper);
messageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
messageConverter.setDefaultCharset(StandardCharsets.UTF_8);
return messageConverter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* {@code BaseController} The base controller every child controller should extend this parent controller
* @param <S>
* @param <S> service class extending {@link BaseService}
*/
public abstract class BaseController<S extends BaseService> {

Expand Down
Loading