diff options
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/repository')
3 files changed, 48 insertions, 21 deletions
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 57d2d07..e9b0466 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/DeliveryRepository.java @@ -11,13 +11,17 @@ import java.util.Optional; @Repository public interface DeliveryRepository { - void add(DeliveryRequestType request); + void store(DeliveryRequestType request); - Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID); + Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID); - void add(MsgResponse response); + void store(MsgResponse response); - Optional<MsgResponse> getResponse(String responseID); + Optional<MsgResponse> retrieveResponse(String responseID); + + void store(String responseID, byte[] data); + + Optional<byte[]> retrieveBinaryResponse(String responseID); } 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 3b5a020..41b742b 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/InMemoryDeliveryRepository.java @@ -4,46 +4,61 @@ package at.gv.egiz.moazs.repository; import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.concurrent.TimeUnit; +import static com.google.common.cache.CacheBuilder.newBuilder; import static java.util.Optional.ofNullable; @Repository @Profile("!cluster") public class InMemoryDeliveryRepository implements DeliveryRepository { - private final Cache<String, DeliveryRequestType> requestRepository = CacheBuilder.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .build(); + private final Cache<String, DeliveryRequestType> requestRepository; + private final Cache<String, MsgResponse> responseRepository; + private final Cache<String, byte[]> binaryResponseRepository; - private final Cache<String, MsgResponse> responseRepository = CacheBuilder.newBuilder() - .expireAfterWrite(30, TimeUnit.MINUTES) - .build(); + public InMemoryDeliveryRepository(int expiresAfterWrite) { + var builder = newBuilder().expireAfterWrite(expiresAfterWrite, TimeUnit.MINUTES); + this.requestRepository = builder.build(); + this.responseRepository = builder.build(); + this.binaryResponseRepository = builder.build(); + } @Override - public void add(DeliveryRequestType request) { + public void store(DeliveryRequestType request) { var key = request.getMetaData().getAppDeliveryID(); requestRepository.put(key, request); } @Override - public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) { + public Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID) { return ofNullable(requestRepository.getIfPresent(appDeliveryID)); } @Override - public void add(MsgResponse response) { + public void store(MsgResponse response) { String key = response.getResponseID(); responseRepository.put(key, response); } @Override - public Optional<MsgResponse> getResponse(String responseID) { + public Optional<MsgResponse> retrieveResponse(String responseID) { return ofNullable(responseRepository.getIfPresent(responseID)); } + + @Override + public void store(String id, byte[] data) { + binaryResponseRepository.put(id, data); + + } + + @Override + public Optional<byte[]> retrieveBinaryResponse(String responseID) { + return ofNullable(binaryResponseRepository.getIfPresent(responseID)); + } + } 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 7ccd236..68e96d9 100644 --- a/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java +++ b/src/main/java/at/gv/egiz/moazs/repository/RedisDeliveryRepository.java @@ -3,8 +3,6 @@ package at.gv.egiz.moazs.repository; import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.egiz.moazs.scheme.MsgResponse; import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType; -import at.gv.zustellung.msg.xsd.DeliveryNotificationType; -import at.gv.zustellung.msg.xsd.DeliveryRequestStatusType; import at.gv.zustellung.app2mzs.xsd.ObjectFactory; import org.apache.tools.ant.filters.StringInputStream; import org.slf4j.Logger; @@ -42,7 +40,7 @@ public class RedisDeliveryRepository implements DeliveryRepository { } @Override - public void add(DeliveryRequestType request) { + public void store(DeliveryRequestType request) { var hashKey = request.getMetaData().getAppDeliveryID(); var serializedRequest = marshaller.marshallXml(factory.createDeliveryRequest(request)); @@ -51,7 +49,7 @@ public class RedisDeliveryRepository implements DeliveryRepository { } @Override - public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) { + public Optional<DeliveryRequestType> retrieveDeliveryRequest(String appDeliveryID) { String serializedRequest = hashOperations.get(KEY, appDeliveryID); if (serializedRequest == null) { @@ -64,14 +62,24 @@ public class RedisDeliveryRepository implements DeliveryRepository { } @Override - public void add(MsgResponse notification) { + public void store(MsgResponse notification) { throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE); } @Override - public Optional<MsgResponse> getResponse(String id) { + public Optional<MsgResponse> retrieveResponse(String id) { throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE); } + @Override + public void store(String responseID, byte[] data) { + + } + + @Override + public Optional<byte[]> retrieveBinaryResponse(String responseID) { + return Optional.empty(); + } + } |