From fdee2faf2a6f08b0a2ec861a085d87f71f071316 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 21 Feb 2023 07:44:26 +0000 Subject: [PATCH 1/9] Update CWA-Parent to 2.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7ff25c6..96d4ab6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ app.coronawarn cwa-parent - 1.7.1 + 2.0.1 eu.europa.ec.dgc From c836db50c5f07c47ea0711fb079964bb3ade68aa Mon Sep 17 00:00:00 2001 From: Morphyum Date: Thu, 23 Feb 2023 13:41:47 +0100 Subject: [PATCH 2/9] * everything green except openapi --- .../dgc/businessrule/config/ErrorHandler.java | 22 +- .../config/WebSecurityConfig.java | 12 +- .../entity/BusinessRuleEntity.java | 10 +- .../entity/CountryListEntity.java | 10 +- .../businessrule/entity/ShedlockEntity.java | 13 +- .../businessrule/entity/SignedListEntity.java | 14 +- .../entity/UserAgentLogEntity.java | 12 +- .../businessrule/entity/ValueSetEntity.java | 10 +- .../BoosterNotificationRuleController.java | 49 ++-- .../controller/BusinessRuleController.java | 49 ++-- .../restapi/controller/CclRuleController.java | 49 ++-- .../controller/DomesticRuleController.java | 49 ++-- .../controller/ValueSetController.java | 241 +++++++++--------- .../interceptor/UserAgentLogInterceptor.java | 7 +- .../BoosterNotificationRuleService.java | 3 +- .../service/BusinessRuleService.java | 14 +- .../businessrule/service/CclRuleService.java | 3 +- .../service/DomesticRuleService.java | 3 +- .../service/JksSigningService.java | 2 +- .../service/UserAgentLogService.java | 2 +- .../businessrule/service/ValueSetService.java | 10 +- .../utils/btp/CredentialStoreCryptoUtil.java | 11 +- 22 files changed, 298 insertions(+), 297 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java b/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java index 98a866d..241fe1b 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java @@ -32,6 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.context.request.WebRequest; import org.springframework.web.server.ResponseStatusException; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; @@ -62,15 +63,24 @@ public ResponseEntity handleException(Exception e) { if (e instanceof ResponseStatusException) { DgcaBusinessRulesResponseException de = (DgcaBusinessRulesResponseException) e; return ResponseEntity - .status(((ResponseStatusException) e).getStatus()) - .contentType(MediaType.APPLICATION_JSON) - .body(new ProblemReportDto(de.getCode(), de.getProblem(), de.getSentValues(), de.getDetails())); + .status(((ResponseStatusException) e).getStatusCode()) + .contentType(MediaType.APPLICATION_JSON) + .body(new ProblemReportDto(de.getCode(), de.getProblem(), de.getSentValues(), de.getDetails())); } else { log.error("Uncatched exception", e); return ResponseEntity - .status(HttpStatus.INTERNAL_SERVER_ERROR) - .contentType(MediaType.APPLICATION_JSON) - .body(new ProblemReportDto("0x500", "Internal Server Error", "", "")); + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .contentType(MediaType.APPLICATION_JSON) + .body(new ProblemReportDto("0x500", "Internal Server Error", "", "")); } } + + @ExceptionHandler(ResponseStatusException.class) + public ResponseEntity handleException(ResponseStatusException e, WebRequest request) { + DgcaBusinessRulesResponseException de = (DgcaBusinessRulesResponseException) e; + return ResponseEntity + .status(e.getStatusCode()) + .contentType(MediaType.APPLICATION_JSON) + .body(new ProblemReportDto(de.getCode(), de.getProblem(), de.getSentValues(), de.getDetails())); + } } diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/config/WebSecurityConfig.java b/src/main/java/eu/europa/ec/dgc/businessrule/config/WebSecurityConfig.java index 452724c..ae2c3f6 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/config/WebSecurityConfig.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/config/WebSecurityConfig.java @@ -20,16 +20,20 @@ package eu.europa.ec.dgc.businessrule.config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.SecurityFilterChain; @EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { +@Configuration +public class WebSecurityConfig { - @Override - protected void configure(HttpSecurity http) throws Exception { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.cors().and().csrf().disable(); + return http.build(); } } 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 3b35a6d..b48f14b 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 @@ -20,11 +20,11 @@ package eu.europa.ec.dgc.businessrule.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/CountryListEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/CountryListEntity.java index a539c08..42bcfe5 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/CountryListEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/CountryListEntity.java @@ -20,11 +20,11 @@ package eu.europa.ec.dgc.businessrule.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/ShedlockEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/ShedlockEntity.java index 4f43e7d..5dee36a 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/ShedlockEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/ShedlockEntity.java @@ -20,13 +20,14 @@ package eu.europa.ec.dgc.businessrule.entity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.util.Date; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; + @Entity @Table(name = "shedlock_br") diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/SignedListEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/SignedListEntity.java index d895fd6..ca3d5f7 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/SignedListEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/SignedListEntity.java @@ -20,13 +20,13 @@ package eu.europa.ec.dgc.businessrule.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/UserAgentLogEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/UserAgentLogEntity.java index c112627..666d755 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/UserAgentLogEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/UserAgentLogEntity.java @@ -21,13 +21,13 @@ package eu.europa.ec.dgc.businessrule.entity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import java.time.ZonedDateTime; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/entity/ValueSetEntity.java b/src/main/java/eu/europa/ec/dgc/businessrule/entity/ValueSetEntity.java index d5083a8..fe5e266 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/entity/ValueSetEntity.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/entity/ValueSetEntity.java @@ -20,11 +20,11 @@ package eu.europa.ec.dgc.businessrule.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BoosterNotificationRuleController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BoosterNotificationRuleController.java index 0a4426f..fdc3ef6 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BoosterNotificationRuleController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/BoosterNotificationRuleController.java @@ -34,9 +34,8 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import java.util.List; +import jakarta.validation.Valid; import java.util.Optional; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -91,11 +90,11 @@ public class BoosterNotificationRuleController { array = @ArraySchema(schema = @Schema(implementation = BoosterNotificationRuleListItemDto.class)))) } ) - public ResponseEntity> getRules( + public ResponseEntity getRules( @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = boosterNotificationRuleService.getRulesSignedList(); - ResponseEntity responseEntity; + ResponseEntity responseEntity; if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); @@ -143,27 +142,27 @@ public ResponseEntity> getRules( mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = String.class), examples = { - @ExampleObject(value = "{\n" - + " \"Identifier\": \"VR-DE-1\",\n" - + " \"Version\": \"1.0.0\",\n" - + " \"SchemaVersion\":\"1.0.0\",\n" - + " \"Engine\":\"CERTLOGIC\",\n" - + " \"EngineVersion\":\"1.0.0\",\n" - + " \"Type\":\"Acceptance\",\n" - + " \"Country\":\"DE\",\n" - + " \"CertificateType\":\"Vaccination\",\n" - + " \"Description\":[{\"lang\":\"en\",\"desc\":\"Vaccination must be from June and " - + "doses must be 2\"}],\n" - + " \"ValidFrom\":\"2021-06-27T07:46:40Z\",\n" - + " \"ValidTo\":\"2021-08-01T07:46:40Z\",\n" - + " \"AffectedFields\":[\"dt\",\"dn\"],\n" - + " \"Logic\":{\n" - + " \"and\": [\n" - + " {\">=\":[ {\"var\":\"dt\"}, \"2021-06-01T00:00:00Z\" ]},\n" - + " {\">=\":[ {\"var\":\"dn\"}, 2 ]}\n" - + " ]\n" - + " }\n" - + "}") + @ExampleObject(value = """ + { + "Identifier": "VR-DE-1", + "Version": "1.0.0", + "SchemaVersion":"1.0.0", + "Engine":"CERTLOGIC", + "EngineVersion":"1.0.0", + "Type":"Acceptance", + "Country":"DE", + "CertificateType":"Vaccination", + "Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}], + "ValidFrom":"2021-06-27T07:46:40Z", + "ValidTo":"2021-08-01T07:46:40Z", + "AffectedFields":["dt","dn"], + "Logic":{ + "and": [ + {">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]}, + {">=":[ {"var":"dn"}, 2 ]} + ] + } + }""") })), @ApiResponse( responseCode = "404", 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 a877057..1e14cc4 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 @@ -34,13 +34,12 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import jakarta.validation.Valid; import java.util.List; import java.util.Locale; import java.util.Optional; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -91,11 +90,11 @@ public class BusinessRuleController { array = @ArraySchema(schema = @Schema(implementation = BusinessRuleListItemDto.class)))) } ) - public ResponseEntity> getRules( + public ResponseEntity getRules( @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = businessRuleService.getBusinessRulesSignedList(); - ResponseEntity responseEntity; + ResponseEntity responseEntity; if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); @@ -194,27 +193,27 @@ public ResponseEntity> getRulesForCountry( mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = String.class), examples = { - @ExampleObject(value = "{\n" - + " \"Identifier\": \"VR-DE-1\",\n" - + " \"Version\": \"1.0.0\",\n" - + " \"SchemaVersion\":\"1.0.0\",\n" - + " \"Engine\":\"CERTLOGIC\",\n" - + " \"EngineVersion\":\"1.0.0\",\n" - + " \"Type\":\"Acceptance\",\n" - + " \"Country\":\"DE\",\n" - + " \"CertificateType\":\"Vaccination\",\n" - + " \"Description\":[{\"lang\":\"en\",\"desc\":\"Vaccination must be from June and " - + "doses must be 2\"}],\n" - + " \"ValidFrom\":\"2021-06-27T07:46:40Z\",\n" - + " \"ValidTo\":\"2021-08-01T07:46:40Z\",\n" - + " \"AffectedFields\":[\"dt\",\"dn\"],\n" - + " \"Logic\":{\n" - + " \"and\": [\n" - + " {\">=\":[ {\"var\":\"dt\"}, \"2021-06-01T00:00:00Z\" ]},\n" - + " {\">=\":[ {\"var\":\"dn\"}, 2 ]}\n" - + " ]\n" - + " }\n" - + "}") + @ExampleObject(value = """ + { + "Identifier": "VR-DE-1", + "Version": "1.0.0", + "SchemaVersion":"1.0.0", + "Engine":"CERTLOGIC", + "EngineVersion":"1.0.0", + "Type":"Acceptance", + "Country":"DE", + "CertificateType":"Vaccination", + "Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}], + "ValidFrom":"2021-06-27T07:46:40Z", + "ValidTo":"2021-08-01T07:46:40Z", + "AffectedFields":["dt","dn"], + "Logic":{ + "and": [ + {">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]}, + {">=":[ {"var":"dn"}, 2 ]} + ] + } + }""") })), @ApiResponse( responseCode = "400", diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/CclRuleController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/CclRuleController.java index f50e97d..d4790bb 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/CclRuleController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/CclRuleController.java @@ -34,9 +34,8 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import java.util.List; +import jakarta.validation.Valid; import java.util.Optional; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -90,11 +89,11 @@ public class CclRuleController { array = @ArraySchema(schema = @Schema(implementation = CclRuleListItemDto.class)))) } ) - public ResponseEntity> getRules( + public ResponseEntity getRules( @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = cclRuleService.getRulesSignedList(); - ResponseEntity responseEntity; + ResponseEntity responseEntity; if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); @@ -142,27 +141,27 @@ public ResponseEntity> getRules( mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = String.class), examples = { - @ExampleObject(value = "{\n" - + " \"Identifier\": \"VR-DE-1\",\n" - + " \"Version\": \"1.0.0\",\n" - + " \"SchemaVersion\":\"1.0.0\",\n" - + " \"Engine\":\"CERTLOGIC\",\n" - + " \"EngineVersion\":\"1.0.0\",\n" - + " \"Type\":\"Acceptance\",\n" - + " \"Country\":\"DE\",\n" - + " \"CertificateType\":\"Vaccination\",\n" - + " \"Description\":[{\"lang\":\"en\",\"desc\":\"Vaccination must be from June and " - + "doses must be 2\"}],\n" - + " \"ValidFrom\":\"2021-06-27T07:46:40Z\",\n" - + " \"ValidTo\":\"2021-08-01T07:46:40Z\",\n" - + " \"AffectedFields\":[\"dt\",\"dn\"],\n" - + " \"Logic\":{\n" - + " \"and\": [\n" - + " {\">=\":[ {\"var\":\"dt\"}, \"2021-06-01T00:00:00Z\" ]},\n" - + " {\">=\":[ {\"var\":\"dn\"}, 2 ]}\n" - + " ]\n" - + " }\n" - + "}") + @ExampleObject(value = """ + { + "Identifier": "VR-DE-1", + "Version": "1.0.0", + "SchemaVersion":"1.0.0", + "Engine":"CERTLOGIC", + "EngineVersion":"1.0.0", + "Type":"Acceptance", + "Country":"DE", + "CertificateType":"Vaccination", + "Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}], + "ValidFrom":"2021-06-27T07:46:40Z", + "ValidTo":"2021-08-01T07:46:40Z", + "AffectedFields":["dt","dn"], + "Logic":{ + "and": [ + {">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]}, + {">=":[ {"var":"dn"}, 2 ]} + ] + } + }""") })), @ApiResponse( responseCode = "404", diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/DomesticRuleController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/DomesticRuleController.java index ef9d209..acd38bf 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/DomesticRuleController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/DomesticRuleController.java @@ -34,9 +34,8 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import java.util.List; +import jakarta.validation.Valid; import java.util.Optional; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -91,11 +90,11 @@ public class DomesticRuleController { array = @ArraySchema(schema = @Schema(implementation = DomesticRuleListItemDto.class)))) } ) - public ResponseEntity> getRules( + public ResponseEntity getRules( @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = domesticRuleService.getRulesSignedList(); - ResponseEntity responseEntity; + ResponseEntity responseEntity; if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); @@ -143,27 +142,27 @@ public ResponseEntity> getRules( mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = String.class), examples = { - @ExampleObject(value = "{\n" - + " \"Identifier\": \"VR-DE-1\",\n" - + " \"Version\": \"1.0.0\",\n" - + " \"SchemaVersion\":\"1.0.0\",\n" - + " \"Engine\":\"CERTLOGIC\",\n" - + " \"EngineVersion\":\"1.0.0\",\n" - + " \"Type\":\"Acceptance\",\n" - + " \"Country\":\"DE\",\n" - + " \"CertificateType\":\"Vaccination\",\n" - + " \"Description\":[{\"lang\":\"en\",\"desc\":\"Vaccination must be from June and " - + "doses must be 2\"}],\n" - + " \"ValidFrom\":\"2021-06-27T07:46:40Z\",\n" - + " \"ValidTo\":\"2021-08-01T07:46:40Z\",\n" - + " \"AffectedFields\":[\"dt\",\"dn\"],\n" - + " \"Logic\":{\n" - + " \"and\": [\n" - + " {\">=\":[ {\"var\":\"dt\"}, \"2021-06-01T00:00:00Z\" ]},\n" - + " {\">=\":[ {\"var\":\"dn\"}, 2 ]}\n" - + " ]\n" - + " }\n" - + "}") + @ExampleObject(value = """ + { + "Identifier": "VR-DE-1", + "Version": "1.0.0", + "SchemaVersion":"1.0.0", + "Engine":"CERTLOGIC", + "EngineVersion":"1.0.0", + "Type":"Acceptance", + "Country":"DE", + "CertificateType":"Vaccination", + "Description":[{"lang":"en","desc":"Vaccination must be from June and doses must be 2"}], + "ValidFrom":"2021-06-27T07:46:40Z", + "ValidTo":"2021-08-01T07:46:40Z", + "AffectedFields":["dt","dn"], + "Logic":{ + "and": [ + {">=":[ {"var":"dt"}, "2021-06-01T00:00:00Z" ]}, + {">=":[ {"var":"dn"}, 2 ]} + ] + } + }""") })), @ApiResponse( responseCode = "404", diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java index b2d7266..d1daede 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java @@ -27,7 +27,6 @@ import eu.europa.ec.dgc.businessrule.restapi.dto.ProblemReportDto; import eu.europa.ec.dgc.businessrule.restapi.dto.ValueSetListItemDto; import eu.europa.ec.dgc.businessrule.service.ValueSetService; -import eu.europa.ec.dgc.businessrule.utils.BusinessRulesUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; @@ -36,12 +35,10 @@ import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import java.util.List; +import jakarta.validation.Valid; import java.util.Optional; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -60,8 +57,6 @@ public class ValueSetController { private static final String API_VERSION_HEADER = "X-VERSION"; - private final BusinessRulesUtils businessRulesUtils; - private final ValueSetService valueSetService; @@ -70,76 +65,79 @@ public class ValueSetController { */ @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) @Operation( - summary = "Gets the a list of all value set ids and value set hash values.", - description = "This method returns a list containing the ids and hash values of all value sets. The" - + " hash value can be used to check, if a value set has changed and needs to be updated. The hash value can" - + " also be used to download a specific value set afterwards.", - tags = {"Value Sets"}, - parameters = { - @Parameter( - in = ParameterIn.HEADER, - name = "X-VERSION", - description = "Version of the API. In preparation of changes in the future. Set it to \"1.0\"", - required = true, - schema = @Schema(implementation = String.class)) - }, - responses = { - @ApiResponse( - responseCode = "200", - description = "Returns a list of all value set ids and there hash values.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - array = @ArraySchema(schema = @Schema(implementation = ValueSetListItemDto.class)), - examples = { - @ExampleObject(value = "[\n" - + " {\n" - + " \"id\": \"country-2-codes\",\n" - + " \"hash\": \"923e4e556fe7936e4a3e92e76cfb3aa87be1bf30000b4df3b755247042eea0e7\"\n" - + " },\n" - + " {\n" - + " \"id\": \"covid-19-lab-result\",\n" - + " \"hash\": \"934e145e9bb1f560d1d3b1ec767ce3a4e9f86ae101260ed04a5cef8c1f5636c4\"\n" - + " },\n" - + " {\n" - + " \"id\": \"covid-19-lab-test-manufacturer-and-name\",\n" - + " \"hash\": \"9da3ed15d036c20339647f8db1cb67bfcfbd04575e10b0c0df8e55a76a173a97\"\n" - + " },\n" - + " {\n" - + " \"id\": \"covid-19-lab-test-type\",\n" - + " \"hash\": \"50ba87d7c774cd9d77e4d82f6ab34871119bc4ad51b5b6fa1100efa687be0094\"\n" - + " },\n" - + " {\n" - + " \"id\": \"disease-agent-targeted\",\n" - + " \"hash\": \"d4bfba1fd9f2eb29dfb2938220468ccb0b481d348f192e6015d36da4b911a83a\"\n" - + " },\n" - + " {\n" - + " \"id\": \"sct-vaccines-covid-19\",\n" - + " \"hash\": \"70505eab33ac1da351f782ee2e78e89451226c47360e7b89b8a6295bbb70eed6\"\n" - + " },\n" - + " {\n" - + " \"id\": \"vaccines-covid-19-auth-holders\",\n" - + " \"hash\": \"55af9c705a95ced1a7d9130043f71a7a01f72e168dbd451d23d1575962518ab6\"\n" - + " },\n" - + " {\n" - + " \"id\": \"vaccines-covid-19-names\",\n" - + " \"hash\": \"8651c3db9ed5332c8fa42943d4656d442a5264debc8482b6d11d4c9176149146\"\n" - + " }\n" - + "]") - })) - } + summary = "Gets the a list of all value set ids and value set hash values.", + description = "This method returns a list containing the ids and hash values of all value sets. The" + + " hash value can be used to check, if a value set has changed and needs to be updated. The hash value can" + + " also be used to download a specific value set afterwards.", + tags = {"Value Sets"}, + parameters = { + @Parameter( + in = ParameterIn.HEADER, + name = "X-VERSION", + description = "Version of the API. In preparation of changes in the future. Set it to \"1.0\"", + required = true, + schema = @Schema(implementation = String.class)) + }, + responses = { + @ApiResponse( + responseCode = "200", + description = "Returns a list of all value set ids and there hash values.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + array = @ArraySchema(schema = @Schema(implementation = ValueSetListItemDto.class)), + examples = { + @ExampleObject(value = """ + [ + { + "id": "country-2-codes", + "hash": "923e4e556fe7936e4a3e92e76cfb3aa87be1bf30000b4df3b755247042eea0e7" + }, + { + "id": "covid-19-lab-result", + "hash": "934e145e9bb1f560d1d3b1ec767ce3a4e9f86ae101260ed04a5cef8c1f5636c4" + }, + { + "id": "covid-19-lab-test-manufacturer-and-name", + "hash": "9da3ed15d036c20339647f8db1cb67bfcfbd04575e10b0c0df8e55a76a173a97" + }, + { + "id": "covid-19-lab-test-type", + "hash": "50ba87d7c774cd9d77e4d82f6ab34871119bc4ad51b5b6fa1100efa687be0094" + }, + { + "id": "disease-agent-targeted", + "hash": "d4bfba1fd9f2eb29dfb2938220468ccb0b481d348f192e6015d36da4b911a83a" + }, + { + "id": "sct-vaccines-covid-19", + "hash": "70505eab33ac1da351f782ee2e78e89451226c47360e7b89b8a6295bbb70eed6" + }, + { + "id": "vaccines-covid-19-auth-holders", + "hash": "55af9c705a95ced1a7d9130043f71a7a01f72e168dbd451d23d1575962518ab6" + }, + { + "id": "vaccines-covid-19-names", + "hash": "8651c3db9ed5332c8fa42943d4656d442a5264debc8482b6d11d4c9176149146" + } + ]""") + })) + } ) - public ResponseEntity> getValueSetList( - @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion + public ResponseEntity getValueSetList( + @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = valueSetService.getValueSetsSignedList(); - ResponseEntity responseEntity; + ResponseEntity responseEntity; if (rulesList.isPresent()) { ResponseEntity.BodyBuilder respBuilder = ResponseEntity.ok(); String signature = rulesList.get().getSignature(); - if (signature != null & signature.length() > 0) { - HttpHeaders responseHeaders = new HttpHeaders(); - responseHeaders.set(BusinessRuleController.X_SIGNATURE_HEADER, signature); - respBuilder.headers(responseHeaders); + if (signature != null) { + if (signature.length() > 0) { + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.set(BusinessRuleController.X_SIGNATURE_HEADER, signature); + respBuilder.headers(responseHeaders); + } } responseEntity = respBuilder.body(rulesList.get().getRawData()); } else { @@ -153,58 +151,59 @@ public ResponseEntity> getValueSetList( */ @GetMapping(path = "/{hash}", produces = MediaType.APPLICATION_JSON_VALUE) @Operation( - summary = "Gets a specific value set by its hash value.", - description = "This method can be used to download a specific value set. Therefore the hash value of the value " - + "set must be provided as path parameter.", - tags = {"Value Sets"}, - parameters = { - @Parameter( - in = ParameterIn.PATH, - name = "hash", - description = "Hash of the value set to download", - required = true, - schema = @Schema(implementation = String.class)), - @Parameter( - in = ParameterIn.HEADER, - name = "X-VERSION", - description = "Version of the API. In preparation of changes in the future.", - required = true, - schema = @Schema(implementation = String.class)) - }, - responses = { - @ApiResponse( - responseCode = "200", - description = "Returns the specified value set.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = String.class), - examples = { - @ExampleObject(value = "{\n" - + " \"valueSetId\": \"disease-agent-targeted\",\n" - + " \"valueSetDate\": \"2021-04-27\",\n" - + " \"valueSetValues\": {\n" - + " \"840539006\": {\n" - + " \"display\": \"COVID-19\",\n" - + " \"lang\": \"en\",\n" - + " \"active\": true,\n" - + " \"version\": \"http://snomed.info/sct/900000000000207008/version/20210131\",\n" - + " \"system\": \"http://snomed.info/sct\"\n" - + " }\n" - + " }\n" - + "}") - })), - @ApiResponse( - responseCode = "404", - description = "Value set could not be found for the given hash value.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = ProblemReportDto.class) - )) - }) + summary = "Gets a specific value set by its hash value.", + description = "This method can be used to download a specific value set. Therefore the hash value of the value " + + "set must be provided as path parameter.", + tags = {"Value Sets"}, + parameters = { + @Parameter( + in = ParameterIn.PATH, + name = "hash", + description = "Hash of the value set to download", + required = true, + schema = @Schema(implementation = String.class)), + @Parameter( + in = ParameterIn.HEADER, + name = "X-VERSION", + description = "Version of the API. In preparation of changes in the future.", + required = true, + schema = @Schema(implementation = String.class)) + }, + responses = { + @ApiResponse( + responseCode = "200", + description = "Returns the specified value set.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = String.class), + examples = { + @ExampleObject(value = """ + { + "valueSetId": "disease-agent-targeted", + "valueSetDate": "2021-04-27", + "valueSetValues": { + "840539006": { + "display": "COVID-19", + "lang": "en", + "active": true, + "version": "http://snomed.info/sct/900000000000207008/version/20210131", + "system": "http://snomed.info/sct" + } + } + }""") + })), + @ApiResponse( + responseCode = "404", + description = "Value set could not be found for the given hash value.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ProblemReportDto.class) + )) + }) public ResponseEntity getValueSet( - @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion, - @Valid @PathVariable("hash") String hash + @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion, + @Valid @PathVariable("hash") String hash ) { ResponseEntity responseEntity; @@ -212,7 +211,7 @@ public ResponseEntity getValueSet( if (vse == null) { throw new DgcaBusinessRulesResponseException(HttpStatus.NOT_FOUND, "0x001", "Possible reasons: " - + "The provided hash value is not correct", hash, ""); + + "The provided hash value is not correct", hash, ""); } if (vse.getSignature() != null) { diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/interceptor/UserAgentLogInterceptor.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/interceptor/UserAgentLogInterceptor.java index ed50b3a..15e0ae8 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/interceptor/UserAgentLogInterceptor.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/interceptor/UserAgentLogInterceptor.java @@ -21,8 +21,9 @@ package eu.europa.ec.dgc.businessrule.restapi.interceptor; import eu.europa.ec.dgc.businessrule.service.UserAgentLogService; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import javax.annotation.Nonnull; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.ObjectProvider; import org.springframework.http.HttpHeaders; @@ -40,7 +41,7 @@ public class UserAgentLogInterceptor implements HandlerInterceptor { */ @Override public void afterCompletion( - HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { + HttpServletRequest request, @Nonnull HttpServletResponse response, @Nonnull Object handler, Exception ex) { String userAgentHeader = request.getHeader(HttpHeaders.USER_AGENT); String userAgent = userAgentHeader == null ? "NO USER AGENT" : userAgentHeader; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/BoosterNotificationRuleService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/BoosterNotificationRuleService.java index 7e4b984..3b19231 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/BoosterNotificationRuleService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/BoosterNotificationRuleService.java @@ -25,13 +25,13 @@ import eu.europa.ec.dgc.businessrule.model.BoosterNotificationRuleItem; import eu.europa.ec.dgc.businessrule.repository.SignedListRepository; import eu.europa.ec.dgc.businessrule.restapi.dto.BoosterNotificationRuleListItemDto; +import jakarta.annotation.PostConstruct; import java.util.Comparator; import java.util.HashMap; import java.util.List; 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; @@ -45,6 +45,7 @@ public class BoosterNotificationRuleService { private final Map boosterNotificationRuleMap = new HashMap<>(); private final ListSigningService listSigningService; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private final Optional signingService; private final SignedListRepository signedListRepository; 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 b302794..f1d7c44 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 @@ -29,13 +29,13 @@ import eu.europa.ec.dgc.businessrule.restapi.dto.BusinessRuleListItemDto; import eu.europa.ec.dgc.businessrule.utils.BusinessRulesUtils; import eu.europa.ec.dgc.gateway.connector.model.ValidationRule; +import jakarta.annotation.PostConstruct; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; 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.cache.annotation.CacheEvict; @@ -51,6 +51,7 @@ public class BusinessRuleService { private final BusinessRuleRepository businessRuleRepository; private final ListSigningService listSigningService; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private final Optional signingService; private final SignedListRepository signedListRepository; @@ -72,8 +73,7 @@ public void businessRuleServiceInit() { @Cacheable("business_rules") public List getBusinessRulesList() { log.debug("Get Rules list executed."); - List rulesItems = businessRuleRepository.findAllByOrderByIdentifierAsc(); - return rulesItems; + return businessRuleRepository.findAllByOrderByIdentifierAsc(); } @Cacheable("business_rules") @@ -88,9 +88,7 @@ public Optional getBusinessRulesSignedList() { @Cacheable("business_rules") public List getBusinessRulesListForCountry(String country) { log.debug("Get Rules list for country ({}) executed.", country); - List rulesItems = - businessRuleRepository.findAllByCountryOrderByIdentifierAsc(country.toUpperCase(Locale.ROOT)); - return rulesItems; + return businessRuleRepository.findAllByCountryOrderByIdentifierAsc(country.toUpperCase(Locale.ROOT)); } /**f @@ -141,9 +139,7 @@ public void saveBusinessRule(BusinessRuleItem rule) { bre.setVersion(rule.getVersion()); bre.setRawData(rule.getRawData()); - if (signingService.isPresent()) { - bre.setSignature(signingService.get().computeSignature(bre.getHash())); - } + signingService.ifPresent(service -> bre.setSignature(service.computeSignature(bre.getHash()))); businessRuleRepository.save(bre); } diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/CclRuleService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/CclRuleService.java index 08cfac1..adde582 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/CclRuleService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/CclRuleService.java @@ -25,13 +25,13 @@ import eu.europa.ec.dgc.businessrule.model.CclRuleItem; import eu.europa.ec.dgc.businessrule.repository.SignedListRepository; import eu.europa.ec.dgc.businessrule.restapi.dto.CclRuleListItemDto; +import jakarta.annotation.PostConstruct; import java.util.Comparator; import java.util.HashMap; import java.util.List; 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; @@ -44,6 +44,7 @@ public class CclRuleService { private final Map cclRuleMap = new HashMap<>(); private final ListSigningService listSigningService; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private final Optional signingService; private final SignedListRepository signedListRepository; 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 23f8e3e..6f5bcb6 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 @@ -25,13 +25,13 @@ import eu.europa.ec.dgc.businessrule.model.DomesticRuleItem; import eu.europa.ec.dgc.businessrule.repository.SignedListRepository; import eu.europa.ec.dgc.businessrule.restapi.dto.DomesticRuleListItemDto; +import jakarta.annotation.PostConstruct; import java.util.Comparator; import java.util.HashMap; import java.util.List; 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; @@ -45,6 +45,7 @@ public class DomesticRuleService { private final Map domesticRuleMap = new HashMap<>(); private final ListSigningService listSigningService; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private final Optional signingService; private final SignedListRepository signedListRepository; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/JksSigningService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/JksSigningService.java index a5766bc..1ab29aa 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/JksSigningService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/JksSigningService.java @@ -21,6 +21,7 @@ package eu.europa.ec.dgc.businessrule.service; import eu.europa.ec.dgc.businessrule.config.JksSigningConfig; +import jakarta.annotation.PostConstruct; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -38,7 +39,6 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.util.Base64; -import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.bouncycastle.jce.provider.BouncyCastleProvider; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/service/UserAgentLogService.java b/src/main/java/eu/europa/ec/dgc/businessrule/service/UserAgentLogService.java index 74ea269..6c25584 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/service/UserAgentLogService.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/service/UserAgentLogService.java @@ -21,6 +21,7 @@ package eu.europa.ec.dgc.businessrule.service; import eu.europa.ec.dgc.businessrule.config.DgcConfigProperties; +import jakarta.annotation.PostConstruct; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.KeyFactory; @@ -34,7 +35,6 @@ import java.util.Base64; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import javax.annotation.PostConstruct; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; 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 ec00a32..e5f821f 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 @@ -28,13 +28,13 @@ import eu.europa.ec.dgc.businessrule.repository.ValueSetRepository; import eu.europa.ec.dgc.businessrule.restapi.dto.ValueSetListItemDto; import eu.europa.ec.dgc.businessrule.utils.BusinessRulesUtils; +import jakarta.annotation.PostConstruct; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; 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.cache.annotation.CacheEvict; @@ -52,6 +52,7 @@ public class ValueSetService { private final ValueSetRepository valueSetRepository; private final ListSigningService listSigningService; private final SignedListRepository signedListRepository; + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private final Optional signingService; /** @@ -69,8 +70,7 @@ public void valueSetServiceInit() { @Cacheable("value_sets") public List getValueSetsList() { log.debug("Get value sets list executed"); - List valueSetItems = valueSetRepository.findAllByOrderByIdAsc(); - return valueSetItems; + return valueSetRepository.findAllByOrderByIdAsc(); } @Cacheable("value_sets") @@ -137,9 +137,7 @@ public void saveValueSet(String hash, String valueSetName, String valueSetData) vse.setId(valueSetName); vse.setRawData(valueSetData); - if (signingService.isPresent()) { - vse.setSignature(signingService.get().computeSignature(vse.getHash())); - } + signingService.ifPresent(service -> vse.setSignature(service.computeSignature(vse.getHash()))); valueSetRepository.save(vse); } diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/utils/btp/CredentialStoreCryptoUtil.java b/src/main/java/eu/europa/ec/dgc/businessrule/utils/btp/CredentialStoreCryptoUtil.java index 07a6813..45559bb 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/utils/btp/CredentialStoreCryptoUtil.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/utils/btp/CredentialStoreCryptoUtil.java @@ -24,6 +24,7 @@ import com.nimbusds.jose.JWEObject; import com.nimbusds.jose.Payload; import com.nimbusds.jose.crypto.RSADecrypter; +import jakarta.annotation.PostConstruct; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; @@ -33,9 +34,7 @@ import java.security.spec.X509EncodedKeySpec; import java.text.ParseException; import java.util.Base64; -import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.NotImplementedException; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -56,8 +55,6 @@ public class CredentialStoreCryptoUtil { private PrivateKey ownPrivateKey; - private PublicKey serverPublicKey; - @PostConstruct private void prepare() throws NoSuchAlgorithmException, InvalidKeySpecException { if (!encryptionEnabled) { @@ -71,11 +68,7 @@ private void prepare() throws NoSuchAlgorithmException, InvalidKeySpecException X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(Base64.getDecoder() .decode(serverPublicKeyBase64)); - this.serverPublicKey = rsaKeyFactory.generatePublic(x509EncodedKeySpec); - } - - protected void encrypt() { - throw new NotImplementedException("Encryption is still to be implemented yet."); + PublicKey serverPublicKey = rsaKeyFactory.generatePublic(x509EncodedKeySpec); } protected String decrypt(String jweResponse) { From fbd5f01999efbed01ca4ea5a6f1b821af658e9b3 Mon Sep 17 00:00:00 2001 From: Morphyum Date: Thu, 23 Feb 2023 13:48:55 +0100 Subject: [PATCH 3/9] * checkstyle fixes --- .../dgc/businessrule/config/ErrorHandler.java | 7 + .../controller/ValueSetController.java | 222 +++++++++--------- 2 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java b/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java index 241fe1b..471a8a5 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/config/ErrorHandler.java @@ -75,6 +75,13 @@ public ResponseEntity handleException(Exception e) { } } + /** + * Global Exception Handler to wrap exceptions into a readable JSON Object. + * + * @param e the thrown exception + * @param request the thrown WebRequest + * @return ResponseEntity with readable data. + */ @ExceptionHandler(ResponseStatusException.class) public ResponseEntity handleException(ResponseStatusException e, WebRequest request) { DgcaBusinessRulesResponseException de = (DgcaBusinessRulesResponseException) e; diff --git a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java index d1daede..90d206c 100644 --- a/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java +++ b/src/main/java/eu/europa/ec/dgc/businessrule/restapi/controller/ValueSetController.java @@ -65,67 +65,67 @@ public class ValueSetController { */ @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) @Operation( - summary = "Gets the a list of all value set ids and value set hash values.", - description = "This method returns a list containing the ids and hash values of all value sets. The" - + " hash value can be used to check, if a value set has changed and needs to be updated. The hash value can" - + " also be used to download a specific value set afterwards.", - tags = {"Value Sets"}, - parameters = { - @Parameter( - in = ParameterIn.HEADER, - name = "X-VERSION", - description = "Version of the API. In preparation of changes in the future. Set it to \"1.0\"", - required = true, - schema = @Schema(implementation = String.class)) - }, - responses = { - @ApiResponse( - responseCode = "200", - description = "Returns a list of all value set ids and there hash values.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - array = @ArraySchema(schema = @Schema(implementation = ValueSetListItemDto.class)), - examples = { - @ExampleObject(value = """ - [ - { - "id": "country-2-codes", - "hash": "923e4e556fe7936e4a3e92e76cfb3aa87be1bf30000b4df3b755247042eea0e7" - }, - { - "id": "covid-19-lab-result", - "hash": "934e145e9bb1f560d1d3b1ec767ce3a4e9f86ae101260ed04a5cef8c1f5636c4" - }, - { - "id": "covid-19-lab-test-manufacturer-and-name", - "hash": "9da3ed15d036c20339647f8db1cb67bfcfbd04575e10b0c0df8e55a76a173a97" - }, - { - "id": "covid-19-lab-test-type", - "hash": "50ba87d7c774cd9d77e4d82f6ab34871119bc4ad51b5b6fa1100efa687be0094" - }, - { - "id": "disease-agent-targeted", - "hash": "d4bfba1fd9f2eb29dfb2938220468ccb0b481d348f192e6015d36da4b911a83a" - }, - { - "id": "sct-vaccines-covid-19", - "hash": "70505eab33ac1da351f782ee2e78e89451226c47360e7b89b8a6295bbb70eed6" - }, - { - "id": "vaccines-covid-19-auth-holders", - "hash": "55af9c705a95ced1a7d9130043f71a7a01f72e168dbd451d23d1575962518ab6" - }, - { - "id": "vaccines-covid-19-names", - "hash": "8651c3db9ed5332c8fa42943d4656d442a5264debc8482b6d11d4c9176149146" - } - ]""") - })) - } + summary = "Gets the a list of all value set ids and value set hash values.", + description = "This method returns a list containing the ids and hash values of all value sets. The" + + " hash value can be used to check, if a value set has changed and needs to be updated. The hash value can" + + " also be used to download a specific value set afterwards.", + tags = {"Value Sets"}, + parameters = { + @Parameter( + in = ParameterIn.HEADER, + name = "X-VERSION", + description = "Version of the API. In preparation of changes in the future. Set it to \"1.0\"", + required = true, + schema = @Schema(implementation = String.class)) + }, + responses = { + @ApiResponse( + responseCode = "200", + description = "Returns a list of all value set ids and there hash values.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + array = @ArraySchema(schema = @Schema(implementation = ValueSetListItemDto.class)), + examples = { + @ExampleObject(value = """ + [ + { + "id": "country-2-codes", + "hash": "923e4e556fe7936e4a3e92e76cfb3aa87be1bf30000b4df3b755247042eea0e7" + }, + { + "id": "covid-19-lab-result", + "hash": "934e145e9bb1f560d1d3b1ec767ce3a4e9f86ae101260ed04a5cef8c1f5636c4" + }, + { + "id": "covid-19-lab-test-manufacturer-and-name", + "hash": "9da3ed15d036c20339647f8db1cb67bfcfbd04575e10b0c0df8e55a76a173a97" + }, + { + "id": "covid-19-lab-test-type", + "hash": "50ba87d7c774cd9d77e4d82f6ab34871119bc4ad51b5b6fa1100efa687be0094" + }, + { + "id": "disease-agent-targeted", + "hash": "d4bfba1fd9f2eb29dfb2938220468ccb0b481d348f192e6015d36da4b911a83a" + }, + { + "id": "sct-vaccines-covid-19", + "hash": "70505eab33ac1da351f782ee2e78e89451226c47360e7b89b8a6295bbb70eed6" + }, + { + "id": "vaccines-covid-19-auth-holders", + "hash": "55af9c705a95ced1a7d9130043f71a7a01f72e168dbd451d23d1575962518ab6" + }, + { + "id": "vaccines-covid-19-names", + "hash": "8651c3db9ed5332c8fa42943d4656d442a5264debc8482b6d11d4c9176149146" + } + ]""") + })) + } ) public ResponseEntity getValueSetList( - @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion + @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion ) { Optional rulesList = valueSetService.getValueSetsSignedList(); ResponseEntity responseEntity; @@ -151,59 +151,59 @@ public ResponseEntity getValueSetList( */ @GetMapping(path = "/{hash}", produces = MediaType.APPLICATION_JSON_VALUE) @Operation( - summary = "Gets a specific value set by its hash value.", - description = "This method can be used to download a specific value set. Therefore the hash value of the value " - + "set must be provided as path parameter.", - tags = {"Value Sets"}, - parameters = { - @Parameter( - in = ParameterIn.PATH, - name = "hash", - description = "Hash of the value set to download", - required = true, - schema = @Schema(implementation = String.class)), - @Parameter( - in = ParameterIn.HEADER, - name = "X-VERSION", - description = "Version of the API. In preparation of changes in the future.", - required = true, - schema = @Schema(implementation = String.class)) - }, - responses = { - @ApiResponse( - responseCode = "200", - description = "Returns the specified value set.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = String.class), - examples = { - @ExampleObject(value = """ - { - "valueSetId": "disease-agent-targeted", - "valueSetDate": "2021-04-27", - "valueSetValues": { - "840539006": { - "display": "COVID-19", - "lang": "en", - "active": true, - "version": "http://snomed.info/sct/900000000000207008/version/20210131", - "system": "http://snomed.info/sct" - } - } - }""") - })), - @ApiResponse( - responseCode = "404", - description = "Value set could not be found for the given hash value.", - content = @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = ProblemReportDto.class) - )) - }) + summary = "Gets a specific value set by its hash value.", + description = "This method can be used to download a specific value set. Therefore the hash value of the value " + + "set must be provided as path parameter.", + tags = {"Value Sets"}, + parameters = { + @Parameter( + in = ParameterIn.PATH, + name = "hash", + description = "Hash of the value set to download", + required = true, + schema = @Schema(implementation = String.class)), + @Parameter( + in = ParameterIn.HEADER, + name = "X-VERSION", + description = "Version of the API. In preparation of changes in the future.", + required = true, + schema = @Schema(implementation = String.class)) + }, + responses = { + @ApiResponse( + responseCode = "200", + description = "Returns the specified value set.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = String.class), + examples = { + @ExampleObject(value = """ + { + "valueSetId": "disease-agent-targeted", + "valueSetDate": "2021-04-27", + "valueSetValues": { + "840539006": { + "display": "COVID-19", + "lang": "en", + "active": true, + "version": "http://snomed.info/sct/900000000000207008/version/20210131", + "system": "http://snomed.info/sct" + } + } + }""") + })), + @ApiResponse( + responseCode = "404", + description = "Value set could not be found for the given hash value.", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ProblemReportDto.class) + )) + }) public ResponseEntity getValueSet( - @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion, - @Valid @PathVariable("hash") String hash + @RequestHeader(value = API_VERSION_HEADER, required = false) String apiVersion, + @Valid @PathVariable("hash") String hash ) { ResponseEntity responseEntity; @@ -211,7 +211,7 @@ public ResponseEntity getValueSet( if (vse == null) { throw new DgcaBusinessRulesResponseException(HttpStatus.NOT_FOUND, "0x001", "Possible reasons: " - + "The provided hash value is not correct", hash, ""); + + "The provided hash value is not correct", hash, ""); } if (vse.getSignature() != null) { From b66c2e9af20a1cae3546f1b7bb8d304fab184035 Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 14 Mar 2023 07:51:52 +0100 Subject: [PATCH 4/9] Update ci-dependency-check.yml --- .github/workflows/ci-dependency-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-dependency-check.yml b/.github/workflows/ci-dependency-check.yml index cdf7da4..1f92bdc 100644 --- a/.github/workflows/ci-dependency-check.yml +++ b/.github/workflows/ci-dependency-check.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-java@v2 with: - java-version: 11 + java-version: 17 distribution: adopt - uses: actions/checkout@v2 with: From b15f4f76568c4f1c9b25173a39633474605f6a1c Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 14 Mar 2023 07:52:16 +0100 Subject: [PATCH 5/9] Update ci-main.yml --- .github/workflows/ci-main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 0464bf3..ecc3f8a 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -11,7 +11,7 @@ jobs: - uses: sigstore/cosign-installer@main - uses: actions/setup-java@v2 with: - java-version: 11 + java-version: 17 distribution: adopt - uses: actions/checkout@v2 with: From 1eb31d5676c9937e33d640554f00c05854e8559a Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 14 Mar 2023 07:52:30 +0100 Subject: [PATCH 6/9] Update ci-openapi.yml --- .github/workflows/ci-openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml index af39673..67c9f5c 100644 --- a/.github/workflows/ci-openapi.yml +++ b/.github/workflows/ci-openapi.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/setup-java@v2 with: - java-version: 11 + java-version: 17 distribution: adopt - uses: actions/checkout@v2 with: From ac3ab817e54e71e6b524a30e33181b1bd86009fc Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 14 Mar 2023 07:52:44 +0100 Subject: [PATCH 7/9] Update ci-pull-request.yml --- .github/workflows/ci-pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-pull-request.yml b/.github/workflows/ci-pull-request.yml index 980c831..47b2e8d 100644 --- a/.github/workflows/ci-pull-request.yml +++ b/.github/workflows/ci-pull-request.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/setup-java@v2 with: - java-version: 11 + java-version: 17 distribution: adopt - uses: actions/checkout@v2 with: From dd1a1e46cb99c0120f229b98ac4528da56bdcab2 Mon Sep 17 00:00:00 2001 From: "Marvin \"Morphyum\" Schwabe" Date: Tue, 14 Mar 2023 07:53:06 +0100 Subject: [PATCH 8/9] Update ci-release.yml --- .github/workflows/ci-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index aa939bb..78056d2 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/setup-java@v2 with: - java-version: 11 + java-version: 17 distribution: adopt - uses: actions/checkout@v2 with: From 36b4b61b0a2807c3369808a8381fc78c7f29d676 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 15 Mar 2023 10:50:44 +0000 Subject: [PATCH 9/9] Update CWA-Parent to 2.0.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7ff25c6..f87fa1d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ app.coronawarn cwa-parent - 1.7.1 + 2.0.2 eu.europa.ec.dgc