Skip to content

Commit

Permalink
🐛 (#195): fix PR requests (#225)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Klaus <[email protected]>
  • Loading branch information
3thr3n and Manuel Klaus authored Dec 30, 2024
1 parent 9108a38 commit 52ae33f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public FinRestClientImpl(URL path) throws URISyntaxException {
.build(FinRestClient.class);
}

/**
* @param accessToken
* without "Bearer "
*
* @return document in byte array
*/
public byte[] getDocumentBase64(String accessToken) {
try (InputStream document = getDocument(accessToken)) {
return document.readAllBytes();
Expand All @@ -24,7 +30,7 @@ public byte[] getDocumentBase64(String accessToken) {
}
}

public InputStream getDocument(String accessToken) {
private InputStream getDocument(String accessToken) {
return restClient.getDocument("Bearer " + accessToken);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@TestSecurity(authorizationEnabled = false)
@TestHTTPEndpoint(DocumentResource.class)
class DocumentResourceTest {
private static final String IMAGE_KEY = "imageKey";

@Inject
Flyway flyway;

Expand All @@ -42,7 +44,7 @@ void setup() {
byte[] byteArray = IOUtils.toByteArray(zugferdInputStream);

s3Client.putObject(PutObjectRequest.builder()
.key("imageKey")
.key(IMAGE_KEY)
.bucket(bucketName)
.build(), RequestBody.fromBytes(byteArray));
} catch (Exception ignored) {
Expand All @@ -63,7 +65,7 @@ void shouldNotGetFile() {
void shouldGetFile() {
given()
.when()
.get("{documentKey}", "imageKey")
.get("{documentKey}", IMAGE_KEY)
.then()
.statusCode(Response.Status.OK.getStatusCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public KafkaConnector(ZugFerdService zugFerdService, @Channel("document-data-out

@Incoming("document-data-in")
public void process(DocumentData documentData) throws URISyntaxException {
LOG.info("Received new document data");
LOG.info("{}: Received new document data", documentData.referenceKey());
FinRestClientImpl restClient = new FinRestClientImpl(documentData.internalFinUrl());

String accessToken = tokensHelper.getTokens(oidcClient).await().atMost(Duration.ofSeconds(3)).getAccessToken();
// Process the incoming message payload and return an updated payload
try (InputStream invoice = restClient.getDocument(accessToken)) {
LOG.info("Document successful downloaded");
LOG.info("{}: Document successful downloaded", documentData.referenceKey());
InvoiceData invoiceData = zugFerdService.scanInvoice(documentData.referenceKey(), invoice);
LOG.info("Invoice scanned");
LOG.info("{}: Invoice scanned", documentData.referenceKey());
emitter.send(invoiceData);
LOG.info("Invoice sent");
LOG.info("{}: Invoice sent", documentData.referenceKey());
} catch (Exception e) {
LOG.error("Could not fetch or process document", e);
LOG.error("{}: Could not fetch or process document", documentData.referenceKey(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public FinRestClientImpl(URL path) throws URISyntaxException {
.build(FinRestClient.class);
}

/**
* @param accessToken
* without "Bearer "
*
* @return document
*/
public InputStream getDocument(String accessToken) {
return restClient.getDocument("Bearer " + accessToken);
}
Expand Down

0 comments on commit 52ae33f

Please sign in to comment.