diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/BusinessRuleEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/BusinessRuleEntity.java index b6cc511..1879119 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/BusinessRuleEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/BusinessRuleEntity.java @@ -22,8 +22,6 @@ import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.Table; @@ -59,4 +57,7 @@ public class BusinessRuleEntity { @Lob @Column(name = "raw_data", nullable = false) String rawData; + + @Column(name = "signature", length = 256) + private String signature; } \ No newline at end of file diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/repository/BusinessRuleRepository.java b/src/main/java/eu/europa/ec/dgc/businessrule/repository/BusinessRuleRepository.java index 98bbd05..69889b2 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/repository/BusinessRuleRepository.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/repository/BusinessRuleRepository.java @@ -21,9 +21,7 @@ package eu.europa.ec.dgc.businessrule.repository; import eu.europa.ec.dgc.businessrule.entity.BusinessRuleEntity; -import eu.europa.ec.dgc.businessrule.entity.ValueSetEntity; import eu.europa.ec.dgc.businessrule.restapi.dto.BusinessRuleListItemDto; -import eu.europa.ec.dgc.businessrule.restapi.dto.ValueSetListItemDto; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BusinessRuleController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BusinessRuleController.java index a0bacd4..d27a0ae 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BusinessRuleController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BusinessRuleController.java @@ -98,7 +98,7 @@ public ResponseEntity> getRules( if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); - if (signature != null & signature.length() > 0) { + if (signature != null && signature.length() > 0) { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set(X_SIGNATURE_HEADER, signature); respBuilder.headers(responseHeaders); @@ -232,6 +232,8 @@ public ResponseEntity getRuleByCountryAndHash( @Valid @PathVariable("country") String country, @Valid @PathVariable("hash") String hash ) { + ResponseEntity responseEntity; + validateCountryParameter(country); if (hash == null || hash.isBlank()) { throw new DgcaBusinessRulesResponseException(HttpStatus.BAD_REQUEST, "0x005", "Possible reasons: " @@ -244,7 +246,16 @@ public ResponseEntity getRuleByCountryAndHash( throw new DgcaBusinessRulesResponseException(HttpStatus.NOT_FOUND, "0x006", "Possible reasons: " + "The provided hash or country may not be correct.", "country: " + country + ", hash: " + hash,""); } - return ResponseEntity.ok(rule.getRawData()); + + if (rule.getSignature() != null) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set(BusinessRuleController.X_SIGNATURE_HEADER, rule.getSignature()); + responseEntity = ResponseEntity.ok().headers(responseHeaders).body(rule.getRawData()); + } else { + responseEntity = ResponseEntity.ok(rule.getRawData()); + } + + return responseEntity; } private void validateCountryParameter(String country) throws DgcaBusinessRulesResponseException { 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 0145dff..3a9728c 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 @@ -53,6 +53,7 @@ public class BusinessRuleService { private final BusinessRuleRepository businessRuleRepository; private final ListSigningService listSigningService; + private final Optional signingService; private final SignedListRepository signedListRepository; private final BusinessRulesUtils businessRulesUtils; @@ -127,6 +128,10 @@ public void saveBusinessRule(BusinessRuleItem rule) { bre.setVersion(rule.getVersion()); bre.setRawData(rule.getRawData()); + if (signingService.isPresent()) { + bre.setSignature(signingService.get().computeSignature(bre.getHash())); + } + businessRuleRepository.save(bre); } diff --git a/src/main/resources/db/changelog.xml b/src/main/resources/db/changelog.xml index fd9d6be..f701e21 100644 --- a/src/main/resources/db/changelog.xml +++ b/src/main/resources/db/changelog.xml @@ -6,5 +6,5 @@ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd"> - + \ No newline at end of file diff --git a/src/main/resources/db/changelog/add_rule_signature_column.xml b/src/main/resources/db/changelog/add_rule_signature_column.xml new file mode 100644 index 0000000..49765c5 --- /dev/null +++ b/src/main/resources/db/changelog/add_rule_signature_column.xml @@ -0,0 +1,15 @@ + + + + + + + + + +