Skip to content

Commit bc44f56

Browse files
committed
missing bean definition
1 parent 3a4401b commit bc44f56

3 files changed

Lines changed: 99 additions & 57 deletions

File tree

artcoded/src/main/java/tech/artcoded/websitev2/pages/fee/camel/FeeRouteBuilder.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package tech.artcoded.websitev2.pages.fee.camel;
22

3-
import lombok.Setter;
3+
import static org.apache.camel.ExchangePattern.InOnly;
4+
import static tech.artcoded.websitev2.utils.common.Constants.NOTIFICATION_ENDPOINT;
5+
import static tech.artcoded.websitev2.utils.common.Constants.NOTIFICATION_HEADER_TITLE;
6+
import static tech.artcoded.websitev2.utils.common.Constants.NOTIFICATION_HEADER_TYPE;
7+
48
import org.apache.camel.builder.RouteBuilder;
59
import org.apache.camel.component.mail.ContentTypeResolver;
610
import org.apache.camel.component.mail.MailComponent;
711
import org.apache.camel.component.mail.MailConfiguration;
812
import org.springframework.beans.factory.annotation.Value;
913
import org.springframework.stereotype.Component;
14+
15+
import lombok.Setter;
1016
import tech.artcoded.websitev2.camel.mail.Mail;
1117
import tech.artcoded.websitev2.camel.mail.MailTransformer;
1218
import tech.artcoded.websitev2.pages.fee.Fee;
1319
import tech.artcoded.websitev2.pages.fee.FeeService;
1420

