Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -16,14 +16,19 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
<version>10.13.1.1</version>
|
||||
<version>${derby.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derbyclient</artifactId>
|
||||
<version>10.13.1.1</version>
|
||||
<version>${derbyclient.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<derby.version>10.13.1.1</derby.version>
|
||||
<derbyclient.version>10.13.1.1</derbyclient.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -44,12 +44,12 @@
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>3.11.11</version>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20220320</version>
|
||||
<version>${json.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -57,6 +57,8 @@
|
||||
<mssql.driver.version>8.4.1.jre11</mssql.driver.version>
|
||||
<oracle.driver.version>10.2.0.4.0</oracle.driver.version>
|
||||
<mysql.driver.version>8.0.22</mysql.driver.version>
|
||||
<jooq.version>3.11.11</jooq.version>
|
||||
<json.version>20220320</json.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -3,11 +3,9 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>fauna</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>fauna</name>
|
||||
<description>Blogging Service built with FaunaDB</description>
|
||||
<description>Code snippets for FaunaDB articles</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -28,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>com.faunadb</groupId>
|
||||
<artifactId>faunadb-java</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>${faunadb.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -41,6 +39,13 @@
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -55,6 +60,7 @@
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven-pmd-plugin.version>3.17.0</maven-pmd-plugin.version>
|
||||
<faunadb.version>4.2.0</faunadb.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.healthapp;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.faunadb.client.FaunaClient;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ConfigurationProperties
|
||||
@Component
|
||||
public class FaunaClients {
|
||||
|
||||
private final Map<String, String> faunaConnections = new HashMap<>();
|
||||
private final Map<String, String> faunaSecrets = new HashMap<>();
|
||||
|
||||
public FaunaClient getFaunaClient(String region) throws MalformedURLException {
|
||||
|
||||
String faunaUrl = faunaConnections.get(region);
|
||||
String faunaSecret = faunaSecrets.get(region);
|
||||
|
||||
log.info("Creating Fauna Client for Region:{} with URL:{}", region, faunaUrl);
|
||||
|
||||
return FaunaClient.builder()
|
||||
.withEndpoint(faunaUrl)
|
||||
.withSecret(faunaSecret)
|
||||
.build();
|
||||
}
|
||||
|
||||
public Map<String, String> getFaunaConnections() {
|
||||
return faunaConnections;
|
||||
}
|
||||
|
||||
public Map<String, String> getFaunaSecrets() {
|
||||
return faunaSecrets;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.healthapp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class FaunaHealthApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FaunaHealthApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.healthapp.domain;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public record HealthData(
|
||||
|
||||
String userId,
|
||||
|
||||
float temperature,
|
||||
float pulseRate,
|
||||
int bpSystolic,
|
||||
int bpDiastolic,
|
||||
|
||||
double latitude,
|
||||
double longitude,
|
||||
ZonedDateTime timestamp) {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.healthapp.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DefaultGeoLocationService implements GeoLocationService {
|
||||
|
||||
@Override
|
||||
public String getRegion(double latitude, double longitude) {
|
||||
return "EU";
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.healthapp.service;
|
||||
|
||||
import static com.faunadb.client.query.Language.Collection;
|
||||
import static com.faunadb.client.query.Language.Create;
|
||||
import static com.faunadb.client.query.Language.Now;
|
||||
import static com.faunadb.client.query.Language.Obj;
|
||||
import static com.faunadb.client.query.Language.Value;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.baeldung.healthapp.FaunaClients;
|
||||
import com.baeldung.healthapp.domain.HealthData;
|
||||
import com.faunadb.client.FaunaClient;
|
||||
import com.faunadb.client.types.Value;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DefaultHealthService implements HealthService {
|
||||
|
||||
@Autowired
|
||||
private GeoLocationService geoLocationService;
|
||||
|
||||
@Autowired
|
||||
private FaunaClients faunaClients;
|
||||
|
||||
@Override
|
||||
public void process(HealthData healthData) throws MalformedURLException, InterruptedException, ExecutionException {
|
||||
|
||||
String region = geoLocationService.getRegion( //
|
||||
healthData.latitude(), //
|
||||
healthData.longitude());
|
||||
|
||||
FaunaClient faunaClient = faunaClients.getFaunaClient(region);
|
||||
|
||||
Value queryResponse = faunaClient.query(
|
||||
Create(Collection("healthdata"),
|
||||
Obj("data",
|
||||
Obj(Map.of(
|
||||
"userId", Value(healthData.userId()),
|
||||
"temperature", Value(healthData.temperature()),
|
||||
"pulseRate", Value(healthData.pulseRate()),
|
||||
"bpSystolic", Value(healthData.bpSystolic()),
|
||||
"bpDiastolic", Value(healthData.bpDiastolic()),
|
||||
"latitude", Value(healthData.latitude()),
|
||||
"longitude", Value(healthData.longitude()),
|
||||
"timestamp", Now()))))
|
||||
).get();
|
||||
|
||||
log.info("Query response received from Fauna: {}", queryResponse);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.healthapp.service;
|
||||
|
||||
public interface GeoLocationService {
|
||||
|
||||
String getRegion(double latitude, double longitude);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.healthapp.service;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.baeldung.healthapp.domain.HealthData;
|
||||
|
||||
public interface HealthService {
|
||||
void process(HealthData healthData) throws MalformedURLException, InterruptedException, ExecutionException;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Fauna Blog Service
|
||||
fauna.region=EU
|
||||
fauna.secret=
|
||||
|
||||
# Fauna Health App
|
||||
fauna-connections.EU=https://db.eu.fauna.com/
|
||||
fauna-secrets.EU=eu-secret
|
||||
|
||||
fauna-connections.US=https://db.us.fauna.com/
|
||||
fauna-secrets.US=us-secret
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.baeldung.healthapp.service;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import com.baeldung.healthapp.FaunaHealthApplication;
|
||||
import com.baeldung.healthapp.domain.HealthData;
|
||||
|
||||
@SpringBootTest(classes = FaunaHealthApplication.class)
|
||||
class DefaultHealthServiceManualTest {
|
||||
|
||||
@Autowired
|
||||
private DefaultHealthService defaultHealthService;
|
||||
|
||||
@MockBean
|
||||
private GeoLocationService geoLocationService;
|
||||
|
||||
@Test
|
||||
void givenEURegion_whenProcess_thenRequestSentToEURegion() throws MalformedURLException, InterruptedException, ExecutionException {
|
||||
|
||||
HealthData healthData = new HealthData("user-1-eu", //
|
||||
37.5f, //
|
||||
99f, //
|
||||
120, 80, //
|
||||
51.50, -0.07, //
|
||||
ZonedDateTime.now());
|
||||
|
||||
when(geoLocationService.getRegion(51.50, -0.07)).thenReturn("EU");
|
||||
|
||||
defaultHealthService.process(healthData);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenUSRegion_whenProcess_thenRequestSentToUSRegion() throws MalformedURLException, InterruptedException, ExecutionException {
|
||||
|
||||
HealthData healthData = new HealthData("user-1-us", //
|
||||
38.0f, //
|
||||
100f, //
|
||||
115, 85, //
|
||||
40.75, -74.30, //
|
||||
ZonedDateTime.now());
|
||||
|
||||
when(geoLocationService.getRegion(40.75, -74.30)).thenReturn("US");
|
||||
|
||||
defaultHealthService.process(healthData);
|
||||
}
|
||||
}
|
||||
@@ -84,10 +84,8 @@
|
||||
<org.springframework.data.version>1.10.6.RELEASE</org.springframework.data.version>
|
||||
<hibernate-core.version>5.6.7.Final</hibernate-core.version>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>
|
||||
<h2.version>2.1.212</h2.version>
|
||||
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
||||
<hsqldb.version>2.3.4</hsqldb.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -82,7 +82,6 @@
|
||||
<mysql.version>6.0.6</mysql.version>
|
||||
<mariaDB4j.version>2.2.3</mariaDB4j.version>
|
||||
<geodb.version>0.9</geodb.version>
|
||||
<hsqldb.version>2.3.4</hsqldb.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -6,4 +6,4 @@
|
||||
- [Hibernate’s “Object References an Unsaved Transient Instance” Error](https://www.baeldung.com/hibernate-unsaved-transient-instance-error)
|
||||
- [EntityNotFoundException in Hibernate](https://www.baeldung.com/hibernate-entitynotfoundexception)
|
||||
- [Hibernate’s “Not-Null Property References a Null or Transient Value” Error](https://www.baeldung.com/hibernate-not-null-error)
|
||||
- [Hibernate's “Detached Entity Passed to Persist” Error](https://www.baeldung.com/hibernate-detached-entity-passed-to-persist)
|
||||
- [Hibernate’s “Detached Entity Passed to Persist” Error](https://www.baeldung.com/hibernate-detached-entity-passed-to-persist)
|
||||
|
||||
+7
-6
@@ -62,12 +62,13 @@ public class ProductRepository {
|
||||
|
||||
executeStatement(createTable.build(), keyspace);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert two variant Product into same table using a batch query.
|
||||
*
|
||||
* @param Product
|
||||
*/
|
||||
* Insert two variant Product into same table using a batch query.
|
||||
*
|
||||
* @param productVariant1
|
||||
* @param productVariant2
|
||||
*/
|
||||
public void insertProductVariantBatch(Product productVariant1,Product productVariant2) {
|
||||
UUID productId = UUID.randomUUID();
|
||||
BoundStatement productBoundStatement1 = this.getProductVariantInsertStatement(productVariant1,productId);
|
||||
@@ -83,7 +84,7 @@ public class ProductRepository {
|
||||
/**
|
||||
* Insert two same Product into related tables using a batch query.
|
||||
*
|
||||
* @param book
|
||||
* @param product
|
||||
*/
|
||||
public void insertProductBatch(Product product) {
|
||||
UUID productId = UUID.randomUUID();
|
||||
|
||||
+5
-5
@@ -16,13 +16,13 @@ public class KeyspaceRepository {
|
||||
/**
|
||||
* Method used to create any keyspace - schema.
|
||||
*
|
||||
* @param schemaName the name of the schema.
|
||||
* @param replicatioonStrategy the replication strategy.
|
||||
* @param keyspaceName the name of the keyspaceName.
|
||||
* @param replicationStrategy the replication strategy.
|
||||
* @param numberOfReplicas the number of replicas.
|
||||
*
|
||||
*/
|
||||
public void createKeyspace(String keyspaceName, String replicatioonStrategy, int numberOfReplicas) {
|
||||
StringBuilder sb = new StringBuilder("CREATE KEYSPACE IF NOT EXISTS ").append(keyspaceName).append(" WITH replication = {").append("'class':'").append(replicatioonStrategy).append("','replication_factor':").append(numberOfReplicas).append("};");
|
||||
public void createKeyspace(String keyspaceName, String replicationStrategy, int numberOfReplicas) {
|
||||
StringBuilder sb = new StringBuilder("CREATE KEYSPACE IF NOT EXISTS ").append(keyspaceName).append(" WITH replication = {").append("'class':'").append(replicationStrategy).append("','replication_factor':").append(numberOfReplicas).append("};");
|
||||
|
||||
final String query = sb.toString();
|
||||
|
||||
@@ -37,7 +37,7 @@ public class KeyspaceRepository {
|
||||
* Method used to delete the specified schema.
|
||||
* It results in the immediate, irreversable removal of the keyspace, including all tables and data contained in the keyspace.
|
||||
*
|
||||
* @param schemaName the name of the keyspace to delete.
|
||||
* @param keyspaceName the name of the keyspace to delete.
|
||||
*/
|
||||
public void deleteKeyspace(String keyspaceName) {
|
||||
StringBuilder sb = new StringBuilder("DROP KEYSPACE ").append(keyspaceName);
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>1.16.0</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -33,13 +33,13 @@
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mongodb</artifactId>
|
||||
<version>1.16.3</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>1.16.3</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver-sync</artifactId>
|
||||
<version>4.6.0</version>
|
||||
<version>${mongodb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.1</version>
|
||||
<version>${junit.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -29,6 +29,8 @@
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<mongodb.version>4.6.0</mongodb.version>
|
||||
<junit.version>5.8.1</junit.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -33,13 +33,13 @@
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mongodb</artifactId>
|
||||
<version>1.16.3</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>1.16.3</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -111,6 +111,8 @@
|
||||
<!-- persistence -->
|
||||
<hibernate.version>5.2.17.Final</hibernate.version>
|
||||
<postgresql.version>42.2.20</postgresql.version>
|
||||
<hsqldb.version>2.3.4</hsqldb.version>
|
||||
<testcontainers.version>1.16.3</testcontainers.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -136,7 +136,6 @@
|
||||
<hibernate.version>5.2.5.Final</hibernate.version>
|
||||
<hibernate-jpa.version>1.0.0.Final</hibernate-jpa.version>
|
||||
<querydsl.version>4.1.4</querydsl.version>
|
||||
<hsqldb.version>2.3.4</hsqldb.version>
|
||||
<commons-pool.version>1.6</commons-pool.version>
|
||||
<commons-dbcp.version>1.4</commons-dbcp.version>
|
||||
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
|
||||
|
||||
@@ -136,7 +136,6 @@
|
||||
<mysql-connector-java.version>8.0.7-dmr</mysql-connector-java.version>
|
||||
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
|
||||
<jta.version>1.1</jta.version>
|
||||
<hsqldb.version>2.3.4</hsqldb.version>
|
||||
<com.sun.xml.version>2.3.0.1</com.sun.xml.version>
|
||||
<javax.xml.bind.version>2.3.1</javax.xml.bind.version>
|
||||
</properties>
|
||||
|
||||
Reference in New Issue
Block a user