package at.gv.egiz.moazs.scheme; import at.gv.zustellung.app2mzs.xsd.Mzs2AppPortType; import at.gv.zustellung.msg.xsd.DeliveryAnswerType; import at.gv.zustellung.msg.xsd.DeliveryNotificationType; import at.gv.zustellung.msg.xsd.ErrorInfoType; import at.gv.zustellung.msg.xsd.ObjectFactory; import javax.xml.bind.JAXBElement; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import static at.gv.zustellung.msg.xsd.DeliveryErrorType.deliveryErrorTypeBuilder; import static at.gv.zustellung.msg.xsd.DeliveryNotificationType.deliveryNotificationTypeBuilder; public class NotificationResponse extends MsgResponse { private final DeliveryNotificationType notification; private static final String ID_SUFFIX = ".NO"; private static final ObjectFactory factory = new ObjectFactory(); public NotificationResponse(DeliveryNotificationType notification) { super.id = createResponseId(notification.getAppDeliveryID(), ID_SUFFIX); this.notification = notification; } public static String getResponseID(String appDeliveryID) { return createResponseId(appDeliveryID, ID_SUFFIX); } @Override public DeliveryNotificationType getResponse() { return notification; } @Override public JAXBElement getResponseAsJAXBElement() { return factory.createDeliveryNotification(notification); } @Override public String getAppDeliveryID() { return notification.getAppDeliveryID(); } @Override public String getZSDeliveryID() { return notification.getZSDeliveryID(); } @Override public DeliveryAnswerType getAnswer() { return notification; } @Override public NotificationResponse generateError(String text, String code) { var info = ErrorInfoType.errorInfoTypeBuilder() .withCode(code) .withText(text) .build(); var error = deliveryErrorTypeBuilder() .withErrorInfo(info) .build(); var notificationType = deliveryNotificationTypeBuilder(notification) .withAnswer(List.of(factory.createAnswer(error))) .build(); return new NotificationResponse(notificationType); } @Override public CompletableFuture sendToAppClient(Msg2MzsConverter converter, Optional signedNotification, Mzs2AppPortType client) { var mzsNotification = converter.convert(notification, signedNotification); client.forwardNotification(mzsNotification); return CompletableFuture.completedFuture(null); } }