diff --git a/Dockerfile b/Dockerfile index f8929e3..9efcde8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,18 +5,9 @@ COPY pom.xml /usr/src/app RUN mvn -f /usr/src/app/pom.xml -gs /usr/share/maven/ref/settings-docker.xml -Dextract.test.name=Extraction_Pro_sante_connect_cartes_de_test_bascule -DskipTests clean package FROM openjdk:11-slim-buster -RUN echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian.org buster main" > /etc/apt/sources.list \ - && echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian.org buster-updates main" >> /etc/apt/sources.list \ - && apt update \ - && apt install -y --allow-downgrades wget gnupg=2.2.12-1+deb10u1 gpgv=2.2.12-1+deb10u1 dos2unix \ - && wget -qO - http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - \ - && echo "deb [trusted=yes] http://repo.proxy-dev-forge.asip.hst.fluxus.net/artifactory/debian-repo.mongodb.org buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list -RUN apt update -RUN apt install -y mongodb-database-tools mongodb-mongosh=1.5.0 COPY --from=build /usr/src/app/target/pscextract-*.jar /usr/app/pscextract.jar RUN mkdir -p /app/extract-repo && mkdir -p /app/resources -COPY --from=build /usr/src/app/src/main/resources/aggregate.mongo /app/resources/ RUN usermod -d /app daemon && chown -R daemon: /app USER daemon EXPOSE 8080 -ENTRYPOINT ["java","-jar","/usr/app/pscextract.jar"] +ENTRYPOINT ["sh", "-c", "exec java -jar /usr/app/pscextract.jar"] diff --git a/Dockerfile.ext b/Dockerfile.ext index 0048428..44e5a5a 100644 --- a/Dockerfile.ext +++ b/Dockerfile.ext @@ -1,20 +1,13 @@ FROM maven:3-jdk-11 AS build COPY src /usr/src/app/src COPY pom.xml /usr/src/app -RUN mvn -f /usr/src/app/pom.xml -Dextract.test.name=Extraction_Pro_sante_connect_cartes_de_test_bascule clean package +RUN mvn -f /usr/src/app/pom.xml clean package -DskipTests=true FROM openjdk:11-slim-buster -RUN apt update \ - && apt install -y wget gnupg dos2unix \ - && wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - \ - && echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list -RUN apt update -RUN apt install -y mongodb-database-tools mongodb-mongosh COPY --from=build /usr/src/app/target/pscextract-*.jar /usr/app/pscextract.jar RUN mkdir -p /app/extract-repo && mkdir -p /app/resources -COPY --from=build /usr/src/app/src/main/resources/aggregate.mongo /app/resources/ RUN chown -R daemon: /app USER daemon EXPOSE 8080 -ENTRYPOINT ["java","-jar","/usr/app/pscextract.jar"] +ENTRYPOINT ["sh", "-c", "exec java -jar /usr/app/pscextract.jar"] diff --git a/pscextract.nomad.tpl b/pscextract.nomad.tpl index cdf4014..c0e1948 100644 --- a/pscextract.nomad.tpl +++ b/pscextract.nomad.tpl @@ -1,6 +1,7 @@ job "pscextract" { datacenters = ["${datacenter}"] type = "service" + namespace = "${nomad_namespace}" vault { policies = ["psc-ecosystem"] @@ -28,7 +29,7 @@ job "pscextract" { mount { type = "volume" target = "/app/extract-repo" - source = "pscextract-data" + source = "${nomad_namespace}-pscextract-data" readonly = false volume_options { no_copy = false @@ -70,7 +71,7 @@ job "pscextract" { extra_hosts = [ "psc-api-maj.internal:$\u007BNOMAD_IP_http\u007D" ] image = "${artifact.image}:${artifact.tag}" volumes = [ - "name=pscextract-data,io_priority=high,size=10,repl=3:/app/extract-repo" + "name=${nomad_namespace}-pscextract-data,io_priority=high,size=10,repl=3:/app/extract-repo" ] volume_driver = "pxd" ports = ["http"] @@ -79,34 +80,39 @@ job "pscextract" { destination = "local/file.env" env = true data = < getDemoExtractFile() { @PostMapping(value = "/generate-extract") public ResponseEntity generateExtract(@RequestParam(required = false) Integer pageSize) { - if(!busy) { + if (!busy) { ForkJoinPool.commonPool().submit(() -> { try { busy = true; - if (pageSize != null) + if (pageSize != null) { this.pageSize = pageSize; - if (this.psApi == null) + } + if (this.psApi == null) { instantiateApi(); + } + File latestExtract = transformationService.extractToCsv(this); FileNamesUtil.cleanup(filesDirectory, extractTestName); - if (latestExtract != null) + if (latestExtract != null) { emailService.sendSimpleMessage("PSCEXTRACT - sécurisation effectuée", latestExtract); - else + } + else { emailService.sendSimpleMessage("PSCEXTRACT - sécurisation échouée", null); + } } catch (IOException e) { log.error("Exception raised :", e); } finally { busy = false; } }); - }else + } else { return new ResponseEntity<>(HttpStatus.CONFLICT); + } return new ResponseEntity<>(HttpStatus.OK); } diff --git a/src/main/java/fr/ans/psc/pscextract/service/EmailService.java b/src/main/java/fr/ans/psc/pscextract/service/EmailService.java index 5b25820..0093c24 100644 --- a/src/main/java/fr/ans/psc/pscextract/service/EmailService.java +++ b/src/main/java/fr/ans/psc/pscextract/service/EmailService.java @@ -28,12 +28,15 @@ public class EmailService { @Value("${pscextract.mail.receiver}") private String receiver; + @Value("${secpsc.environment}") + private String platform; + public void sendSimpleMessage(String subject, File latestExtract) { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(sender); String[] allReceivers = receiver.split(","); message.setTo(allReceivers); - message.setSubject(subject); + message.setSubject(platform + " - " + subject); message.setText(getEmailMessage(latestExtract)); emailSender.send(message); diff --git a/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java b/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java index 3d5b04c..a94d2a6 100644 --- a/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java +++ b/src/main/java/fr/ans/psc/pscextract/service/TransformationService.java @@ -29,6 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.zip.ZipEntry; @@ -37,311 +38,327 @@ @Service public class TransformationService { - /** - * logger. - */ - private static final Logger log = LoggerFactory.getLogger(TransformationService.class); + /** + * logger. + */ + private static final Logger log = LoggerFactory.getLogger(TransformationService.class); - @Value("${extract.name}") - private String extractName; + @Value("${extract.name}") + private String extractName; - @Value("${extract.test.name}") - public String extractTestName; + @Value("${extract.test.name}") + public String extractTestName; - @Value("${files.directory}") - private String filesDirectory; + @Value("${files.directory}") + private String filesDirectory; - @Value("${working.directory}") - private String workingDirectory; + @Value("${working.directory}") + private String workingDirectory; - @Value("${first.name.count}") - private Integer firstNameCount; + private String extractTime = "197001010001"; - private String extractTime = "197001010001"; + public String getLinkString(String id) { + if (id.isEmpty()) { + return ""; + } + switch (id.charAt(0)) { + case ('1'): + // if (s.charAt(1) == '0') return s+','+"MSSante"+','+'1'; + return id + ',' + "ADELI" + ',' + '1'; + case ('3'): + return id + ',' + "FINESS" + ',' + '1'; + case ('4'): + return id + ',' + "SIREN" + ',' + '1'; + case ('5'): + return id + ',' + "SIRET" + ',' + '1'; + case ('6'): + case ('8'): + return id + ',' + "RPPS" + ',' + '1'; + default: + return id + ',' + "ADELI" + ',' + '1'; + } + } - public String getLinkString(String id) { - if (id.isEmpty()) { - return ""; + public String transformIdsToString(List ids) { + if (ids == null) + return ""; + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < ids.size(); i++) { + sb.append(getLinkString(ids.get(i))); + if (i != ids.size() - 1) { + sb.append(";"); + } + } + return sb.toString(); } - switch (id.charAt(0)) { - case ('1'): - // if (s.charAt(1) == '0') return s+','+"MSSante"+','+'1'; - return id + ',' + "ADELI" + ',' + '1'; - case ('3'): - return id + ',' + "FINESS" + ',' + '1'; - case ('4'): - return id + ',' + "SIREN" + ',' + '1'; - case ('5'): - return id + ',' + "SIRET" + ',' + '1'; - case ('6'): - case ('8'): - return id + ',' + "RPPS" + ',' + '1'; - default: - return id + ',' + "ADELI" + ',' + '1'; + + public String transformFirstNamesToStringWithApostrophes(List firstNames) { + if (firstNames != null) { + firstNames.sort(Comparator.comparing(FirstName::getOrder)); + StringBuilder sb = new StringBuilder(); + + firstNames.forEach(firstName -> sb.append(firstName.getFirstName()).append("'")); + + sb.deleteCharAt(sb.length() - 1); + return sb.toString(); + } else return null; } - } - - public String transformIdsToString(List ids) { - if (ids == null) - return ""; - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < ids.size(); i++) { - sb.append(getLinkString(ids.get(i))); - if (i != ids.size() - 1) { - sb.append(";"); - } + + public String getFileNameWithExtension(String fileExtension) { + return extractName + "_" + extractTime + fileExtension; } - return sb.toString(); - } - - public String transformFirstNamesToStringWithApostrophes(List firstNames) { - if (firstNames != null) { - firstNames.sort(Comparator.comparing(FirstName::getOrder)); - StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < firstNameCount; i++) { - if (i < firstNames.size()) sb.append(firstNames.get(i).getFirstName()); - sb.append("'"); - } - - sb.deleteCharAt(sb.length() - 1); - return sb.toString(); - } else return null; - } - - public String getFileNameWithExtension(String fileExtension) { - return extractName + "_" + extractTime + fileExtension; - } - - public ArrayList unwind(List psList) { - ArrayList unwoundPsList = new ArrayList<>(); - Ps tempPs; - for (Ps ps : psList) { - if (ps.getDeactivated() == null || ps.getActivated() > ps.getDeactivated()) { - if (ps.getProfessions() == null) { - tempPs = CloneUtil.clonePs(ps, null, null, null); - unwoundPsList.add(tempPs); - } else - for (Profession profession : ps.getProfessions()) { - if (profession.getExpertises() == null && profession.getWorkSituations() == null) { - tempPs = CloneUtil.clonePs(ps, profession, null, null); - unwoundPsList.add(tempPs); - } else if (profession.getExpertises() == null && profession.getWorkSituations() != null) { - for (WorkSituation workSituation : profession.getWorkSituations()) { - tempPs = CloneUtil.clonePs(ps, profession, null, workSituation); - unwoundPsList.add(tempPs); - } - } else - for (Expertise expertise : profession.getExpertises()) { - if (profession.getWorkSituations() == null) { - tempPs = CloneUtil.clonePs(ps, profession, expertise, null); - unwoundPsList.add(tempPs); - } else - for (WorkSituation workSituation : profession.getWorkSituations()) { - tempPs = CloneUtil.clonePs(ps, profession, expertise, workSituation); + + public ArrayList unwind(List psList) { + ArrayList unwoundPsList = new ArrayList<>(); + Ps tempPs; + for (Ps ps : psList) { + if (ps.getDeactivated() == null || ps.getActivated() > ps.getDeactivated()) { + if (ps.getProfessions() == null) { + tempPs = CloneUtil.clonePs(ps, null, null, null); unwoundPsList.add(tempPs); - } - } - } - } + } else + for (Profession profession : ps.getProfessions()) { + if (profession.getExpertises() == null && profession.getWorkSituations() == null) { + tempPs = CloneUtil.clonePs(ps, profession, null, null); + unwoundPsList.add(tempPs); + } else if (profession.getExpertises() == null && profession.getWorkSituations() != null) { + for (WorkSituation workSituation : profession.getWorkSituations()) { + tempPs = CloneUtil.clonePs(ps, profession, null, workSituation); + unwoundPsList.add(tempPs); + } + } else + for (Expertise expertise : profession.getExpertises()) { + if (profession.getWorkSituations() == null) { + tempPs = CloneUtil.clonePs(ps, profession, expertise, null); + unwoundPsList.add(tempPs); + } else + for (WorkSituation workSituation : profession.getWorkSituations()) { + tempPs = CloneUtil.clonePs(ps, profession, expertise, workSituation); + unwoundPsList.add(tempPs); + } + } + } + } + } + return unwoundPsList; } - return unwoundPsList; - } - - public String transformPsToLine(Ps ps) { - String activityCode = null; - StringBuilder sb = new StringBuilder(); - sb.append(Optional.ofNullable(ps.getIdType()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getId()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getNationalId()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getLastName()).orElse("")).append("|"); - sb.append(Optional.ofNullable(transformFirstNamesToStringWithApostrophes(ps.getFirstNames())).orElse("''")).append("|"); - sb.append(Optional.ofNullable(ps.getDateOfBirth()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getBirthAddressCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getBirthCountryCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getBirthAddress()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getGenderCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getPhone()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getEmail()).orElse("")).append("|"); - sb.append(Optional.ofNullable(ps.getSalutationCode()).orElse("")).append("|"); - - if (ps.getProfessions() != null && ps.getProfessions().get(0) != null) { - Profession profession = ps.getProfessions().get(0); - sb.append(Optional.ofNullable(profession.getCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(profession.getCategoryCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(profession.getSalutationCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(profession.getLastName()).orElse("")).append("|"); - sb.append(Optional.ofNullable(profession.getFirstName()).orElse("")).append("|"); - - if (profession.getExpertises() != null && profession.getExpertises().get(0) != null) { - Expertise expertise = profession.getExpertises().get(0); - sb.append(Optional.ofNullable(expertise.getTypeCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(expertise.getCode()).orElse("")).append("|"); - } else { - sb.append("|".repeat(2)); - } - - if (profession.getWorkSituations() != null && profession.getWorkSituations().get(0) != null) { - WorkSituation workSituation = profession.getWorkSituations().get(0); - sb.append(Optional.ofNullable(workSituation.getModeCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(workSituation.getActivitySectorCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(workSituation.getPharmacistTableSectionCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(workSituation.getRoleCode()).orElse("")).append("|"); - - if (workSituation.getStructure() != null) { - Structure structure = workSituation.getStructure(); - sb.append(Optional.ofNullable(structure.getSiteSIRET()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getSiteSIREN()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getSiteFINESS()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getLegalEstablishmentFINESS()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getStructureTechnicalId()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getLegalCommercialName()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getPublicCommercialName()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getRecipientAdditionalInfo()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getGeoLocationAdditionalInfo()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getStreetNumber()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getStreetNumberRepetitionIndex()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getStreetCategoryCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getStreetLabel()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getDistributionMention()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getCedexOffice()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getPostalCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getCommuneCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getCountryCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getPhone()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getPhone2()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getFax()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getEmail()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getDepartmentCode()).orElse("")).append("|"); - sb.append(Optional.ofNullable(structure.getOldStructureId()).orElse("")).append("|"); + + public String transformPsToLine(Ps ps, String id) { + String activityCode = null; + StringBuilder sb = new StringBuilder(); + sb.append(id.charAt(0)).append("|"); + sb.append(id.substring(1)).append("|"); + sb.append(Optional.ofNullable(id).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getLastName()).orElse("")).append("|"); + sb.append(Optional.ofNullable(transformFirstNamesToStringWithApostrophes(ps.getFirstNames())).orElse("''")).append("|"); + sb.append(Optional.ofNullable(ps.getDateOfBirth()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getBirthAddressCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getBirthCountryCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getBirthAddress()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getGenderCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getPhone()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getEmail()).orElse("")).append("|"); + sb.append(Optional.ofNullable(ps.getSalutationCode()).orElse("")).append("|"); + + if (ps.getProfessions() != null && ps.getProfessions().get(0) != null) { + Profession profession = ps.getProfessions().get(0); + sb.append(Optional.ofNullable(profession.getCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(profession.getCategoryCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(profession.getSalutationCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(profession.getLastName()).orElse("")).append("|"); + sb.append(Optional.ofNullable(profession.getFirstName()).orElse("")).append("|"); + + if (profession.getExpertises() != null && profession.getExpertises().get(0) != null) { + Expertise expertise = profession.getExpertises().get(0); + sb.append(Optional.ofNullable(expertise.getTypeCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(expertise.getCode()).orElse("")).append("|"); + } else { + sb.append("|".repeat(2)); + } + + if (profession.getWorkSituations() != null && profession.getWorkSituations().get(0) != null) { + WorkSituation workSituation = profession.getWorkSituations().get(0); + sb.append(Optional.ofNullable(workSituation.getModeCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(workSituation.getActivitySectorCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(workSituation.getPharmacistTableSectionCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(workSituation.getRoleCode()).orElse("")).append("|"); + + if (workSituation.getStructure() != null) { + Structure structure = workSituation.getStructure(); + sb.append(Optional.ofNullable(structure.getSiteSIRET()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getSiteSIREN()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getSiteFINESS()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getLegalEstablishmentFINESS()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getStructureTechnicalId()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getLegalCommercialName()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getPublicCommercialName()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getRecipientAdditionalInfo()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getGeoLocationAdditionalInfo()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getStreetNumber()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getStreetNumberRepetitionIndex()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getStreetCategoryCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getStreetLabel()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getDistributionMention()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getCedexOffice()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getPostalCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getCommuneCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getCountryCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getPhone()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getPhone2()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getFax()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getEmail()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getDepartmentCode()).orElse("")).append("|"); + sb.append(Optional.ofNullable(structure.getOldStructureId()).orElse("")).append("|"); + } else { + sb.append("|".repeat(24)); + } + sb.append(Optional.ofNullable(workSituation.getRegistrationAuthority()).orElse("")).append("|"); + activityCode = (Optional.ofNullable(workSituation.getActivityKindCode()).orElse("")); + + } else { + sb.append("|".repeat(29)); + } } else { - sb.append("|".repeat(24)); + sb.append("|".repeat(36)); } - sb.append(Optional.ofNullable(workSituation.getRegistrationAuthority()).orElse("")).append("|"); - activityCode = (Optional.ofNullable(workSituation.getActivityKindCode()).orElse("")); - - } else { - sb.append("|".repeat(29)); - } - } else { - sb.append("|".repeat(36)); + sb.append(Optional.ofNullable(transformIdsToString(ps.getIds())).orElse("")).append("|"); + sb.append(Optional.ofNullable(activityCode).orElse("")).append("|"); + sb.append("\n"); + + return sb.toString(); } - sb.append(Optional.ofNullable(transformIdsToString(ps.getIds())).orElse("")).append("|"); - sb.append(Optional.ofNullable(activityCode).orElse("")).append("|"); - sb.append("\n"); - - return sb.toString(); - } - - public void setExtractionTime() { - DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); - LocalDateTime now = LocalDateTime.now(); - extractTime = dtf.format(now); - } - - public File extractToCsv(ExtractionController extractionController) throws IOException { - File tempExtractFile = File.createTempFile("tempExtract", "tmp"); - BufferedWriter bw = Files.newBufferedWriter(tempExtractFile.toPath(), StandardCharsets.UTF_8); - log.info("BufferedWriter initialized"); - - String header = "Type d'identifiant PP|Identifiant PP|Identification nationale PP|Nom de famille|Prénoms|" + - "Date de naissance|Code commune de naissance|Code pays de naissance|Lieu de naissance|Code sexe|" + - "Téléphone (coord. correspondance)|Adresse e-mail (coord. correspondance)|Code civilité|Code profession|" + - "Code catégorie professionnelle|Code civilité d'exercice|Nom d'exercice|Prénom d'exercice|" + - "Code type savoir-faire|Code savoir-faire|Code mode exercice|Code secteur d'activité|" + - "Code section tableau pharmaciens|Code rôle|Numéro SIRET site|Numéro SIREN site|Numéro FINESS site|" + - "Numéro FINESS établissement juridique|Identifiant technique de la structure|Raison sociale site|" + - "Enseigne commerciale site|Complément destinataire (coord. structure)|" + - "Complément point géographique (coord. structure)|Numéro Voie (coord. structure)|" + - "Indice répétition voie (coord. structure)|Code type de voie (coord. structure)|" + - "Libellé Voie (coord. structure)|Mention distribution (coord. structure)|" + - "Bureau cedex (coord. structure)|Code postal (coord. structure)|Code commune (coord. structure)|" + - "Code pays (coord. structure)|Téléphone (coord. structure)|Téléphone 2 (coord. structure)|" + - "Télécopie (coord. structure)|Adresse e-mail (coord. structure)|Code département (coord. structure)|" + - "Ancien identifiant de la structure|Autorité d'enregistrement|Autres identifiants|Code genre d'activité|\n"; - bw.write(header); - log.info("Header written"); - - - setExtractionTime(); - - int page = 0; - List responsePsList; - List tempPsList; - - log.info("Starting extraction at " + extractionController.getApiBaseUrl()); - - try { - BigDecimal size = BigDecimal.valueOf(extractionController.getPageSize()); - List response = extractionController.getPsApi().getPsByPage(BigDecimal.valueOf(page), size); - log.info("Page " + page + " of size " + size + " received"); - boolean outOfPages = false; - - do { - responsePsList = response; - tempPsList = unwind(responsePsList); - - for (Ps ps : tempPsList) { - bw.write(transformPsToLine(ps)); - log.debug("Ps " + ps.getId() + " transformed and written"); - } - page++; + + public void setExtractionTime() { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); + LocalDateTime now = LocalDateTime.now(ZoneId.of("Europe/Paris")); + extractTime = dtf.format(now); + } + + public File extractToCsv(ExtractionController extractionController) throws IOException { + File tempExtractFile = File.createTempFile("tempExtract", "tmp"); + BufferedWriter bw = Files.newBufferedWriter(tempExtractFile.toPath(), StandardCharsets.UTF_8); + log.info("BufferedWriter initialized"); + + String header = getCsvHeader(); + bw.write(header); + log.info("Header written"); + + setExtractionTime(); + + int page = 0; + List responsePsList; + List tempPsList; + + log.info("Starting extraction at " + extractionController.getApiBaseUrl()); + try { - response = extractionController.getPsApi().getPsByPage(BigDecimal.valueOf(page), size); - log.info("Page " + page + " of size " + size + " received, writing to file..."); + BigDecimal size = BigDecimal.valueOf(extractionController.getPageSize()); + List response = extractionController.getPsApi().getPsByPage(BigDecimal.valueOf(page), size); + assert !response.isEmpty(); + log.debug("number of Ps : {}", response.size()); + log.debug("Page " + page + " of size " + size + " received"); + boolean outOfPages = false; + + do { + responsePsList = response; + tempPsList = unwind(responsePsList); + + for (Ps ps : tempPsList) { + for (String id : ps.getIds()) { + bw.write(transformPsToLine(ps, id)); + } + log.trace("Ps " + ps.getId() + " transformed and written"); + } + page++; + try { + response = extractionController.getPsApi().getPsByPage(BigDecimal.valueOf(page), size); + log.debug("Page " + page + " of size " + size + " received, writing to file..."); + } catch (HttpStatusCodeException e) { + log.warn("Out of pages: " + e.getMessage()); + if (e.getStatusCode() != HttpStatus.GONE) { + log.info("Extraction failed, exiting without replacing the extract file"); + if (tempExtractFile.delete()) { + log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); + } else { + log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); + } + return null; + } + outOfPages = true; + } catch (Exception e) { + log.error("exception raised : ", e); + } + } while (!outOfPages); } catch (HttpStatusCodeException e) { - log.warn("Out of pages: " + e.getMessage()); - if(e.getStatusCode()!= HttpStatus.GONE) { + log.error("No pages found :" + e.getMessage()); log.info("Extraction failed, exiting without replacing the extract file"); if (tempExtractFile.delete()) { - log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); + log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); } else { - log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); + log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); } return null; - } - outOfPages = true; + } catch (Exception e) { + log.error("exception raised : ", e); + } finally { + bw.close(); + log.info("BufferedWriter closed"); } - } while (!outOfPages); - } catch (HttpStatusCodeException e) { - log.error("No pages found :"+ e.getMessage()); - log.info("Extraction failed, exiting without replacing the extract file"); - if (tempExtractFile.delete()) { - log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); - } else { - log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); - } - return null; - } finally { - bw.close(); - log.info("BufferedWriter closed"); - } - InputStream fileContent = new FileInputStream(tempExtractFile); + InputStream fileContent = new FileInputStream(tempExtractFile); - log.info("Zipping up the extract file..."); - ZipEntry zipEntry = new ZipEntry(getFileNameWithExtension(extractionController.getTXT_EXTENSION())); - zipEntry.setTime(System.currentTimeMillis()); - ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION())))); - zos.putNextEntry(zipEntry); - StreamUtils.copy(fileContent, zos); + log.info("Zipping up the extract file..."); + ZipEntry zipEntry = new ZipEntry(getFileNameWithExtension(extractionController.getTXT_EXTENSION())); + zipEntry.setTime(System.currentTimeMillis()); + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION())))); + zos.putNextEntry(zipEntry); + StreamUtils.copy(fileContent, zos); - fileContent.close(); - zos.closeEntry(); - zos.finish(); - zos.close(); + fileContent.close(); + zos.closeEntry(); + zos.finish(); + zos.close(); - if (tempExtractFile.delete()) { - log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); - } else { - log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); + if (tempExtractFile.delete()) { + log.info("Temp file at " + tempExtractFile.getAbsolutePath() + " deleted"); + } else { + log.warn("Temp file at " + tempExtractFile.getAbsolutePath() + " not deleted"); + } + + Files.move( + Path.of(FileNamesUtil.getFilePath( + extractionController.getWorkingDirectory(), + getFileNameWithExtension(extractionController.getZIP_EXTENSION()))), + Path.of(FileNamesUtil.getFilePath( + extractionController.getFilesDirectory(), + getFileNameWithExtension(extractionController.getZIP_EXTENSION())))); + + log.info("File at " + FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(), + getFileNameWithExtension(extractionController.getZIP_EXTENSION())) + + " moved to " + FileNamesUtil.getFilePath(extractionController.getFilesDirectory(), + getFileNameWithExtension(extractionController.getZIP_EXTENSION()))); + + return FileNamesUtil.getLatestExtract(extractionController.getFilesDirectory(), + getFileNameWithExtension(extractionController.getZIP_EXTENSION())); } - Files.move(Path.of(FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION()))), - Path.of(FileNamesUtil.getFilePath(extractionController.getFilesDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION())))); - log.info("File at " + FileNamesUtil.getFilePath(extractionController.getWorkingDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION())) + " moved to " + FileNamesUtil.getFilePath(extractionController.getFilesDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION()))); - return FileNamesUtil.getLatestExtract(extractionController.getFilesDirectory(), getFileNameWithExtension(extractionController.getZIP_EXTENSION())); - } + private String getCsvHeader() { + return "Type d'identifiant PP|Identifiant PP|Identification nationale PP|Nom de famille|Prénoms|" + + "Date de naissance|Code commune de naissance|Code pays de naissance|Lieu de naissance|Code sexe|" + + "Téléphone (coord. correspondance)|Adresse e-mail (coord. correspondance)|Code civilité|Code profession|" + + "Code catégorie professionnelle|Code civilité d'exercice|Nom d'exercice|Prénom d'exercice|" + + "Code type savoir-faire|Code savoir-faire|Code mode exercice|Code secteur d'activité|" + + "Code section tableau pharmaciens|Code rôle|Numéro SIRET site|Numéro SIREN site|Numéro FINESS site|" + + "Numéro FINESS établissement juridique|Identifiant technique de la structure|Raison sociale site|" + + "Enseigne commerciale site|Complément destinataire (coord. structure)|" + + "Complément point géographique (coord. structure)|Numéro Voie (coord. structure)|" + + "Indice répétition voie (coord. structure)|Code type de voie (coord. structure)|" + + "Libellé Voie (coord. structure)|Mention distribution (coord. structure)|" + + "Bureau cedex (coord. structure)|Code postal (coord. structure)|Code commune (coord. structure)|" + + "Code pays (coord. structure)|Téléphone (coord. structure)|Téléphone 2 (coord. structure)|" + + "Télécopie (coord. structure)|Adresse e-mail (coord. structure)|Code département (coord. structure)|" + + "Ancien identifiant de la structure|Autorité d'enregistrement|Autres identifiants|Code genre d'activité|\n"; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d183afa..367418d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -25,4 +25,5 @@ spring.mail.username=testdev.ans@gmail.com spring.mail.password=password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true +secpsc.environment=default diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index e3a470b..e5084b5 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -14,7 +14,7 @@ - + diff --git a/src/test/java/fr/ans/psc/pscextract/ExtractionControllerTests.java b/src/test/java/fr/ans/psc/pscextract/ExtractionControllerTests.java index 6df056b..69b597f 100644 --- a/src/test/java/fr/ans/psc/pscextract/ExtractionControllerTests.java +++ b/src/test/java/fr/ans/psc/pscextract/ExtractionControllerTests.java @@ -13,6 +13,7 @@ import fr.ans.psc.pscextract.controller.ExtractionController; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; @@ -88,7 +89,7 @@ void singlePageExtractionAndResultConformityTest() throws Exception { byte[] expectedResponseBytes = Files.readAllBytes(Paths.get(responsePath)); httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("multiple-work-situations.json"))); - httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(420))); + httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410))); controller.generateExtract(null); @@ -142,6 +143,7 @@ void noPagesExtractionTest() { } @Test + @Disabled void emptyPsExtractionTest() throws Exception { String responseFilename = "empty-ps-result"; @@ -149,7 +151,7 @@ void emptyPsExtractionTest() throws Exception { byte[] expectedResponseBytes = Files.readAllBytes(Paths.get(responsePath)); httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("empty-ps.json"))); - httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(420))); + httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410))); controller.generateExtract(null); @@ -173,7 +175,7 @@ void fullyEmptyPsExtractionTest() throws Exception { byte[] expectedResponseBytes = Files.readAllBytes(Paths.get(responsePath)); httpMockServer.stubFor(get("/v2/ps?page=0&size=1").willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("very-empty-ps.json"))); - httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(420))); + httpMockServer.stubFor(get("/v2/ps?page=1&size=1").willReturn(aResponse().withStatus(410))); controller.generateExtract(null); diff --git a/src/test/java/fr/ans/psc/pscextract/TransformationServiceTest.java b/src/test/java/fr/ans/psc/pscextract/TransformationServiceTest.java new file mode 100644 index 0000000..824d049 --- /dev/null +++ b/src/test/java/fr/ans/psc/pscextract/TransformationServiceTest.java @@ -0,0 +1,43 @@ +package fr.ans.psc.pscextract; + +import fr.ans.psc.model.FirstName; +import fr.ans.psc.pscextract.service.TransformationService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@SpringBootTest +@ContextConfiguration(classes = PscextractApplication.class) +public class TransformationServiceTest { + + @Autowired + TransformationService transformationService; + + @DynamicPropertySource + static void registerPgProperties(DynamicPropertyRegistry propertiesRegistry) { + propertiesRegistry.add("page.size", () -> "1"); + } + + @Test + public void transformFirstNamesTest() { + FirstName fn1 = new FirstName("KADER", 0); + FirstName fn2 = new FirstName("HASSAN", 1); + FirstName fn3 = new FirstName("JOHNNY", 2); + + List fnList = new ArrayList<>(); + fnList.add(fn1); + fnList.add(fn3); + fnList.add(fn2); + + String namesString = transformationService.transformFirstNamesToStringWithApostrophes(fnList); + assertEquals("KADER'HASSAN'JOHNNY", namesString); + } +} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index d5fb380..f6f5f5a 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -17,5 +17,6 @@ spring.mail.password=lepassworddetoto spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true pscextract.mail.receiver=toto@gmail.com +secpsc.environment=default api.base.url=http://localhost:8080/psc-api-maj/api diff --git a/src/test/resources/wiremock/__files/multiple-pages-result.txt b/src/test/resources/wiremock/__files/multiple-pages-result.txt index e784990..73877f7 100644 --- a/src/test/resources/wiremock/__files/multiple-pages-result.txt +++ b/src/test/resources/wiremock/__files/multiple-pages-result.txt @@ -1,37 +1,37 @@ Type d'identifiant PP|Identifiant PP|Identification nationale PP|Nom de famille|Prénoms|Date de naissance|Code commune de naissance|Code pays de naissance|Lieu de naissance|Code sexe|Téléphone (coord. correspondance)|Adresse e-mail (coord. correspondance)|Code civilité|Code profession|Code catégorie professionnelle|Code civilité d'exercice|Nom d'exercice|Prénom d'exercice|Code type savoir-faire|Code savoir-faire|Code mode exercice|Code secteur d'activité|Code section tableau pharmaciens|Code rôle|Numéro SIRET site|Numéro SIREN site|Numéro FINESS site|Numéro FINESS établissement juridique|Identifiant technique de la structure|Raison sociale site|Enseigne commerciale site|Complément destinataire (coord. structure)|Complément point géographique (coord. structure)|Numéro Voie (coord. structure)|Indice répétition voie (coord. structure)|Code type de voie (coord. structure)|Libellé Voie (coord. structure)|Mention distribution (coord. structure)|Bureau cedex (coord. structure)|Code postal (coord. structure)|Code commune (coord. structure)|Code pays (coord. structure)|Téléphone (coord. structure)|Téléphone 2 (coord. structure)|Télécopie (coord. structure)|Adresse e-mail (coord. structure)|Code département (coord. structure)|Ancien identifiant de la structure|Autorité d'enregistrement|Autres identifiants|Code genre d'activité| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -3|750821092/|067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||111,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|2|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| -|3|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +3|750821092/067L-06067983|3750821092/067L-06067983|HOLLIER|NELSON'THOMAS'||||||||M||||||||||||||||1.1.1|||||||||||||||||||||3750821092/067L-06067983,FINESS,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +2|22|222||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||222,ADELI,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| +3|33|333||''||||||||||||||||||||||||1.1.1|||||||||||||||||||||333,FINESS,1|| diff --git a/src/test/resources/wiremock/__files/multiple-work-situations-result.txt b/src/test/resources/wiremock/__files/multiple-work-situations-result.txt index 974d559..f4fedd4 100644 --- a/src/test/resources/wiremock/__files/multiple-work-situations-result.txt +++ b/src/test/resources/wiremock/__files/multiple-work-situations-result.txt @@ -1,3 +1,7 @@ Type d'identifiant PP|Identifiant PP|Identification nationale PP|Nom de famille|Prénoms|Date de naissance|Code commune de naissance|Code pays de naissance|Lieu de naissance|Code sexe|Téléphone (coord. correspondance)|Adresse e-mail (coord. correspondance)|Code civilité|Code profession|Code catégorie professionnelle|Code civilité d'exercice|Nom d'exercice|Prénom d'exercice|Code type savoir-faire|Code savoir-faire|Code mode exercice|Code secteur d'activité|Code section tableau pharmaciens|Code rôle|Numéro SIRET site|Numéro SIREN site|Numéro FINESS site|Numéro FINESS établissement juridique|Identifiant technique de la structure|Raison sociale site|Enseigne commerciale site|Complément destinataire (coord. structure)|Complément point géographique (coord. structure)|Numéro Voie (coord. structure)|Indice répétition voie (coord. structure)|Code type de voie (coord. structure)|Libellé Voie (coord. structure)|Mention distribution (coord. structure)|Bureau cedex (coord. structure)|Code postal (coord. structure)|Code commune (coord. structure)|Code pays (coord. structure)|Téléphone (coord. structure)|Téléphone 2 (coord. structure)|Télécopie (coord. structure)|Adresse e-mail (coord. structure)|Code département (coord. structure)|Ancien identifiant de la structure|Autorité d'enregistrement|Autres identifiants|Code genre d'activité| 8|10106820706|810106820706|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S|SA43|||26890206100038||||R10100000489889|CENTRE COMMUNAL ACTION SOCIALE||||5|||RUE JULES DUMONT D URVILLE||89300 JOIGNY|89300|89206|99000||||||326890206100038|//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| +2|63462378544|263462378544|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S|SA43|||26890206100038||||R10100000489889|CENTRE COMMUNAL ACTION SOCIALE||||5|||RUE JULES DUMONT D URVILLE||89300 JOIGNY|89300|89206|99000||||||326890206100038|//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| +1|19294682980|119294682980|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S|SA43|||26890206100038||||R10100000489889|CENTRE COMMUNAL ACTION SOCIALE||||5|||RUE JULES DUMONT D URVILLE||89300 JOIGNY|89300|89206|99000||||||326890206100038|//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| 8|10106820706|810106820706|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S||||||||||||||||||||||||||||//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| +2|63462378544|263462378544|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S||||||||||||||||||||||||||||//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| +1|19294682980|119294682980|D'ARCO|ANNE'CATHERINE'|25/09/1975|91521|99000||F|0033681162661||MME|60|C||D'ARCO|ANNE-CATHERINE|||S||||||||||||||||||||||||||||//|810106820706,RPPS,1;263462378544,ADELI,1;119294682980,ADELI,1|GENR01| diff --git a/src/test/resources/wiremock/__files/page1size1.json b/src/test/resources/wiremock/__files/page1size1.json index d943723..45589f9 100644 --- a/src/test/resources/wiremock/__files/page1size1.json +++ b/src/test/resources/wiremock/__files/page1size1.json @@ -1,7 +1,7 @@ [ { "idType": "3", - "id": "750821092/|067L-06067983", + "id": "750821092/067L-06067983", "nationalId": "3750821092/067L-06067983", "lastName": "HOLLIER", "firstNames": [ @@ -61,7 +61,7 @@ ], "activated": 1, "ids": [ - "111" + "3750821092/067L-06067983" ] } ] diff --git a/src/test/resources/wiremock/__files/page2size1.json b/src/test/resources/wiremock/__files/page2size1.json index 356bcda..aa478f0 100644 --- a/src/test/resources/wiremock/__files/page2size1.json +++ b/src/test/resources/wiremock/__files/page2size1.json @@ -1,5 +1,6 @@ [ { + "idType": "0", "id": "2", "nationalId": "222", "professions": [ diff --git a/src/test/resources/wiremock/__files/page3size1.json b/src/test/resources/wiremock/__files/page3size1.json index ea99e06..3ce38a3 100644 --- a/src/test/resources/wiremock/__files/page3size1.json +++ b/src/test/resources/wiremock/__files/page3size1.json @@ -1,5 +1,6 @@ [ { + "idType": "0", "id": "3", "nationalId": "333", "professions": [ diff --git a/src/test/resources/wiremock/__files/very-empty-ps-result.txt b/src/test/resources/wiremock/__files/very-empty-ps-result.txt index 446d555..66171a1 100644 --- a/src/test/resources/wiremock/__files/very-empty-ps-result.txt +++ b/src/test/resources/wiremock/__files/very-empty-ps-result.txt @@ -1,6 +1 @@ Type d'identifiant PP|Identifiant PP|Identification nationale PP|Nom de famille|Prénoms|Date de naissance|Code commune de naissance|Code pays de naissance|Lieu de naissance|Code sexe|Téléphone (coord. correspondance)|Adresse e-mail (coord. correspondance)|Code civilité|Code profession|Code catégorie professionnelle|Code civilité d'exercice|Nom d'exercice|Prénom d'exercice|Code type savoir-faire|Code savoir-faire|Code mode exercice|Code secteur d'activité|Code section tableau pharmaciens|Code rôle|Numéro SIRET site|Numéro SIREN site|Numéro FINESS site|Numéro FINESS établissement juridique|Identifiant technique de la structure|Raison sociale site|Enseigne commerciale site|Complément destinataire (coord. structure)|Complément point géographique (coord. structure)|Numéro Voie (coord. structure)|Indice répétition voie (coord. structure)|Code type de voie (coord. structure)|Libellé Voie (coord. structure)|Mention distribution (coord. structure)|Bureau cedex (coord. structure)|Code postal (coord. structure)|Code commune (coord. structure)|Code pays (coord. structure)|Téléphone (coord. structure)|Téléphone 2 (coord. structure)|Télécopie (coord. structure)|Adresse e-mail (coord. structure)|Code département (coord. structure)|Ancien identifiant de la structure|Autorité d'enregistrement|Autres identifiants|Code genre d'activité| -||||''||||||||||||||||||||||||||||||||||||||||||||||| -||||''||||||||||||||||||||||||||||||||||||||||||||||| -||||''||||||||||||||||||||||||||||||||||||||||||||||| -||||''||||||||||||||||||||||||||||||||||||||||||||||| -||||''||||||||||||||||||||||||||||||||||||||||||||||| diff --git a/waypoint.hcl b/waypoint.hcl index e94c78e..1721404 100644 --- a/waypoint.hcl +++ b/waypoint.hcl @@ -1,36 +1,38 @@ -project = "prosanteconnect/pscextract" +project = "prosanteconnect/${workspace.name}/pscextract" # Labels can be specified for organizational purposes. labels = { "domaine" = "psc" } runner { enabled = true + profile = "secpsc-${workspace.name}" data_source "git" { url = "https://github.com/prosanteconnect/pscextract.git" - ref = var.datacenter + ref = "${workspace.name}" } poll { - enabled = true + enabled = false } } # An application to deploy. app "prosanteconnect/pscextract" { - # the Build step is required and specifies how an application image should be built and published. In this case, - # we use docker-pull, we simply pull an image as is. build { use "docker" { build_args = { "proxy_address" = var.proxy_address } dockerfile = "${path.app}/${var.dockerfile_path}" + disable_entrypoint = true } # Uncomment below to use a remote docker registry to push your built images. registry { use "docker" { - image = "${var.registry_path}/pscextract" + image = "${var.registry_username}/pscextract" tag = gitrefpretty() - encoded_auth = filebase64("/secrets/dockerAuth.json") + username = var.registry_username + password = var.registry_password + local = true } } } @@ -40,35 +42,47 @@ app "prosanteconnect/pscextract" { use "nomad-jobspec" { jobspec = templatefile("${path.app}/pscextract.nomad.tpl", { datacenter = var.datacenter - registry_path = var.registry_path + nomad_namespace = var.nomad_namespace + registry_username = var.registry_username }) } } } variable "datacenter" { - type = string - default = "dc1" + type = string + default = "" + env = ["NOMAD_DATACENTER"] +} + +variable "nomad_namespace" { + type = string + default = "" + env = ["NOMAD_NAMESPACE"] } variable "registry_username" { type = string default = "" + env = ["REGISTRY_USERNAME"] + sensitive = true } variable "registry_password" { type = string default = "" + env = ["REGISTRY_PASSWORD"] + sensitive = true } variable "dockerfile_path" { type = string - default = "Dockerfile" + default = "Dockerfile.ext" } variable "proxy_address" { type = string - default = "proxy_address" + default = "" } variable "registry_path" {