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

Merge pull request...

Merge pull request 'OZG-6275-MeinUnternehmenskonto-Nachricht-im-Alfa-empfangen' (#14) from OZG-6275-MeinUnternehmenskonto-Nachricht-im-Alfa-empfangen into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/muk-postfach/pulls/14


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents dfc1e77b d840e0f8
Branches
Tags
No related merge requests found
......@@ -13,4 +13,4 @@ services:
ETR_NETZ: "e4k"
ETR_EINSTELLUNGEN_ELSTERZERTIFIKAT_PASSWORT: "-siehe-keepass-"
ETR_EINSTELLUNGEN_ELSTERZERTIFIKAT_DATEIPFAD: "/opt/ELSTER-Transfer/elster-org-cert.pfx"
ETR_ACCESS_ALLOWFROM: '\d+.\d+\.\d+\.\d+;\d*|::1;\d*|0:0:0:0:0:0:0:1;\d*'
ETR_ACCESS_ALLOWFROM: '.*'
......@@ -37,6 +37,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
import org.bson.types.ObjectId;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
......@@ -148,7 +149,7 @@ public class ElsterTransferRemoteService {
BereitstellungAntwort createAntwort(PostfachNachricht nachricht) {
var antwort = new BereitstellungAntwort();
antwort.setZuordnungskriterium(ObjectIdToUUIDConverter.toUUID(nachricht.getVorgangId()));
antwort.setZuordnungskriterium(ObjectIdToUUIDConverter.toUUID(nachricht.getId()));
antwort.setAntwortBetreffe(Set.of(postfachProperties.getReplySubjectPrefix() + nachricht.getSubject()));
antwort.setAntwortFrist(LocalDate.now().plusDays(postfachProperties.getReplyInDays()));
return antwort;
......@@ -177,31 +178,39 @@ public class ElsterTransferRemoteService {
.mailBody(postfachProperties.getBody());
if (Objects.nonNull(antwortDetails.getZuordnungskriterium())) {
var vorgangId = ObjectIdToUUIDConverter.toObjectId(antwortDetails.getZuordnungskriterium());
nachrichtBuilder.vorgangId(vorgangId.toHexString());
if (Objects.nonNull(antwortDetails.getAnhaenge())) {
nachrichtBuilder.attachments(antwortDetails.getAnhaenge().stream()
.filter(Objects::nonNull)
.map(downloadAnhangDetails -> this.downloadAnhang(downloadAnhangDetails, vorgangId.toHexString()))
.filter(Optional::isPresent)
.map(Optional::get)
.toList());
}
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);
}
return nachrichtBuilder.build();
}
Optional<String> downloadAnhang(DownloadAnhangDetails downloadAnhangDetails, String vorgangId) {
Optional<String> fileIdOptional = Optional.empty();
private void addAttachments(final PostfachNachricht.PostfachNachrichtBuilder nachrichtBuilder, final AntwortDetails antwortDetails, final ObjectId nachrichtId) {
if (Objects.nonNull(antwortDetails.getAnhaenge())) {
nachrichtBuilder.attachments(antwortDetails.getAnhaenge().stream()
.filter(Objects::nonNull)
.map(downloadAnhangDetails -> saveAnhang(downloadAnhang(downloadAnhangDetails), downloadAnhangDetails, nachrichtId.toHexString()))
.filter(Optional::isPresent)
.map(Optional::get)
.toList());
}
}
byte[] downloadAnhang(DownloadAnhangDetails downloadAnhangDetails) {
var url = postfachProperties.getServer() + downloadAnhangDetails.getDownloadUrl();
var data = (byte[]) restClient.getForObject(url, byte[].class);
return restClient.getForObject(url, byte[].class);
}
Optional<String> saveAnhang(byte[] data, DownloadAnhangDetails downloadAnhangDetails, String nachrichtId) {
Optional<String> fileIdOptional = Optional.empty();
if (Objects.nonNull(data)) {
try (var dataIn = new ByteArrayInputStream(data)) {
fileIdOptional = storeToOzgCloud(downloadAnhangDetails, vorgangId, dataIn);
fileIdOptional = storeToOzgCloud(downloadAnhangDetails, nachrichtId, dataIn);
} catch (IOException e) {
LOG.error("Error transferring attachment body from Elster-Transfer to OZG-Cloud.", e);
throw new TechnicalException("Error downloading anhang", e);
......@@ -228,12 +237,11 @@ public class ElsterTransferRemoteService {
return Optional.empty();
}
static OzgCloudUploadFile createOzgCloudUploadFile(final DownloadAnhangDetails downloadAnhangDetails, final String vorgangId) {
static OzgCloudUploadFile createOzgCloudUploadFile(final DownloadAnhangDetails downloadAnhangDetails, final String nachrichtId) {
return OzgCloudUploadFile.builder()
.fileName(downloadAnhangDetails.getDatei())
.fieldName(POSTFACH)
.contentType(downloadAnhangDetails.getMimeType())
.vorgangId(vorgangId).build();
.contentType(downloadAnhangDetails.getMimeType()).build();
}
}
......
......@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -140,6 +141,7 @@ public class MukPostfachRemoteServiceITCase {
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldDownloadAntwort() {
var antworten = mukPostfachRemoteService.getAllMessages().toList();
......
......@@ -37,7 +37,7 @@ import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction;
public class PostfachNachrichtTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String ID = ObjectId.get().toHexString();
public static final String CREATED_AT_STR = "2020-04-01T10:30:10Z";
public static final ZonedDateTime CREATED_AT = ZonedDateTime.parse(CREATED_AT_STR);
public static final String CREATED_BY = UUID.randomUUID().toString();
......@@ -57,7 +57,7 @@ public class PostfachNachrichtTestFactory {
public static final int POSTFACH_TYPE = 1;
public static final String SUBJECT = LoremIpsum.getInstance().getTitle(1);
public static final String MESSAGE_ID = UUID.randomUUID().toString();
public static final String VORGANG_ID = new ObjectId().toHexString();
public static final String NACHRICHT_ID = ObjectId.get().toHexString();
public static PostfachNachricht create() {
return createBuilder().build();
......@@ -68,7 +68,7 @@ public class PostfachNachrichtTestFactory {
.id(ID)
.postfachAddress(postfachAddress())
.messageId(MESSAGE_ID)
.vorgangId(VORGANG_ID)
.vorgangId(NACHRICHT_ID)
.direction(DIRECTION)
.createdAt(CREATED_AT)
.createdBy(CREATED_BY)
......
......@@ -37,7 +37,7 @@ public class AntwortDetailsTestFactory {
public static final String DATEI_BEZEICHNUNG = "test daten";
public static final URI DOWNLOAD_URI = URI.create("/download");
public static final String TEXT_CSV = "text/csv";
public static final UUID ZUORDNUNG = ObjectIdToUUIDConverter.toUUID(VORGANG_ID);
public static final UUID ZUORDNUNG = ObjectIdToUUIDConverter.toUUID(NACHRICHT_ID);
static AntwortDetails create() {
var antwortDetails = new AntwortDetails();
......
......@@ -36,6 +36,7 @@ import java.util.UUID;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
......@@ -260,6 +261,7 @@ class ElsterTransferRemoteServiceTest {
@Nested
class TestLoadingAntwort {
byte[] data = "test data".getBytes();
@Test
void shouldLoadAntwort() {
var antwort = elsterTransferService.getAntwort(AntwortDetailsTestFactory.create());
......@@ -268,15 +270,17 @@ class ElsterTransferRemoteServiceTest {
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldCallDownloadAntwort() {
setupForAttachments();
elsterTransferService.getAntwort(AntwortDetailsTestFactory.create());
verify(elsterTransferService).downloadAnhang(any(), anyString());
verify(elsterTransferService).downloadAnhang(any());
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldCallStoreToOzgCloud() throws IOException {
setupForAttachments();
......@@ -293,8 +297,6 @@ class ElsterTransferRemoteServiceTest {
@Test
void shouldHandleAttachmentSaveError() {
when(postfachProperties.getServer()).thenReturn("http://localhost");
when(restClient.getForObject(matches(postfachProperties.getServer() + DOWNLOAD_URI), any())).thenReturn("Test,Data".getBytes());
when(attachmentService.store(any(), any())).thenReturn(null);
DownloadAnhangDetails downloadAnhangDetails = new DownloadAnhangDetails();
......@@ -303,7 +305,7 @@ class ElsterTransferRemoteServiceTest {
downloadAnhangDetails.setDateiBezeichnung(OzgCloudFileTestFactory.NAME);
downloadAnhangDetails.setDatei("");
var res = elsterTransferService.downloadAnhang(downloadAnhangDetails, ObjectId.get().toHexString());
var res = elsterTransferService.saveAnhang(data, downloadAnhangDetails, ObjectId.get().toHexString());
assertThat(res).isNotPresent();
......@@ -319,13 +321,14 @@ class ElsterTransferRemoteServiceTest {
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldHaveVorgangId() {
when(restClient.getForObject(matches(postfachProperties.getServer() + DOWNLOAD_URI), any())).thenReturn("Test,Data".getBytes());
when(attachmentService.store(any(), any())).thenReturn(OzgCloudFileId.from(new ObjectId().toHexString()));
var antwort = elsterTransferService.getAntwort(AntwortDetailsTestFactory.create());
assertThat(antwort.getVorgangId()).isEqualTo(VORGANG_ID);
assertThat(antwort.getVorgangId()).isEqualTo(NACHRICHT_ID);
}
@Test
......@@ -370,6 +373,7 @@ class ElsterTransferRemoteServiceTest {
@Nested
class TestExceptionHandling {
byte[] data = "test data".getBytes();
@Test
void shouldThrowTechnicalExceptionOnUpload() throws IOException {
doThrow(IOException.class).when(elsterTransferService).uploadFile(any());
......@@ -381,11 +385,11 @@ class ElsterTransferRemoteServiceTest {
@Test
void shouldThrowTechnicalExceptionOnStore() throws IOException {
var downloadAnhangDetails = AntwortDetailsTestFactory.createDownloadAnhangDetails();
when(restClient.getForObject(eq("null" + downloadAnhangDetails.getDownloadUrl()), any())).thenReturn("data".getBytes());
doThrow(IOException.class).when(elsterTransferService).storeToOzgCloud(any(), any(), any());
assertThatExceptionOfType(TechnicalException.class).isThrownBy(
() -> elsterTransferService.downloadAnhang(downloadAnhangDetails, VORGANG_ID)
() -> elsterTransferService.saveAnhang(data, downloadAnhangDetails, NACHRICHT_ID)
);
}
}
......@@ -418,6 +422,7 @@ class ElsterTransferRemoteServiceTest {
}
@Test
@Disabled("Needs to be reimplemented when the new File API is available")
void shouldHaveVorgangId() {
var file = ElsterTransferRemoteService.createOzgCloudUploadFile(downloadAnhangDetails, vorgangId);
......
......@@ -64,14 +64,14 @@ class MukPostfachMessageMapperTest {
void shouldMapVorgangIdToEmpfaengerreferenz() {
var result = map();
assertThat(result.getEmpfaengerreferenz()).isEqualTo(VORGANG_ID);
assertThat(result.getEmpfaengerreferenz()).isEqualTo(NACHRICHT_ID);
}
@Test
void shouldMapVorgangIdToGeschaeftszeichen() {
var result = map();
assertThat(result.getEmpfaengerreferenz()).isEqualTo(VORGANG_ID);
assertThat(result.getEmpfaengerreferenz()).isEqualTo(NACHRICHT_ID);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment