Commit 9045a4d2 authored by Thomas Lang's avatar Thomas Lang
Browse files

added data seeding

parent c9c109e4
......@@ -3,9 +3,8 @@ Link here:
https://jira.spring.io/browse/DATAJPA-1225
## Install:
Please use the database dump included in `resources/static/`
This is named `spring-data-jpa-1225`
Please note that this is a postgres dump
The Runner installs a database every run.
It seeds one invoice for test.
## How to reproduce:
Let the project run.
......
package de.thd.bugs.report;
import de.thd.bugs.report.model.Invoice;
import de.thd.bugs.report.model.InvoiceProjection;
import de.thd.bugs.report.model.InvoiceState;
import de.thd.bugs.report.service.InvoiceService;
......@@ -49,7 +50,13 @@ public class ReportApplication extends AsyncConfigurerSupport implements Command
@Override
public void run(String... strings) throws InterruptedException, ExecutionException {
log.error("Calling method ... ");
log.error("first, let´s seed a test invoice ... ");
final Future<String> invoice = invoiceService.invoiceInvoice(Invoice.makeTestInvoice());
while (!invoice.isDone()) {
Thread.sleep(100);
}
log.error("then do the select ...");
final Future<Iterable<InvoiceProjection>> invoices = invoiceService.findAllProjectedByUserAndApiGroupsAndInvoiceState("tlang", "%tlang%|%Seminare%", InvoiceState.Invoiced);
while (!invoices.isDone()) {
Thread.sleep(100);
......
......@@ -107,6 +107,36 @@ public class Biller implements java.io.Serializable {
this.information = new Information();
}
private Biller(Campus billerCampus, String billerSalutation, String biller, String billerContactPerson,
String billerContactDetails, String billerStreet, String billerBox, String billerPostalcode,
String billerCity, String billerCountry, String billerWeb) {
this();
this.billerCampus = billerCampus;
this.billerSalutation = billerSalutation;
this.biller = biller;
this.billerContactPerson = billerContactPerson;
this.billerContactDetails = billerContactDetails;
this.billerStreet = billerStreet;
this.billerBox = billerBox;
this.billerPostalcode = billerPostalcode;
this.billerCity = billerCity;
this.billerCountry = billerCountry;
this.billerWeb = billerWeb;
}
/**
* Make a test biller.
*
* @return Biller
*/
public static Biller makeTestBiller() {
Biller biller = new Biller(Campus.THD, "Fa", "Test", "Herr Thomas Test",
"test@test.com", "Testgasse 22", "", "64567", "Test",
"Test", "www.test.com");
biller.getInformation().setCreatedBy("tlang");
biller.getInformation().setModifiedBy("tlang");
return biller;
}
/**
* Compares this instance with another instance of this.
......
......@@ -149,6 +149,77 @@ public class Invoice implements java.io.Serializable {
this.serviceDateUntil = LocalDate.now();
}
/**
* Helper constructor.
* Builds a new invoice to be saved later.
*
* @param bookingTag a given booking tag
* @param invoiceNumber a given invoice number
* @param invoiceMemo a given invoice memo
* @param invoiceDate a given invoice date
* @param serviceDateFrom a given service date from
* @param serviceDateUntil a given service date until
* @param accountingConnection given accounting connecting
* @param paymentTerms given payment terms
* @param taxId given tax id
* @param salesTaxId given sales tax id
* @param lineItemSet a given line set
* @param invoiceProtocolSet a given invoice protocol set
* @param invoiceApiGroups given invcoice api groups
* @param invoiceState a given invoice state
* @param recipient a given recipient
* @param biller a given biller
*/
private Invoice(String bookingTag, String invoiceNumber, String invoiceMemo, LocalDate invoiceDate, LocalDate serviceDateFrom,
LocalDate serviceDateUntil, String accountingConnection, String paymentTerms, String taxId,
String salesTaxId, Set<LineItem> lineItemSet, Set<InvoiceProtocol> invoiceProtocolSet,
String invoiceApiGroups, InvoiceState invoiceState, Recipient recipient, Biller biller) {
this();
this.bookingTag = bookingTag;
this.invoiceNumber = invoiceNumber;
this.invoiceMemo = invoiceMemo;
this.invoiceDate = invoiceDate;
this.serviceDateFrom = serviceDateFrom;
this.serviceDateUntil = serviceDateUntil;
this.accountingConnection = accountingConnection;
this.paymentTerms = paymentTerms;
this.taxId = taxId;
this.salesTaxId = salesTaxId;
this.lineItemSet = lineItemSet;
this.invoiceProtocolSet = invoiceProtocolSet;
this.invoiceApiGroups = invoiceApiGroups;
this.invoiceState = invoiceState;
this.recipient = recipient;
this.biller = biller;
this.information.setCreatedBy("tlang");
this.information.setModifiedBy("tlang");
}
/**
* Makes a test invoice.
*
* @return Invoice
*/
public static Invoice makeTestInvoice() {
Invoice test = new Invoice("1546.784.5122", "0001-2017", "Testrechnung",
LocalDate.now(), LocalDate.now().minusDays(2), LocalDate.now().minusDays(1),
"Kontoverbindung: 123", "Einige Zahlungsmodalitäten",
"Steuer ID Nummer", "UST ID Nummer", null, null,
"tlang, Seminare", InvoiceState.Invoiced, null, null);
test.lineItemSet = new HashSet<>();
test.lineItemSet.add(LineItem.makeTestLineItem());
test.lineItemSet.forEach(s -> s.setInvoice(test));
test.setBiller(Biller.makeTestBiller());
test.getBiller().getInvoiceSet().add(test);
test.setRecipient(Recipient.makeTestRecipient());
test.getRecipient().getInvoiceSet().add(test);
return test;
}
/**
* Compares this instance with another instance of this.
......
......@@ -110,7 +110,7 @@ public class LineItem implements java.io.Serializable {
*/
public LineItem(int lineItemNumber, @NonNull BigDecimal lineItemQuantity, @NonNull String lineItemUnit,
@NonNull String lineItemText, @NonNull BigDecimal lineItemUnitPrice, int bettermentTaxRate,
@NonNull Invoice invoice) {
Invoice invoice) {
this();
this.lineItemNumber = lineItemNumber;
this.lineItemQuantity = lineItemQuantity;
......@@ -132,6 +132,15 @@ public class LineItem implements java.io.Serializable {
lineItem.getLineItemText(), lineItem.lineItemUnitPrice, lineItem.getBettermentTaxRate(), lineItem.getInvoice());
}
/**
* Makes a test line item.
*
* @return LineItem
*/
public static LineItem makeTestLineItem() {
return new LineItem(1, BigDecimal.ONE, "Einheit", "Test", BigDecimal.TEN, 19, null);
}
/**
* Compares this instance with another instance of this.
*
......
......@@ -123,8 +123,8 @@ public class Recipient implements java.io.Serializable {
this.recipientCity = recipientCity;
this.recipientCountry = recipientCountry;
this.recipientWeb = recipientWeb;
this.information.setCreatedBy(information.getCreatedBy());
this.information.setModifiedBy(information.getModifiedBy());
this.information.setCreatedBy("tlang");
this.information.setModifiedBy("tlang");
}
/**
......@@ -140,6 +140,16 @@ public class Recipient implements java.io.Serializable {
recipient.getRecipientCountry(), recipient.getRecipientWeb(), recipient.getInformation());
}
/**
* Makes a test recipient.
*
* @return Recipient
*/
public static Recipient makeTestRecipient() {
return new Recipient("Fa", "Test", "Test", "Gasse 123", "",
"55555", "Teststadt", "Deutschland", "www.rechnung.de", new Information());
}
/**
* Compares this instance with another instance of this.
*
......
package de.thd.bugs.report.service;
import de.thd.bugs.report.model.Invoice;
import de.thd.bugs.report.model.InvoiceProjection;
import de.thd.bugs.report.model.InvoiceState;
import lombok.NonNull;
import org.springframework.scheduling.annotation.Async;
import java.util.concurrent.Future;
......@@ -16,6 +18,18 @@ import java.util.concurrent.Future;
*/
public interface IInvoiceService {
/**
* Creates a new invoice.
*
* @param invoice a given new invoice.
* @throws Exception a given exception
*/
@Async
Future<String> invoiceInvoice(@NonNull Invoice invoice) throws Exception;
/**
* Finds all invoices projected by the needed values.
*
......
package de.thd.bugs.report.service;
import de.thd.bugs.report.model.Invoice;
import de.thd.bugs.report.model.InvoiceProjection;
import de.thd.bugs.report.model.InvoiceState;
import lombok.NonNull;
......@@ -33,6 +34,18 @@ public class InvoiceService implements IInvoiceService {
@NonNull
IInvoiceRepository invoiceRepository;
/**
* Creates a new invoice.
*
* @param invoice a given new invoice.
* @throws Exception a given exception
*/
@Override
@Async
public Future<String> invoiceInvoice(Invoice invoice) {
return new AsyncResult(invoiceRepository.save(Invoice.makeTestInvoice()));
}
/**
* Finds all invoices projected by the needed values.
*
......
......@@ -37,7 +37,7 @@ spring.datasource.username=postgres
spring.datasource.password=admin
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#spring.jpa.properties.hibernate.id.new_generator_mappings=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=create-drop
#sequence generation
spring.jpa.properties.hibernate.id.new_generator_mappings=true
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment