aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java102
-rw-r--r--src/main/resources/mzs/app2mzs.xsd23
2 files changed, 113 insertions, 12 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java b/src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java
index 271cf67..65b6425 100644
--- a/src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java
+++ b/src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java
@@ -1,21 +1,38 @@
package at.gv.egiz.moazs.scheme;
+import at.gv.zustellung.app2mzs.xsd.DeliveryNotificationType;
import at.gv.zustellung.app2mzs.xsd.*;
-import at.gv.zustellung.msg.xsd.DeliveryAnswerType;
-import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType;
+import at.gv.zustellung.msg.xsd.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import javax.xml.bind.JAXBElement;
import java.math.BigInteger;
+import java.util.List;
import java.util.Optional;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
+import static at.gv.zustellung.app2mzs.xsd.DeliveryNotificationType.AdditionalFormat.additionalFormatBuilder;
+import static at.gv.zustellung.app2mzs.xsd.DeliveryNotificationType.deliveryNotificationTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryResponseType.deliveryResponseTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.ErrorType.errorTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.PartialSuccessType.partialSuccessTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.SuccessType.successTypeBuilder;
+import static java.util.stream.Collectors.toList;
@Component
public class Msg2MzsConverter {
+ private static final Logger log = LoggerFactory.getLogger(Msg2MzsConverter.class);
+
+ private static final String ANSWERS_MISSING_ERROR_MSG = "msg:DeliveryNotification contains no msg:Answer elements" +
+ " and cannot be converted to mzs:DeliveryNotification.";
+ private static final String UNKNOWN_ANSWER_ERROR_MSG = "msg:DeliveryNotification/msg:Answer is of unknown type" +
+ " and cannot be converted.";
+ private static final String TOO_MANY_ANSWERS_MSG = "msg:DeliveryNotification contains more msg:Answer elements than" +
+ " expected. All answers except the first one will be ignored.";
+
public DeliveryResponseType convert(DeliveryRequestStatusType status, Optional<byte[]> signedStatus) {
var responseBuilder = deliveryResponseTypeBuilder();
@@ -31,12 +48,6 @@ public class Msg2MzsConverter {
return responseBuilder.build();
}
- public DeliveryNotificationType convert(at.gv.zustellung.msg.xsd.DeliveryNotificationType notificatione, Optional<byte[]> signedStatus) {
- //TODO
- return null;
- }
-
-
private SuccessType convert(DeliveryRequestStatusType.Success success, Optional<byte[]> signedStatus) {
return successTypeBuilder()
.withAppDeliveryID(success.getAppDeliveryID())
@@ -74,5 +85,80 @@ public class Msg2MzsConverter {
return builder.build();
}
+ public DeliveryNotificationType convert(at.gv.zustellung.msg.xsd.DeliveryNotificationType msgNotification,
+ Optional<byte[]> signedNotification) {
+
+ var builder = deliveryNotificationTypeBuilder();
+
+ if (msgNotification.getAnswer().isEmpty()) {
+ throw moaZSException(ANSWERS_MISSING_ERROR_MSG);
+ }
+
+ if (msgNotification.getAnswer().size() > 1) {
+ log.warn(TOO_MANY_ANSWERS_MSG);
+ }
+
+ JAXBElement<? extends AbstractOperationType> answer = msgNotification.getAnswer().get(0);
+
+ if(answer.getValue() instanceof AcceptedType) {
+ var accepted = (AcceptedType) answer.getValue();
+ builder.withSuccess(extractSuccess(msgNotification, signedNotification))
+ .withNotificationsPerformed(accepted.getNotificationsPerformed());
+ } else if(answer.getValue() instanceof DeliveryErrorType) {
+ var error = (DeliveryErrorType) answer.getValue();
+ builder.withError(extractError(msgNotification, error, signedNotification))
+ .withNotificationsPerformed(error.getNotificationsPerformed());
+ } else {
+ throw moaZSException(UNKNOWN_ANSWER_ERROR_MSG);
+ }
+
+ return builder
+ .withSenderDetails(msgNotification.getSenderDetails())
+ .withReceiverDetails(msgNotification.getReceiverDetails())
+ .withUser(msgNotification.getUser())
+ .withAdditionalFormat(convert(msgNotification.getAdditionalFormat()))
+ .build();
+ }
+
+ private ErrorType extractError(at.gv.zustellung.msg.xsd.DeliveryNotificationType msgNotification,
+ DeliveryErrorType error, Optional<byte[]> signedNotification) {
+ return errorTypeBuilder()
+ .withAppDeliveryID(msgNotification.getAppDeliveryID())
+ .withDeliverySystem(msgNotification.getDeliverySystem())
+ .withZSDeliveryID(msgNotification.getZSDeliveryID())
+ .withGZ(msgNotification.getGZ())
+ .withSignedDeliveryRequestStatus(signedNotification.orElse(null))
+ .withCode(new BigInteger(error.getErrorInfo().getCode()))
+ .withText(error.getErrorInfo().getText())
+ .build();
+ }
+
+ private SuccessType extractSuccess(at.gv.zustellung.msg.xsd.DeliveryNotificationType msgNotification,
+ Optional<byte[]> signedNotification) {
+ return successTypeBuilder()
+ .withAppDeliveryID(msgNotification.getAppDeliveryID())
+ .withDeliverySystem(msgNotification.getDeliverySystem())
+ .withZSDeliveryID(msgNotification.getZSDeliveryID())
+ .withGZ(msgNotification.getGZ())
+ .withSignedDeliveryRequestStatus(signedNotification.orElse(null))
+ .withRelayedViaERV(msgNotification.isRelayedViaERV())
+ .withDeliveryTimestamp(msgNotification.getTimestamp())
+ .build();
+ }
+
+ private List<DeliveryNotificationType.AdditionalFormat> convert(
+ List<at.gv.zustellung.msg.xsd.DeliveryNotificationType.AdditionalFormat> additionalFormat) {
+ return additionalFormat.stream()
+ .map(this::convert)
+ .collect(toList());
+ }
+
+ private DeliveryNotificationType.AdditionalFormat convert(
+ at.gv.zustellung.msg.xsd.DeliveryNotificationType.AdditionalFormat format) {
+ return additionalFormatBuilder()
+ .withType(format.getType())
+ .withValue(format.getValue())
+ .build();
+ }
}
diff --git a/src/main/resources/mzs/app2mzs.xsd b/src/main/resources/mzs/app2mzs.xsd
index a2d1bde..da49631 100644
--- a/src/main/resources/mzs/app2mzs.xsd
+++ b/src/main/resources/mzs/app2mzs.xsd
@@ -166,10 +166,25 @@
</xs:annotation>
</xs:element>
<xs:complexType name="DeliveryNotificationType">
- <xs:choice>
- <xs:element ref="Success"/>
- <xs:element ref="Error"/>
- </xs:choice>
+ <xs:sequence>
+ <xs:choice>
+ <xs:element ref="Success"/>
+ <xs:element ref="Error"/>
+ </xs:choice>
+ <xs:element ref="msg:SenderDetails"/>
+ <xs:element ref="msg:ReceiverDetails"/>
+ <xs:element ref="msg:User" minOccurs="0" />
+ <xs:element name="AdditionalFormat" minOccurs="0" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="xs:base64Binary">
+ <xs:attribute name="Type" type="xs:token" use="required"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+ <xs:element ref="msg:NotificationsPerformed" minOccurs="0"/>
+ </xs:sequence>
</xs:complexType>
<xs:element name="DeliveryRequestStatusACK" type="DeliveryNotificationACKType" />
<xs:element name="DeliveryNotificationACK" type="DeliveryNotificationACKType">