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 cbc3fb57..07ce7282 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,7 +20,8 @@ package eu.europa.ec.dgc.gateway.client; -import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse; +import eu.europa.ec.dgc.gateway.model.JrcRatValueset; +import java.util.List; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; @@ -38,5 +39,5 @@ public interface JrcClient { */ @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE ) - JrcRatValuesetResponse downloadRatValues(); + List 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 deleted file mode 100644 index 767a0af2..00000000 --- a/src/main/java/eu/europa/ec/dgc/gateway/model/JrcRatValuesetResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ---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 46a9f4ae..557a6e52 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,7 +26,6 @@ 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; @@ -35,6 +34,7 @@ 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() { } } - JrcRatValuesetResponse jrcResponse; + List jrcResponse; try { jrcResponse = jrcClient.downloadRatValues(); } catch (FeignException e) { @@ -95,7 +95,7 @@ public void update() { return; } - for (JrcRatValueset device : jrcResponse.getDeviceList()) { + for (JrcRatValueset device : jrcResponse) { 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 bcd44952..b59fc785 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,7 +29,6 @@ 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; @@ -142,11 +141,7 @@ void testRatValuesetUpdateActiveFalse() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -184,11 +179,7 @@ void testRatValuesetUpdateActiveTrue() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -228,11 +219,7 @@ void testRatValuesetInsertedIfNotExist() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -273,11 +260,7 @@ void testRatValuesetUpdatedIfJsonInDbIsInvalid() throws JsonProcessingException jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -305,11 +288,7 @@ void testRatValuesetUpdatedSkipIfHistoryEmpty() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(Collections.emptyList()); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -336,11 +315,7 @@ void testRatValuesetUpdatedSkipIfHistoryNull() throws JsonProcessingException { jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(null); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -394,11 +369,7 @@ void testRatValuesetUpdateLatestAllHistoryEntriesAreInFuture() throws JsonProces jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update(); @@ -442,11 +413,7 @@ void testRatValuesetUpdateLatestHistoryEntryNotInFuture() throws JsonProcessingE jrcValueset.setManufacturer(manufacturer); jrcValueset.setHscListHistory(List.of(history1, history2, history3)); - JrcRatValuesetResponse jrcResponse = new JrcRatValuesetResponse(); - jrcResponse.setExtractedOn(ZonedDateTime.now()); - jrcResponse.setDeviceList(List.of(jrcValueset)); - - when(jrcClientMock.downloadRatValues()).thenReturn(jrcResponse); + when(jrcClientMock.downloadRatValues()).thenReturn(List.of(jrcValueset)); ratValuesetUpdateService.update();