Skip to content

Commit 2affa0a

Browse files
committed
chore(ticketing-eai/handler-core): add attachment download
1 parent e65a3e1 commit 2affa0a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
package de.muenchen.oss.dbs.ticketing.eventing.handlercore.adapter.out.zammad;
22

3+
import de.muenchen.oss.dbs.ticketing.eai.client.api.AttachmentsApi;
34
import de.muenchen.oss.dbs.ticketing.eai.client.api.TicketsApi;
45
import de.muenchen.oss.dbs.ticketing.eai.client.model.TicketInternal;
56
import de.muenchen.oss.dbs.ticketing.eventing.handlercore.application.port.out.TicketingOutPort;
7+
import java.io.InputStream;
68
import lombok.RequiredArgsConstructor;
9+
import org.springframework.core.io.buffer.DataBuffer;
710
import org.springframework.stereotype.Service;
811
import org.springframework.web.reactive.function.client.WebClientResponseException;
912

1013
@Service
1114
@RequiredArgsConstructor
1215
public class ZammadAdapter implements TicketingOutPort {
1316
private final TicketsApi ticketsApi;
17+
private final AttachmentsApi attachmentsApi;
1418

1519
@Override
1620
public TicketInternal getTicket(final String ticketId) {
1721
try {
1822
return ticketsApi.getTicketByIdWithUser(ticketId, null, null, null).block();
1923
} catch (final WebClientResponseException e) {
20-
throw new ZammadApiException("Getting ticket with id %s failed".formatted(ticketId), e);
24+
throw new ZammadApiException("Getting ticket with id %s failed: %s"
25+
.formatted(ticketId, e.getResponseBodyAsString()), e);
26+
}
27+
}
28+
29+
@Override
30+
public InputStream getAttachmentContent(final String ticketId, final String articleId, final String attachmentId) {
31+
try {
32+
final DataBuffer response = attachmentsApi.getAttachmentWithResponseSpec(ticketId, articleId, attachmentId).bodyToMono(DataBuffer.class).block();
33+
assert response != null;
34+
return response.asInputStream();
35+
} catch (final WebClientResponseException e) {
36+
throw new ZammadApiException("Getting attachment with id %s failed: %s"
37+
.formatted(attachmentId, e.getResponseBodyAsString()), e);
2138
}
2239
}
2340
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package de.muenchen.oss.dbs.ticketing.eventing.handlercore.application.port.out;
22

33
import de.muenchen.oss.dbs.ticketing.eai.client.model.TicketInternal;
4+
import java.io.InputStream;
45

56
public interface TicketingOutPort {
67
TicketInternal getTicket(String ticketId);
8+
9+
InputStream getAttachmentContent(String ticketId, String articleId, String attachmentId);
710
}

0 commit comments

Comments
 (0)