From aed1250912476f47fd772b0cedd20c850cdcff6e Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 18 Apr 2019 11:05:31 +0200 Subject: Change App2mzs Interface and Init Delivery Pipeline - Change app2mzs interface: output message from app2mzs:DeliveryRequest was app2mzs:DeliveryResponse, now its msg:DeliveryRequestStatus. Reason: ZD returns msg:DeliveryRequestStatus which is signed. Moazs does not convert msg:DeliveryRequestStatus into app2mzs:DeliveryResponse because the conversion woudl break the signature. - App2MzsService: Make beans final and inject them with constructor; Refactor DeliveryRequestHandler into App2MZSService. - DeliveryPipeline: Add Interface and a "SameThreadImplementation" that executes the pipeline in the same threat and can be used in single mode. - DeliveryRepository: Augment interface for storing and retrieving request status objects; Add in-memory-implementation for status objects. - Utils: Add helper function for coalescing multiple values --- .../egiz/moazs/repository/DeliveryRepository.java | 6 ++++ .../repository/InMemoryDeliveryRepository.java | 34 ++++++++++++++++------ .../moazs/repository/RedisDeliveryRepository.java | 10 +++++++ 3 files changed, 41 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/repository') diff --git a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java index d5766b6..f736160 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs.repository; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; import org.springframework.stereotype.Repository; @@ -12,4 +13,9 @@ public interface DeliveryRepository { Optional getDeliveryRequest(String appDeliveryID); + void add(DeliveryRequestStatusType status); + + Optional getDeliveryRequestStatus(String appDeliveryID); + + } diff --git a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java index e5486d7..5712c2d 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs.repository; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -11,30 +12,45 @@ import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.concurrent.TimeUnit; +import static at.gv.egiz.moazs.util.NullCoalesce.coalesce; +import static java.util.Optional.ofNullable; + @Repository @Profile("!cluster") public class InMemoryDeliveryRepository implements DeliveryRepository { private static final Logger logger = LoggerFactory.getLogger(InMemoryDeliveryRepository.class); - private static final Cache rep = CacheBuilder.newBuilder() + private static final Cache requestRepository = CacheBuilder.newBuilder() .expireAfterWrite(30, TimeUnit.MINUTES) .build(); - public InMemoryDeliveryRepository() { - logger.info("InMemoryDeliveryRepository()"); - } + private static final Cache statusRepository = CacheBuilder.newBuilder() + .expireAfterWrite(30, TimeUnit.MINUTES) + .build(); @Override public void add(DeliveryRequestType request) { - String key = request.getMetaData().getAppDeliveryID(); - logger.info("Save DeliveryRequest with AppDeliveryId = {} to Cache.", key); - rep.put(key, request); + var key = request.getMetaData().getAppDeliveryID(); + requestRepository.put(key, request); } @Override public Optional getDeliveryRequest(String appDeliveryID) { - DeliveryRequestType deliveryRequestType = rep.getIfPresent(appDeliveryID); - return Optional.ofNullable(deliveryRequestType); + var deliveryRequestType = requestRepository.getIfPresent(appDeliveryID); + return ofNullable(deliveryRequestType); + } + + @Override + public void add(DeliveryRequestStatusType status) { + var key = coalesce(status.getSuccess(), status.getPartialSuccess(), status.getError()) + .get().getAppDeliveryID(); + statusRepository.put(key, status); + } + + @Override + public Optional getDeliveryRequestStatus(String appDeliveryID) { + var deliveryRequestType = statusRepository.getIfPresent(appDeliveryID); + return ofNullable(deliveryRequestType); } } diff --git a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java index 4f39f31..cd02dac 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java @@ -1,5 +1,6 @@ package at.gv.egiz.moazs.repository; +import at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.DeliveryRequestStatusType; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory; import at.gv.egiz.moazs.Marshaller; @@ -59,4 +60,13 @@ public class RedisDeliveryRepository implements DeliveryRepository { return Optional.of(request.getValue()); } + @Override + public void add(DeliveryRequestStatusType status) { + throw new RuntimeException("Not Implemented Yet"); + } + + @Override + public Optional getDeliveryRequestStatus(String appDeliveryID) { + throw new RuntimeException("Not Implemented Yet"); + } } -- cgit v1.2.3