diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-17 15:22:18 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-17 15:22:18 +0200 |
commit | 8e362d5feaf5535bb59bacc1be677d8f10d08f86 (patch) | |
tree | e37505498ad18361df3fa3de973b094dced59f61 /src/main/java/at/gv/egiz/moazs/RedisRepository.java | |
parent | ef9a86858a5e05b4dd9bff3992c477f49b0b20f2 (diff) | |
download | moa-zs-8e362d5feaf5535bb59bacc1be677d8f10d08f86.tar.gz moa-zs-8e362d5feaf5535bb59bacc1be677d8f10d08f86.tar.bz2 moa-zs-8e362d5feaf5535bb59bacc1be677d8f10d08f86.zip |
Add Redis and InMemory Implementation of DeliveryRequestRepository
- Deployer can choose which implementation to use (by activating
- corresponding profile)
- Add guava dependency
- Extract DeliveryRequestRepository to Interface
- Implement InMemory Repository using guava's cache
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/RedisRepository.java')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/RedisRepository.java | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/RedisRepository.java b/src/main/java/at/gv/egiz/moazs/RedisRepository.java deleted file mode 100644 index db49b23..0000000 --- a/src/main/java/at/gv/egiz/moazs/RedisRepository.java +++ /dev/null @@ -1,63 +0,0 @@ -package at.gv.egiz.moazs; - -import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; -import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory; -import org.apache.tools.ant.filters.StringInputStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.HashOperations; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Repository; - -import javax.annotation.PostConstruct; -import javax.xml.bind.JAXBElement; -import java.util.Optional; - -@Repository -public class RedisRepository { - - private static final Logger logger = LoggerFactory.getLogger(RedisRepository.class); - - private static final String KEY = "MZS_DELIVERY_REQUEST"; - - private final RedisTemplate<String, Object> redisTemplate; - - private final Marshaller marshaller; - - private HashOperations<String, String, String> hashOperations; - - private final ObjectFactory factory = new ObjectFactory(); - - @Autowired - public RedisRepository(RedisTemplate<String, Object> redisTemplate, Marshaller marshaller){ - this.redisTemplate = redisTemplate; - this.marshaller = marshaller; - } - - @PostConstruct - private void init(){ - hashOperations = redisTemplate.opsForHash(); - } - - public void add(DeliveryRequestType request) { - var hashKey = request.getMetaData().getAppDeliveryID(); - var serializedRequest = marshaller.marshallXml(factory.createDeliveryRequest(request)); - - logger.info("Save DeliveryRequest with AppDeliveryId = {}", hashKey); - hashOperations.put(KEY, hashKey, serializedRequest); - } - - public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) { - var serializedRequest = (String) hashOperations.get(KEY, appDeliveryID); - - if (serializedRequest == null) { - return Optional.empty(); - } - - var stream = new StringInputStream(serializedRequest); - var request = (JAXBElement<DeliveryRequestType>) marshaller.unmarshallXml(stream); - return Optional.of(request.getValue()); - } - -} |