Skip to content

Commit

Permalink
Revert "Fix: New JRC Format (#193)" (#199)
Browse files Browse the repository at this point in the history
This reverts commit ee51852.
  • Loading branch information
f11h committed Aug 9, 2022
1 parent 2bd10a1 commit 49182d1
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,5 +38,5 @@ public interface JrcClient {
*/
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE
)
List<JrcRatValueset> downloadRatValues();
JrcRatValuesetResponse downloadRatValues();
}
Original file line number Diff line number Diff line change
@@ -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<JrcRatValueset> deviceList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -87,25 +87,25 @@ public void update() {
}
}

List<JrcRatValueset> jrcResponse;
JrcRatValuesetResponse jrcResponse;
try {
jrcResponse = jrcClient.downloadRatValues();
} catch (FeignException e) {
log.error("Failed to download RatValueset from JRC", e);
return;
}

for (JrcRatValueset device : jrcResponse) {
for (JrcRatValueset device : jrcResponse.getDeviceList()) {
JrcRatValueset.HscListHistory latestHistoryEntryNotInFuture = null;
JrcRatValueset.HscListHistory latestHistoryEntry = null;
long now = ZonedDateTime.now().toEpochSecond();

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 49182d1

Please sign in to comment.