-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add booking replace endpoint for testing
- Loading branch information
Alexander Schwarz
committed
Sep 30, 2021
1 parent
c0e2c69
commit 5eed8ea
Showing
7 changed files
with
299 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...ava/eu/europa/ec/dgc/booking/converter/BookingReplaceRequestToBookingEntityConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/*- | ||
* ---license-start | ||
* European Digital COVID Certificate Booking Demo / dgca-booking-demo-backend | ||
* --- | ||
* 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.booking.converter; | ||
|
||
import eu.europa.ec.dgc.booking.dto.BookingReplaceRequest; | ||
import eu.europa.ec.dgc.booking.dto.BookingReplaceRequest.BookingFlightInfoRequest; | ||
import eu.europa.ec.dgc.booking.dto.BookingReplaceRequest.DccStatusRequest; | ||
import eu.europa.ec.dgc.booking.dto.BookingReplaceRequest.PassengerRequest; | ||
import eu.europa.ec.dgc.booking.dto.BookingReplaceRequest.ResultRequest; | ||
import eu.europa.ec.dgc.booking.entity.BookingEntity; | ||
import eu.europa.ec.dgc.booking.entity.DccStatusEntity; | ||
import eu.europa.ec.dgc.booking.entity.DccStatusResultEntity; | ||
import eu.europa.ec.dgc.booking.entity.FlightInfoEntity; | ||
import eu.europa.ec.dgc.booking.entity.PassengerEntity; | ||
import java.time.OffsetDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class BookingReplaceRequestToBookingEntityConverter implements Converter<BookingReplaceRequest, BookingEntity> { | ||
|
||
@Override | ||
public BookingEntity convert(BookingReplaceRequest request) { | ||
final BookingEntity entity = new BookingEntity(); | ||
entity.setReference(request.getReference()); | ||
entity.setTime(request.getTime() != null ? request.getTime() : OffsetDateTime.now()); | ||
entity.setPassengers(this.convertPassengers(request.getPassengers())); | ||
entity.setFlightInfo(this.convert(request.getFlightInfo())); | ||
return entity; | ||
} | ||
|
||
public List<PassengerEntity> convertPassengers(List<PassengerRequest> requests) { | ||
if (requests != null && !requests.isEmpty()) { | ||
return requests.stream() | ||
.map(this::convert) | ||
.collect(Collectors.toList()); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
public PassengerEntity convert(PassengerRequest request) { | ||
final PassengerEntity entity = new PassengerEntity(); | ||
entity.setId(request.getId() != null ? request.getId() : UUID.randomUUID()); | ||
entity.setForename(request.getForename()); | ||
entity.setLastname(request.getLastname()); | ||
entity.setBirthDate(request.getBirthDate()); | ||
entity.setDccStatus(this.convert(request.getDccStatus())); | ||
entity.setServiceIdUsed(request.getServiceIdUsed()); | ||
entity.setJti(request.getJti()); | ||
return entity; | ||
} | ||
|
||
public DccStatusEntity convert(final DccStatusRequest request) { | ||
if (request != null) { | ||
return DccStatusEntity.builder() | ||
.issuer(request.getIssuer()) | ||
.iat(request.getIat()) | ||
.sub(request.getSub()) | ||
.results(this.convertResults(request.getResults())) | ||
.confirmation(request.getConfirmation()) | ||
.build(); | ||
} | ||
return null; | ||
} | ||
|
||
public List<DccStatusResultEntity> convertResults(List<ResultRequest> requests) { | ||
if (requests != null && !requests.isEmpty()) { | ||
return requests.stream() | ||
.map(this::convert) | ||
.collect(Collectors.toList()); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
public DccStatusResultEntity convert(ResultRequest request) { | ||
return DccStatusResultEntity.builder() | ||
.identifier(request.getIdentifier()) | ||
.result(request.getResult()) | ||
.type(request.getType()) | ||
.details(request.getDetails()) | ||
.build(); | ||
} | ||
|
||
private FlightInfoEntity convert(BookingFlightInfoRequest request) { | ||
if (request != null) { | ||
return FlightInfoEntity.builder() | ||
.from(request.getFrom()) | ||
.to(request.getTo()) | ||
.time(request.getTime()) | ||
.countryOfArrival(request.getCountryOfArrival()) | ||
.countryOfDeparture(request.getCountryOfDeparture()) | ||
.regionOfArrival(request.getRegionOfArrival()) | ||
.regionOfDeparture(request.getRegionOfDeparture()) | ||
.departureTime(request.getDepartureTime()) | ||
.arrivalTime(request.getArrivalTime()) | ||
.type(request.getType()) | ||
.categories(request.getCategories() != null | ||
? request.getCategories() | ||
: new ArrayList<>()) | ||
.language(request.getLanguage()) | ||
.conditionTypes(request.getConditionTypes() != null | ||
? request.getConditionTypes() | ||
: new ArrayList<>()) | ||
.build(); | ||
} | ||
return null; | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
src/main/java/eu/europa/ec/dgc/booking/dto/BookingReplaceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/*- | ||
* ---license-start | ||
* European Digital COVID Certificate Booking Demo / dgca-booking-demo-backend | ||
* --- | ||
* 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.booking.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.time.OffsetDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotBlank; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class BookingReplaceRequest { | ||
|
||
@NotBlank | ||
private String reference; | ||
|
||
private OffsetDateTime time; | ||
|
||
@Valid | ||
private List<PassengerRequest> passengers = new ArrayList<>(); | ||
|
||
@Valid | ||
private BookingFlightInfoRequest flightInfo; | ||
|
||
@Data | ||
public static final class PassengerRequest { | ||
|
||
private UUID id; | ||
|
||
@NotBlank | ||
private String forename; | ||
|
||
@NotBlank | ||
private String lastname; | ||
|
||
private String birthDate; | ||
|
||
@Valid | ||
private DccStatusRequest dccStatus; | ||
|
||
private String serviceIdUsed; | ||
|
||
// AccessTokenPayload.jti | ||
private String jti; | ||
} | ||
|
||
@Data | ||
public static final class DccStatusRequest { | ||
|
||
private String issuer; | ||
|
||
private long iat; | ||
|
||
private String sub; | ||
|
||
@Valid | ||
private List<ResultRequest> results; | ||
|
||
private String confirmation; | ||
} | ||
|
||
@Data | ||
public static final class ResultRequest { | ||
|
||
private String identifier; | ||
|
||
private String result; | ||
|
||
private String type; | ||
|
||
private String details; | ||
} | ||
|
||
@Data | ||
public static final class BookingFlightInfoRequest { | ||
|
||
private String from; | ||
|
||
private String to; | ||
|
||
private OffsetDateTime time; | ||
|
||
@JsonProperty("coa") | ||
private String countryOfArrival; | ||
|
||
@JsonProperty("cod") | ||
private String countryOfDeparture; | ||
|
||
@JsonProperty("roa") | ||
private String regionOfArrival; | ||
|
||
@JsonProperty("rod") | ||
private String regionOfDeparture; | ||
|
||
@JsonProperty("departureTime") | ||
private OffsetDateTime departureTime; | ||
|
||
@JsonProperty("arrivalTime") | ||
private OffsetDateTime arrivalTime; | ||
|
||
private int type; | ||
|
||
private List<String> categories; | ||
|
||
@JsonProperty("lang") | ||
private String language; | ||
|
||
private List<String> conditionTypes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters