Invoice import modified with existing partner lookup
authorelgekko <vasary@elgekko.net>
Tue, 19 Sep 2023 08:04:54 +0000 (10:04 +0200)
committerelgekko <vasary@elgekko.net>
Tue, 19 Sep 2023 08:04:54 +0000 (10:04 +0200)
lis-app/src/main/resources/logback-spring.xml
lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql
lis-db/migrations/scripts/004_create_test_data.sql
lis-db/migrations/scripts/005_create_profile.sql
lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql [new file with mode: 0644]
lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql [new file with mode: 0644]
lis-db/src/main/java/hu/user/lis/db/Partner.java
lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepository.java
lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java
lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java
lis-workflow/src/main/java/hu/user/lis/workflow/invoice/DownloadInvoiceData.java

index cf0a9f0571ab73fb287b21a5f62866afb26cc7e0..99f82ffc55906517ea57d3060ef8db7b9ef5bdc3 100644 (file)
 
     <!-- LOG everything at INFO level -->
     <root level="info">
-        <appender-ref ref="RollingFile"/>
+        <!--        <appender-ref ref="RollingFile"/>-->
         <appender-ref ref="Console"/>
     </root>
 
     <!-- LOG "com.baeldung*" at TRACE level -->
     <logger name="hu.user.lis" level="trace" additivity="false">
-        <appender-ref ref="RollingFile"/>
+        <!--        <appender-ref ref="RollingFile"/>-->
         <appender-ref ref="Console"/>
     </logger>
 
index bd50d37f9b47da0aef8b7e64b4a58e0a435c3fc7..cb8b83f34ae66c13ef1fb40bb700ccf836111ab8 100644 (file)
@@ -1,12 +1,10 @@
 -- // add_remotely_authenticated_to_associate
 -- Migration SQL that makes the change goes here.
 
-ALTER TABLE associate
-    ADD COLUMN remotely_authenticated SMALLINT NOT NULL DEFAULT 0;
+ALTER TABLE ASSOCIATE ADD COLUMN remotely_authenticated SMALLINT NOT NULL DEFAULT 0;
 
 -- //@UNDO
 -- SQL to undo the change goes here.
 
-ALTER TABLE associate
-    DROP COLUMN remotely_authenticated;
+ALTER TABLE ASSOCIATE DROP COLUMN remotely_authenticated;
 
index 0da1d67e859202edb2f975e0e4e9a405910f0706..ba552bc0b221390b3863f3524874fb062793dfb7 100644 (file)
@@ -7,19 +7,19 @@ VALUES
     ('Test User', 'user', 'password', 1, 1);
 
 INSERT INTO PARTNER
-    (ID, NAME, VAT_NR, ACTIVE)
+    (id, name, vat_nr, active)
 VALUES
     (1, 'NYÍRŐ', '00000000-00-0', 1),
     (2, 'KOLOS', '00000000-00-0', 1);
 
 
 INSERT INTO PROJECT_STATUS
-    (ID, NAME, ACTIVE, "ORDER")
+    (id, name, active, "ORDER")
 VALUES
     (1, 'START', 1, 1);
 
 INSERT INTO PROJECT
-    (ID, PROJECT_STATUS_ID, NAME, HUMAN_ID, CONTACT_NAME, PARTNER_ID, ACTIVE)
+    (id, project_status_id, name, human_id, contact_name, partner_id, active)
 VALUES
     (1, 1, 'Halászat', '2023-0001', 'Kovács', 1, 1);
 
index cfc8ed2b09fdd0d77cd5bfc748cab0664d6dc9fc..d89efa8d84aba7786d08db90f354bb5c9ca9cc9e 100644 (file)
@@ -1,16 +1,16 @@
 -- // create profile
 -- Migration SQL that makes the change goes here.
 
