Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge for release 1.2 (#44)
Browse files Browse the repository at this point in the history
* Fix disabled test

* Add assert to test case

* Change visibility of constructors

* github action: use commit SHA

* VACCINECER-853: update libs

* VACCINECER-853: update libs

* Add cantonCodeSender validation

* VACCINECER-955: validate canton

* VACCINECER-890 create indexes

* VACCINECER-890 create indexes only for postgres

* Revert "VACCINECER-977: update pdf"

This reverts commit 161006a

* Validate address and city length

* VACCINECER-977: update pdf

* Feature/vaccinecer 950 import csv (#43)

VACCINECER-950: added a rest controller for upload of csv

* Update pom.xml

updated version to 1.2.0

* VACCINECER-950: updated validation and added unit tests

* VACCINECER-950: added content type log

* VACCINECER-950: removed content type check

* VACCINECER-950: fixed build

* VACCINECER-950: updated the pdf file names to also include UVCI.

* VACCINECER-684: updated countrie value sets

* VACCINECER-684: updated Taiwan display name

Co-authored-by: Yannik Inniger <[email protected]>
Co-authored-by: Fabien Cerf <[email protected]>
Co-authored-by: Yannik Inniger <[email protected]>
Co-authored-by: Fabien Cerf <[email protected]>
Co-authored-by: George Papadopoulos <[email protected]>
Co-authored-by: Nicola Keller <[email protected]>
  • Loading branch information
7 people authored Jun 18, 2021
1 parent 6d7bbd8 commit 1cce0c9
Show file tree
Hide file tree
Showing 54 changed files with 10,794 additions and 679 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}

- name: Create Snapshot Release
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@880be3d0a71bc0fa98db60201d2cbdc27324f547
if: github.ref == 'refs/heads/develop'
id: create_release
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
TESTCONTAINERS_RYUK_DISABLED: true

- name: Create new release
uses: marvinpinto/action-automatic-releases@latest
uses: marvinpinto/action-automatic-releases@919008cf3f741b179569b7a6fb4d8860689ab7f0
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
Expand Down
23 changes: 15 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<version>2.4.6</version>
<relativePath/>
</parent>
<groupId>ch.admin.bag.covidcertificate</groupId>
<artifactId>cc-management-service</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>cc-management-service</name>
<description>Service for generating Covid Certificates</description>

<properties>
<java.version>11</java.version>

<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<logstash.version>5.2</logstash.version>
<janino.version>2.6.1</janino.version>
<guava.version>24.1-jre</guava.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
<logstash.version>6.6</logstash.version>
<janino.version>3.1.4</janino.version>
<guava.version>30.1.1-jre</guava.version>
<itextpdf.version>5.5.13.2</itextpdf.version>
<springdoc.version>1.5.8</springdoc.version>
<jacoco-maven-plugin.version>0.8.5</jacoco-maven-plugin.version>
<dgc-java.version>0.9.4</dgc-java.version>
<spring-cloud-starter-sleuth.version>2.2.0.RELEASE</spring-cloud-starter-sleuth.version>
<spring-cloud-starter-sleuth.version>3.0.3</spring-cloud-starter-sleuth.version>
<httpclient.version>4.5.13</httpclient.version>
<jjwt.version>0.11.1</jjwt.version>
<jjwt.version>0.11.2</jjwt.version>
<google-zxing.version>3.3.0</google-zxing.version>
<opencsv.version>5.4</opencsv.version>

<maven.javadoc.skip>true</maven.javadoc.skip>

Expand Down Expand Up @@ -224,6 +225,12 @@
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>${opencsv.version}</version>
</dependency>

<!-- test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ public class Constants {

public static final RevocationError DUPLICATE_UVCI = new RevocationError(480, "Duplicate UVCI.", HttpStatus.CONFLICT);

public static final CreateCertificateError INVALID_CSV = new CreateCertificateError(481, "The CSV can not be read!", HttpStatus.BAD_REQUEST);
public static final CreateCertificateError INVALID_CSV_SIZE = new CreateCertificateError(482, "The CSV has an ivalid size! Must contain 1 to 100 entries.", HttpStatus.BAD_REQUEST);
public static final CreateCertificateError NOT_A_CSV = new CreateCertificateError(483, "The sent file is not a CSV file.", HttpStatus.BAD_REQUEST);
public static final CreateCertificateError INVALID_CERTIFICATE_TYPE = new CreateCertificateError(484, "Invalid certificate type! 'vaccination', 'test', and 'recovery' are allowed", HttpStatus.BAD_REQUEST);
public static final CreateCertificateError INVALID_CREATE_REQUESTS = new CreateCertificateError(485, "One or more of the requests in the CSV contain invalid data. For more detailed error messages check the returned CSV", HttpStatus.BAD_REQUEST);

public static final CreateCertificateError CREATE_COSE_PROTECTED_HEADER_FAILED = new CreateCertificateError(550, "Creating COSE protected header failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError CREATE_COSE_PAYLOAD_FAILED = new CreateCertificateError(551, "Creating COSE payload failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError CREATE_COSE_SIGNATURE_DATA_FAILED = new CreateCertificateError(552, "Creating COSE signature data failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError CREATE_SIGNATURE_FAILED = new CreateCertificateError(553, "Creating signature failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError CREATE_COSE_SIGN1_FAILED = new CreateCertificateError(554, "Creating COSE_Sign1 failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError CREATE_BARCODE_FAILED = new CreateCertificateError(555, "Creating barcode failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError PRINTING_FAILED = new CreateCertificateError(556, "Printing failed.", HttpStatus.INTERNAL_SERVER_ERROR);
public static final CreateCertificateError WRITING_RETURN_CSV_FAILED = new CreateCertificateError(557, "Write CSV failed", HttpStatus.INTERNAL_SERVER_ERROR);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ public class CreateCertificateError implements Serializable {
private final int errorCode;
private final String errorMessage;
private final HttpStatus httpStatus;

@Override
public String toString() {
return "{\"errorCode\":" + errorCode + "," +
"\"errorMessage\":\"" + errorMessage + "\"," +
"\"httpStatus\":\"" + httpStatus.name() + "\"}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ch.admin.bag.covidcertificate.api.exception;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class CsvError extends CreateCertificateError {
private final byte[] csv;

public CsvError(CreateCertificateError createCertificateError, byte[] csv) {
super(
createCertificateError.getErrorCode(),
createCertificateError.getErrorMessage(),
createCertificateError.getHttpStatus()
);
this.csv = csv;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ch.admin.bag.covidcertificate.api.exception;

import lombok.Getter;
import org.springframework.core.NestedRuntimeException;

@Getter
public class CsvException extends NestedRuntimeException {
private final CsvError error;

public CsvException(CsvError error) {
super(error.getErrorMessage());
this.error = error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public abstract class CertificateCreateDto {
private String language;
private CovidCertificateAddressDto address;

public CertificateCreateDto(CovidCertificatePersonDto personData, String language) {
this.personData = personData;
this.language = language;
}

public void validate() {
if (personData == null) {
throw new CreateCertificateException(NO_PERSON_DATA);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package ch.admin.bag.covidcertificate.api.request;

import ch.admin.bag.covidcertificate.api.exception.CreateCertificateException;
import com.opencsv.bean.CsvBindByName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.time.LocalDate;
import java.util.List;

import static ch.admin.bag.covidcertificate.api.Constants.INVALID_ADDRESS;
import static ch.admin.bag.covidcertificate.api.Constants.INVALID_DATE_OF_BIRTH;

@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public abstract class CertificateCsvBean {

@CsvBindByName(column = "id")
private String id;
@CsvBindByName(column = "givenName")
private String givenName;
@CsvBindByName(column = "familyName")
private String familyName;
@CsvBindByName(column = "dateOfBirth")
private String dateOfBirth;
@CsvBindByName(column = "language")
private String language;
@CsvBindByName(column = "streetAndNr")
private String streetAndNr;
@CsvBindByName(column = "zipCode")
private String zipCode;
@CsvBindByName(column = "city")
private String city;
@CsvBindByName(column = "cantonCodeSender")
private String cantonCodeSender;
@CsvBindByName(column = "error")
private String error;

public abstract CertificateCreateDto mapToCreateDto();

public void setError(String error) {
this.error = error;
}

protected VaccinationCertificateCreateDto mapToCreateDto(VaccinationCertificateDataDto dataDto) {
return new VaccinationCertificateCreateDto(
mapToPersonDto(),
List.of(dataDto),
getLanguage(),
mapToAddressDto()
);
}

protected TestCertificateCreateDto mapToCreateDto(TestCertificateDataDto dataDto) {
return new TestCertificateCreateDto(
mapToPersonDto(),
List.of(dataDto),
getLanguage(),
mapToAddressDto()
);
}

protected RecoveryCertificateCreateDto mapToCreateDto(RecoveryCertificateDataDto dataDto) {
return new RecoveryCertificateCreateDto(
mapToPersonDto(),
List.of(dataDto),
getLanguage(),
mapToAddressDto()
);
}

private CovidCertificatePersonDto mapToPersonDto() {
LocalDate birthDate;
try {
birthDate = LocalDate.parse(getDateOfBirth());
} catch (Exception e) {
throw new CreateCertificateException(INVALID_DATE_OF_BIRTH);
}
return new CovidCertificatePersonDto(
new CovidCertificatePersonNameDto(
getFamilyName(),
getGivenName()
),
birthDate
);
}

private CovidCertificateAddressDto mapToAddressDto() {
int zipCode;
try {
zipCode = Integer.parseInt(this.zipCode);
} catch (NumberFormatException e) {
throw new CreateCertificateException(INVALID_ADDRESS);
}
return new CovidCertificateAddressDto(
streetAndNr,
zipCode,
city,
cantonCodeSender
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ch.admin.bag.covidcertificate.api.request;

public enum CertificateType {
recovery, test, vaccination
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.admin.bag.covidcertificate.api.request;

import ch.admin.bag.covidcertificate.api.exception.CreateCertificateException;
import ch.admin.bag.covidcertificate.api.valueset.AcceptedCantons;
import lombok.*;
import org.springframework.util.StringUtils;

Expand All @@ -11,17 +12,32 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class CovidCertificateAddressDto {
private static final int MAX_FIELD_LENGTH = 128;

private String streetAndNr;
private int zipCode;
private String city;
private String cantonCodeSender;

public void validate() {
if (!StringUtils.hasText(streetAndNr) || !StringUtils.hasText(city) || !StringUtils.hasText(cantonCodeSender)) {
if (this.hasInvalidLength(streetAndNr) || this.hasInvalidLength(city)) {
throw new CreateCertificateException(INVALID_ADDRESS);
}
if (zipCode < 1000 || zipCode > 9999) {
throw new CreateCertificateException(INVALID_ADDRESS);
}
if (!AcceptedCantons.isAccepted(this.cantonCodeSender)) {
throw new CreateCertificateException(INVALID_ADDRESS);
}
}

/**
* Validates that a given text has characters and is not larger than MAX_FIELD_LENGTH.
*
* @param text String to check.
* @return boolean if the text contains characters and is not longer than MAX_FIELD_LENGTH
*/
private boolean hasInvalidLength(String text) {
return !StringUtils.hasText(text) || text.length() > MAX_FIELD_LENGTH;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class RecoveryCertificateCreateDto extends CertificateCreateDto {
public RecoveryCertificateCreateDto(
CovidCertificatePersonDto personData,
List<RecoveryCertificateDataDto> recoveryInfo,
String language
String language,
CovidCertificateAddressDto address
) {
super(personData, language);
super(personData, language, address);
this.recoveryInfo = recoveryInfo;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ch.admin.bag.covidcertificate.api.request;

import ch.admin.bag.covidcertificate.api.exception.CreateCertificateException;
import com.opencsv.bean.CsvBindByName;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.time.LocalDate;

import static ch.admin.bag.covidcertificate.api.Constants.INVALID_DATE_OF_FIRST_POSITIVE_TEST_RESULT;

@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class RecoveryCertificateCsvBean extends CertificateCsvBean {

@CsvBindByName(column = "dateOfFirstPositiveTestResult")
private String dateOfFirstPositiveTestResult;
@CsvBindByName(column = "countryOfTest")
private String countryOfTest;

@Override
public RecoveryCertificateCreateDto mapToCreateDto() {
LocalDate dateOfFirstPositiveTestResult;
try {
dateOfFirstPositiveTestResult = LocalDate.parse(this.dateOfFirstPositiveTestResult);
} catch (Exception e) {
throw new CreateCertificateException(INVALID_DATE_OF_FIRST_POSITIVE_TEST_RESULT);
}
RecoveryCertificateDataDto dataDto = new RecoveryCertificateDataDto(
dateOfFirstPositiveTestResult,
countryOfTest
);
return super.mapToCreateDto(dataDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class TestCertificateCreateDto extends CertificateCreateDto {
public TestCertificateCreateDto(
CovidCertificatePersonDto personData,
List<TestCertificateDataDto> testInfo,
String language
String language,
CovidCertificateAddressDto address
) {
super(personData, language);
super(personData, language, address);
this.testInfo = testInfo;
}

Expand Down
Loading

0 comments on commit 1cce0c9

Please sign in to comment.