From 49182d114744a7e6e9d23bdad17e7fa43c1cec0a Mon Sep 17 00:00:00 2001 From: Felix Dittrich <31076102+f11h@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:10:01 +0200 Subject: [PATCH] Revert "Fix: New JRC Format (#193)" (#199) This reverts commit ee51852ff9e722912dcf607919cd6b6447cbd1e9. --- .../ec/dgc/gateway/client/JrcClient.java | 5 +- .../gateway/model/JrcRatValuesetResponse.java | 38 ++++++++++++++ .../service/RatValuesetUpdateService.java | 12 ++--- .../service/RatValuesetUpdateServiceTest.java | 49 ++++++++++++++++--- 4 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 src/main/java/eu/europa/ec/dgc/gateway/model/JrcRatValuesetResponse.java diff --git a/src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java b/src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java index 07ce7282..cbc3fb57 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java @@ -20,8 +20,7 @@ package eu.europa.ec.dgc.gateway.client; -import eu.europa.ec.dgc.gateway.model.JrcRatValueset; -import java.util.List; +import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; @@ -39,5 +38,5 @@ public interface JrcClient { */ @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE ) - List downloadRatValues(); + JrcRatValuesetResponse downloadRatValues(); } diff --git a/src/main/java/eu/europa/ec/dgc/gateway/model/JrcRatValuesetResponse.java b/src/main/java/eu/europa/ec/dgc/gateway/model/JrcRatValuesetResponse.java new file mode 100644 index 00000000..767a0af2 --- /dev/null +++ b/src/main/java/eu/europa/ec/dgc/gateway/model/JrcRatValuesetResponse.java @@ -0,0 +1,38 @@ +/*- + * ---license-start + * EU Digital Green Certificate Gateway Service / dgc-gateway + * --- + * Copyright (C) 2021 - 2022 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + +package eu.europa.ec.dgc.gateway.model; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.time.ZonedDateTime; +import java.util.List; +import lombok.Data; + +@Data +public class JrcRatValuesetResponse { + + @JsonProperty("extracted_on") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z") + ZonedDateTime extractedOn; + + @JsonProperty("deviceList") + List deviceList; +} diff --git a/src/main/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateService.java b/src/main/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateService.java index 557a6e52..46a9f4ae 100644 --- a/src/main/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateService.java +++ b/src/main/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateService.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.europa.ec.dgc.gateway.client.JrcClient; import eu.europa.ec.dgc.gateway.model.JrcRatValueset; +import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse; import eu.europa.ec.dgc.gateway.model.RatValueset; import eu.europa.ec.dgc.gateway.model.Valueset; import eu.europa.ec.dgc.gateway.utils.DgcMdc; @@ -34,7 +35,6 @@ import java.time.ZonedDateTime; import java.util.Comparator; import java.util.HashMap; -import java.util.List; import java.util.Optional; import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; @@ -87,7 +87,7 @@ public void update() { } } - List jrcResponse; + JrcRatValuesetResponse jrcResponse; try { jrcResponse = jrcClient.downloadRatValues(); } catch (FeignException e) { @@ -95,7 +95,7 @@ public void update() { return; } - for (JrcRatValueset device : jrcResponse) { + for (JrcRatValueset device : jrcResponse.getDeviceList()) { JrcRatValueset.HscListHistory latestHistoryEntryNotInFuture = null; JrcRatValueset.HscListHistory latestHistoryEntry = null; long now = ZonedDateTime.now().toEpochSecond(); @@ -103,9 +103,9 @@ public void update() { if (device.getHscListHistory() != null) { latestHistoryEntryNotInFuture = device.getHscListHistory().stream() - .sorted(Comparator - .comparing((JrcRatValueset.HscListHistory x) -> x.getListDate().toEpochSecond()) - .reversed()) + .sorted(Comparator + .comparing((JrcRatValueset.HscListHistory x) -> x.getListDate().toEpochSecond()) + .reversed()) .dropWhile(x -> x.getListDate().toEpochSecond() > now) .findFirst() .orElse(null); diff --git a/src/test/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateServiceTest.java b/src/test/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateServiceTest.java index b59fc785..bcd44952 100644 --- a/src/test/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateServiceTest.java +++ b/src/test/java/eu/europa/ec/dgc/gateway/service/RatValuesetUpdateServiceTest.java @@ -29,6 +29,7 @@ import eu.europa.ec.dgc.gateway.client.JrcClient; import eu.europa.ec.dgc.gateway.entity.ValuesetEntity; import eu.europa.ec.dgc.gateway.model.JrcRatValueset; +import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse; import eu.europa.ec.dgc.gateway.model.RatValueset; import eu.europa.ec.dgc.gateway.model.Valueset; import eu.europa.ec.dgc.gateway.repository.ValuesetRepository; @@ -141,7 +142,11 @@ void testRatValuesetUpdateActiveFalse() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -179,7 +184,11 @@ void testRatValuesetUpdateActiveTrue() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -219,7 +228,11 @@ void testRatValuesetInsertedIfNotExist() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -260,7 +273,11 @@ void testRatValuesetUpdatedIfJsonInDbIsInvalid() throws JsonProcessingException jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -288,7 +305,11 @@ void testRatValuesetUpdatedSkipIfHistoryEmpty() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(Collections.emptyList()); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -315,7 +336,11 @@ void testRatValuesetUpdatedSkipIfHistoryNull() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(null); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -369,7 +394,11 @@ void testRatValuesetUpdateLatestAllHistoryEntriesAreInFuture() throws JsonProces jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update(); @@ -413,7 +442,11 @@ void testRatValuesetUpdateLatestHistoryEntryNotInFuture() throws JsonProcessingE jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2, history3)); - when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); + JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); + jrcResponse.setExtractedOn(ZonedDateTime.now()); + jrcResponse.setDeviceList(List.of(jrcValueset)); + + when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); ratValuesetUpdateService.update();