15-
import static org.apache.camel.ExchangePattern.InOnly;
16-
import static tech.artcoded.websitev2.utils.common.Constants.*;
17-
1821
@Component
1922
public class FeeRouteBuilder extends RouteBuilder {
2023

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package tech.artcoded.websitev2.peppol;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
import org.apache.camel.spi.IdempotentRepository;
5+
import org.apache.camel.support.processor.idempotent.FileIdempotentRepository;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.nio.file.Files;
12+
import java.util.Date;
13+
import java.util.List;
14+
15+
import org.apache.camel.Body;
16+
import org.apache.camel.Exchange;
17+
import org.apache.camel.Header;
18+
import org.springframework.beans.factory.annotation.Value;
19+
20+
import lombok.SneakyThrows;
21+
import tech.artcoded.websitev2.pages.fee.FeeService;
22+
import tech.artcoded.websitev2.pages.invoice.InvoiceGenerationRepository;
23+
import tech.artcoded.websitev2.rest.util.MockMultipartFile;
24+
25+
@Configuration
26+
public class PeppolRouteBuilder extends RouteBuilder {
27+
@Value("${application.upload.pathToPeppolExpenditure}")
28+
private String pathToPeppolExpenditure;
29+
30+
@Value("${application.upload.pathToPeppolInvoice}")
31+
private String pathToPeppolInvoice;
32+
33+
@Value("${application.upload.pathToPeppolFTP}")
34+
private String pathToPeppolFTP;
35+
36+
private final FeeService feeService;
37+
private final InvoiceGenerationRepository invoiceRepository;
38+
39+
public PeppolRouteBuilder(
40+
FeeService feeService,
41+
InvoiceGenerationRepository invoiceRepository) {
42+
this.invoiceRepository = invoiceRepository;
43+
this.feeService = feeService;
44+
}
45+
46+
@Bean("invoiceIdempotentRepository")
47+
public IdempotentRepository fileIdempotentRepository() {
48+
return FileIdempotentRepository.fileIdempotentRepository(new java.io.File(pathToPeppolFTP, "invoice_idempot"));
49+
}
50+
51+
void updatePeppolStatus(@Header(Exchange.FILE_NAME) String fileName) throws IOException {
52+
var invoiceId = fileName.replace(".xml", "");
53+
invoiceRepository.findById(invoiceId).map(i -> i.toBuilder().peppolStatus(PeppolStatus.SUCCESS).build())
54+
.ifPresentOrElse(invoiceRepository::save,
55+
() -> log.error(fileName + ": cannot extract invoice id or invoice doesn't exist."));
56+
57+
}
58+
59+
@SneakyThrows
60+
void pushFee(@Body File file, @Header(Exchange.FILE_NAME) String fileName,
61+
@Header(Exchange.FILE_CONTENT_TYPE) String contentType) {
62+
63+
this.feeService.save("[PEPPOL]: " + fileName, "New peppol expense", new Date(), List.of(MockMultipartFile.builder()
64+
.originalFilename(fileName)
65+
.contentType(contentType)
66+
.name(fileName)
67+
.bytes(Files.readAllBytes(file.toPath()))
68+
.build()));
69+
70+
}
71+
72+
@Override
73+
public void configure() throws Exception {
74+
onException(Exception.class)
75+
.handled(true)
76+
.transform().simple("Exception occurred due: ${exception.message}")
77+
.log("${body}");
78+
79+
from("file:%s/success?noop=true&idempotent=true&idempotentRepository=#invoiceIdempotentRepository"
80+
.formatted(pathToPeppolInvoice))
81+
.routeId("Peppol::UpdateProcessedInvoices")
82+
.log("receiving file '${headers.%s}', will update peppol status".formatted(Exchange.FILE_NAME))
83+
.bean(() -> this, "updatePeppolStatus");
84+
85+
from("file:" + pathToPeppolExpenditure)
86+
.routeId("Peppol::PeppolExpenseToFee")
87+
.log("receiving file '${headers.%s}', will convert it to fee".formatted(Exchange.FILE_NAME))
88+
.bean(() -> this, "pushFee");
89+
}
90+
91+
}
Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
package tech.artcoded.websitev2.peppol;
22

33
import java.io.File;
4-
import java.io.IOException;
54
import java.nio.file.Files;
6-
import java.util.Date;
7-
import java.util.List;
8-
9-
import org.apache.camel.Body;
10-
import org.apache.camel.Exchange;
11-
import org.apache.camel.Header;
12-
import org.apache.camel.builder.RouteBuilder;
135
import org.springframework.beans.factory.annotation.Value;
146
import org.springframework.stereotype.Service;
157

168
import lombok.SneakyThrows;
179
import lombok.extern.slf4j.Slf4j;
18-
import tech.artcoded.websitev2.pages.fee.FeeService;
1910
import tech.artcoded.websitev2.pages.invoice.InvoiceGeneration;
2011
import tech.artcoded.websitev2.pages.invoice.InvoiceGenerationRepository;
21-
import tech.artcoded.websitev2.rest.util.MockMultipartFile;
2212
import tech.artcoded.websitev2.upload.FileUploadService;
2313

2414
@Service
2515
@Slf4j
26-
public class PeppolService extends RouteBuilder {
16+
public class PeppolService {
2717

2818
@Value("${application.upload.pathToPeppolExpenditure}")
2919
private String pathToPeppolExpenditure;
@@ -32,15 +22,12 @@ public class PeppolService extends RouteBuilder {
3222
private String pathToPeppolInvoice;
3323

3424
private final FileUploadService uploadService;
35-
private final FeeService feeService;
3625
private final InvoiceGenerationRepository invoiceRepository;
3726

3827
public PeppolService(FileUploadService uploadService,
39-
FeeService feeService,
4028
InvoiceGenerationRepository invoiceRepository) {
4129
this.uploadService = uploadService;
4230
this.invoiceRepository = invoiceRepository;
43-
this.feeService = feeService;
4431
}
4532

4633
@SneakyThrows
@@ -58,43 +45,4 @@ public void addInvoice(InvoiceGeneration invoice) {
5845
.ifPresent(invoiceRepository::save);
5946
}
6047

61-
void updatePeppolStatus(@Header(Exchange.FILE_NAME) String fileName) throws IOException {
62-
var invoiceId = fileName.replace(".xml", "");
63-
invoiceRepository.findById(invoiceId).map(i -> i.toBuilder().peppolStatus(PeppolStatus.SUCCESS).build())
64-
.ifPresentOrElse(invoiceRepository::save,
65-
() -> log.error(fileName + ": cannot extract invoice id or invoice doesn't exist."));
66-
67-
}
68-
69-
@SneakyThrows
70-
void pushFee(@Body File file, @Header(Exchange.FILE_NAME) String fileName,
71-
@Header(Exchange.FILE_CONTENT_TYPE) String contentType) {
72-
73-
this.feeService.save("[PEPPOL]: " + fileName, "New peppol expense", new Date(), List.of(MockMultipartFile.builder()
74-
.originalFilename(fileName)
75-
.contentType(contentType)
76-
.name(fileName)
77-
.bytes(Files.readAllBytes(file.toPath()))
78-
.build()));
79-
80-
}
81-
82-
@Override
83-
public void configure() throws Exception {
84-
onException(Exception.class)
85-
.handled(true)
86-
.transform().simple("Exception occurred due: ${exception.message}")
87-
.log("${body}");
88-
89-
from("file:%s/success?noop=true&idempotent=true&idempotentRepository=#fileIdempotentRepository"
90-
.formatted(pathToPeppolInvoice))
91-
.routeId("Peppol::UpdateProcessedInvoices")
92-
.log("receiving file '${headers.%s}', will update peppol status".formatted(Exchange.FILE_NAME))
93-
.bean(() -> this, "updatePeppolStatus");
94-
95-
from("file:" + pathToPeppolExpenditure)
96-
.routeId("Peppol::PeppolExpenseToFee")
97-
.log("receiving file '${headers.%s}', will convert it to fee".formatted(Exchange.FILE_NAME))
98-
.bean(() -> this, "pushFee");
99-
}
10048
}

0 commit comments

Comments
 (0)