|
1 | 1 | package de.muenchen.oss.dbs.ticketing.eventing.handlercore.adapter.out.zammad;
|
2 | 2 |
|
| 3 | +import de.muenchen.oss.dbs.ticketing.eai.client.api.AttachmentsApi; |
3 | 4 | import de.muenchen.oss.dbs.ticketing.eai.client.api.TicketsApi;
|
4 | 5 | import de.muenchen.oss.dbs.ticketing.eai.client.model.TicketInternal;
|
5 | 6 | import de.muenchen.oss.dbs.ticketing.eventing.handlercore.application.port.out.TicketingOutPort;
|
| 7 | +import java.io.InputStream; |
6 | 8 | import lombok.RequiredArgsConstructor;
|
| 9 | +import org.springframework.core.io.buffer.DataBuffer; |
7 | 10 | import org.springframework.stereotype.Service;
|
8 | 11 | import org.springframework.web.reactive.function.client.WebClientResponseException;
|
9 | 12 |
|
10 | 13 | @Service
|
11 | 14 | @RequiredArgsConstructor
|
12 | 15 | public class ZammadAdapter implements TicketingOutPort {
|
13 | 16 | private final TicketsApi ticketsApi;
|
| 17 | + private final AttachmentsApi attachmentsApi; |
14 | 18 |
|
15 | 19 | @Override
|
16 | 20 | public TicketInternal getTicket(final String ticketId) {
|
17 | 21 | try {
|
18 | 22 | return ticketsApi.getTicketByIdWithUser(ticketId, null, null, null).block();
|
19 | 23 | } 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); |
21 | 38 | }
|
22 | 39 | }
|
23 | 40 | }
|
0 commit comments