diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-16 16:53:41 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-16 16:53:41 +0200 |
commit | 896195cc9b287a3f41008cc85997b9c2209120b8 (patch) | |
tree | 09d4e4f0ef965a369c2dce03363e09593ca5bbc7 /src/main/java/at/gv/egiz | |
parent | 8f3b805a558c4ed454db2b691032cea800d7b6dd (diff) | |
download | moa-zs-896195cc9b287a3f41008cc85997b9c2209120b8.tar.gz moa-zs-896195cc9b287a3f41008cc85997b9c2209120b8.tar.bz2 moa-zs-896195cc9b287a3f41008cc85997b9c2209120b8.zip |
DeliveryNotification: Change Mzs Schema, Convert From Msg to Mzs
Mzs Schema Changes:
- Formerly: The mzs:DeliveryNotificationType is a choice between
Success And Error; Change: Wrap choice in a sequence. Reason: msg
2.0.0 adds fields that fit best in this sequence. Adding new fields
to Success or Error duplicates code, whereas adding it to the base
type (which is MessageType) also affects mzs:DeliveryRequestStatus.
- Add msg:SenderDetails, ReceiverDetails, user, AdditionalFormat,
NotificationsPerformed; Reason: It was added to zusemsg 2.0.0.
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/scheme/Msg2MzsConverter.java | 102 |
1 files changed, 94 insertions, 8 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(); + } } |