Skip to content

Commit

Permalink
Merge pull request #10 from eu-digital-green-certificates/feat/refact…
Browse files Browse the repository at this point in the history
…oring

refactoring
  • Loading branch information
SchulzeStTSI authored Sep 17, 2021
2 parents 5a39587 + a33fb87 commit 9b33c7f
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 154 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 @@ -41,13 +41,15 @@ public class IdentityController {

private static final String PATH_ELEMENT = "/identity/{element}";

private static final String PATH_ELEMENT_ID = "/identity/{element}/{id}";
private static final String PATH_ELEMENT_TYPE = "/identity/{element}/{type}";

private final IdentityService identityService;

/**
* Delivers a JSON description of public keys and endpoints.
*
* @param element Name of element (optional)
* @param type Type of element (optional)
* @return {@link IdentityResponse}
*/
@Operation(summary = "The identity document endpoint delivers a JSON description of public keys and endpoints",
Expand All @@ -59,57 +61,12 @@ public class IdentityController {
@ApiResponse(responseCode = "404", description = "Not Found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error"),
})
@GetMapping(value = PATH_ALL, produces = MediaType.APPLICATION_JSON_VALUE)
public IdentityResponse identityAll() {
log.debug("Incoming GET request to '{}' with element '{}' and id '{}'", PATH_ALL);

return identityService.getIdentity(null, null);
}

/**
* Delivers a JSON description of public keys and endpoints.
*
* @param element Name of element
* @return {@link IdentityResponse}
*/
@Operation(summary = "The identity document endpoint delivers a JSON description of public keys and endpoints",
description = "The identity document endpoint delivers a JSON description of public keys and endpoints")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "Bad Request / Validation errors"),
@ApiResponse(responseCode = "401", description = "Unauthorized, if no active session is attached"),
@ApiResponse(responseCode = "404", description = "Not Found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error"),
})
@GetMapping(value = PATH_ELEMENT, produces = MediaType.APPLICATION_JSON_VALUE)
public IdentityResponse identity(@PathVariable(name = "element", required = true) final String element) {
log.debug("Incoming GET request to '{}' with element '{}'", PATH_ELEMENT, element);

return identityService.getIdentity(element, null);
}

/**
* Delivers a JSON description of public keys and endpoints.
*
* @param element Name of element
* @param id ID of element
* @return {@link IdentityResponse}
*/
@Operation(summary = "The identity document endpoint delivers a JSON description of public keys and endpoints",
description = "The identity document endpoint delivers a JSON description of public keys and endpoints")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "Bad Request / Validation errors"),
@ApiResponse(responseCode = "401", description = "Unauthorized, if no active session is attached"),
@ApiResponse(responseCode = "404", description = "Not Found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error"),
})
@GetMapping(value = PATH_ELEMENT_ID, produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = {PATH_ALL, PATH_ELEMENT, PATH_ELEMENT_TYPE}, produces = MediaType.APPLICATION_JSON_VALUE)
public IdentityResponse identity(
@PathVariable(name = "element", required = true) final String element,
@PathVariable(name = "id", required = true) final String id) {
log.debug("Incoming GET request to '{}' with element '{}' and id '{}'", PATH_ELEMENT_ID, element, id);
@PathVariable(name = "element", required = false) final String element,
@PathVariable(name = "type", required = false) final String type) {
log.debug("Incoming GET request to '{}' with element '{}' and type '{}'", PATH_ELEMENT_TYPE, element, type);

return identityService.getIdentity(element, id);
return identityService.getIdentity(element, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ValidationStatusController {
@ApiResponse(responseCode = "500", description = "Internal Server Error")
})
@GetMapping(value = PATH, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity reject(@RequestHeader("Authorization") final String token) {
public ResponseEntity status(@RequestHeader("Authorization") final String token) {
log.debug("Incoming GET request to '{}' with token '{}'", PATH, token);

if (accessTokenService.isValid(token)) {
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 All @@ -51,7 +59,7 @@ public static final class PassengerResponse {
private LocalDate birthDate;

private DccStatusResponse dccStatus;

private String serviceIdUsed;
}

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

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

private String from;

private String to;

private OffsetDateTime time;

@JsonProperty("coa")
private String countryOfArrival;

Expand All @@ -107,5 +115,14 @@ public static final class FlightInfoResponse {

@JsonProperty("arrivalTime")
private OffsetDateTime arrivalTime;

private int type;

private List<String> categories;

@JsonProperty("lang")
private String language;

private List<String> conditionTypes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package eu.europa.ec.dgc.validation.decorator.exception;

import java.io.UnsupportedEncodingException;

public class UncheckedUnsupportedEncodingException extends RuntimeException {

public UncheckedUnsupportedEncodingException(UnsupportedEncodingException e) {
super(e);
}
}
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
Loading

0 comments on commit 9b33c7f

Please sign in to comment.