diff --git a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachException.java b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachException.java new file mode 100644 index 0000000000000000000000000000000000000000..f5187621d37cc7b48e47a1884e0df775636fca86 --- /dev/null +++ b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachException.java @@ -0,0 +1,9 @@ +package de.ozgcloud.nachrichten.postfach.osiv2; + +import de.ozgcloud.common.errorhandling.TechnicalException; + +public class OsiPostfachException extends TechnicalException { + public OsiPostfachException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteService.java b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteService.java index 88a7720b790dfd4c4e4c875e677522d03c7b8ea9..b3625b4713d2cddf4aa1e484cbe57eb13e15199f 100644 --- a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteService.java +++ b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteService.java @@ -16,12 +16,15 @@ import lombok.extern.log4j.Log4j2; public record OsiPostfachRemoteService( PostfachApiFacadeService postfachApiFacadeService ) implements PostfachRemoteService { - public static final String POSTFACH_TYPE_OSIV2 = "OSIV2"; + public static final String POSTFACH_TYPE_OSI = "OSI"; @Override public void sendMessage(PostfachNachricht nachricht) { - postfachApiFacadeService.sendMessage(nachricht); - // TODO handle exceptions? + try { + postfachApiFacadeService.sendMessage(nachricht); + } catch (RuntimeException e) { + throw new OsiPostfachException("Failed to send message", e); + } } @Override @@ -37,7 +40,7 @@ public record OsiPostfachRemoteService( @Override public String getPostfachType() { - return POSTFACH_TYPE_OSIV2; + return POSTFACH_TYPE_OSI; } @Override diff --git a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/PostfachApiFacadeService.java b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/PostfachApiFacadeService.java index 0e9a8979c20e843e84dc63c4a4e44f076687a24b..b48e8cb7e5569003e37d0586bbc3b12388a5b6ad 100644 --- a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/PostfachApiFacadeService.java +++ b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/PostfachApiFacadeService.java @@ -2,6 +2,7 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; import java.util.stream.Stream; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import de.ozgcloud.nachrichten.postfach.PostfachNachricht; @@ -10,6 +11,7 @@ import lombok.extern.log4j.Log4j2; @Log4j2 @Service +@ConditionalOnProperty("ozgcloud.osiv2-postfach.enabled") public record PostfachApiFacadeService( MessageExchangeApi messageExchangeApi, RequestMapper requestMapper, diff --git a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapper.java b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapper.java index 91a9d58c3a5880cadb70bf5706aafb98e8faa49f..c9a42ae3fa9756dfe2ac34d20bfd73405f85a5fe 100644 --- a/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapper.java +++ b/src/main/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapper.java @@ -19,16 +19,14 @@ import de.ozgcloud.nachrichten.postfach.osiv2.gen.model.V1ReplyBehavior; @Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) public interface RequestMapper { - String ORIGIN_SENDER = "OZG-Cloud"; - @Mapping(target = "sequencenumber", source = "vorgangId") @Mapping(target = "body", source = "mailBody") @Mapping(target = "displayName", source = "createdBy") - @Mapping(target = "originSender", constant = ORIGIN_SENDER) + @Mapping(target = "originSender", ignore = true) @Mapping(target = "replyAction", source = "replyOption") @Mapping(target = "eidasLevel", constant = "LOW") @Mapping(target = "isObligatory", expression = "java( false )") - @Mapping(target = "isHtml", expression = "java( true )") + @Mapping(target = "isHtml", expression = "java( false )") @Mapping(target = "files", expression = "java( mapMessageExchangeFiles() )") @Mapping(target = "references", expression = "java( mapReferences() )") OutSendMessageRequestV2 mapOutSendMessageRequestV2(PostfachNachricht nachricht); diff --git a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceTest.java b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceTest.java index b82448d57e272a516b01b91b313873e6c224988d..2759035d7ff6c1a76a7bf31ed01f9cfe12fbfbf4 100644 --- a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceTest.java +++ b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/OsiPostfachRemoteServiceTest.java @@ -43,6 +43,15 @@ class OsiPostfachRemoteServiceTest { verify(postfachApiFacadeService).sendMessage(nachricht1); } + + @DisplayName("should throw osi postfach exception on runtime exception") + @Test + void shouldThrowOsiPostfachExceptionOnRuntimeException() { + doThrow(new RuntimeException()).when(postfachApiFacadeService).sendMessage(nachricht1); + + assertThatThrownBy(() -> osiPostfachRemoteService.sendMessage(nachricht1)) + .isInstanceOf(OsiPostfachException.class); + } } @DisplayName("get all messages") @@ -74,7 +83,7 @@ class OsiPostfachRemoteServiceTest { void shouldReturn() { var result = osiPostfachRemoteService.getPostfachType(); - assertThat(result).isEqualTo(OsiPostfachRemoteService.POSTFACH_TYPE_OSIV2); + assertThat(result).isEqualTo(OsiPostfachRemoteService.POSTFACH_TYPE_OSI); } } diff --git a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapperTest.java b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapperTest.java index 957d440acaadcb07690857899f081c151bbadb6b..0e67c3c307449847d9e9e89e936f6812938ae98a 100644 --- a/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapperTest.java +++ b/src/test/java/de/ozgcloud/nachrichten/postfach/osiv2/transfer/RequestMapperTest.java @@ -2,7 +2,6 @@ package de.ozgcloud.nachrichten.postfach.osiv2.transfer; import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachAddressTestFactory.*; import static de.ozgcloud.nachrichten.postfach.osiv2.factory.PostfachNachrichtTestFactory.*; -import static de.ozgcloud.nachrichten.postfach.osiv2.transfer.RequestMapper.*; import static org.assertj.core.api.Assertions.*; import java.util.stream.Stream; @@ -79,7 +78,6 @@ class RequestMapperTest { assertThat(result.getSequencenumber()).isEqualTo(VORGANG_ID); } - @DisplayName("should map subject") @Test void shouldMapSubject() { @@ -104,12 +102,12 @@ class RequestMapperTest { assertThat(result.getDisplayName()).isEqualTo(USER_ID); } - @DisplayName("should map origin sender") + @DisplayName("should map origin sender to null") @Test - void shouldMapOriginSender() { + void shouldMapOriginSenderToNull() { var result = doMapping(); - assertThat(result.getOriginSender()).isEqualTo(ORIGIN_SENDER); + assertThat(result.getOriginSender()).isNull(); } @DisplayName("should map forbidden reply action") @@ -165,7 +163,7 @@ class RequestMapperTest { void shouldSetIsHtml() { var result = doMapping(); - assertThat(result.getIsHtml()).isTrue(); + assertThat(result.getIsHtml()).isFalse(); } @DisplayName("should map files") @@ -181,7 +179,7 @@ class RequestMapperTest { void shouldMapReferences() { var result = doMapping(); - assertThat(result.getFiles()).isEmpty(); + assertThat(result.getReferences()).isEmpty(); } private OutSendMessageRequestV2 doMapping() {