<!-- 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>
-- // 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;
('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);
-- // 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;
--- /dev/null
+-- // 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;
--- /dev/null
+-- // 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';
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
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
String name;
+ @Column(unique = true)
String vatNr;
String address;
boolean active;
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);
+
}
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);
}
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) {
}
}
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;
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);
}