-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ (195): Start integrating commons module
- Loading branch information
Manuel Klaus
committed
Dec 22, 2024
1 parent
4864460
commit bb70a13
Showing
28 changed files
with
338 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 29 additions & 31 deletions
60
backend/app.hopps.az-document-ai/src/main/java/app/hopps/DocumentKafkaConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
backend/app.hopps.az-document-ai/src/main/java/app/hopps/model/DocumentImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
backend/app.hopps.az-document-ai/src/main/java/app/hopps/model/DocumentType.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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> | ||
|
||
<parent> | ||
<groupId>app.hopps</groupId> | ||
<artifactId>hopps</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>commons</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
</project> |
10 changes: 10 additions & 0 deletions
10
backend/app.hopps.commons/src/main/java/app/hopps/commons/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.hopps.commons; | ||
|
||
public record Address( | ||
String countryOrRegion, | ||
String postalCode, | ||
String state, | ||
String city, | ||
String road, | ||
String houseNumber) { | ||
} |
5 changes: 5 additions & 0 deletions
5
backend/app.hopps.commons/src/main/java/app/hopps/commons/Data.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package app.hopps.commons; | ||
|
||
public interface Data { | ||
Long referenceKey(); | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/app.hopps.commons/src/main/java/app/hopps/commons/DocumentData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package app.hopps.commons; | ||
|
||
import java.net.URL; | ||
|
||
public record DocumentData(URL internalFinUrl, Long referenceKey, DocumentType type) { | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/app.hopps.commons/src/main/java/app/hopps/commons/DocumentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package app.hopps.commons; | ||
|
||
public enum DocumentType { | ||
RECEIPT, | ||
INVOICE, | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/app.hopps.commons/src/main/java/app/hopps/commons/InvoiceData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package app.hopps.commons; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
public record InvoiceData( | ||
Long referenceKey, | ||
BigDecimal total, | ||
LocalDate invoiceDate, | ||
String currencyCode, | ||
Optional<String> customerName, | ||
Optional<Address> billingAddress, | ||
Optional<String> purchaseOrderNumber, | ||
Optional<String> invoiceId, | ||
Optional<LocalDate> dueDate, | ||
Optional<BigDecimal> subTotal, | ||
Optional<BigDecimal> amountDue) implements Data { | ||
|
||
public InvoiceData(Long referenceKey, BigDecimal total, LocalDate invoiceDate, String currencyCode) { | ||
this(referenceKey, total, invoiceDate, currencyCode, Optional.empty(), Optional.empty(), Optional.empty(), | ||
Optional.empty(), | ||
Optional.empty(), Optional.empty(), Optional.empty()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/app.hopps.commons/src/main/java/app/hopps/commons/ReceiptData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package app.hopps.commons; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
public record ReceiptData( | ||
Long referenceKey, | ||
BigDecimal total, | ||
Optional<BigDecimal> subTotal, | ||
Optional<String> storeName, | ||
Optional<Address> storeAddress, | ||
Optional<LocalDateTime> transactionTime) implements Data { | ||
|
||
public ReceiptData(Long referenceKey, BigDecimal total) { | ||
this(referenceKey, total, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/app.hopps.fin/src/main/java/app/hopps/fin/AbstractDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package app.hopps.fin; | ||
|
||
import app.hopps.commons.Data; | ||
import app.hopps.fin.jpa.TransactionRecordRepository; | ||
import app.hopps.fin.jpa.entities.TransactionRecord; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
|
||
import java.util.Optional; | ||
|
||
@SuppressWarnings("java:S6813") | ||
public abstract class AbstractDataHandler { | ||
@Inject | ||
TransactionRecordRepository repository; | ||
|
||
@Transactional | ||
public void handleData(Data data) { | ||
TransactionRecord transactionRecord = getAndVerify(data.referenceKey()); | ||
|
||
updateData(transactionRecord, data); | ||
repository.persist(transactionRecord); | ||
} | ||
|
||
private TransactionRecord getAndVerify(Long referenceKey) { | ||
Optional<TransactionRecord> optionalTransactionRecord = repository.findByIdOptional(referenceKey); | ||
if (optionalTransactionRecord.isEmpty()) { | ||
throw new IllegalStateException("Reference key is not found!"); | ||
} | ||
return optionalTransactionRecord.get(); | ||
} | ||
|
||
protected abstract void updateData(TransactionRecord transactionRecord, Data data); | ||
} |
37 changes: 0 additions & 37 deletions
37
backend/app.hopps.fin/src/main/java/app/hopps/fin/DataHandler.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
backend/app.hopps.fin/src/main/java/app/hopps/fin/InvoiceDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package app.hopps.fin; | ||
|
||
import app.hopps.commons.Data; | ||
import app.hopps.commons.InvoiceData; | ||
import app.hopps.fin.jpa.entities.TransactionRecord; | ||
import app.hopps.fin.kafka.model.AddressHelper; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import java.time.ZoneId; | ||
|
||
@ApplicationScoped | ||
@SuppressWarnings("java:S3740") | ||
public class InvoiceDataHandler extends AbstractDataHandler { | ||
@Override | ||
protected void updateData(TransactionRecord transactionRecord, Data data) { | ||
if (data instanceof InvoiceData invoiceData) { | ||
handleInvoice(transactionRecord, invoiceData); | ||
} | ||
} | ||
|
||
private void handleInvoice(TransactionRecord transactionRecord, InvoiceData data) { | ||
transactionRecord.setTotal(data.total()); | ||
|
||
// Required | ||
transactionRecord.setTransactionTime(data.invoiceDate().atStartOfDay(ZoneId.systemDefault()).toInstant()); | ||
transactionRecord.setCurrencyCode(data.currencyCode()); | ||
|
||
// Optional | ||
data.customerName().ifPresent(transactionRecord::setName); | ||
data.billingAddress().ifPresent(address -> transactionRecord.setAddress(AddressHelper.convertToJpa(address))); | ||
data.purchaseOrderNumber().ifPresent(transactionRecord::setOrderNumber); | ||
data.invoiceId().ifPresent(transactionRecord::setInvoiceId); | ||
data.dueDate() | ||
.ifPresent( | ||
dueDate -> transactionRecord | ||
.setDueDate(dueDate.atStartOfDay(ZoneId.systemDefault()).toInstant())); | ||
data.subTotal().ifPresent(transactionRecord::setSubTotal); | ||
data.amountDue().ifPresent(transactionRecord::setAmountDue); | ||
} | ||
} |
Oops, something went wrong.