package at.gv.egiz.moazs.backend; import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.zustellung.app2mzs.xsd.MsgResponseSinksType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import static java.util.concurrent.CompletableFuture.supplyAsync; @Component public class MsgResponseSinkHub { private static final Logger log = LoggerFactory.getLogger(MsgResponseSinkHub.class); private final SaveResponseToFileSink saveResponseSink; private final LogResponseSink logResponseSink; private final ForwardResponseToServiceSink forwardResponseSink; @Autowired public MsgResponseSinkHub(SaveResponseToFileSink saveResponseSink, LogResponseSink logResponseSink, ForwardResponseToServiceSink forwardResponseSink) { this.saveResponseSink = saveResponseSink; this.logResponseSink = logResponseSink; this.forwardResponseSink = forwardResponseSink; } /** * Apply all sinks that are configured in {@code sinkParams} to {@code msgResponse}. */ public void applySinks(MsgResponse msgResponse, MsgResponseSinksType sinkParams) { log.info("Apply Sinks to msg:{} with appDeliveryID={}.", msgResponse.getRootElementLocalPart(), msgResponse.getAppDeliveryID()); if (sinkParams.getSaveResponseToFile().isActive()) { supplyAsync(() -> saveResponseSink.save(msgResponse, sinkParams.getSaveResponseToFile().getPath())); } if (sinkParams.isLogResponse()) { supplyAsync(() -> logResponseSink.log(msgResponse)); } if (sinkParams.getForwardResponseToService().isActive()) { supplyAsync(() -> forwardResponseSink.send( msgResponse, sinkParams.getForwardResponseToService().getAppClient())); } } }