-CREATE TABLE profile (
+CREATE TABLE PROFILE (
     id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
     login VARCHAR(255),
     type VARCHAR(255),
     setting CLOB,
     CONSTRAINT pk_profile PRIMARY KEY (id)
 );
-CREATE UNIQUE INDEX UDX_PROFILE_LOGIN_TYPE ON PROFILE(LOGIN, TYPE);
+CREATE UNIQUE INDEX UDX_PROFILE_LOGIN_TYPE ON PROFILE(login, type);
 
 -- //@UNDO
 -- SQL to undo the change goes here.
-DROP TABLE profile;
+DROP TABLE PROFILE;
 
diff --git a/lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql b/lis-db/migrations/scripts/008_add_unique_index_to_partner_vatnr.sql
new file mode 100644 (file)
index 0000000..161472c
--- /dev/null
@@ -0,0 +1,9 @@
+-- // add unique index to partner vatnr
+-- Migration SQL that makes the change goes here.
+
+CREATE UNIQUE INDEX UX_PARTNER_VAT_NR ON PARTNER(vat_nr);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+DROP INDEX UX_PARTNER_VAT_NR;
diff --git a/lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql b/lis-db/migrations/scripts/009_add_partner_for_invoice_import_test.sql
new file mode 100644 (file)
index 0000000..b9e0435
--- /dev/null
@@ -0,0 +1,10 @@
+-- // add partner for invoice import test
+-- Migration SQL that makes the change goes here.
+
+INSERT INTO PARTNER(name, vat_nr, address, active)
+VALUES('Értékesítő Kft', '99999999-2-41', '1234 Budapest, Hármas utca 1', 1);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+DELETE FROM PARTNER WHERE name = 'Értékesítő Kft';
index 4e3e5dc5c6cfa9b5f98ace72b11cb0ed8c2d9d9f..7bce08c89a71c08cf2406c9966a4f10da60b5523 100644 (file)
@@ -2,10 +2,7 @@ package hu.user.lis.db;
 
 import lombok.*;
 
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
+import javax.persistence.*;
 import java.io.Serializable;
 
 @Getter
@@ -19,6 +16,7 @@ public class Partner implements Serializable {
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     Long id;
     String name;
+    @Column(unique = true)
     String vatNr;
     String address;
     boolean active;
index 9104831bb91563251e17d2c39a94497bc93d60a6..daabdb68af015b4dfc13bb5b76c75c8a1a417916 100644 (file)
@@ -3,5 +3,10 @@ package hu.user.lis.db.repository;
 import hu.user.lis.db.Partner;
 import org.springframework.data.jpa.repository.JpaRepository;
 
+import java.util.Optional;
+
 public interface PartnerRepository extends JpaRepository<Partner, Long>, PartnerRepositorySearch {
+
+    Optional<Partner> findByVatNr(String vatNr);
+
 }
index 9e07be70cb485e951f5ca5e4abc6cc901c5138de..b7dc072ef9981cb1f4f6619f40ec9b80bb7f5f07 100644 (file)
@@ -8,5 +8,5 @@ import java.util.List;
 public interface PartnerRepositorySearch {
     List<Partner> search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable);
 
-    long count(String ppartialSearch, boolean filterShowActive, boolean filterShowInActive);
+    long count(String partialSearch, boolean filterShowActive, boolean filterShowInActive);
 }
index f8cbc29793063dcddd63545bc5465d0b707a088c..27fac65b4f8d96a6bd6aa82931467c4b1c99f534 100644 (file)
@@ -29,25 +29,27 @@ public class EventBus {
         return EventQueues.lookup(Constants.BINDING_QUEUE, EventQueues.DESKTOP, true);
     }
 
-    public void register(EventListener listener) {
+    public void register(EventListener<Event> listener) {
         getQueue().subscribe(listener);
     }
 
-    public void registerForBinding(EventListener listener) {
+    public void registerForBinding(EventListener<Event> listener) {
         getBindingQueue().subscribe(listener);
     }
 
-    public void registerForProcessEvent(EventListener listener) {
+    public void registerForProcessEvent(EventListener<Event> listener) {
         getProcessEventQueue().subscribe(listener);
     }
 
-    public void unregister(EventListener listener) {
+    public void unregister(EventListener<Event> listener) {
         try {
             getQueue().unsubscribe(listener);
             getBindingQueue().unsubscribe(listener);
-            getProcessEventQueue().unsubscribe(listener);
-        } catch (Exception e) {
-//            log.warn("Not necessary to unregister");
+            EventQueue<Event> processEventQueue = getProcessEventQueue();
+            if (Objects.nonNull(processEventQueue)) {
+                processEventQueue.unsubscribe(listener);
+            }
+        } catch (Exception ignored) {
         }
     }
 
index 88bedc0ce245488188b34fd7913fff8a52de3265..3a52917ad2226a54af3767dd304e95f4e2fc01c4 100644 (file)
@@ -1,7 +1,8 @@
 package hu.user.lis.workflow.invoice;
 
 import hu.user.lis.db.IncomingInvoice;
-import hu.user.lis.db.repository.InvoiceRepository;
+import hu.user.lis.db.Partner;
+import hu.user.lis.db.repository.PartnerRepository;
 import hu.user.lis.workflow.invoice.service.IncomingInvoiceFetcherService;
 import lombok.extern.log4j.Log4j2;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
@@ -10,22 +11,25 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.nio.file.Paths;
+import java.util.Optional;
 
 @Log4j2
 @Component
 public class DownloadInvoiceData implements JavaDelegate {
+
     @Autowired
-    InvoiceRepository invoiceRepository;
+    PartnerRepository partnerRepository;
 
     @Autowired
     IncomingInvoiceFetcherService incomingInvoiceFetcherService;
 
-
     @Override
     public void execute(DelegateExecution delegateExecution) throws Exception {
         String invoiceId = (String) delegateExecution.getVariable("invoice");
         log.info("Processing invoice {}", invoiceId);
         IncomingInvoice invoice = incomingInvoiceFetcherService.getInvoiceFromPath(Paths.get(invoiceId));
+        Optional<Partner> partnerEntity = partnerRepository.findByVatNr(invoice.getPartner().getVatNr());
+        partnerEntity.ifPresent(invoice::setPartner);
         delegateExecution.setVariableLocal("invoiceEntity", invoice);
         log.info("Invoice {} processed", invoiceId);
     }