/******************************************************************************* * Copyright 2020 Graz University of Technology * MOA ZS has been developed in a cooperation between EGIZ * and Graz University of Technology. * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ 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.Optional; import java.util.concurrent.CompletableFuture; import static at.gv.zustellung.msg.xsd.DeliveryErrorType.deliveryErrorTypeBuilder; import static at.gv.zustellung.msg.xsd.DeliveryNotificationType.deliveryNotificationTypeBuilder; /** * @author Christof Rabensteiner * */ 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(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); } }