Skip to content
Snippets Groups Projects
Commit beec6d70 authored by OZGCloud's avatar OZGCloud
Browse files

WIP: OZG-6275 added more todos

parent cb77738f
Branches
Tags
No related merge requests found
......@@ -24,14 +24,15 @@ package de.ozgcloud.nachrichten.postfach.muk.transfer;
import static de.ozgcloud.nachrichten.postfach.muk.transfer.MukPostfachMessageMapper.*;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
......@@ -182,25 +183,31 @@ public class ElsterTransferRemoteService {
if (Objects.nonNull(antwortDetails.getZuordnungskriterium())) {
var nachrichtId = ObjectIdToUUIDConverter.toObjectId(antwortDetails.getZuordnungskriterium());
nachrichtBuilder
.referencedNachricht(nachrichtId.toHexString())
.replyOption(PostfachNachricht.ReplyOption.POSSIBLE);
// TODO update to new API as soon the new api is available.
//addAttachments(nachrichtBuilder, antwortDetails, nachrichtId);
.replyOption(PostfachNachricht.ReplyOption.POSSIBLE)
.attachments(getAttachmentIds(antwortDetails, nachrichtId));
}
return nachrichtBuilder.build();
}
private void addAttachments(final PostfachNachricht.PostfachNachrichtBuilder nachrichtBuilder, final AntwortDetails antwortDetails, final ObjectId nachrichtId) {
// TODO update to new API as soon the new api is available.
private List<String> getAttachmentIds(final AntwortDetails antwortDetails, final ObjectId nachrichtId) {
List<String> attachmentIds = new ArrayList<>();
if (Objects.nonNull(antwortDetails.getAnhaenge())) {
nachrichtBuilder.attachments(antwortDetails.getAnhaenge().stream()
var idList = antwortDetails.getAnhaenge().stream()
.filter(Objects::nonNull)
.map(downloadAnhangDetails -> saveAnhang(downloadAnhang(downloadAnhangDetails), downloadAnhangDetails, nachrichtId.toHexString()))
.filter(Optional::isPresent)
.map(Optional::get)
.toList());
.toList();
attachmentIds.addAll(idList);
}
return attachmentIds;
}
byte[] downloadAnhang(DownloadAnhangDetails downloadAnhangDetails) {
......@@ -210,8 +217,10 @@ public class ElsterTransferRemoteService {
}
Optional<String> saveAnhang(byte[] data, DownloadAnhangDetails downloadAnhangDetails, String nachrichtId) {
LOG.info("Saving Attachment from DownloadAnhangDetails {}", downloadAnhangDetails);
Optional<String> fileIdOptional = Optional.empty();
if (Objects.nonNull(data)) {
// TODO update to new API as soon the new api is available. Save to file here and then upload attachment
try (var dataIn = new ByteArrayInputStream(data)) {
fileIdOptional = storeToOzgCloud(downloadAnhangDetails, nachrichtId, dataIn);
} catch (IOException e) {
......@@ -228,7 +237,8 @@ public class ElsterTransferRemoteService {
Optional<String> storeToOzgCloud(DownloadAnhangDetails downloadAnhangDetails, String vorgangId, ByteArrayInputStream dataIn) throws IOException {
OzgCloudFileId ozgCloudFileId;
try (BufferedInputStream dataStream = new BufferedInputStream(dataIn)) {
// TODO update to new API as soon the new api is available. Use saved temp file
/*try (BufferedInputStream dataStream = new BufferedInputStream(dataIn)) {
ozgCloudFileId = attachmentService.store(createOzgCloudUploadFile(downloadAnhangDetails, vorgangId), dataStream);
}
......@@ -237,6 +247,7 @@ public class ElsterTransferRemoteService {
}
LOG.error("Received no OzgCloudFileId when saving attachment {} to vorgangId {}", downloadAnhangDetails, vorgangId);
*/
return Optional.empty();
}
......
......@@ -297,6 +297,7 @@ class ElsterTransferRemoteServiceTest {
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldHandleAttachmentSaveError() {
when(attachmentService.store(any(), any())).thenReturn(null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment