Skip to content

Commit

Permalink
rename 'booking' to 'backend' or remove / rename 'passenger' to 'subj…
Browse files Browse the repository at this point in the history
…ect' / rename 'flightinfo' to 'occurrence'
  • Loading branch information
Alexander Schwarz committed Sep 17, 2021
1 parent 403eb3f commit a33fb87
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import eu.europa.ec.dgc.validation.decorator.dto.CallbackRequest;
import eu.europa.ec.dgc.validation.decorator.service.AccessTokenService;
import eu.europa.ec.dgc.validation.decorator.service.BookingService;
import eu.europa.ec.dgc.validation.decorator.service.BackendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand All @@ -48,7 +48,7 @@ public class CallbackController {

private final AccessTokenService accessTokenService;

private final BookingService bookingService;
private final BackendService backendService;

/**
* Callback endpoint receives the validation result to a subject.
Expand All @@ -69,14 +69,14 @@ public ResponseEntity callback(
@PathVariable(value = "subject", required = true) final String subject,
@RequestHeader("Authorization") final String token,
@RequestHeader("X-Version") final String version,
@Valid @RequestBody CallbackRequest request) {
@Valid @RequestBody final CallbackRequest request) {
log.debug("Incoming PUT request to '{}' with subject '{}'", PATH, subject);

if (accessTokenService.isValid(token)) {
final Map<String, String> tokenContent = accessTokenService.parseAccessToken(token);
if (tokenContent.containsKey("sub") && tokenContent.get("sub") != null) {

bookingService.saveResult(subject, request);
this.backendService.saveResult(subject, request);
return ResponseEntity.ok().build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@

import eu.europa.ec.dgc.validation.decorator.dto.CallbackRequest;
import eu.europa.ec.dgc.validation.decorator.dto.CallbackRequest.Result;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest.DccStatusRequest;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest.DccStatusResult;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest.DccStatusType;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest.ResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest.DccStatusRequest;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest.DccStatusResult;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest.DccStatusType;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest.ResultRequest;
import eu.europa.ec.dgc.validation.decorator.exception.NotFoundException;
import java.util.stream.Collectors;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Service;

@Service
public class CallbackRequestToBookingServiceResultRequestConverter
implements Converter<CallbackRequest, BookingServiceResultRequest> {
public class CallbackRequestToServiceResultRequestConverter
implements Converter<CallbackRequest, ServiceResultRequest> {

@Override
public BookingServiceResultRequest convert(CallbackRequest callback) {
BookingServiceResultRequest result = new BookingServiceResultRequest();
public ServiceResultRequest convert(CallbackRequest callback) {
ServiceResultRequest result = new ServiceResultRequest();
result.setDccStatus(new DccStatusRequest());
result.getDccStatus().setIssuer(callback.getIssuer());
result.getDccStatus().setIat(callback.getIat());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class QrCodeDto {
// used from application.yml
// currently disabled // private String validationIdentity;

// JWT for access Validation Decorator from booking service
// JWT for access Validation Decorator from backend service
private String token;

// Consent text which is shown to the user by the wallet app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import lombok.Getter;

@Data
public class BookingServiceResultRequest {
public class ServiceResultRequest {

private String token;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,26 @@
import lombok.Data;

@Data
public class BookingServiceTokenContentResponse {
public class ServiceTokenContentResponse {

private String reference;

private OffsetDateTime time;

private List<PassengerResponse> passengers = new ArrayList<>();
private List<SubjectResponse> passengers = new ArrayList<>();

private FlightInfoResponse flightInfo;
private OccurrenceInfoResponse flightInfo;

public List<SubjectResponse> getSubjects() {
return this.getPassengers();
}

public OccurrenceInfoResponse getOccurrenceInfo() {
return this.getFlightInfo();
}

@Data
public static final class PassengerResponse {
public static final class SubjectResponse {

private UUID id;

Expand Down Expand Up @@ -82,7 +90,7 @@ public static final class ResultResponse {
}

@Data
public static final class FlightInfoResponse {
public static final class OccurrenceInfoResponse {

private String from;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*-
* ---license-start
* European Digital COVID Certificate Validation Decorator Service / dgca-validation-decorator
* ---
* Copyright (C) 2021 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.validation.decorator.repository;

import eu.europa.ec.dgc.validation.decorator.config.DgcProperties.ServiceProperties;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse;

public interface BackendRepository {

/**
* Booking service token content endpoint.
*
* @param subject {@link String}
* @return {@link BookingServiceTokenContentResponse}
*/
ServiceTokenContentResponse tokenContent(String subject);

/**
* Booking service token content endpoint.
*
* @param subject {@link String}
* @param service Used service
* @return {@link BookingServiceTokenContentResponse}
*/
ServiceTokenContentResponse tokenContent(String subject, ServiceProperties service);

/**
* Booking service result endpoint.
*
* @param subject {@link String}
* @param body {@link BookingServiceResultRequest}
*/
void result(String subject, ServiceResultRequest body);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package eu.europa.ec.dgc.validation.decorator.repository;

import eu.europa.ec.dgc.validation.decorator.config.DgcProperties.ServiceProperties;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceTokenContentResponse;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse;
import eu.europa.ec.dgc.validation.decorator.service.AccessTokenService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -38,7 +38,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class BookingServiceRepository {
public class BookingBackendRepository implements BackendRepository {

private static final String PLACEHOLDER_SUBJECT = "{subject}";

Expand All @@ -58,7 +58,8 @@ public class BookingServiceRepository {
* @param subject {@link String}
* @return {@link BookingServiceTokenContentResponse}
*/
public BookingServiceTokenContentResponse tokenContent(final String subject) {
@Override
public ServiceTokenContentResponse tokenContent(final String subject) {
return this.tokenContent(subject, null);
}

Expand All @@ -69,7 +70,8 @@ public BookingServiceTokenContentResponse tokenContent(final String subject) {
* @param service Used service
* @return {@link BookingServiceTokenContentResponse}
*/
public BookingServiceTokenContentResponse tokenContent(final String subject, final ServiceProperties service) {
@Override
public ServiceTokenContentResponse tokenContent(final String subject, final ServiceProperties service) {
final UriComponentsBuilder urlBuilder = UriComponentsBuilder
.fromUriString(this.tokenContentUrl.replace(PLACEHOLDER_SUBJECT, subject));
if (service != null) {
Expand All @@ -83,8 +85,8 @@ public BookingServiceTokenContentResponse tokenContent(final String subject, fin
final HttpEntity<String> entity = new HttpEntity<>(headers);

log.debug("REST Call to '{}' starting", url);
final ResponseEntity<BookingServiceTokenContentResponse> response = this.restTpl.exchange(url, HttpMethod.GET,
entity, BookingServiceTokenContentResponse.class);
final ResponseEntity<ServiceTokenContentResponse> response = this.restTpl.exchange(url, HttpMethod.GET,
entity, ServiceTokenContentResponse.class);
return response.getBody();
}

Expand All @@ -94,13 +96,14 @@ public BookingServiceTokenContentResponse tokenContent(final String subject, fin
* @param subject {@link String}
* @param body {@link BookingServiceResultRequest}
*/
public void result(final String subject, final BookingServiceResultRequest body) {
@Override
public void result(final String subject, final ServiceResultRequest body) {
final String url = this.resultUrl.replace(PLACEHOLDER_SUBJECT, subject);

final HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", accessTokenService.buildHeaderToken(subject));

final HttpEntity<BookingServiceResultRequest> entity = new HttpEntity<>(body, headers);
final HttpEntity<ServiceResultRequest> entity = new HttpEntity<>(body, headers);

log.debug("REST Call to '{}' starting", url);
this.restTpl.exchange(url, HttpMethod.PUT, entity, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
package eu.europa.ec.dgc.validation.decorator.service;

import eu.europa.ec.dgc.validation.decorator.dto.CallbackRequest;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.repository.BookingServiceRepository;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceResultRequest;
import eu.europa.ec.dgc.validation.decorator.repository.BackendRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class BookingService {
public class BackendService {

private final BookingServiceRepository bookingServiceRepository;
private final BackendRepository backendRepository;

private final ConversionService converter;

Expand All @@ -41,9 +41,8 @@ public class BookingService {
* @param subject {@link String}
* @param request {@link CallbackRequest}
*/
public void saveResult(String subject, CallbackRequest request) {
final BookingServiceResultRequest resultRequest = this.converter
.convert(request, BookingServiceResultRequest.class);
bookingServiceRepository.result(subject, resultRequest);
public void saveResult(final String subject, final CallbackRequest request) {
final ServiceResultRequest resultRequest = this.converter.convert(request, ServiceResultRequest.class);
this.backendRepository.result(subject, resultRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import eu.europa.ec.dgc.validation.decorator.dto.AccessTokenPayload;
import eu.europa.ec.dgc.validation.decorator.dto.AccessTokenPayload.AccessTokenConditions;
import eu.europa.ec.dgc.validation.decorator.dto.DccTokenRequest;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceTokenContentResponse;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceTokenContentResponse.FlightInfoResponse;
import eu.europa.ec.dgc.validation.decorator.entity.BookingServiceTokenContentResponse.PassengerResponse;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.OccurrenceInfoResponse;
import eu.europa.ec.dgc.validation.decorator.entity.ServiceTokenContentResponse.SubjectResponse;
import eu.europa.ec.dgc.validation.decorator.entity.ValidationServiceInitializeResponse;
import eu.europa.ec.dgc.validation.decorator.exception.NotFoundException;
import eu.europa.ec.dgc.validation.decorator.exception.NotImplementedException;
import eu.europa.ec.dgc.validation.decorator.repository.BookingServiceRepository;
import eu.europa.ec.dgc.validation.decorator.repository.BackendRepository;
import eu.europa.ec.dgc.validation.decorator.repository.ValidationServiceRepository;
import java.time.Instant;
import java.time.OffsetDateTime;
Expand All @@ -53,12 +53,12 @@ public class DccTokenService {

private final ValidationServiceRepository validationServiceRepository;

private final BookingServiceRepository bookingServiceRepository;
private final BackendRepository backendRepository;

private final IdentityService identityService;

/**
* Request validation- and booking service to create token.
* Request validation- and backend service to create token.
*
* @param dccToken {@link DccTokenRequest}
* @return {@link AccessTokenPayload}
Expand All @@ -73,37 +73,37 @@ public AccessTokenPayload getAccessTockenForValidationService(
final ValidationServiceInitializeResponse initialize = validationServiceRepository
.initialize(service, dccToken, subject);

final BookingServiceTokenContentResponse tokenContent = bookingServiceRepository.tokenContent(subject, service);
if (tokenContent.getPassengers() == null || tokenContent.getPassengers().isEmpty()) {
final ServiceTokenContentResponse tokenContent = backendRepository.tokenContent(subject, service);
if (tokenContent.getSubjects() == null || tokenContent.getSubjects().isEmpty()) {
throw new NotFoundException("Passenger not found by subject");
}
final PassengerResponse passenger = tokenContent.getPassengers().get(0);
final FlightInfoResponse flightInfo = tokenContent.getFlightInfo();
final SubjectResponse subjectResponse = tokenContent.getSubjects().get(0);
final OccurrenceInfoResponse occurrenceInfo = tokenContent.getOccurrenceInfo();

return this.buildAccessToken(subject, initialize, passenger, flightInfo);
return this.buildAccessToken(subject, initialize, subjectResponse, occurrenceInfo);
}

private AccessTokenPayload buildAccessToken(
final String subject,
final ValidationServiceInitializeResponse initialize,
final PassengerResponse passenger,
final FlightInfoResponse flightInfo) {
final SubjectResponse subjectResponse,
final OccurrenceInfoResponse occurrenceInfo) {
final AccessTokenConditions accessTokenConditions = new AccessTokenConditions();
// TODO add hash
accessTokenConditions.setLang(flightInfo.getLanguage());
accessTokenConditions.setFnt(passenger.getForename());
accessTokenConditions.setGnt(passenger.getLastname());
accessTokenConditions.setDob(passenger.getBirthDate().format(BIRTH_DATE_FORMATTER));
accessTokenConditions.setCoa(flightInfo.getCountryOfArrival());
accessTokenConditions.setCod(flightInfo.getCountryOfDeparture());
accessTokenConditions.setRoa(flightInfo.getRegionOfArrival());
accessTokenConditions.setRod(flightInfo.getRegionOfDeparture());
accessTokenConditions.setType(flightInfo.getConditionTypes());
accessTokenConditions.setCategory(flightInfo.getCategories());

final OffsetDateTime departureTime = flightInfo.getDepartureTime();
accessTokenConditions.setLang(occurrenceInfo.getLanguage());
accessTokenConditions.setFnt(subjectResponse.getForename());
accessTokenConditions.setGnt(subjectResponse.getLastname());
accessTokenConditions.setDob(subjectResponse.getBirthDate().format(BIRTH_DATE_FORMATTER));
accessTokenConditions.setCoa(occurrenceInfo.getCountryOfArrival());
accessTokenConditions.setCod(occurrenceInfo.getCountryOfDeparture());
accessTokenConditions.setRoa(occurrenceInfo.getRegionOfArrival());
accessTokenConditions.setRod(occurrenceInfo.getRegionOfDeparture());
accessTokenConditions.setType(occurrenceInfo.getConditionTypes());
accessTokenConditions.setCategory(occurrenceInfo.getCategories());

final OffsetDateTime departureTime = occurrenceInfo.getDepartureTime();
accessTokenConditions.setValidFrom(departureTime.format(FORMATTER));
accessTokenConditions.setValidationClock(flightInfo.getArrivalTime().format(FORMATTER));
accessTokenConditions.setValidationClock(occurrenceInfo.getArrivalTime().format(FORMATTER));
accessTokenConditions.setValidTo(departureTime.plusDays(2).format(FORMATTER));

final AccessTokenPayload accessTokenPayload = new AccessTokenPayload();
Expand All @@ -113,7 +113,7 @@ private AccessTokenPayload buildAccessToken(
accessTokenPayload.setExp(initialize.getExp());
accessTokenPayload.setSub(subject);
accessTokenPayload.setAud(initialize.getAud());
accessTokenPayload.setType(flightInfo.getType());
accessTokenPayload.setType(occurrenceInfo.getType());
accessTokenPayload.setConditions(accessTokenConditions);
accessTokenPayload.setVersion("1.0");
return accessTokenPayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ public QrCodeDto getBySubject(String subject) {
.subject(subject)
.serviceProvider(properties.getServiceProvider())
.build();
}
}
}
Loading

0 comments on commit a33fb87

Please sign in to comment.