modular monolith, context maps left in app-monolith
This commit is contained in:
54
adapter-commons/pom.xml
Normal file
54
adapter-commons/pom.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
|
||||
<groupId>pl.com.bottega</groupId>
|
||||
<artifactId>adapter-commons</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.8.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package pl.com.bottega.tools;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface CommandRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(ID id);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(T entity);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(Iterable<? extends T> entities);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void deleteAll();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package pl.com.bottega.tools;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class JsonConverter<T> implements AttributeConverter<T, String> {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper()
|
||||
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
|
||||
.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE)
|
||||
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
|
||||
.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY)
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.enable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID)
|
||||
.registerModule(new JavaTimeModule());
|
||||
|
||||
private final Class<T> type;
|
||||
|
||||
public JsonConverter(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(T object) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T convertToEntityAttribute(String data) {
|
||||
try {
|
||||
return objectMapper.readValue(data, type);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package pl.com.bottega.tools;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface ProjectionRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
<S extends T> S save(S entity);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(ID id);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(T entity);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void delete(Iterable<? extends T> entities);
|
||||
|
||||
@Override
|
||||
@RestResource(exported = false)
|
||||
void deleteAll();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package pl.com.bottega.tools;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface TechnicalId {
|
||||
|
||||
Long getId();
|
||||
|
||||
default boolean isPersisted() {
|
||||
return getId() != null;
|
||||
}
|
||||
|
||||
static Long get(Object id) {
|
||||
return isPersisted(id) ? ((TechnicalId) id).getId() : null;
|
||||
}
|
||||
|
||||
static boolean isPersisted(Object id) {
|
||||
return (id instanceof TechnicalId) && ((TechnicalId) id).isPersisted();
|
||||
}
|
||||
|
||||
static <T> T findOrDefault(Object id, Function<Long, T> ifPresent, Supplier<T> orElse) {
|
||||
if (isPersisted(id)) {
|
||||
return ifPresent.apply(get(id));
|
||||
} else {
|
||||
return orElse.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
10
adapter-commons/src/test/resources/application.properties
Normal file
10
adapter-commons/src/test/resources/application.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
spring.main.banner-mode=off
|
||||
spring.jpa.database=default
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
|
||||
logging.level.org.hibernate.SQL=debug
|
||||
logging.level.=error
|
||||
Reference in New Issue
Block a user