Merge pull request #3 from michal-michaluk/tech/first-integration-test

This commit is contained in:
Michał Michaluk
2018-03-11 15:59:31 +01:00
committed by GitHub
24 changed files with 568 additions and 138 deletions

View File

@@ -28,6 +28,11 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>

View File

@@ -0,0 +1,18 @@
package pl.com.bottega.tools;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.ActiveProfiles;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@SpringBootTest
@ActiveProfiles
public @interface IntegrationTest {
@AliasFor(annotation = ActiveProfiles.class, attribute = "profiles") String[] activeProfiles() default {"test"};
}

View File

@@ -99,6 +99,12 @@
<version>1.1-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.194</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
@@ -125,6 +131,29 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Spec.java</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -1,12 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SEQUENCE hibernate_sequence
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE CAST (character varying AS json) WITH INOUT AS ASSIGNMENT;

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<changeSet author="jakubpilimon" id="1.init">
<createSequence sequenceName="hibernate_sequence" startValue="1" incrementBy="1" cacheSize="1"/>
</changeSet>
<changeSet author="jakubpilimon" id="2.postgres.json" dbms="postgresql">
<sql>CREATE CAST (character varying AS jsonb) WITH INOUT AS ASSIGNMENT</sql>
</changeSet>
</databaseChangeLog>

View File

@@ -2,10 +2,10 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="/schema/commons.sql"/>
<include file="/schema/delivery-planning.sql"/>
<include file="/schema/demand-forecasting.sql"/>
<include file="/schema/product-management.sql"/>
<include file="/schema/production-planning.sql"/>
<include file="/schema/shortages-prediction.sql"/>
<include file="/schema/commons.xml"/>
<include file="/schema/delivery-planning.xml"/>
<include file="/schema/demand-forecasting.xml"/>
<include file="/schema/product-management.xml"/>
<include file="/schema/production-planning.xml"/>
<include file="/schema/shortages-prediction.xml"/>
</databaseChangeLog>

View File

@@ -1,17 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SCHEMA delivery_planning;
CREATE TABLE delivery_planning.delivery_planner_definition (
ref_no character varying(64) NOT NULL PRIMARY KEY,
definition json NOT NULL
);
CREATE TABLE delivery_planning.delivery_forecast (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"time" timestamp without time zone NOT NULL,
"date" timestamp without time zone NOT NULL,
level bigint NOT NULL
);

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<property name="json" value="clob" dbms="h2"/>
<property name="json" value="jsonb" dbms="postgresql"/>
<changeSet author="jakubpilimon" id="1.delivery-planning-init">
<sql>
CREATE SCHEMA delivery_planning
</sql>
<createTable tableName="delivery_planner_definition" schemaName="delivery_planning">
<column name="ref_no" type="varchar(64)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="definition" type="${json}">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="delivery_forecast" schemaName="delivery_planning">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="time" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="level" type="bigint">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -1,49 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SCHEMA demand_forecasting;
CREATE TABLE demand_forecasting.product_demand (
id serial NOT NULL PRIMARY KEY,
version bigint NOT NULL,
ref_no character varying(64) NOT NULL,
UNIQUE(ref_no)
);
CREATE TABLE demand_forecasting."demand" (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"date" timestamp without time zone NOT NULL,
value json NOT NULL,
UNIQUE(ref_no, "date")
);
CREATE TABLE demand_forecasting.current_demand (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"date" timestamp without time zone NOT NULL,
level bigint NOT NULL,
"schema" character varying(64) NOT NULL,
UNIQUE(ref_no, "date")
);
CREATE TABLE demand_forecasting.demand_adjustment (
id serial NOT NULL PRIMARY KEY,
customer_representative character varying(255) NOT NULL,
note character varying(255) NOT NULL,
adjustment json NOT NULL,
clean_after timestamp without time zone
);
CREATE TABLE demand_forecasting.demand_review (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"date" timestamp without time zone NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
review json NOT NULL,
decision character varying(64),
clean_after timestamp without time zone
);
--changeset michaluk.michal:2.rename.review.table
ALTER TABLE demand_forecasting.demand_review RENAME TO required_review;

View File

