Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Revert "Fix: New JRC Format (#193)" #199

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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