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

Feature/sample couchbase modules #251

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions data/data-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<module>sample-data-mysql-book</module>
<module>sample-data-mysql-reactive-book</module>
<module>sample-data-redis-book</module>
<module>sample-data-couchbase-reactive</module>
</modules>

</project>
43 changes: 43 additions & 0 deletions data/data-samples/sample-data-couchbase-reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>data-samples</artifactId>
<version>0.3.8-SNAPSHOT</version>
</parent>

<artifactId>sample-data-couchbase-reactive</artifactId>

<dependencies>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-data-couchbase</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/
package io.americanexpress.data.book.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.americanexpress.synapse.data.couchbase.config.BaseReactiveCouchbaseDataConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;

import static io.americanexpress.data.book.config.BookDataConfig.PACKAGE_NAME;

@Configuration
@PropertySource("classpath:/data-book-application.properties")
@EnableReactiveCouchbaseRepositories(basePackages = PACKAGE_NAME)
public class BookDataConfig extends BaseReactiveCouchbaseDataConfig {

/**
* The Package name.
*/
static final String PACKAGE_NAME = "io.americanexpress.data.book";

protected BookDataConfig(Environment environment, ObjectMapper objectMapper) {
super(environment, objectMapper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/
package io.americanexpress.data.book.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
import org.springframework.data.couchbase.core.mapping.id.GeneratedValue;

import static org.springframework.data.couchbase.core.mapping.id.GenerationStrategy.UNIQUE;

/**
* The type Book entity.
*/
@Document
public class BookEntity {

@Id
@GeneratedValue(strategy = UNIQUE)
private String id;

@Field
private String title;

@Field
private String author;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/
package io.americanexpress.data.book.repository;

import io.americanexpress.data.book.entity.BookEntity;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BookRepository extends ReactiveCrudRepository<BookEntity, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#/*
#* 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.
#*/
spring.main.allow-bean-definition-overriding=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#/*
#* 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.
#*/
spring.couchbase.connection-string=127.0.0.1
spring.couchbase.bucket-name=synapse
spring.couchbase.username=admin
spring.couchbase.password=password
9 changes: 8 additions & 1 deletion data/synapse-data-couchbase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- An open to extension base configuration java file with the standard connection parameters needed to connect to
couchbase using Spring Data. The connection parameters will be provided by the property files on the module(s)that
you as a developer are creating that will use this base-data-postgres module as a dependency.
- An open to extension BaseEntity containing the generated key identifier and the common auditing fields maintained
- An open to extension `BaseEntity` containing the generated key identifier and the common auditing fields maintained
by the Spring Data framework itself (createdBy, lastModifiedBy, createdDate, lastModifiedDate and version).

## Usage
Expand All @@ -26,3 +26,10 @@ Or add the following to the build.gradle file:
```
implementation 'io.americanexpress.synapse:synapse-data-couchbase:0.2.1!!'
```
- Create a configuration class extending `BaseReactiveCouchbaseDataConfig` for reactive support or `BaseCrudCouchbaseDataConfig` for non-reactive usage.
- Create repository interfaces extending `ReactiveCrudRepository` for reactive support or `BaseCrudCouchbaseRepository` for non-reactive.

## Examples
Examples of utilizing the synapse-data-couchbase module can be found in the following modules:
- sample-data-couchbase-reactive
- sample-service-reactive-couchbase-book
12 changes: 5 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@
<artifactId>sample-data-cassandra-reactive</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-data-couchbase-reactive</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-data-mongodb-book</artifactId>
Expand Down Expand Up @@ -597,13 +602,6 @@
</dependency>

<!--Spring Cloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2022.0.0-RC3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-web</artifactId>
Expand Down
1 change: 1 addition & 0 deletions service/service-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<module>sample-service-rest-mysql-book</module>
<module>sample-service-rest-oracle-book</module>
<module>sample-service-rest-postgres-book</module>
<module>sample-service-reactive-couchbase-book</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>service-samples</artifactId>
<version>0.3.8-SNAPSHOT</version>
</parent>

<artifactId>sample-service-reactive-couchbase-book</artifactId>

<!--Dependencies-->
<dependencies>
<!--Synapse-->
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-service-rest</artifactId>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-data-couchbase-reactive</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/
package io.americanexpress.service.book.rest;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* BookApplication starts the Spring Boot Application for the book rest sample.
*/
@OpenAPIDefinition(info = @Info(
title = "Book API",
version = "v1.0.0",
description = "Rest API that provides book related information."))
@SpringBootApplication
public class BookApplication {

private static final XLogger LOGGER = XLoggerFactory.getXLogger(BookApplication.class);

/**
* Main method to run the Spring Boot Book Application.
*
* @param args the args
*/
public static void main(String[] args) {
SpringApplication.run(BookApplication.class, args);
LOGGER.info("Rest Book Application is up and running ...");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.
*/
package io.americanexpress.service.book.rest.config;

import io.americanexpress.data.book.config.BookDataConfig;
import io.americanexpress.synapse.service.rest.config.ServiceRestConfig;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

/**
* {@code BookConfig} is the configuration class for the Book Application.
*/
@Configuration
@PropertySource("classpath:/service-book-application.properties")
@ComponentScan(basePackages = "io.americanexpress.service.book.rest")
@Import({ServiceRestConfig.class, BookDataConfig.class})
public class BookConfig {

}
Loading