Commit 6b1d0604 authored by Jujube Orange's avatar Jujube Orange
Browse files

refactor(format): format source code

parent 43f3a322
Pipeline #260658 passed with stage
in 2 minutes
Ce composant à été écrit par
* Groupe Capgemini (Capgemini, Idean, Sogeti)
- Groupe Capgemini (Capgemini, Idean, Sogeti)
Les personnes suivantes ont contribué
* Pour Groupe Capgemini (Capgemini, Idean, Sogeti)
* redford.stopcovid@idean.com
* palmer.stopcovid@capgemini.com
* marley.stopcovid@capgemini.com
* stanley.stopcovid@capgemini.com
* begnini.stopcovid@capgemini.com
* deniro.stopcovid@capgemini.com
- Pour Groupe Capgemini (Capgemini, Idean, Sogeti)
- redford.stopcovid@idean.com
- palmer.stopcovid@capgemini.com
- marley.stopcovid@capgemini.com
- stanley.stopcovid@capgemini.com
- begnini.stopcovid@capgemini.com
- deniro.stopcovid@capgemini.com
......@@ -3,5 +3,4 @@
Les changements ne faisant pas encore partie d'une release doivent être
consignés dans ce fichier.
## [Unreleased]
......@@ -9,4 +9,4 @@ Ce fichier ne doit pas être mis à jour directement, il faut utiliser le fichie
Par la suite les changements de `CHANGELOG-UNRELEASED.md` sont reversé dans ce
fichier lors de la création d'une nouvelle release.
##
##
# Mozilla Public License
# Version 2.0
# 1. Definitions
### 1.1. “Contributor”
means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
### 1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor’s Contribution.
### 1.3. “Contribution”
means Covered Software of a particular Contributor.
### 1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
### 1.5. “Incompatible With Secondary Licenses”
means
a. that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
a. that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
b. that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
b. that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
### 1.6. “Executable Form”
means any form of the work other than Source Code Form.
### 1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
### 1.8. “License”
means this document.
### 1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
### 1.10. “Modifications”
means any of the following:
a. any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
a. any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
b. any new file in Source Code Form that contains any Covered Software.
b. any new file in Source Code Form that contains any Covered Software.
### 1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
### 1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
### 1.13. “Source Code Form”
means the form of the work preferred for making modifications.
### 1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this License. For legal entities, “You” includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
# 2. License Grants and Conditions
......@@ -59,9 +74,9 @@ means an individual or a legal entity exercising rights under this License. For
Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
a. under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
a. under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
b. under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
b. under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
## 2.2. Effective Date
......@@ -71,11 +86,11 @@ The licenses granted in Section 2.1 with respect to any Contribution become effe
The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
a. for any code that a Contributor has removed from Covered Software; or
a. for any code that a Contributor has removed from Covered Software; or
b. for infringements caused by: (i) Your and any other third party’s modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
b. for infringements caused by: (i) Your and any other third party’s modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
c. under Patent Claims infringed by Covered Software in the absence of its Contributions.
c. under Patent Claims infringed by Covered Software in the absence of its Contributions.
This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
......@@ -105,9 +120,9 @@ All distribution of Covered Software in Source Code Form, including any Modifica
If You distribute Covered Software in Executable Form then:
a. such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
a. such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
b. You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients’ rights in the Source Code Form under this License.
b. You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients’ rights in the Source Code Form under this License.
### 3.3. Distribution of a Larger Work
......@@ -169,7 +184,7 @@ If You choose to distribute Source Code Form that is Incompatible With Secondary
# Exhibit A - Source Code Form License Notice
> This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
> This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
......@@ -177,4 +192,4 @@ You may add additional accurate notices of copyright ownership.
# Exhibit B - “Incompatible With Secondary Licenses” Notice
> This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
\ No newline at end of file
> This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
......@@ -3,6 +3,6 @@
Ce projet gitlab.inria.fr est un des composants de la solution plus globale [StopCovid](https://gitlab.inria.fr/stopcovid19/accueil/-/blob/master/README.md).
Ce composant propose les services suivants :
* génération de codes courts et longs : pour les professionnels de santé (laboratoires, médecins...)
* vérification et consommation de codes par la partie de la plateforme StopCovid
- génération de codes courts et longs : pour les professionnels de santé (laboratoires, médecins...)
- vérification et consommation de codes par la partie de la plateforme StopCovid
openapi: 3.0.0
info:
description: Submission Code Server Client API Spec. This server generates one-time codes
description:
Submission Code Server Client API Spec. This server generates one-time codes
to be used in the StopCovid app.
version: 0.0.1
title: Submission Code Server Client API Spec
......@@ -45,7 +46,8 @@ paths:
tags:
- Generate Code
summary: Generate 6-alphanum code
description: Generate a new submission code. Codes are usable once and are valid
description:
Generate a new submission code. Codes are usable once and are valid
after a specific date and until a validity date.
operationId: generate
responses:
......@@ -68,7 +70,8 @@ components:
properties:
code:
type: string
description: The submission code to display. Should be encoded as a QR code by
description:
The submission code to display. Should be encoded as a QR code by
the client (combined with type info).
example: AS3F5Z
pattern: "[a-zA-Z0-9]{6}"
......
......@@ -2,8 +2,8 @@ package fr.gouv.stopc.submission.code.server.commun;
public class SubmissionCodeServerClientApiCommunApplication {
public static void main(String[] args) {
}
public static void main(String[] args) {
}
}
......@@ -11,7 +11,6 @@ public enum CodeTypeEnum {
LONG("1", "UUIDv4", Pattern.LONG),
SHORT("2", "6-alphanum", Pattern.SHORT);
/**
* type code is an numeric in string (ex. "1")
*/
......@@ -29,8 +28,9 @@ public enum CodeTypeEnum {
/**
* Default and only constructor
*
* @param typeCode {@link #typeCode}
* @param type {@link #type}
* @param type {@link #type}
*/
CodeTypeEnum(final String typeCode, final String type, final String pattern) {
this.typeCode = typeCode;
......@@ -39,27 +39,35 @@ public enum CodeTypeEnum {
}
public static Optional<CodeTypeEnum> searchMatchType(String type) {
for (CodeTypeEnum et : Arrays.asList(values())) {
if(et.isTypeOrTypeCodeOf(type)) return Optional.of(et);
for (CodeTypeEnum et : Arrays.asList(values())) {
if (et.isTypeOrTypeCodeOf(type))
return Optional.of(et);
}
return Optional.empty();
}
/**
* Method equals get a string (ex. "1" or "UUIDv4") to know if the enum is corresponding to the value.
* @param typeOrTypeCode (ex. "1" or "UUIDv4") value to test if the enum is corresponding to "typeOrTypeCode"
* @return if the enum is corresponding to the parameter in method returned value is "true" otherwise returned value is "false"
* Method equals get a string (ex. "1" or "UUIDv4") to know if the enum is
* corresponding to the value.
*
* @param typeOrTypeCode (ex. "1" or "UUIDv4") value to test if the enum is
* corresponding to "typeOrTypeCode"
* @return if the enum is corresponding to the parameter in method returned
* value is "true" otherwise returned value is "false"
*/
public final Boolean isTypeOrTypeCodeOf(String typeOrTypeCode) {
return this.type.equals(typeOrTypeCode) || this.typeCode.equals(typeOrTypeCode) ;
return this.type.equals(typeOrTypeCode) || this.typeCode.equals(typeOrTypeCode);
}
/**
* Static method exists get a string (ex. "1" or "UUIDv4") to know if an enum is corresponding to the value.
* It uses the methode {@link #isTypeOrTypeCodeOf(String)} to check the value.
* @param typeOrTypeCode (ex. "1" or "UUIDv4") value to test if the enum is corresponding to "typeOrTypeCode"
* @return if an enum is corresponding to the parameter in method returned value is "true" otherwise returned value is "false"
* Static method exists get a string (ex. "1" or "UUIDv4") to know if an enum is
* corresponding to the value. It uses the methode
* {@link #isTypeOrTypeCodeOf(String)} to check the value.
*
* @param typeOrTypeCode (ex. "1" or "UUIDv4") value to test if the enum is
* corresponding to "typeOrTypeCode"
* @return if an enum is corresponding to the parameter in method returned value
* is "true" otherwise returned value is "false"
*/
public static final Boolean exists(final String typeOrTypeCode) {
Optional<CodeTypeEnum> matchType = searchMatchType(typeOrTypeCode);
......@@ -67,8 +75,10 @@ public enum CodeTypeEnum {
}
public interface Pattern {
String SHORT = "([a-zA-Z0-9]{6})";
String LONG = "([a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8})";
}
}
\ No newline at end of file
}
......@@ -6,15 +6,15 @@ public interface ILongCodeService {
/**
* generate and stringify a long code
* @return A randomly generated long code
*
* @return A randomly generated long code
*/
String generateCode();
String generateCode();
/**
*
* @param size number of code to be generated
* @return
*/
List<String> generateCodes(long size);
List<String> generateCodes(long size);
}
package fr.gouv.stopc.submission.code.server.commun.service;
public interface IShortCodeService {
/**
* generate and stringify short code
* @return A randomly generated code of insensitive case alphanumeric char
*
* @return A randomly generated code of insensitive case alphanumeric char
*/
String generateCode();
......
......@@ -13,7 +13,6 @@ import java.util.stream.Stream;
@Slf4j
public class LongCodeServiceImpl implements ILongCodeService {
public String generateCode() {
return (UUID.randomUUID()).toString();
}
......
......@@ -15,7 +15,9 @@ import java.util.stream.Collectors;
public class ShortCodeServiceImpl implements IShortCodeService {
private static final String ALPHA_UPPER_CASE = "abcdefghijklmnopqrstuvwxyz".toUpperCase();
private static final String NUMERIC= "0123456789";
private static final String NUMERIC = "0123456789";
private static final Integer CODE_SIZE = 6;
private static final SecureRandom sRandom = new SecureRandom();
......@@ -24,7 +26,8 @@ public class ShortCodeServiceImpl implements IShortCodeService {
.format(
"%s%s",
ALPHA_UPPER_CASE,
NUMERIC)
NUMERIC
)
.chars()
.mapToObj(c -> (char) c)
.collect(Collectors.toList());
......@@ -34,8 +37,8 @@ public class ShortCodeServiceImpl implements IShortCodeService {
final List<Character> characters = getShuffledAlphaNumList();
/**
* The function sRandom.nexInt(i) create a number random from 0 to i-1.
* The StringBuilder is more performing than string+=string.tu
* The function sRandom.nexInt(i) create a number random from 0 to i-1. The
* StringBuilder is more performing than string+=string.tu
*/
StringBuilder alphaNum = new StringBuilder();
for (int i = 0; i < CODE_SIZE; i++) {
......@@ -49,7 +52,7 @@ public class ShortCodeServiceImpl implements IShortCodeService {
*/
protected static List<Character> getShuffledAlphaNumList() {
final ArrayList<Character> tempAlphaNumList = new ArrayList<>(ALPHA_NUMERIC_CHAR_ARRAY);
Collections.shuffle(tempAlphaNumList,sRandom);
Collections.shuffle(tempAlphaNumList, sRandom);
return tempAlphaNumList;
}
......
......@@ -11,9 +11,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
class CodeShortCodeServiceImplTest {
@Test
@Disabled( "for benchmark only")
@Disabled("for benchmark only")
void generateCodeShortCodeTest() {
Long size = new Long("300000");
final long start = System.currentTimeMillis();
......@@ -21,7 +20,12 @@ class CodeShortCodeServiceImplTest {
.distinct()
.limit(size)
.collect(Collectors.toList());
System.out.println(String.format("expected %s and get %s in %s millis", size, shortCodeIds.size(), System.currentTimeMillis()-start));
System.out.println(
String.format(
"expected %s and get %s in %s millis", size, shortCodeIds.size(),
System.currentTimeMillis() - start
)
);
assertEquals(size, shortCodeIds.size());
}
......@@ -29,11 +33,13 @@ class CodeShortCodeServiceImplTest {
void getShuffledAlphaNumListTest() {
final long start = System.currentTimeMillis();
final List<Character> shuffledAlphaNumList = ShortCodeServiceImpl.getShuffledAlphaNumList();
System.out.println(String.format("expected %s and get %s in %s millis", 26+10, shuffledAlphaNumList.size(), System.currentTimeMillis()-start));
assertEquals(26+10, shuffledAlphaNumList.size());
System.out.println(
String.format(
"expected %s and get %s in %s millis", 26 + 10, shuffledAlphaNumList.size(),
System.currentTimeMillis() - start
)
);
assertEquals(26 + 10, shuffledAlphaNumList.size());
}
}
\ No newline at end of file
}
......@@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SubmissionCodeServerClientApiDatabaseApplication {
public static void main(String[] args) {
SpringApplication.run(SubmissionCodeServerClientApiDatabaseApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SubmissionCodeServerClientApiDatabaseApplication.class, args);
}
}
package fr.gouv.stopc.submission.code.server.database.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.OffsetDateTime;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@Valid
public class SubmissionCodeDto {
/*
Empty for short codes, required for long codes
*/
private long lot;
@NotNull
@NotBlank
private String code;
@NotNull
private String type;
@NotNull
private OffsetDateTime dateEndValidity;
@NotNull
private OffsetDateTime dateAvailable;
private OffsetDateTime dateUse;
@NotNull
private OffsetDateTime dateGeneration;
@NotNull
private Boolean used;
}
package fr.gouv.stopc.submission.code.server.database.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.OffsetDateTime;
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@Valid
public class SubmissionCodeDto {
/*
* Empty for short codes, required for long codes
*/
private long lot;
@NotNull
@NotBlank
private String code;
@NotNull
private String type;
@NotNull
private OffsetDateTime dateEndValidity;
@NotNull
private OffsetDateTime dateAvailable;
private OffsetDateTime dateUse;
@NotNull
private OffsetDateTime dateGeneration;
@NotNull
private Boolean used;
}
......@@ -6,8 +6,9 @@ import javax.persistence.*;
@Data
@Entity
@Table(name ="lot_keys")
@Table(name = "lot_keys")
public class Lot {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
......
package fr.gouv.stopc.submission.code.server.database.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
......@@ -7,33 +12,28 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@Entity
@Table(name ="seq_fichier")
@Table(name = "seq_fichier")
public class SequenceFichier {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "annee", nullable = false)
private int annee;
@Column(name = "annee", nullable = false)
private int annee;
@Column(name = "mois", nullable = false)
private int mois;
@Column(name = "mois", nullable = false)
private int mois;