@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<property name="json" value="clob" dbms="h2"/>
<property name="json" value="jsonb" dbms="postgresql"/>
<changeSet author="jakubpilimon" id="1.demand_forecasting-init">
<sql>
CREATE SCHEMA demand_forecasting
</sql>
<createTable tableName="product_demand" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="version" type="bigint">
<constraints nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints unique="true"/>
</column>
</createTable>
<createTable tableName="demand" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="value" type="${json}">
<constraints nullable="false"/>
</column>
</createTable>
<addUniqueConstraint
columnNames="ref_no, date"
constraintName="demand_refno_date_unique"
schemaName="demand_forecasting"
tableName="demand"/>
<createTable tableName="current_demand" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="level" type="bigint">
<constraints nullable="false"/>
</column>
<column name="schema" type="varchar(64)">
<constraints nullable="false"/>
</column>
</createTable>
<addUniqueConstraint
columnNames="ref_no, date"
constraintName="cr_demand_refno_date_unique"
schemaName="demand_forecasting"
tableName="current_demand"/>
<createTable tableName="demand_adjustment" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="customer_representative" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="note" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="adjustment" type="${json}">
<constraints nullable="false"/>
</column>
<column name="clean_after" type="timestamp"/>
</createTable>
<createTable tableName="demand_review" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="timestamp" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="review" type="${json}">
<constraints nullable="false"/>
</column>
<column name="decision" type="varchar(64)"/>
<column name="clean_after" type="timestamp"/>
</createTable>
</changeSet>
<changeSet author="jakubpilimon" id="2.rename.review.table">
<renameTable oldTableName="demand_review" newTableName="required_review" schemaName="demand_forecasting"/>
</changeSet>
<changeSet author="jakubpilimon" id="3.create.document.table">
<createTable tableName="document" schemaName="demand_forecasting">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="original_uri" type="varchar(1024)">
<constraints nullable="false"/>
</column>
<column name="stored_uri" type="varchar(1024)">
<constraints nullable="false"/>
</column>
<column name="saved" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="document" type="${json}">
<constraints nullable="false"/>
</column>
<column name="clean_after" type="timestamp"/>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -1,9 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SCHEMA product_management;
CREATE TABLE product_management.product_description (
ref_no character varying(64) NOT NULL PRIMARY KEY,
description json NOT NULL
);

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<property name="json" value="clob" dbms="h2"/>
<property name="json" value="jsonb" dbms="postgresql"/>
<changeSet author="jakubpilimon" id="1.product_management-init">
<sql>
CREATE SCHEMA product_management
</sql>
<createTable tableName="product_description" schemaName="product_management">
<column name="ref_no" type="varchar(64)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="description" type="${json}">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -1,22 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SCHEMA production_planning;
CREATE TABLE production_planning.production_daily_output (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"date" timestamp without time zone NOT NULL,
output bigint NOT NULL,
UNIQUE(ref_no, "date")
);
CREATE TABLE production_planning.production_output (
id serial NOT NULL PRIMARY KEY,
ref_no character varying(64) NOT NULL,
"start" timestamp without time zone NOT NULL,
"end" timestamp without time zone NOT NULL,
duration bigint NOT NULL,
parts_per_minute integer NOT NULL,
total bigint NOT NULL
);

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<property name="json" value="clob" dbms="h2"/>
<property name="json" value="jsonb" dbms="postgresql"/>
<changeSet author="jakubpilimon" id="1.production_planning-init">
<sql>
CREATE SCHEMA production_planning
</sql>
<createTable tableName="production_daily_output" schemaName="production_planning">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="date" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="output" type="bigint">
<constraints nullable="false"/>
</column>
</createTable>
<addUniqueConstraint
columnNames="ref_no, date"
constraintName="pp_output_refno_date_unique"
schemaName="production_planning"
tableName="production_daily_output"/>
<createTable tableName="production_output" schemaName="production_planning">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints nullable="false"/>
</column>
<column name="start" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="end" type="timestamp">
<constraints nullable="false"/>
</column>
<column name="duration" type="bigint">
<constraints nullable="false"/>
</column>
<column name="parts_per_minute" type="integer">
<constraints nullable="false"/>
</column>
<column name="total" type="bigint">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -1,19 +0,0 @@
--liquibase formatted sql
--changeset michaluk.michal:1.init
CREATE SCHEMA shortages_prediction;
CREATE TABLE shortages_prediction.shortage (
id serial NOT NULL PRIMARY KEY,
version bigint NOT NULL,
ref_no character varying(64) NOT NULL,
shortages json NOT NULL,
UNIQUE(ref_no)
);
CREATE TABLE shortages_prediction.stock_forecast (
ref_no character varying(64) NOT NULL PRIMARY KEY
);
--changeset michaluk.michal:2.rename.shortages.column
ALTER TABLE shortages_prediction.shortage RENAME shortages TO shortage;

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<property name="json" value="clob" dbms="h2"/>
<property name="json" value="jsonb" dbms="postgresql"/>
<changeSet author="jakubpilimon" id="1.shortages_prediction-init">
<sql>
CREATE SCHEMA shortages_prediction
</sql>
<createTable tableName="shortage" schemaName="shortages_prediction">
<column name="id" type="serial">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="version" type="bigint">
<constraints nullable="false"/>
</column>
<column name="ref_no" type="varchar(64)">
<constraints unique="true" nullable="false"/>
</column>
<column name="shortages" type="${json}">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="stock_forecast" schemaName="shortages_prediction">
<column name="ref_no" type="varchar(64)">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="jakubpilimon" id="2.rename.shortages.column">
<renameColumn tableName="shortage" oldColumnName="shortages" newColumnName="shortage" schemaName="shortages_prediction"/>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,35 @@
package pl.com.bottega.factory
import pl.com.bottega.factory.demand.forecasting.Demand
import pl.com.bottega.factory.demand.forecasting.Document
import pl.com.bottega.factory.demand.forecasting.persistence.DocumentEntity
import pl.com.bottega.factory.product.management.ProductDescription
import pl.com.bottega.factory.product.management.ProductDescriptionEntity
import java.time.Instant
import java.time.LocalDate
import java.time.OffsetTime
import java.time.ZoneOffset
trait ProductTrait {
DocumentEntity documentFor(String refNo, LocalDate date, long ... levels) {
Document document = document(refNo, date, levels)
return new DocumentEntity("uri", "storedUri", document)
}
ProductDescriptionEntity productDescription(String refNo) {
ProductDescription desc = new ProductDescription("461952398951", ["PROWAD.POJ.NA JARZ.ESSENT"])
return new ProductDescriptionEntity(refNo, desc)
}
Document document(String refNo, LocalDate date, long ... levels) {
Instant created = date.atTime(OffsetTime.of(8, 0, 0, 0, ZoneOffset.UTC)).toInstant()
SortedMap<LocalDate, Demand> results = new TreeMap<>()
for (long level : levels) {
results.put(date, Demand.of(level))
date = date.plusDays(1)
}
new Document(created, refNo, results)
}
}

