Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from corona-warn-app/fix/signatureFix
Browse files Browse the repository at this point in the history
fix: add signature creation for empty list responses
  • Loading branch information
ascheibal authored Sep 14, 2021
2 parents 2d9e761 + 2757a07 commit b140eea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));
Expand All @@ -84,10 +80,7 @@ public void saveCountryList(String listData) {
if (signingService.isPresent()) {
cle.setSignature(signingService.get().computeSignature(cle.getHash()));
}
countryListRepository.save(cle);
return cle;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +47,15 @@ public class DomesticRuleService {
private final Optional<SigningService> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +53,15 @@ public class ValueSetService {
private final SignedListRepository signedListRepository;
private final Optional<SigningService> 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.
*/
Expand Down

0 comments on commit b140eea

Please sign in to comment.