Skip to content

Commit

Permalink
Fix: New JRC Format (#193)
Browse files Browse the repository at this point in the history
* Fix JRC Download to accept new format

* Delete not needed class
  • Loading branch information
f11h authored Jul 21, 2022
1 parent a7711bb commit ee51852
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 87 deletions.
5 changes: 3 additions & 2 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,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;
Expand All @@ -38,5 +39,5 @@ public interface JrcClient {
*/
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE
)
JrcRatValuesetResponse downloadRatValues();
List<JrcRatValueset> downloadRatValues();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -87,25 +87,25 @@ public void update() {
}
}

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

for (JrcRatValueset device : jrcResponse.getDeviceList()) {
for (JrcRatValueset device : jrcResponse) {
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,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;
Expand Down Expand Up @@ -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();

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

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

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

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

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

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

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

Expand Down

0 comments on commit ee51852

Please sign in to comment.