View File

@@ -0,0 +1,86 @@
package pl.com.bottega.factory.integration
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.ParameterizedTypeReference
import org.springframework.hateoas.Resources
import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
import pl.com.bottega.factory.AppConfiguration
import pl.com.bottega.factory.ProductTrait
import pl.com.bottega.factory.demand.forecasting.persistence.DocumentEntity
import pl.com.bottega.factory.demand.forecasting.projection.CurrentDemandEntity
import pl.com.bottega.factory.product.management.ProductDescriptionEntity
import pl.com.bottega.tools.IntegrationTest
import spock.lang.Specification
import java.time.Clock
import java.time.LocalDate
import java.time.ZoneId
import static java.time.Instant.from
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
@IntegrationTest
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = AppConfiguration)
class CallOffDocumentIntegrationSpec extends Specification implements ProductTrait {
public static final String PRODUCT_REF_NO = "3009000"
public static final LocalDate ANY_DATE = LocalDate.now()
@Autowired TestRestTemplate restTemplate
def 'receiving call off document should create new product demands for subsequent days'() {
given:
productDescriptionIsSuccessfullyCreated(PRODUCT_REF_NO)
when:
callOffDocumentIsSuccessfullyRequested(PRODUCT_REF_NO, ANY_DATE, 100, 200, 300)
and:
Collection<CurrentDemandEntity> demands =
demandsForProductStartingFromDateAreRequested(PRODUCT_REF_NO, ANY_DATE.minusDays(1))
then:
demands.size() == 3
thereIsDemand(demands, ANY_DATE, 100)
thereIsDemand(demands, ANY_DATE.plusDays(1), 200)
thereIsDemand(demands, ANY_DATE.plusDays(2), 300)
}
void productDescriptionIsSuccessfullyCreated(String refNo) {
ResponseEntity response = restTemplate
.postForEntity("/product-descriptions", productDescription(refNo), ProductDescriptionEntity)
assert response.statusCode.is2xxSuccessful()
}
void callOffDocumentIsSuccessfullyRequested(String refNo, LocalDate date, long ... levels) {
ResponseEntity response = restTemplate
.postForEntity("/demand-documents", documentFor(refNo, date, levels), DocumentEntity)
assert response.statusCode.is2xxSuccessful()
}
Collection<CurrentDemandEntity> demandsForProductStartingFromDateAreRequested(String refNo, LocalDate date) {
ResponseEntity<Resources<CurrentDemandEntity>> res = restTemplate
.exchange("/demand-forecasts/search/refNos?refNo={refNo}&date={date}",
HttpMethod.GET,
null,
new ParameterizedTypeReference<Resources<CurrentDemandEntity>>() {},
["refNo": refNo, "date": date])
assert res.statusCode.is2xxSuccessful()
return res.getBody().getContent()
}
void thereIsDemand(Collection<CurrentDemandEntity> demands, LocalDate date, long expectedLevel) {
assert demands.find { it.date == date && it.level == expectedLevel }
}
@Configuration
static class TestConfiguration {
@Bean
Clock clock() {
return Clock.fixed(from(ANY_DATE), ZoneId.systemDefault())
}
}
}

