From 2757a0784542eb61470801869bd1285782c143df Mon Sep 17 00:00:00 2001 From: Simon Laurenz Date: Tue, 14 Sep 2021 15:58:21 +0200 Subject: [PATCH] Add signature creation for empty list responses --- .../service/BusinessRuleService.java | 10 ++++++++++ .../service/CountryListService.java | 17 +++++------------ .../service/DomesticRuleService.java | 10 ++++++++++ .../businessrule/service/ValueSetService.java | 10 ++++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/BusinessRuleService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/BusinessRuleService.java index 37fc053..ec5ba8a 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/BusinessRuleService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/BusinessRuleService.java @@ -35,6 +35,7 @@ import java.util.Locale; import java.util.Optional; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -53,6 +54,15 @@ public class BusinessRuleService { private final BusinessRulesUtils businessRulesUtils; + /** + * Creates the signature for the empty rules list after start up. + */ + @PostConstruct + @Transactional + public void businessRuleServiceInit() { + listSigningService.updateSignedList(getBusinessRulesList(),ListType.Rules); + } + /** * Gets list of all business rules ids and hashes. * diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/CountryListService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/CountryListService.java index 660e6bc..638a71a 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/CountryListService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/CountryListService.java @@ -50,7 +50,8 @@ public class CountryListService { public CountryListEntity getCountryList() { CountryListEntity cle = countryListRepository.getFirstById(COUNTRY_LIST_ID); if (cle == null) { - cle = new CountryListEntity(COUNTRY_LIST_ID,"[]",null,null); + cle = createCountryListEntity("[]"); + countryListRepository.save(cle); } return cle; } @@ -64,17 +65,12 @@ public CountryListEntity getCountryList() { public void updateCountryList(String newCountryListData) { CountryListEntity oldList = getCountryList(); if (!newCountryListData.equals(oldList.getRawData())) { - saveCountryList(newCountryListData); + countryListRepository.save(createCountryListEntity(newCountryListData)); } } - /** - * Saves a country list by replacing an old one. - * @param listData the country list to be saved. - */ - @Transactional - public void saveCountryList(String listData) { + private CountryListEntity createCountryListEntity(String listData) { CountryListEntity cle = new CountryListEntity(COUNTRY_LIST_ID,listData,null,null); try { cle.setHash(businessRulesUtils.calculateHash(listData)); @@ -84,10 +80,7 @@ public void saveCountryList(String listData) { if (signingService.isPresent()) { cle.setSignature(signingService.get().computeSignature(cle.getHash())); } - countryListRepository.save(cle); + return cle; } - - - } diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/DomesticRuleService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/DomesticRuleService.java index 4de7d38..2a03fd0 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/DomesticRuleService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/DomesticRuleService.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -46,6 +47,15 @@ public class DomesticRuleService { private final Optional signingService; private final SignedListRepository signedListRepository; + /** + * Creates the signature for the empty rules list after start up. + */ + @PostConstruct + @Transactional + public void domesticRuleServiceInit() { + listSigningService.updateSignedList(getRulesList(), ListType.DomesticRules); + } + /** * Gets list of all rules ids and hashes. diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/ValueSetService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/ValueSetService.java index aace061..5ea7e44 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/ValueSetService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/ValueSetService.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -52,6 +53,15 @@ public class ValueSetService { private final SignedListRepository signedListRepository; private final Optional signingService; + /** + * Creates the signature for the empty value sets list after start up. + */ + @PostConstruct + @Transactional + public void valueSetServiceInit() { + listSigningService.updateSignedList(getValueSetsList(), ListType.ValueSets); + } + /** * Gets list of all value set ids and hashes. */