From 8aba1b4f18f5fbfebdf239b4b4945b628e439905 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Tue, 9 Jul 2019 14:11:47 +0200 Subject: Refactor Needles Interfaces and Rename "process" to "backend" Reason: - Interfaces with a single method can be replaced with interfaces from java.util.function. - Less interfaces = less code = less maintenance! - Spring can inject beans by name so we name dependencies correctly to prevent ambiguity. Others: - Rename process to backend since backend gives a better description of its components. --- src/main/java/at/gv/egiz/moazs/service/MsgService.java | 11 ++++++----- src/main/java/at/gv/egiz/moazs/service/MzsService.java | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/service') diff --git a/src/main/java/at/gv/egiz/moazs/service/MsgService.java b/src/main/java/at/gv/egiz/moazs/service/MsgService.java index 87644a0..9f94cb3 100644 --- a/src/main/java/at/gv/egiz/moazs/service/MsgService.java +++ b/src/main/java/at/gv/egiz/moazs/service/MsgService.java @@ -1,5 +1,4 @@ package at.gv.egiz.moazs.service; -import at.gv.egiz.moazs.process.MsgResponseHandler; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.egiz.moazs.scheme.NameSpace; @@ -10,6 +9,8 @@ import org.apache.cxf.annotations.SchemaValidation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.function.Consumer; + import static at.gv.zustellung.msg.xsd.DeliveryNotificationACKType.deliveryNotificationACKTypeBuilder; import static at.gv.zustellung.msg.xsd.DeliveryRequestStatusACKType.deliveryRequestStatusACKTypeBuilder; import static at.gv.zustellung.msg.xsd.GetVersionResponse.getVersionResponseBuilder; @@ -20,12 +21,12 @@ import static java.util.concurrent.CompletableFuture.runAsync; public class MsgService implements Zuse2AppPort { private final DeliveryRepository repository; - private final MsgResponseHandler handler; + private final Consumer backend; @Autowired - public MsgService(DeliveryRepository repository, MsgResponseHandler handler) { + public MsgService(DeliveryRepository repository, Consumer msgResponseBackend) { this.repository = repository; - this.handler = handler; + this.backend = msgResponseBackend; } @Override @@ -59,7 +60,7 @@ public class MsgService implements Zuse2AppPort { private void sendToWork(MsgResponse response) { runAsync(() -> repository.store(response)) - .thenRunAsync(() -> handler.handle(response.getResponseID())); + .thenRunAsync(() -> backend.accept(response.getResponseID())); } private DeliveryNotificationACKType notificationAck(String appDeliveryID, String zsDeliveryID) { diff --git a/src/main/java/at/gv/egiz/moazs/service/MzsService.java b/src/main/java/at/gv/egiz/moazs/service/MzsService.java index 2755a37..c8c0878 100644 --- a/src/main/java/at/gv/egiz/moazs/service/MzsService.java +++ b/src/main/java/at/gv/egiz/moazs/service/MzsService.java @@ -1,7 +1,6 @@ package at.gv.egiz.moazs.service; import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter; -import at.gv.egiz.moazs.process.DeliveryPipeline; import at.gv.egiz.moazs.repository.DeliveryRepository; import at.gv.egiz.moazs.scheme.Msg2MzsConverter; import at.gv.egiz.moazs.client.MzsClient; @@ -19,6 +18,7 @@ import org.springframework.stereotype.Service; import javax.jws.WebParam; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.function.Consumer; import static at.gv.egiz.moazs.MoaZSException.moaZSException; import static at.gv.egiz.moazs.MoaZSException.moaZSExceptionBuilder; @@ -36,16 +36,16 @@ public class MzsService implements App2MzsPortType { private static final int TIMEOUT_FOR_ANWSER = 10; private final DeliveryRepository repository; - private final DeliveryPipeline pipeline; + private final Consumer backend; private final MzsClient appClient; private final DeliveryRequestAugmenter augmenter; private final Msg2MzsConverter converter; @Autowired - public MzsService(DeliveryRepository repository, DeliveryPipeline pipeline, MzsClient appClient, + public MzsService(DeliveryRepository repository, Consumer deliveryRequestBackend, MzsClient appClient, DeliveryRequestAugmenter augmenter, Msg2MzsConverter converter) { this.repository = repository; - this.pipeline = pipeline; + this.backend = deliveryRequestBackend; this.appClient = appClient; this.augmenter = augmenter; this.converter = converter; @@ -87,7 +87,7 @@ public class MzsService implements App2MzsPortType { logger.info("Receive request with appDeliveryID = {}.", appDeliveryID); repository.store(deliveryRequest); - pipeline.processRequest(appDeliveryID); + backend.accept(appDeliveryID); var statusId = RequestStatusResponse.getResponseID(appDeliveryID); var response = repository.retrieveResponse(statusId) -- cgit v1.2.3