View File

@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.driver-class-name=org.h2.Driver

View File

@@ -3,6 +3,7 @@ package pl.com.bottega.factory.demand.forecasting.command;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.rest.core.annotation.HandleAfterCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
@@ -10,6 +11,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import pl.com.bottega.factory.demand.forecasting.DemandService;
import pl.com.bottega.factory.demand.forecasting.persistence.DocumentEntity;
import java.time.Clock;
import java.time.LocalDate;
@@ -35,6 +37,11 @@ public class CommandsHandler {
service.adjust(adjustment.getAdjustment());
}
@HandleAfterCreate
public void process(DocumentEntity document) {
service.process(document.getDocument());
}
@HandleBeforeSave
public void review(RequiredReviewEntity review) {
if (review.decisionTaken()) {

View File

@@ -0,0 +1,13 @@
package pl.com.bottega.factory.demand.forecasting.persistence;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;
import pl.com.bottega.tools.CommandRepository;
@Repository("documentDao")
@RepositoryRestResource(path = "demand-documents",
collectionResourceRel = "demand-documents",
itemResourceRel = "demand-document")
public interface DocumentDao extends CommandRepository<DocumentEntity, Long> {
}

View File

@@ -0,0 +1,49 @@
package pl.com.bottega.factory.demand.forecasting.persistence;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.LastModifiedDate;
import pl.com.bottega.factory.demand.forecasting.Document;
import pl.com.bottega.tools.JsonConverter;
import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDate;
@Entity(name = "Document")
@Table(schema = "demand_forecasting")
@Getter
@NoArgsConstructor
public class DocumentEntity implements Serializable {
@Id
@GeneratedValue
private Long id;
private String refNo;
@LastModifiedDate
private Instant saved;
private String originalUri;
private String storedUri;
@Setter
@Convert(converter = DocumentAsJson.class)
private Document document;
@Setter
private LocalDate cleanAfter;
public DocumentEntity(String originalUri, String storedUri, Document document) {
saved = Instant.now();
this.originalUri = originalUri;
this.storedUri = storedUri;
this.document = document;
this.refNo = document.getRefNo();
}
public static class DocumentAsJson extends JsonConverter<Document> {
public DocumentAsJson() {
super(Document.class);
}
}
}

View File

@@ -1,7 +1,9 @@
package pl.com.bottega.factory.demand.forecasting.projection;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;
import pl.com.bottega.tools.ProjectionRepository;
@@ -14,7 +16,7 @@ import java.util.List;
itemResourceRel = "demand-forecast")
public interface CurrentDemandDao extends ProjectionRepository<CurrentDemandEntity, Long> {
@RestResource(path = "refNos", rel = "refNos")
List<CurrentDemandEntity> findByRefNoAndDateGreaterThanEqual(String refNo, LocalDate date);
List<CurrentDemandEntity> findByRefNoAndDateGreaterThanEqual(@Param("refNo") String refNo, @Param("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date);
@RestResource(exported = false)
void deleteByRefNoAndDate(String refNo, LocalDate date);

View File

@@ -1,6 +1,6 @@
package pl.com.bottega.factory.demand.forecasting;
import lombok.AllArgsConstructor;
import lombok.Value;
import java.time.Instant;
import java.time.LocalDate;
@@ -9,7 +9,7 @@ import java.util.SortedMap;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@AllArgsConstructor
@Value
public class Document {
private final Instant created;
@@ -27,4 +27,3 @@ public class Document {
return refNo;
}
}