diff --git a/CHANGELOG.md b/CHANGELOG.md index 70469509a3cb7622872390f3434e456b74f26594..625c26bb07362c99d34e114a334a2c47db22a8a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Tous les changements de ce projet seront documentés dans ce document. ## [Non livré] +- Customisation des référentiels par organisation : les référentiels TypeItem, FacteurCaracterisation, CorrespondanceRefEquipement et Hypotheses peuvent être personnalisés par une organisation -> [Issue9](https://gitlab-forge.din.developpement-durable.gouv.fr/pub/numeco/m4g/numecoeval/-/issues/9) ## [2.1.0] - 2024-08-02 diff --git a/docs/MoteurDeCalculG4IT_V1.1.adoc b/docs/MoteurDeCalculG4IT_V1.1.adoc index fe2a19afc968f1c0696e1a950f377165054452b7..4329f42d3301042a47898b791b3d0d0c41a11aa8 100644 --- a/docs/MoteurDeCalculG4IT_V1.1.adoc +++ b/docs/MoteurDeCalculG4IT_V1.1.adoc @@ -97,7 +97,7 @@ Comme indiqué dans le schéma d'architecture fonctionnel simplifié ci-dessus, [#_donnees_de_reference] ==== Données de référence -Les données de références correspondent aux données qui ne proviennent pas directement de l'organisation (<<_Organisation>>) souhaitant utiliser NumEcoEval. Ces données peuvent être issues de la littérature scientifique, de bases de données de références externes et reconnues (NegaOctet, Base IMPACT de l'ADEME, bases de données BOAVIZTA...), ou issues de travaux empiriques. Ces données doivent nécessairement être sourcées pour assurer la traçabilité des calculs. +Les données de références peuvent être issues de la littérature scientifique, de bases de données de références externes et reconnues (NegaOctet, Base IMPACT de l'ADEME, bases de données BOAVIZTA...), ou issues de travaux empiriques. Ces données doivent nécessairement être sourcées pour assurer la traçabilité des calculs. Le tableau suivant permet de connaitre les données de référence utilisées dans les différentes règles de calcul. Ces données seront précédées du préfixe "ref_" suivi d'une suite de lettre permettant d'identifier la table concernée. @@ -113,7 +113,7 @@ exemple : |=== -**Pour chaque type d'objet, des endpoints de CRUD (Create/Read/Update/Delete) sont disponibles** +**Pour chaque type d'objet, des endpoints de CRU (Create/Read/Update) sont disponibles** Le format de ces références est contraint pour garantir la capacité du moteur de calul (cf.<<_moteur_de_calcul>>) à produire les indicateurs. @@ -123,28 +123,20 @@ Toutes ces données sont nécessaires au calcul des règles d'impact. Elles doiv **Précisions sur l'import CSV de certains référentiels** - Les API permettant d'importer de nouvelles données et d'exporter les références existantes sont décrites https://gitlab-forge.din.developpement-durable.gouv.fr/pub/numeco/m4g/numecoeval/-/blob/develop/services/common/src/main/resources/static/api-referentiels-openapi.yaml?ref_type=heads[ici]. -**Points d'attention ** - -- Par construction, une suppression sur le référentiel ref_EtapeACV supprime les référentiels référençant cette étape : ref_facteursCaracterisation et ref_ImpactMessagerie. -- Par construction, un import CSV sur le référentiel ref_EtapeACV supprime les référentiels référençant les étapes : ref_facteursCaracterisation et ref_ImpactMessagerie. -- Par construction, une suppression sur le référentiel ref_Critere supprime les référentiels référençant le critère : ref_facteursCaracterisation et ref_ImpactMessagerie. -- Par construction, un import CSV sur le référentiel ref_Critere supprime les référentiels référençant les critères : ref_facteursCaracterisation et ref_ImpactMessagerie. - ==== Précision sur les hypothèses Les hypothèses de travail se trouvent dans la table "Hypothèses". -Elles sont uniques pour une clé donnée. +Elles sont uniques pour une clé et une organisation données. À l'usage dans la suite du document, une hypothèse peut être retrouvée via la formule : -`ref_Hypothese(<clé d'hypothèse>)` +`ref_Hypothese(<clé d'hypothèse>,<nom de l'organisation>)` .Exemple d'hypothèses : |=== -|clé|valeur|source | description -|dureeVieParDefaut|1| dans le cas où la durée de vie d'un type d'équipement ne serait pas renseignée, on considère une hypothèse majorante d'une mise a rebut de l'équipement au bout de 1 an.| +|clé|valeur|source | description | nomOrganisation +|dureeVieParDefaut|1| dans le cas où la durée de vie d'un type d'équipement ne serait pas renseignée, on considère une hypothèse majorante d'une mise a rebut de l'équipement au bout de 1 an.| | SSG |=== - +Les hypothèses par défaut sont celles qui ont un nom d'organisation vide. Les références par défaut peuvent être utilisées par n'importe quelle organisation mais si elles souhaitent avoir des références customisées, les organisations puevent également le faire. [#_api_donnees_dentrees] === API pour les données d'entrées @@ -230,14 +222,14 @@ Le bloc Indicateurs expose les points suivants : * Pour les référentiels et les hypothèses : les éléments entre `()` correspondent aux clés uniques de lecture ** Exemples: -*** `ref_Hypothese(dureeVieParDefaut)` correspond à utiliser l'API GET /referentiels/hypotheses?cle={cle} avec la clé `dureeVieParDefaut` (cf.<<GET_Hypotheses>>) +*** `ref_Hypothese(dureeVieParDefaut, SSG)` correspond à utiliser l'API GET /referentiels/hypotheses?cle={cle}&nomOrganisation={nomOrganisation} avec la clé `dureeVieParDefaut` et l'organisation `SSG` (cf.<<GET_Hypotheses>>) pour obtenir l'objet ref_Hypothese correspondant -*** `ref_facteurCaracterisation(nom,etape,critere)` (cf.<<GET_FacteursCaracterisation>>) correspond à utiliser l'API GET /referentiels/facteursCaracterisation?nom={nomFacteurCaracterisation}&etapeacv={etapeacv}&critere={critere}& avec les paramètres `Etape`,`Critere` et `Nom` correspondants +*** `ref_facteurCaracterisation(nom,etape,critere, nomOrganisation)` (cf.<<GET_FacteursCaracterisation>>) correspond à utiliser l'API GET /referentiels/facteursCaracterisation?nom={nomFacteurCaracterisation}&etapeacv={etapeacv}&critere={critere}&nomOrganisation={nomOrganisation} avec les paramètres `Etape`,`Critere`, `Nom` et `nomOrganisation` correspondants * Le "." derrière un objet (déclaré ou obtenu après une méthode d'exposition) indique l'accès à un attribut de l'objet. ** Exemples : -*** `ref_Hypothese(dureeVieParDefaut).valeur` correspond au champ valeur de l'objet ref_Hypothese de clé `dureeVieParDefaut` -*** `ref_facteurCaracterisation(nom,etape,critere).valeur` correspond au champ valeur de l'objet ref_FacteurCaracterisation correspondant à `Etape`,`Critere` et `Nom` +*** `ref_Hypothese(cle,nomOrganisation).valeur` correspond au champ valeur de l'objet ref_Hypothese corréspondant à `Cle` et `nomOrganisation` +*** `ref_facteurCaracterisation(nom,etape,critere, nomOrganisation).valeur` correspond au champ valeur de l'objet ref_FacteurCaracterisation correspondant à `Etape`,`Critere`,`Nom` et `nomOrganisation` * Tous les indicateurs créés sont enregistrés en base de données grâce à la méthode sauvegarder_impact(ImpactUnitaire) : cf.<<sauvegarder_impact>> @@ -259,6 +251,8 @@ Il existe 2 paramètres associés à cette requête : * dureeUsage : la méthode de calcul de la durée de vie des équipements physiques utilisée, qui peut être ** FIXE (valeur par defaut): la méthode de calcul de la durée de vie se base sur l'attribut 'dureeUsageInterne' de l'équipement physique ** REEL : la méthode de calcul de la durée de vie se base sur l'âge réel de l'équipement physique (dateRetrait-dateAchat quand les données sont disponibles) +* nomOrganisation : L'organisation pour laquelle on veut utiliser les références, on peut laisser le champ vide pour n'utiliser que les valeurs par défaut. +Si on renseigne un nom d'organisation, dans les tables ref_facteurcaracterisation, ref_type_item, ref_correspondance_ref_eqp et ref_hypothese, on ira dans un premier temps chercher les lignes reliées à l'organisation et si la ligne n'existe pas, alors on prend la référence par défaut (celle dont le nomOrganisation est vide). NumEcoEval effectue alors les calculs des indicateurs et les sauvegardes dans la base correspondante. @@ -452,9 +446,9 @@ Règle RG_DureeVieItem(equipementPhysique, dureeVieItem) { SINON dureeVieItem= (((equipementPhysique.DateAchat - date du jour) / 365) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) 'dans les autres cas, une durée de vie moyenne de l'équipement est déduite SINON - SI (RG_DureeVieItem_Defaut(equipementPhysique) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval < 1) + SI (RG_DureeVieItem_Defaut(equipementPhysique, nomOrganisation) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval < 1) ALORS dureeVieItem= 1 - SINON dureeVieItem= (RG_DureeVieItem_Defaut(equipementPhysique) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) + SINON dureeVieItem= (RG_DureeVieItem_Defaut(equipementPhysique, nomOrganisation) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) FIN SI 'par défaut, la méthode de calcul de la durée de vie est la méthode "FIXE" SINON @@ -465,9 +459,9 @@ Règle RG_DureeVieItem(equipementPhysique, dureeVieItem) { ALORS dureeVieItem= 1 SINON dureeVieItem= (equipementPhysique.DureeUsageInterne + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) SINON - SI (RG_DureeVieItem_Defaut(equipementPhysique) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval < 1) + SI (RG_DureeVieItem_Defaut(equipementPhysique, nomOrganisation) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval < 1) ALORS dureeVieItem= 1 - SINON dureeVieItem= (RG_DureeVieItem_Defaut(equipementPhysique) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) + SINON dureeVieItem= (RG_DureeVieItem_Defaut(equipementPhysique, nomOrganisation) + equipementPhysique.DureeUsageAmont + equipementPhysique.DureeUsageAval) FIN SI FIN SI } @@ -482,9 +476,9 @@ Règle RG_DureeVieItem(operationNonIT, dureeVieItem) { SINON dureeVieItem= operationNonIT.dureeDeVie 'dans les autres cas, une durée de vie moyenne de l'équipement est déduite SINON - SI RG_DureeVieItem_Defaut(operationNonIT) < 1 + SI RG_DureeVieItem_Defaut(operationNonIT, nomOrganisation) < 1 ALORS dureeVieItem= 1 - SINON dureeVieItem= RG_DureeVieItem_Defaut(operationNonIT) + SINON dureeVieItem= RG_DureeVieItem_Defaut(operationNonIT, nomOrganisation) FIN SI } ---- @@ -509,15 +503,15 @@ La durée de vie des items peut être déterminée par défaut dans le cas où l [pseudocode] ---- -Règle RG_DureeVieItem_Defaut(Item, dureeVieItem_Defaut) { +Règle RG_DureeVieItem_Defaut(Item, dureeVieItem_Defaut, nomOrganisation) { 'la durée de vie par défaut des items est celle renseignée dans la table des types d'items SI l'item en entrée est présent dans la table des références d'items (si Item.type = ref_TypeItem.nom) ALORS dureeVieItem_Defaut= ref_TypeItem.dureeVieDefaut 'on retient l'hypothèse d'une durée de vie par défaut des items égale à la durée de vie des items enregistrés dans les hypothèses - SINON (SI Item='equipementPhysique' ET SI ref_Hypothese(dureeVieParDefaut) existe) - ALORS dureeVieItem_Defaut= ref_Hypothese(dureeVieParDefaut).valeur - SINON (SI Item='operationNonIT' ET SI ref_Hypothese(dureeVieBatimentParDefaut) existe) - ALORS dureeVieItem_Defaut= ref_Hypothese(dureeVieBatimentParDefaut).valeur + SINON (SI Item='equipementPhysique' ET SI ref_Hypothese(dureeVieParDefaut, nomOrganisation) existe) + ALORS dureeVieItem_Defaut= ref_Hypothese(dureeVieParDefaut, nomOrganisation).valeur + SINON (SI Item='operationNonIT' ET SI ref_Hypothese(dureeVieBatimentParDefaut, nomOrganisation) existe) + ALORS dureeVieItem_Defaut= ref_Hypothese(dureeVieBatimentParDefaut, nomOrganisation).valeur SINON ErrCalcul("la durée de vie par défaut de l'item n'a pas pu être déterminée") FIN SI @@ -544,15 +538,13 @@ Cette règle permet de retrouver l'équipement de référence, c'est à dire cel [pseudocode] ---- Règle RG_correspondanceRefEquipement(equipement, refEquipementRetenu) { - - SI ref_CorrespondanceRefEqP(equipement.modele) existe - refEquipementRetenu= ref_CorrespondanceRefEqP(equipement.modele).refEquipementCible - SINON SI ref_TypeItem(equipement.type).refEquipementParDefaut existe - refEquipementRetenu= ref_TypeItem(equipement.type).refEquipementParDefaut + SI ref_CorrespondanceRefEqP(equipement.modele, nomOrganisation) existe + refEquipementRetenu= ref_CorrespondanceRefEqP(equipement.modele, nomOrganisation).refEquipementCible + SINON SI ref_TypeItem(equipement.type, nomOrganisation).refEquipementParDefaut existe + refEquipementRetenu= ref_TypeItem(equipement.type, nomOrganisation).refEquipementParDefaut SINON ErrCalcul("aucune correspondance avec un équipement de référence n'a pu être déterminée") FIN SI - } ---- @@ -577,8 +569,8 @@ Cette règle permet de retrouver l'item de référence, c'est à dire celui dont ---- Règle RG_correspondanceRefOperationNonIT(nomOrganisation, item, refItemRetenu) { - SI ref_TypeItem(item.type).refItemParDefaut existe - refItemRetenu = ref_TypeItem(equipement.type).refItemParDefaut + SI ref_TypeItem(item.type, nomOrganisation).refItemParDefaut existe + refItemRetenu = ref_TypeItem(equipement.type, nomOrganisation).refItemParDefaut SINON ErrCalcul("aucune correspondance avec un item de référence n'a pu être déterminée") FIN SI @@ -638,28 +630,28 @@ Règle calculIndicateurImpactEquipementPhysique(critere, etape, nomOrganisation, ind_ImpactEquipementPhysique.consoElecMoyenne = EqP.consoElecAnnuelle SINON SI 'récupération de la consommation électrique de la référence de l'équipement retenue - result = result x Ref_FacteurCaracterisation(refEquipementRetenu, EtapeACV, Critere).consoElecAnMoyenne + result = result x Ref_FacteurCaracterisation(refEquipementRetenu, EtapeACV, Critere, nomOrganisation).consoElecAnMoyenne 'enregistrement de la consommation electrique retenue - ind_ImpactEquipementPhysique.consoElecMoyenne = Ref_FacteurCaracterisation(refEquipementRetenu, EtapeACV, Critere).consoElecAnMoyenne + ind_ImpactEquipementPhysique.consoElecMoyenne = Ref_FacteurCaracterisation(refEquipementRetenu, EtapeACV, Critere, nomOrganisation).consoElecAnMoyenne SINON ErrCalcFonc("donnée de consommation electrique manquante") Arret du calcul FIN SI SI EqP.NomCourtDatacenter est renseigné - SI n_DC(EqP.NomCourtDatacenter).PUE existe + result = result x en_DC(EqP.NomCourtDatacenter).PUE - SINON SI ref_Hypothese(PUEParDefaut) existe - result = result x ref_Hypothese(PUEParDefaut).valeur + SINON SI ref_Hypothese(PUEParDefaut, nomOrganisation) existe + result = result x ref_Hypothese(PUEParDefaut, nomOrganisation).valeur SINON ErrCalcFonc("le PUE est manquant et ne permet le calcul de l'impact à l'usage de l'équipement") Arret du calcul FIN SI - result = result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = en_DC(NomCourtDatacenter).localisation).valeur + result = result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = en_DC(NomCourtDatacenter).localisation, nomOrganisation).valeur SINON - result = result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = EqP.PaysDUtilisation).valeur + result = result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = EqP.PaysDUtilisation, nomOrganisation).valeur FIN SI @@ -667,9 +659,10 @@ Règle calculIndicateurImpactEquipementPhysique(critere, etape, nomOrganisation, result= result + EqP.quantité 'récupération de l'impact pour le critère et l'étape ACV en cours, de la référence de l'équipement retenue - result = result x Ref_FacteurCaracterisation(refEquipementretenu, EtapeACV, Critere).valeur + result = result x Ref_FacteurCaracterisation(refEquipementretenu, EtapeACV, Critere, nomOrganisation).valeur - result = result/ RG_DureeVieItem_Defaut(equipementPhysique) + result = result/ RG_DureeVieItem_Defaut(equipementPhysique, nomOrganisation) + FIN SI 'pour toutes les étapes, on multiplie par un taux d'utilisation @@ -700,7 +693,7 @@ EqP.quantité = 1 x en_EqP.ConsoElecAnMoyenne= 1000 kWh x en_EqP.tauxUtilisation = 0,85 x en_DC(NomCourtDatacenter = "googleCloud").PUE = 1,13 -x ref_FacteurCaracterisation("Changement Climatique", "FABRICATION", Categorie=electricity-mix, Localisation = "France").valeur = 0,0813225 +x ref_FacteurCaracterisation("Changement Climatique", "FABRICATION", Categorie=electricity-mix, Localisation = "France", nomOrganisation= "SSG").valeur = 0,0813225 ImpactUnitaireEqP = 78,11 kg CO2eq /an ==== @@ -810,7 +803,7 @@ Cette règle permet le calcul de l'impact moyen d'une opération Non IT sur une |parametre|entree/sortie|Description |critere|entrée|le critere dont on cherche à calculer la durée de Vie par défaut |etapeACV|entrée|l'étape ACV dont on cherche à calculer la durée de Vie par défaut -|nomOrganisation|entrée|le nom de l'organisation en cours de traitement +|nomOrganisation|entrée|le nom de l'organisation en cours de traitement, récupéré de en_DonneesEntrees.nomOrganisation |operationNonIT|entrée|l'opération non IT dont on cherche à calculer l'impact environnemental |ind_ImpactOperationNonIT.nomItemNonIT|sortie|le nom de l'item dont on a calculé l'impact |ind_ImpactOperationNonIT.critere|sortie|le critere calculé @@ -842,30 +835,28 @@ Règle calculIndicateurImpactOperationNonIT(critere, etape, nomOrganisation, OpN ind_ImpactOperationNonIT.consoElecMoyenne = OpNIT.consoElecAnnuelle SINON SI 'récupération de la consommation électrique de la référence de l'équipement retenue - result= result x Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere).consoElecAnMoyenne + result= result x Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere, nomOrganisation).consoElecAnMoyenne 'enregistrement de la consommation electrique retenue - ind_ImpactOperationNonIT.consoElecMoyenne = Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere).consoElecAnMoyenne + ind_ImpactOperationNonIT.consoElecMoyenne = Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere, nomOrganisation).consoElecAnMoyenne SINON ErrCalcFonc("donnée de consommation electrique manquante") Arret du calcul FIN SI - - result= result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = OpNIT.Localisation).valeur + result= result x ref_FacteurCaracterisation(EtapeACV, Critere, Categorie=electricity-mix, Localisation = OpNIT.Localisation, nomOrganisation).valeur SINON SI EtapeACV.code != "UTILISATION" result= result + OpNIT.quantité - 'récupération de l'impact pour le critère, de l'étape ACV en cours et de la référence de l'item retenu - result= result x Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere).valeur + result= result x Ref_FacteurCaracterisation(refItemRetenu, EtapeACV, Critere, nomOrganisation).valeur SI OpNIT.categorie = "RESEAU_FIXE" - referenceHypothese= ref_TypeItem(OpNIT.type).refHypothese + referenceHypothese= ref_TypeItem(OpNIT.type, nomOrganisation).refHypothese SI referenceHypothese existe - SI ref_Hypothese(referenceHypothese) existe - result= result / ref_Hypothese(referenceHypothese).valeur + SI ref_Hypothese(referenceHypothese, nomOrganisation) existe + result= result / ref_Hypothese(referenceHypothese, nomOrganisation).valeur SINON SI OpNIT.categorie = "BATIMENT" - result= result / RG_DureeVieItem_Defaut(operationNonIT) + result= result / RG_DureeVieItem_Defaut(operationNonIT, nomOrganisation) FIN SI SINON SI OpNIT.categorie = "DEPLACEMENT_ELECTRIQUE" OU "DEPLACEMENT_ESSENCE" OU DEPLACEMENT_HYBRIDE @@ -873,25 +864,24 @@ Règle calculIndicateurImpactOperationNonIT(critere, etape, nomOrganisation, OpN result= result + OpNIT.quantité 'récupération de la consommation moyenne pour le véhicule choisi, valeur récupérée dans ref_hypothèses - referenceHypothese= ref_TypeItem(OpNIT.type).refHypothese + referenceHypothese= ref_TypeItem(OpNIT.type, nomOrganisation).refHypothese SI referenceHypothese existe - SI ref_Hypothese(referenceHypothese) existe - result= result x ref_Hypothese(referenceHypothese).valeur + SI ref_Hypothese(referenceHypothese, nomOrganisation) existe + result= result x ref_Hypothese(referenceHypothese, nomOrganisation).valeur SI OpNIT.categorie = "DEPLACEMENT_ELECTRIQUE" 'récupération du mix électrique pour le critère de Fabrication et pour l'étape ACV en cours - result= result x ref_FacteurCaracterisation(FABRICATION, Critère, mix elec, OpNIT.Localisation).valeur + result= result x ref_FacteurCaracterisation(FABRICATION, Critère, mix elec, OpNIT.Localisation, nomOrganisation).valeur SINON SI OpNIT.categorie = "DEPLACEMENT_ESSENCE" 'récupération de l'impact de la production d'essence pour le critère de Fabrication et pour l'étape ACV en cours - result= result x ref_FacteurCaracterisation(FABRICATION, Critère, Production essence).valeur + result= result x ref_FacteurCaracterisation(FABRICATION, Critère, Production essence, nomOrganisation).valeur SINON SI OpNIT.categorie = "DEPLACEMENT_HYBRIDE" 'récupération de l'impact de la production d'essence pour le critère de Fabrication et pour l'étape ACV en cours - result= result x ref_FacteurCaracterisation(FABRICATION, Critère, Production essence).valeur + result= result x ref_FacteurCaracterisation(FABRICATION, Critère, Production essence, nomOrganisation).valeur 'récupération du taux utile pour le calcul d'impact des véhicules hybrides, valeur récupérée dans ref_hypothèses - result= result x ref_Hypothese('taux_vehicule_hybride').valeur - + result= result x ref_Hypothese('taux_vehicule_hybride', nomOrganisation).valeur FIN SI FIN SI ind_ImpactOperationNonIT.impactUnitaire = result @@ -904,9 +894,9 @@ ind_ImpactOperationNonIT.impactUnitaire = result Item = exemple d'un réseau fixe localisé en France OpNIT.quantité = 400 -x ref_FacteurCaracterisation(reseau-fixe, UTILISATION, Changement Climatique).ConsoElecAnMoyenne = 180 kWh -x ref_FacteurCaracterisation( UTILISATION, Changement Climatique,mixelec,France).valeur = 0.0813225 -/ ref_Hypothese(CAPACITE_LIGNE_FIXE_FR) = 2640 +x ref_FacteurCaracterisation(reseau-fixe, UTILISATION, Changement Climatique,SSG).ConsoElecAnMoyenne = 180 kWh +x ref_FacteurCaracterisation( UTILISATION, Changement Climatique,mixelec,France,SSG).valeur = 0.0813225 +/ ref_Hypothese(CAPACITE_LIGNE_FIXE_FR,SSG) = 2640 ImpactUnitaireOpNIT = 2,21788 kg CO2eq /an ==== diff --git a/docs/References.plantuml b/docs/References.plantuml index a0715b6ab244b18eaf7fec06cc5710d5b94cd978..1eba6507bd00f3a50f3cd365b85624825e5f36dd 100644 --- a/docs/References.plantuml +++ b/docs/References.plantuml @@ -3,6 +3,7 @@ 'les hypothèses permettant le calcul de certains indicateurs class ref_Hypothese{ *String clé +*String nomOrganisation String valeur String source } @@ -10,6 +11,7 @@ String source 'liste des types d'items autorisés class ref_TypeItem{ *String type +*String nomOrganisation ' Equipement, BATIMENT, RESEAU_FIXE, DEPLACEMENT_ELECTRIQUE... String categorie 'le booléen "serveur" permet de distinguer les équipements inclus dans le calcul de l'impact d'un serveur applicatif à l'utilisation @@ -29,6 +31,7 @@ class ref_FacteurCaracterisation { * String nom * String etape * String critere +* String nomOrganisation 'description du facteur de caractérisation String description String niveau @@ -44,6 +47,7 @@ String source class ref_CorrespondanceRefEqP { 'modèle d'équipement de l'organisation, la valeur du champ doit exister dans en_EqP.modele * String modeleEquipementSource +*String nomOrganisation 'Equipement de référence, la valeur du champ doit exister dans ref_ImpactEquipement.refEquipement String refEquipementCible } diff --git a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/client/ReferentielClient.java b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/client/ReferentielClient.java index ad6ddc9fc3e234d20bb564e96c2188553df41fe1..e68734cfca1a7c966ce11d2f02490e0b8b92a418 100644 --- a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/client/ReferentielClient.java +++ b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/client/ReferentielClient.java @@ -48,65 +48,91 @@ public class ReferentielClient { } @Cacheable(value = "Hypothese") - public HypotheseDTO getHypothese(String code) { - try { - return interneNumEcoEvalApi.getHypothese(code).block(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { - throw new ExternalApiException(e); + public HypotheseDTO getHypothese(String code, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var hy = interneNumEcoEvalApi.getHypothese(code, nomOrg).block(); + if (hy != null) { + return hy; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + throw new ExternalApiException(e); + } } } return null; } @Cacheable(value = "CorrespondanceRefEquipement") - public CorrespondanceRefEquipementDTO getCorrespondanceRefEquipement(String modele) { - try { - return interneNumEcoEvalApi.getCorrespondanceRefEquipement(modele).block(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { - throw new ExternalApiException(e); + public CorrespondanceRefEquipementDTO getCorrespondanceRefEquipement(String modele, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var corr = interneNumEcoEvalApi.getCorrespondanceRefEquipement(modele, nomOrg).block(); + if (corr != null) { + return corr; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + throw new ExternalApiException(e); + } } } return null; } @Cacheable(value = "TypeItem") - public TypeItemDTO getTypeItem(String type) { - try { - return interneNumEcoEvalApi.getTypeItem(type).block(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { - throw new ExternalApiException(e); + public TypeItemDTO getTypeItem(String type, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var ti = interneNumEcoEvalApi.getTypeItem(type, nomOrg).block(); + if (ti != null) { + return ti; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + throw new ExternalApiException(e); + } } } return null; } @Cacheable(value = "FacteurCaracterisationMixElec") - public FacteurCaracterisationDTO getMixElectriqueFromFacteurCaracterisation(String critere, String localisation) { - try { - return interneNumEcoEvalApi.getFacteurCaracterisation(critere, null, null, localisation, Constants.ELECTRICITY_MIX_CATEGORY).blockFirst(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { - throw new ExternalApiException(e); + public FacteurCaracterisationDTO getMixElectriqueFromFacteurCaracterisation(String critere, String localisation, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var fc = interneNumEcoEvalApi.getFacteurCaracterisation(critere, null, null, localisation, Constants.ELECTRICITY_MIX_CATEGORY, nomOrg).blockFirst(); + if (fc != null) { + return fc; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + throw new ExternalApiException(e); + } } } return null; } @Cacheable(value = "FacteurCaracterisation") - public FacteurCaracterisationDTO getFacteurCaracterisationByCritereAndEtapeAndNom(String critere, String etape, String nom) { - try { - return interneNumEcoEvalApi.getFacteurCaracterisation(critere, etape, nom, null, null).blockFirst(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { - throw new ExternalApiException(e); + public FacteurCaracterisationDTO getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation(String critere, String etape, String nom, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var fc = interneNumEcoEvalApi.getFacteurCaracterisation(critere, etape, nom, null, null, nomOrg).blockFirst(); + if (fc != null) { + return fc; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + throw new ExternalApiException(e); + } } } return null; } + @Cacheable(value = "ImpactMessagerie") public ImpactMessagerieDTO getMessagerie(String critere) { try { diff --git a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/config/CacheConfig.java b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/config/CacheConfig.java index 90538c3dc77b63e7e6a9a69c99b819785f3da4d4..77b917c42d66b969748b459f5589fc71b27357ab 100644 --- a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/config/CacheConfig.java +++ b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/config/CacheConfig.java @@ -21,17 +21,14 @@ public class CacheConfig { "Etapes", "Criteres", "Hypothese", - "TypeEquipement", "TypeItem", "CorrespondanceRefEquipement", "FacteurCaracterisationMixElec", "FacteurCaracterisation", - "ImpactEquipement", - "ImpactReseau", - "MixElectrique", "ImpactOperationNonIT", "ImpactMessagerie", "DureeUsage", + "NomOrganisation", }, allEntries = true) @Scheduled(fixedRateString = "${numecoeval.cache.ttl}", timeUnit = TimeUnit.MINUTES) public void emptyAllCaches() { diff --git a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/repository/DonneesEntreeRepository.java b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/repository/DonneesEntreeRepository.java index 965c8c4f4f29fe12ef1627d5155ec3249888f404..4edb84216aa1ebf0266181c3aa81568fd385e3e4 100644 --- a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/repository/DonneesEntreeRepository.java +++ b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/repository/DonneesEntreeRepository.java @@ -97,4 +97,30 @@ public class DonneesEntreeRepository { } return result.getFirst(); } + + @Cacheable("NomOrganisation") + public String findNomOrganisation(String nomLot) { + List<String> result = new ArrayList<>(); + try (Connection conn = dataSource.getConnection()) { + try (var ps = conn.prepareStatement(""" + SELECT nom_organisation + FROM en_donnees_entrees + WHERE nom_lot = ? + """)) { + + ps.setString(1, nomLot); + var rs = ps.executeQuery(); + while (rs.next()) { + result.add(rs.getString("nom_organisation")); + } + } + } catch (SQLException e) { + log.error("Une erreur s'est produite lors de la selection dans PostgreSQL. Exception: ", e); + throw new DatabaseException(e); + } + if (result.isEmpty()) { + return null; + } + return result.getFirst(); + } } diff --git a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementEquipementPhysiqueService.java b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementEquipementPhysiqueService.java index cf2ea565b473209d6dfd46f0d0763e8ff3ab4ccb..98bbcd6d998981e47e3781496a676b2d28ccc9f0 100644 --- a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementEquipementPhysiqueService.java +++ b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementEquipementPhysiqueService.java @@ -70,53 +70,57 @@ public class EnrichissementEquipementPhysiqueService { calculEquipementPhysique.setCriteres(criteresCalcul); } + String nomOrganisation = donneesEntreeRepository.findNomOrganisation(calculEquipementPhysique.getEquipementPhysique().getNomLot()); + var hypotheses = new ArrayList<HypotheseDTO>(); Arrays.stream(hypothesesEquipementPhysique.replaceAll(" +", "").split(",")) .forEach(hypothese -> { - var h = referentielClient.getHypothese(hypothese); + var h = referentielClient.getHypothese(hypothese, nomOrganisation); if (h != null) hypotheses.add(h); }); calculEquipementPhysique.setHypotheses(hypotheses); if (equipementPhysiqueDTO.getModele() != null) { - calculEquipementPhysique.setCorrespondanceRefEquipement(referentielClient.getCorrespondanceRefEquipement(equipementPhysiqueDTO.getModele())); + calculEquipementPhysique.setCorrespondanceRefEquipement(referentielClient.getCorrespondanceRefEquipement(equipementPhysiqueDTO.getModele(), nomOrganisation)); } - calculEquipementPhysique.setTypeItem(referentielClient.getTypeItem(equipementPhysiqueDTO.getType())); + calculEquipementPhysique.setTypeItem(referentielClient.getTypeItem(equipementPhysiqueDTO.getType(), nomOrganisation)); calculEquipementPhysique.setFacteurCaracterisations(new ArrayList<>()); for (var critere : calculEquipementPhysique.getCriteres()) { for (var etape : calculEquipementPhysique.getEtapes()) { if (calculEquipementPhysique.getCorrespondanceRefEquipement() != null) { calculEquipementPhysique.getFacteurCaracterisations().add( - referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom( + referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation( critere.getNomCritere(), etape.getCode(), - calculEquipementPhysique.getCorrespondanceRefEquipement().getRefEquipementCible() + calculEquipementPhysique.getCorrespondanceRefEquipement().getRefEquipementCible(), + nomOrganisation ) ); } else if (calculEquipementPhysique.getTypeItem() != null && StringUtils.isNotBlank(calculEquipementPhysique.getTypeItem().getRefItemParDefaut())) { calculEquipementPhysique.getFacteurCaracterisations().add( - referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom( + referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation( critere.getNomCritere(), etape.getCode(), - calculEquipementPhysique.getTypeItem().getRefItemParDefaut() + calculEquipementPhysique.getTypeItem().getRefItemParDefaut(), + nomOrganisation ) ); } } - var mixElec = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), equipementPhysiqueDTO.getPaysDUtilisation()); + var mixElec = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), equipementPhysiqueDTO.getPaysDUtilisation(), nomOrganisation); if (mixElec != null) calculEquipementPhysique.getFacteurCaracterisations().add(mixElec); if (equipementPhysiqueDTO.getDataCenter() != null && StringUtils.isNotBlank(equipementPhysiqueDTO.getDataCenter().getLocalisation()) && !StringUtils.equals(equipementPhysiqueDTO.getPaysDUtilisation(), equipementPhysiqueDTO.getDataCenter().getLocalisation())) { - var mixElecDataCenter = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), equipementPhysiqueDTO.getDataCenter().getLocalisation()); + var mixElecDataCenter = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), equipementPhysiqueDTO.getDataCenter().getLocalisation(), nomOrganisation); if (mixElecDataCenter != null) calculEquipementPhysique.getFacteurCaracterisations().add(mixElecDataCenter); } diff --git a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementOperationNonITService.java b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementOperationNonITService.java index ef39f73e81226088b557b6b3bd519d29a77da726..57b0d5b67f3cbdd9105b4140eeaa1682770f3625 100644 --- a/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementOperationNonITService.java +++ b/services/api-event-calculs/src/main/java/org/mte/numecoeval/calculs/infrastructure/service/enrichissement/EnrichissementOperationNonITService.java @@ -27,7 +27,7 @@ public class EnrichissementOperationNonITService { private String hypothesesOperationNonIt; @Autowired - private ReferentielClient referentielClient; + ReferentielClient referentielClient; public CalculOperationNonIT serviceEnrichissementOperationNonIT(OperationNonITDTO operationNonITDTO) { if (operationNonITDTO == null) return null; @@ -70,15 +70,17 @@ public class EnrichissementOperationNonITService { calculOperationNonIT.setCriteres(criteresCalcul); } - calculOperationNonIT.setTypeItem(referentielClient.getTypeItem(operationNonITDTO.getType())); + String nomOrganisation = donneesEntreeRepository.findNomOrganisation(calculOperationNonIT.getOperationNonIT().getNomLot()); + + calculOperationNonIT.setTypeItem(referentielClient.getTypeItem(operationNonITDTO.getType(), nomOrganisation)); var hypotheses = new ArrayList<HypotheseDTO>(); - var hTypeItem = referentielClient.getHypothese(referentielClient.getTypeItem(operationNonITDTO.getType()).getRefHypothese()); + var hTypeItem = referentielClient.getHypothese(referentielClient.getTypeItem(operationNonITDTO.getType(), nomOrganisation).getRefHypothese(), nomOrganisation); if (hTypeItem != null) hypotheses.add(hTypeItem); Arrays.stream(hypothesesOperationNonIt.replaceAll(" +", "").split(",")) .forEach(hypothese -> { - var h = referentielClient.getHypothese(hypothese); + var h = referentielClient.getHypothese(hypothese, nomOrganisation); if (h != null) hypotheses.add(h); }); @@ -89,15 +91,16 @@ public class EnrichissementOperationNonITService { for (var etape : calculOperationNonIT.getEtapes()) { if (calculOperationNonIT.getTypeItem() != null && StringUtils.isNotBlank(calculOperationNonIT.getTypeItem().getRefItemParDefaut())) { calculOperationNonIT.getFacteurCaracterisations().add( - referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom( + referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation( critere.getNomCritere(), etape.getCode(), - calculOperationNonIT.getTypeItem().getRefItemParDefaut() + calculOperationNonIT.getTypeItem().getRefItemParDefaut(), + nomOrganisation ) ); } } - var mixElec = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), operationNonITDTO.getLocalisation()); + var mixElec = referentielClient.getMixElectriqueFromFacteurCaracterisation(critere.getNomCritere(), operationNonITDTO.getLocalisation(), nomOrganisation); if (mixElec != null) calculOperationNonIT.getFacteurCaracterisations().add(mixElec); } return calculOperationNonIT; diff --git a/services/api-event-calculs/src/main/resources/schema.sql b/services/api-event-calculs/src/main/resources/schema.sql index 9a7df953e6de23bd18a508b6c6c6275d3cf5c8e6..115c76329bcb13382655b3e6cc783ec1a62d5f45 100644 --- a/services/api-event-calculs/src/main/resources/schema.sql +++ b/services/api-event-calculs/src/main/resources/schema.sql @@ -86,29 +86,29 @@ CREATE TABLE IF NOT EXISTS ind_indicateur_impact_application CREATE TABLE IF NOT EXISTS ind_indicateur_impact_operation_non_it ( - date_calcul timestamp NULL, - date_lot date NULL, - nom_lot varchar(255) NULL, - etapeacv varchar(255) NULL, - critere varchar(255) NULL, - "source" varchar(255) NULL, - statut_indicateur varchar(255) NULL, - trace text NULL, - version_calcul varchar(255) NULL, - conso_elec_moyenne float8 NULL, - impact_unitaire float8 NULL, - quantite int4 NULL, - type_item varchar(255) NULL, - unite varchar(255) NULL, - nom_entite varchar(255) NULL, - nom_organisation varchar(255) NULL, - nom_source_donnee varchar(255) NULL, - nom_item_non_it varchar(255) NULL, - qualite varchar(255) NULL, - date_lot_discriminator date NOT NULL DEFAULT('1970-01-01'), - nom_organisation_discriminator varchar(255) NOT NULL DEFAULT(''), - nom_entite_discriminator varchar(255) NOT NULL DEFAULT(''), - nom_source_donnee_discriminator varchar(255) NOT NULL DEFAULT('') + date_calcul timestamp NULL, + date_lot date NULL, + nom_lot varchar(255) NULL, + etapeacv varchar(255) NULL, + critere varchar(255) NULL, + "source" varchar(255) NULL, + statut_indicateur varchar(255) NULL, + trace text NULL, + version_calcul varchar(255) NULL, + conso_elec_moyenne float8 NULL, + impact_unitaire float8 NULL, + quantite int4 NULL, + type_item varchar(255) NULL, + unite varchar(255) NULL, + nom_entite varchar(255) NULL, + nom_organisation varchar(255) NULL, + nom_source_donnee varchar(255) NULL, + nom_item_non_it varchar(255) NULL, + qualite varchar(255) NULL, + date_lot_discriminator date NOT NULL DEFAULT('1970-01-01'), + nom_organisation_discriminator varchar(255) NOT NULL DEFAULT(''), + nom_entite_discriminator varchar(255) NOT NULL DEFAULT(''), + nom_source_donnee_discriminator varchar(255) NOT NULL DEFAULT('') ); CREATE TABLE IF NOT EXISTS ind_indicateur_impact_messagerie diff --git a/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementEquipementPhysiqueServiceTest.java b/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementEquipementPhysiqueServiceTest.java index b7259e49add5948299c301a13bebca6959f5bb60..e6d6ab827a47913b2fb228c0ff38a73d3d50b064 100644 --- a/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementEquipementPhysiqueServiceTest.java +++ b/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementEquipementPhysiqueServiceTest.java @@ -107,7 +107,7 @@ class EnrichissementEquipementPhysiqueServiceTest { """, CritereDTO[].class))); /* MOCK REFERENTIEL : Hypothese */ - Mockito.lenient().when(referentielClient.getHypothese(any())).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielClient.getHypothese(any(), any())).thenReturn(mapper.readValue(""" { "code": "hyp code", "valeur": "val", @@ -118,8 +118,8 @@ class EnrichissementEquipementPhysiqueServiceTest { var mixFr = new FacteurCaracterisationDTO(); mixFr.setLocalisation("FR"); - Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation("Climate change", "France")).thenReturn(mixFr); - Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation("Climate change", null)).thenReturn(null); + Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation(eq("Climate change"), eq("France"), any())).thenReturn(mixFr); + Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation(eq("Climate change"), eq(null), any())).thenReturn(null); } @Test @@ -131,7 +131,7 @@ class EnrichissementEquipementPhysiqueServiceTest { void testServiceEnrichissementEquipementPhysique_correspondanceRefEquipement() throws JsonProcessingException { /* MOCK REFERENTIEL : CorrespondanceRefEquipement */ - Mockito.when(referentielClient.getCorrespondanceRefEquipement("blade-server--28")).thenReturn(mapper.readValue(""" + Mockito.when(referentielClient.getCorrespondanceRefEquipement(eq("blade-server--28"), any())).thenReturn(mapper.readValue(""" { "modeleEquipementSource": "srv", "refEquipementCible": "cible" @@ -142,7 +142,7 @@ class EnrichissementEquipementPhysiqueServiceTest { var fcDTO = new FacteurCaracterisationDTO(); fcDTO.setValeur(1.1); - Mockito.when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom(any(), any(), eq("cible"))).thenReturn(fcDTO); + Mockito.when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation(any(), any(), eq("cible"), any())).thenReturn(fcDTO); var actual = enrichissementEquipementPhysiqueService.serviceEnrichissementEquipementPhysique(equipementPhysiqueDTO); @@ -158,7 +158,7 @@ class EnrichissementEquipementPhysiqueServiceTest { void testServiceEnrichissementEquipementPhysique_typeEquipement() throws JsonProcessingException { /* MOCK REFERENTIEL : CorrespondanceRefEquipement */ - Mockito.when(referentielClient.getTypeItem("Server")).thenReturn(mapper.readValue(""" + Mockito.when(referentielClient.getTypeItem(eq("Server"), any())).thenReturn(mapper.readValue(""" { "refItemParDefaut": "default-ref-server" } @@ -168,7 +168,7 @@ class EnrichissementEquipementPhysiqueServiceTest { var fcDTO = new FacteurCaracterisationDTO(); fcDTO.setValeur(2.2); - Mockito.when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom(any(), any(), eq("default-ref-server"))).thenReturn(fcDTO); + Mockito.when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation(any(), any(), eq("default-ref-server"), any())).thenReturn(fcDTO); var actual = enrichissementEquipementPhysiqueService.serviceEnrichissementEquipementPhysique(equipementPhysiqueDTO); diff --git a/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementOperationNonITServiceTest.java b/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementOperationNonITServiceTest.java index f9042c30515fa695907987f5544dd83cf2fe9eb3..191c577e99151eb77f4e3f5ec7196e5f429089c6 100644 --- a/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementOperationNonITServiceTest.java +++ b/services/api-event-calculs/src/test/java/org/mte/numecoeval/calculs/infrastructure/service/calcul/EnrichissementOperationNonITServiceTest.java @@ -26,6 +26,7 @@ import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; @ExtendWith({MockitoExtension.class, SpringExtension.class}) @ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @@ -86,7 +87,7 @@ class EnrichissementOperationNonITServiceTest { """, CritereDTO[].class))); /* MOCK REFERENTIEL : Hypothese */ - Mockito.lenient().when(referentielClient.getHypothese("CAPACITE_LIGNE_FIXE_FR")).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielClient.getHypothese(eq("CAPACITE_LIGNE_FIXE_FR"), any())).thenReturn(mapper.readValue(""" { "code": "CAPACITE_LIGNE_FIXE_FR", "valeur": 2640, @@ -95,7 +96,7 @@ class EnrichissementOperationNonITServiceTest { """, HypotheseDTO.class)); /* MOCK REFERENTIEL : TypeItem */ - Mockito.lenient().when(referentielClient.getTypeItem("reseau-fixe-france")).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielClient.getTypeItem(eq("reseau-fixe-france"), any())).thenReturn(mapper.readValue(""" { "type": "reseau-fixe-france", "categorie" : "RESEAU_FIXE", @@ -105,7 +106,7 @@ class EnrichissementOperationNonITServiceTest { """, TypeItemDTO.class)); /* MOCK REFERENTIEL : FacteurCaracterisation */ - Mockito.lenient().when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNom("Climate change", "UTILISATION", "reseau-fixe-1")).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielClient.getFacteurCaracterisationByCritereAndEtapeAndNomAndNomOrganisation(eq("Climate change"), eq("UTILISATION"), eq("reseau-fixe-1"), any())).thenReturn(mapper.readValue(""" { "nom": "reseau-fixe-1", "etape" : "UTILISATION", @@ -117,7 +118,7 @@ class EnrichissementOperationNonITServiceTest { """, FacteurCaracterisationDTO.class)); /* MOCK REFERENTIEL : MixElectrique */ - Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation("Climate change", "France")).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielClient.getMixElectriqueFromFacteurCaracterisation(eq("Climate change"), eq("France"), any())).thenReturn(mapper.readValue(""" { "nom": "Electricity Mix/ Production mix/ Low voltage/ CL", "etape" : "FABRICATION", diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/domain/ports/output/ReferentielServicePort.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/domain/ports/output/ReferentielServicePort.java index 2cd2bfeab6bcefd5bc17eebfe0435d92155eb852..926cd9b4a304eb0241afe5a0fa012b72d9adc3a1 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/domain/ports/output/ReferentielServicePort.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/domain/ports/output/ReferentielServicePort.java @@ -5,13 +5,13 @@ import org.mte.numecoeval.expositiondonneesentrees.referentiels.generated.api.mo import java.util.List; public interface ReferentielServicePort { - boolean hasMixElec(String pays); + boolean hasMixElec(String pays, String nomOrganisation); List<TypeItemDTO> getAllTypesItem(); - CorrespondanceRefEquipementDTO getCorrespondance(String modele); + CorrespondanceRefEquipementDTO getCorrespondance(String modele, String nomOrganisation); - FacteurCaracterisationDTO getFacteurCaracterisation(String critere, String etape, String refItem); + FacteurCaracterisationDTO getFacteurCaracterisation(String critere, String etape, String refItem, String nomOrganisation); List<EtapeDTO> getAllEtapes(); diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/adapters/ReferentielRestClient.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/adapters/ReferentielRestClient.java index ac417db6b0d852b1e57828a65dbdcfd058909711..f2f6fde384baae9c13846932448b404fc4a4acc3 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/adapters/ReferentielRestClient.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/adapters/ReferentielRestClient.java @@ -2,13 +2,12 @@ package org.mte.numecoeval.expositiondonneesentrees.infrastructure.adapters; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.mte.numecoeval.expositiondonneesentrees.domain.exception.RestException; import org.mte.numecoeval.expositiondonneesentrees.domain.ports.output.ReferentielServicePort; import org.mte.numecoeval.expositiondonneesentrees.referentiels.generated.api.client.InterneNumEcoEvalApi; import org.mte.numecoeval.expositiondonneesentrees.referentiels.generated.api.model.*; import org.mte.numecoeval.expositiondonneesentrees.utils.Constants; import org.springframework.cache.annotation.Cacheable; -import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClientResponseException; @@ -23,16 +22,20 @@ public class ReferentielRestClient implements ReferentielServicePort { @Cacheable("hasMixElec") @Override - public boolean hasMixElec(String pays) { - boolean result = false; - try { - var res = interneNumEcoEvalApi.getFacteurCaracterisation(null, null, null, pays, Constants.ELECTRICITY_MIX_CATEGORY).blockFirst(); - if (res == null) return result; - return true; - } catch (Exception e) { - log.error("Une erreur est survenue lors de l'appel au référentiel facteurcaracterisation", e); + public boolean hasMixElec(String pays, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var mixelec = interneNumEcoEvalApi.getFacteurCaracterisation(null, null, null, pays, Constants.ELECTRICITY_MIX_CATEGORY, nomOrg).blockFirst(); + if (mixelec != null) { + return true; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + log.error("Une erreur est survenue lors de l'appel au référentiel facteurcaracterisation", e); + } + } } - return result; + return false; } @Override @@ -43,29 +46,35 @@ public class ReferentielRestClient implements ReferentielServicePort { @Cacheable("CorrespondanceRefEquipement") @Override - public CorrespondanceRefEquipementDTO getCorrespondance(String modele) { - try { - return interneNumEcoEvalApi.getCorrespondanceRefEquipement(modele).block(); - } catch (WebClientResponseException e) { - if (e.getStatusCode() == HttpStatus.NOT_FOUND) { - return null; + public CorrespondanceRefEquipementDTO getCorrespondance(String modele, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var corr = interneNumEcoEvalApi.getCorrespondanceRefEquipement(modele, nomOrg).block(); + if (corr != null) { + return corr; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + log.error("Une erreur est survenue lors de l'appel au référentiel correspondanceRefEquipement", e); + } } - throw new RestException(e); } + return null; } @Cacheable("FacteurCaracterisation") @Override - public FacteurCaracterisationDTO getFacteurCaracterisation(String critere, String etape, String refEquipement) { - try { - var res = interneNumEcoEvalApi.getFacteurCaracterisation(critere, etape, refEquipement, null, null).blockFirst(); - if (res != null) { - return res; - } - } catch (WebClientResponseException e) { - if (e.getStatusCode() != HttpStatus.NOT_FOUND) { - log.error("Une erreur est survenue lors de l'appel au référentiel facteurcaracterisation", e); - return null; + public FacteurCaracterisationDTO getFacteurCaracterisation(String critere, String etape, String nom, String nomOrganisation) { + for (String nomOrg : List.of(nomOrganisation, "")) { + try { + var fc = interneNumEcoEvalApi.getFacteurCaracterisation(critere, etape, nom, null, null, nomOrg).blockFirst(); + if (fc != null) { + return fc; + } + } catch (WebClientResponseException e) { + if (e.getStatusCode() != HttpStatusCode.valueOf(404)) { + log.error("Une erreur est survenue lors de l'appel au référentiel facteurcaracterisation", e); + } } } return null; diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/controller/CalculController.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/controller/CalculController.java index 2a40f112da19383755233fe7725d1ea14289646a..78e652b4729a259c23fe96d0355dbe1a1300a2e1 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/controller/CalculController.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/controller/CalculController.java @@ -39,16 +39,16 @@ public class CalculController implements CalculsApi { } @Override - public ResponseEntity<RapportDemandeCalculRest> soumissionPourCalcul(DemandeCalculRest demandeCalculRest, DureeUsage dureeUsage, ModeRest mode) { + public ResponseEntity<RapportDemandeCalculRest> soumissionPourCalcul(DemandeCalculRest demandeCalculRest, DureeUsage dureeUsage, String nomOrganisation, ModeRest mode) { var modeDureeUsage = dureeUsage == null ? DureeUsage.fromValue(defaultDureeUsage) : dureeUsage; if (DureeUsage.REEL != modeDureeUsage) { modeDureeUsage = DureeUsage.FIXE; } - log.info("Soumission de calcul pour nom_lot: {}, dureeUsage: {}, mode: {}, etapes:{}, criteres:{}", demandeCalculRest.getNomLot(), modeDureeUsage, mode, demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres()); - var demandeCalcul = calculRestMapper.toDomain(demandeCalculRest); - donneesEntreesService.manageDonneesEntrees(demandeCalculRest.getNomLot(), dureeUsage, demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres(), TYPE_CALCUL_SOUMISSION); + log.info("Soumission de calcul pour nom_lot: {}, dureeUsage: {}, nomOrganisation: {}, mode: {}", demandeCalculRest.getNomLot(), modeDureeUsage, nomOrganisation, mode); + var demandeCalcul = calculRestMapper.toDomain(demandeCalculRest); + donneesEntreesService.manageDonneesEntrees(demandeCalculRest.getNomLot(), dureeUsage, demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres(), nomOrganisation, TYPE_CALCUL_SOUMISSION); var soumission = ModeRest.ASYNC == mode ? soumissionCalculPort.soumissionCalcul(demandeCalcul) : @@ -63,7 +63,7 @@ public class CalculController implements CalculsApi { log.info("Rejeu de calcul, nom_lot: {}, etapes:{}, criteres:{}", demandeCalculRest.getNomLot(), demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres()); var demandeCalcul = calculRestMapper.toDomain(demandeCalculRest); - donneesEntreesService.manageDonneesEntrees(demandeCalculRest.getNomLot(), null, demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres(), TYPE_CALCUL_REJEU); + donneesEntreesService.manageDonneesEntrees(demandeCalculRest.getNomLot(), null, demandeCalculRest.getEtapes(), demandeCalculRest.getCriteres(), null, TYPE_CALCUL_REJEU); var soumission = soumissionCalculPort.rejeuCalcul(demandeCalcul); diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/jpa/entity/DonneesEntreesEntity.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/jpa/entity/DonneesEntreesEntity.java index cddc63a2bdb12ed5f9e9ae849d852ab4a7e12f73..91a143c76747e8e0a0f6e58172a97640dd30061c 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/jpa/entity/DonneesEntreesEntity.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/jpa/entity/DonneesEntreesEntity.java @@ -54,6 +54,10 @@ public class DonneesEntreesEntity extends AbstractEntreeEntity { */ private String dureeUsage; + /** + * nom de l'organisation pour laquelle on va chercher des références customisées + */ + private String nomOrganisation; /** * Liste des étapes pour lesquelles on veut calculer les impacts * séparés par ## @@ -64,6 +68,4 @@ public class DonneesEntreesEntity extends AbstractEntreeEntity { * séparés par ## */ private String criteres; - - } diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesService.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesService.java index a5f0ca4fd921c47abb89d632052d7634b829253e..d2024a97025f5b4fd378fdfb8c171141ae52ad5f 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesService.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesService.java @@ -26,19 +26,20 @@ public class DonneesEntreesService { final ReferentielRestClient referentielRestClient; final DonneesEntreesRepository donneesEntreesRepository; - public void manageDonneesEntrees(String nomLot, DureeUsage modeDureeUsage, List<String> etapes, List<String> criteres, String typeCalcul) { + public void manageDonneesEntrees(String nomLot, DureeUsage modeDureeUsage, List<String> etapes, List<String> criteres, String nomOrganisation, String typeCalcul) { var donneeEntreeEntity = donneesEntreesRepository.findByNomLot(nomLot).getFirst(); - donneeEntreeEntity = enrichi(donneeEntreeEntity, modeDureeUsage, etapes, criteres, typeCalcul); + donneeEntreeEntity = enrichi(donneeEntreeEntity, modeDureeUsage, etapes, criteres, nomOrganisation, typeCalcul); donneesEntreesRepository.save(donneeEntreeEntity); } - private DonneesEntreesEntity enrichi(DonneesEntreesEntity donneeEntreeEntity, DureeUsage dureeUsage, List<String> etapes, List<String> criteres, String typeCalcul) { + private DonneesEntreesEntity enrichi(DonneesEntreesEntity donneeEntreeEntity, DureeUsage dureeUsage, List<String> etapes, List<String> criteres, String nomOrganisation, String typeCalcul) { if (typeCalcul.equals(TYPE_CALCUL_SOUMISSION)) { var modeDureeUsage = dureeUsage == null ? DureeUsage.fromValue(defaultDureeUsage) : dureeUsage; if (DureeUsage.REEL != modeDureeUsage) { modeDureeUsage = DureeUsage.FIXE; } donneeEntreeEntity.setDureeUsage(String.valueOf(modeDureeUsage)); + donneeEntreeEntity.setNomOrganisation(nomOrganisation); } if (etapes != null) { var allEtapes = referentielRestClient.getAllEtapes().stream().map(EtapeDTO::getCode).toList(); diff --git a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementService.java b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementService.java index f803a3fdf824a3a8d0e31b96c24108b80c22f8ce..797b8093d6e3d564f5441b3b228777773b344940 100644 --- a/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementService.java +++ b/services/api-expositiondonneesentrees/src/main/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementService.java @@ -73,7 +73,7 @@ public class ErrorManagementService { var result = new ArrayList<String>(); // CA 1.3 - if (!referentielServicePort.hasMixElec(dataCenter.getLocalisation())) { + if (!referentielServicePort.hasMixElec(dataCenter.getLocalisation(), dataCenter.getNomOrganisation())) { result.add(messageProperties.getMessages().get("DATACENTER_MIX_ELEC_LOCALISATION_INCONNUE").formatted(dataCenter.getLocalisation(), dataCenter.getNomLongDatacenter())); } @@ -93,7 +93,7 @@ public class ErrorManagementService { // CA 1.2 // L'ajout d'un équipement physique dont le pays d'utilisation n'existe pas dans la table ref_MixElec.pays sort l'erreur suivante dans le rapport de contrôle if (StringUtils.isNotBlank(equipementPhysique.getPaysDUtilisation()) && - !referentielServicePort.hasMixElec(equipementPhysique.getPaysDUtilisation())) { + !referentielServicePort.hasMixElec(equipementPhysique.getPaysDUtilisation(), equipementPhysique.getNomOrganisation())) { erreurs.add(messageProperties.getMessages().get("ITEM_MIX_ELEC_LOCALISATION_INCONNUE").formatted(equipementPhysique.getPaysDUtilisation(), equipementPhysique.getNomEquipementPhysique())); } @@ -106,7 +106,7 @@ public class ErrorManagementService { if (equipementPhysique.getModele() == null) { erreurs.add(messageProperties.getMessages().get("EQUIPEMENT_CORRESPONDANCE_INCONNUE").formatted(equipementPhysique.getNomEquipementPhysique(), equipementPhysique.getType())); } else { - CorrespondanceRefEquipementDTO refCorrespondance = referentielServicePort.getCorrespondance(equipementPhysique.getModele()); + CorrespondanceRefEquipementDTO refCorrespondance = referentielServicePort.getCorrespondance(equipementPhysique.getModele(), equipementPhysique.getNomOrganisation()); if (refCorrespondance == null) { erreurs.add(messageProperties.getMessages().get("EQUIPEMENT_CORRESPONDANCE_INCONNUE").formatted(equipementPhysique.getNomEquipementPhysique(), equipementPhysique.getType())); } else { @@ -123,7 +123,7 @@ public class ErrorManagementService { var criteres = referentielServicePort.getAllCriteres(); for (var critere : criteres) { for (var etape : etapes) { - var impact = referentielServicePort.getFacteurCaracterisation(critere.getNomCritere(), etape.getCode(), refEquipement); + var impact = referentielServicePort.getFacteurCaracterisation(critere.getNomCritere(), etape.getCode(), refEquipement, equipementPhysique.getNomOrganisation()); if (impact == null) { avertissements.add(messageProperties.getMessages().get("ITEM_IMPACT_INCONNU").formatted(refEquipement, etape.getCode(), critere.getNomCritere())); } @@ -181,7 +181,7 @@ public class ErrorManagementService { var criteres = referentielServicePort.getAllCriteres(); for (var critere : criteres) { for (var etape : etapes) { - var impact = referentielServicePort.getFacteurCaracterisation(critere.getNomCritere(), etape.getCode(), type); + var impact = referentielServicePort.getFacteurCaracterisation(critere.getNomCritere(), etape.getCode(), type, operationNonIT.getNomOrganisation()); if (impact == null) { avertissements.add(messageProperties.getMessages().get("ITEM_IMPACT_INCONNU").formatted(type, etape.getCode(), critere.getNomCritere())); } diff --git a/services/api-expositiondonneesentrees/src/main/resources/schema.sql b/services/api-expositiondonneesentrees/src/main/resources/schema.sql index c5059800bae89349bc000bfc4454413bb9a87c99..827e8916abd3e8ab6ecf14807d834ed0d36d68f8 100644 --- a/services/api-expositiondonneesentrees/src/main/resources/schema.sql +++ b/services/api-expositiondonneesentrees/src/main/resources/schema.sql @@ -200,6 +200,7 @@ ALTER TABLE IF EXISTS en_equipement_physique ADD COLUMN IF NOT EXISTS duree_usag ALTER TABLE IF EXISTS en_equipement_physique ADD COLUMN IF NOT EXISTS duree_usage_aval float8; ALTER TABLE IF EXISTS en_donnees_entrees ADD COLUMN IF NOT EXISTS duree_usage varchar(255); + ALTER TABLE IF EXISTS en_donnees_entrees ADD COLUMN IF NOT EXISTS etapes text; ALTER TABLE IF EXISTS en_donnees_entrees ADD COLUMN IF NOT EXISTS criteres text; diff --git a/services/api-expositiondonneesentrees/src/main/resources/static/openapi.yaml b/services/api-expositiondonneesentrees/src/main/resources/static/openapi.yaml index e395cf1dc9a74f3ef4686b2e4eb4afcd7aa6ca3d..bd72cdfd0e22dc16c29c8dfa8eb860c7d9aaa0ef 100644 --- a/services/api-expositiondonneesentrees/src/main/resources/static/openapi.yaml +++ b/services/api-expositiondonneesentrees/src/main/resources/static/openapi.yaml @@ -76,6 +76,12 @@ paths: $ref: "#/components/schemas/DureeUsage" required: false description: "Choix de la méthode de calcul de la durée d'usage : FIXE ou REEL" + - in: query + name: nomOrganisation + schema: + $ref: "#/components/schemas/NomOrganisation" + required: false + description: "Choix des références à utiliser pour les calculs, si vous souhaitez utiliser des références propres à une organisation, saisissez son nom, sinon laissez la valeur vide pour utiliser les références par défaut" - in: query name: mode schema: @@ -304,6 +310,9 @@ components: enum: - FIXE - REEL + NomOrganisation: + type: string + default: "" StatutCalculRest: description: Statut des calculs. properties: diff --git a/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesServiceTest.java b/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesServiceTest.java index 76ed19eb5b3ed3f1138b9a079e963e20dbc2801c..fe05e414552413492cef36c9ed956bc9ab15c565 100644 --- a/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesServiceTest.java +++ b/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/DonneesEntreesServiceTest.java @@ -73,64 +73,71 @@ public class DonneesEntreesServiceTest { @Test void enrichiDonneesEntrees_with_dureeUsageNull() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, null, null, null, TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, null, null, null, null, TYPE_CALCUL_SOUMISSION); assertEquals("FIXE", actual.getDureeUsage()); } @Test void enrichiDonneesEntrees_with_dureeUsageFixe() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, null, TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, null, null, TYPE_CALCUL_SOUMISSION); assertEquals("FIXE", actual.getDureeUsage()); } @Test void enrichiDonneesEntrees_with_dureeUsageReel() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("REEL"), null, null, TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("REEL"), null, null, null, TYPE_CALCUL_SOUMISSION); assertEquals("REEL", actual.getDureeUsage()); } @Test void enrichiDonneesEntrees_with_etapesFiltree_shouldFilter() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of("UTILISATION", "FABRICATION"), List.of(), TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of("UTILISATION", "FABRICATION"), List.of(), null, TYPE_CALCUL_SOUMISSION); assertEquals("UTILISATION##FABRICATION", actual.getEtapes()); } @Test void enrichiDonneesEntrees_with_etapesFiltreeNull_shouldReturnNull() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, List.of(), TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, List.of(), null, TYPE_CALCUL_SOUMISSION); Assertions.assertNull(actual.getEtapes()); } @Test void enrichiDonneesEntrees_with_etapeFiltreeNotInReferentiel_shouldThrowError() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - var exception = assertThrows(ValidationException.class, () -> ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of("FAB"), List.of(), TYPE_CALCUL_SOUMISSION)); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + var exception = assertThrows(ValidationException.class, () -> ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of("FAB"), List.of(), null, TYPE_CALCUL_SOUMISSION)); assertEquals("La liste d'étapes n'est pas valide, elle doit être comprise dans: [UTILISATION, FABRICATION, DISTRIBUTION]", exception.getErreur()); } @Test void enrichiDonneesEntrees_with_criteresFiltree_shouldFilter() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of(), List.of("Acidification", "Ionising radiation", "Climate change"), TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of(), List.of("Acidification", "Ionising radiation", "Climate change"), null, TYPE_CALCUL_SOUMISSION); assertEquals("Acidification##Ionising radiation##Climate change", actual.getCriteres()); } @Test void enrichiDonneesEntrees_with_criteresFiltreeNull_shouldReturnNull() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, null, TYPE_CALCUL_SOUMISSION); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, null, null, TYPE_CALCUL_SOUMISSION); Assertions.assertNull(actual.getCriteres()); } @Test void enrichiDonneesEntrees_with_critereFiltreeNotInReferentiel_shouldThrowError() { - DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null); - var exception = assertThrows(ValidationException.class, () -> ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, List.of("CLIMATE CHANGE"), TYPE_CALCUL_SOUMISSION)); + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + var exception = assertThrows(ValidationException.class, () -> ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), null, List.of("CLIMATE CHANGE"), null, TYPE_CALCUL_SOUMISSION)); Assertions.assertEquals("La liste de critères n'est pas valide, elle doit être comprise dans: [Climate change, Particulate matter and respiratory inorganics, Ionising radiation, Acidification]", exception.getErreur()); } + + @Test + void enrichiDonneesEntrees_with_nomOrganisation() { + DonneesEntreesEntity donneeEntreeEntity = new DonneesEntreesEntity(Long.parseLong("10000"), Long.parseLong("10"), Long.parseLong("20"), Long.parseLong("4"), Long.parseLong("4"), Long.parseLong("4"), null, null, null, null); + DonneesEntreesEntity actual = ReflectionTestUtils.invokeMethod(donneesEntreesService, "enrichi", donneeEntreeEntity, DureeUsage.valueOf("FIXE"), List.of(), List.of(), "SSG", TYPE_CALCUL_SOUMISSION); + assertEquals("SSG", actual.getNomOrganisation()); + } } diff --git a/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementServiceTest.java b/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementServiceTest.java index d49ebddcbe2ecaedb34ffb0b029e400a8b722e9a..9967f600033573b1912e759e1bd98b211a27e3e9 100644 --- a/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementServiceTest.java +++ b/services/api-expositiondonneesentrees/src/test/java/org/mte/numecoeval/expositiondonneesentrees/infrastructure/service/ErrorManagementServiceTest.java @@ -35,6 +35,7 @@ import java.util.List; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; @ExtendWith({MockitoExtension.class, SpringExtension.class}) @ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @@ -192,14 +193,14 @@ public class ErrorManagementServiceTest { .paysDUtilisation("France") .build(); - Mockito.lenient().when(referentielServicePort.getCorrespondance(eq1.getType())).thenReturn(null); + Mockito.lenient().when(referentielServicePort.getCorrespondance(eq(eq1.getType()), any())).thenReturn(null); var actual = errorManagementService.checkEquipementPhysique(eq1, ""); Assertions.assertTrue(actual.getKey().stream().anyMatch("L'équipement physical-eq-001 de type phone ne possède pas de référence d'équipement par défaut dans la table ref_type_item et pas de correspondance dans la table ref_correspondance_ref_eqp"::equals)); } @Test - void importEqPhysique_with_ModeleAndCorrepondance_shouldReportWithoutError() throws JsonProcessingException { + void importEqPhysique_with_ModeleAndCorrespondance_shouldReportWithoutError() throws JsonProcessingException { EquipementPhysique eq1 = EquipementPhysique.builder() .nomEquipementPhysique("physical-eq-001") .quantite(1.0) @@ -212,7 +213,7 @@ public class ErrorManagementServiceTest { .build(); /* MOCK REFERENTIEL : CorrespondanceRefEquipement */ - Mockito.lenient().when(referentielServicePort.getCorrespondance(eq1.getModele())).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielServicePort.getCorrespondance(eq(eq1.getModele()), any())).thenReturn(mapper.readValue(""" { "modeleEquipementSource": "P123", "refEquipementCible": "smartphone-1" @@ -235,7 +236,7 @@ public class ErrorManagementServiceTest { .build(); /* MOCK REFERENTIEL : CorrespondanceRefEquipement */ - Mockito.lenient().when(referentielServicePort.getCorrespondance(eq1.getModele())).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielServicePort.getCorrespondance(eq(eq1.getModele()), any())).thenReturn(mapper.readValue(""" { "modeleEquipementSource": "P123", "refEquipementCible": "smartphone-1" @@ -269,7 +270,7 @@ public class ErrorManagementServiceTest { .localisation("France").build(); /* MOCK REFERENTIEL : FacteurCaracterisation */ - Mockito.lenient().when(referentielServicePort.getFacteurCaracterisation(any(), any(), any())).thenReturn(null); + Mockito.lenient().when(referentielServicePort.getFacteurCaracterisation(any(), any(), any(), any())).thenReturn(null); /* MOCK REFERENTIEL : Etapes */ Mockito.lenient().when(referentielServicePort.getAllEtapes()).thenReturn(Arrays.asList(mapper.readValue(""" @@ -298,7 +299,7 @@ public class ErrorManagementServiceTest { .localisation("France").build(); /* MOCK REFERENTIEL : FacteurCaracterisation */ - Mockito.lenient().when(referentielServicePort.getFacteurCaracterisation(any(), any(), any())).thenReturn(mapper.readValue(""" + Mockito.lenient().when(referentielServicePort.getFacteurCaracterisation(any(), any(), any(), any())).thenReturn(mapper.readValue(""" { "nom": "reseau-fixe-1", "etape" : "UTILISATION", diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/CorrespondanceRefEquipement.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/CorrespondanceRefEquipement.java index 7bfc53c16e198d2a6125d0fadc6355b126177fdc..4c8b478ccade5de747559a647cae99e0d606de7d 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/CorrespondanceRefEquipement.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/CorrespondanceRefEquipement.java @@ -12,5 +12,7 @@ public class CorrespondanceRefEquipement implements AbstractReferentiel { String modeleEquipementSource; String refEquipementCible; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/FacteurCaracterisation.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/FacteurCaracterisation.java index d88b97a46ecdd86dafc9ee6ffb61ecfdf53cf006..17f8fb81e92a0e74e7934dd5aefc0f9baf8d74f7 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/FacteurCaracterisation.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/FacteurCaracterisation.java @@ -23,4 +23,6 @@ public class FacteurCaracterisation implements AbstractReferentiel { Double valeur; String unite; String source; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/Hypothese.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/Hypothese.java index a1248c8efa5f5d142e89b60b449fc5b95a707494..639b7e86c75f1e47e7d420b2aba1e35d5133d30a 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/Hypothese.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/Hypothese.java @@ -15,5 +15,7 @@ public class Hypothese implements AbstractReferentiel { String valeur; String source; String description; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/TypeItem.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/TypeItem.java index 363366091d269083926b4fd1e6f5a7bc628605f0..011b831d83e317dac69e46845ed247b5e58de63d 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/TypeItem.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/TypeItem.java @@ -18,5 +18,7 @@ public class TypeItem implements AbstractReferentiel { String source; // Référence de l'item par défaut, permet des correspondances en cas d'absence de correspondance directe. String refItemParDefaut; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/CorrespondanceRefEquipementId.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/CorrespondanceRefEquipementId.java new file mode 100644 index 0000000000000000000000000000000000000000..9c5c784c2ce0ffe8433d81a8588caeef8df1086e --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/CorrespondanceRefEquipementId.java @@ -0,0 +1,16 @@ +package org.mte.numecoeval.referentiel.domain.model.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +@Getter +@Setter +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +public class CorrespondanceRefEquipementId { + String modeleEquipementSource; + String nomOrganisation; +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/FacteurCaracterisationId.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/FacteurCaracterisationId.java index 499191de89ce7ad7b7c945d43acc60b6996875ad..273fbcadf880fd6fced8ee6385c6acf3ccd0e696 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/FacteurCaracterisationId.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/FacteurCaracterisationId.java @@ -14,4 +14,6 @@ public class FacteurCaracterisationId { String nom; String etape; String critere; + String nomOrganisation; + } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/HypotheseId.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/HypotheseId.java index 2c95cf398a6365094e0f287b44eea53d66c93885..41863c266b5acb051ce7534c7b9c731581d16a3d 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/HypotheseId.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/HypotheseId.java @@ -1,11 +1,6 @@ package org.mte.numecoeval.referentiel.domain.model.id; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import lombok.experimental.Accessors; import lombok.experimental.FieldDefaults; @@ -19,7 +14,6 @@ import java.io.Serializable; @NoArgsConstructor @AllArgsConstructor public class HypotheseId implements Serializable { - String code; - + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/TypeItemId.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/TypeItemId.java new file mode 100644 index 0000000000000000000000000000000000000000..56d28c02d37f617ffdeb48b729d15b8962e4e4ac --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/model/id/TypeItemId.java @@ -0,0 +1,16 @@ +package org.mte.numecoeval.referentiel.domain.model.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +@Getter +@Setter +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +public class TypeItemId { + String type; + String nomOrganisation; +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/ImportCSVReferentielPort.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/ImportCSVReferentielPort.java index 85affa82b959e335c2a5d376c08435e676a98fad..76f3ce35f93e1eef0ad99c125d08b0cfc513159a 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/ImportCSVReferentielPort.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/ImportCSVReferentielPort.java @@ -17,30 +17,42 @@ public interface ImportCSVReferentielPort<T> { String MESSAGE_LIGNE_INVALIDE = "La ligne n°%d est invalide : %s"; - void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException; - - default void checkAllHeadersAreMapped(CSVRecord csvRecord, String[] headers) throws ReferentielException{ - if(!Arrays.stream(headers).allMatch(csvRecord::isMapped)) { - throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber()+1, "Entêtes incohérentes")); + default void checkAllHeadersAreMapped(CSVRecord csvRecord, String[] headers) throws ReferentielException { + if (!Arrays.stream(headers).allMatch(csvRecord::isMapped)) { + throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber() + 1, "Entêtes incohérentes")); } } - default void checkFieldIsMappedInCSVRecord(CSVRecord csvRecord, String field) throws ReferentielException{ - if(!csvRecord.isMapped(field)) { - throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber()+1, "La colonne "+field+" doit être présente")); + default void checkFieldIsMappedInCSVRecord(CSVRecord csvRecord, String field) throws ReferentielException { + if (!csvRecord.isMapped(field)) { + throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber() + 1, "La colonne " + field + " doit être présente")); } } - default void checkFieldIsMappedAndNotBlankInCSVRecord(CSVRecord csvRecord, String field) throws ReferentielException{ + default void checkFieldIsMappedAndNotBlankInCSVRecord(CSVRecord csvRecord, String field) throws ReferentielException { checkFieldIsMappedInCSVRecord(csvRecord, field); - if(StringUtils.isBlank(csvRecord.get(field))) { - throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber()+1, "La colonne "+field+" ne peut être vide")); + if (StringUtils.isBlank(csvRecord.get(field))) { + throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber() + 1, "La colonne " + field + " ne peut être vide")); + } + } + + default void checkNomOrganisation(CSVRecord csvRecord, String nomOrganisation) throws ReferentielException { + String nomOrgLigne = getStringValueFromRecordDefaultEmpty(csvRecord, "nomOrganisation"); + if (!nomOrganisation.equals(nomOrgLigne)) { + throw new ReferentielException(MESSAGE_LIGNE_INVALIDE.formatted(csvRecord.getRecordNumber() + 1, "elle est spécifique à l'organisation : '" + nomOrgLigne + "' or l'import actuel ne se fait que sur les lignes de l'organisation '" + nomOrganisation + "'")); } } - ResultatImport<T> importCSV(InputStream csvInputStream); + default ResultatImport<T> importCSV(InputStream csvInputStream) { + return null; + } + + default ResultatImport<T> importCSV(InputStream csvInputStream, String nomOrganisation) { + return null; + } + default Double getDoubleValueFromRecord(CSVRecord csvRecord, String field, Double defaultValue) { - if(!NumberUtils.isCreatable(StringUtils.trim(csvRecord.get(field)))) { + if (!NumberUtils.isCreatable(StringUtils.trim(csvRecord.get(field)))) { return defaultValue; } return NumberUtils.toDouble(csvRecord.get(field)); @@ -50,21 +62,45 @@ public interface ImportCSVReferentielPort<T> { * Renvoie la valeur de la colonne {@param mainName} dans le {@param csvRecord}. * Si le {@param mainName} n'est pas mappé dans le {@link CSVRecord}, la liste des noms alternatifs est utilisée. * Si aucune colonne n'est mappée ou que la liste alternative est vide, la valeur {@code null} est renvoyée. - * @param csvRecord La ligne de CSV à traiter - * @param mainName Le nom de la colonne souhaitée en 1er + * + * @param csvRecord La ligne de CSV à traiter + * @param mainName Le nom de la colonne souhaitée en 1er * @param alternativeNames Les noms de colonnes alternatifs à utiliser, peut être vide * @return La valeur de la 1er colonne correctement mappée sur la ligne de CSV, {@code null} en absence de mapping */ default String getStringValueFromRecord(CSVRecord csvRecord, String mainName, String... alternativeNames) { - if(csvRecord.isMapped(mainName)) { + if (csvRecord.isMapped(mainName)) { return StringUtils.trim(csvRecord.get(mainName)); } for (String alternativeName : alternativeNames) { - if(csvRecord.isMapped(alternativeName)) { + if (csvRecord.isMapped(alternativeName)) { return StringUtils.trim(csvRecord.get(alternativeName)); } } return null; } + + /** + * Renvoie la valeur de la colonne {@param mainName} dans le {@param csvRecord}. + * Si le {@param mainName} n'est pas mappé dans le {@link CSVRecord}, la liste des noms alternatifs est utilisée. + * Si aucune colonne n'est mappée ou que la liste alternative est vide, la valeur "" est renvoyée. + * + * @param csvRecord La ligne de CSV à traiter + * @param mainName Le nom de la colonne souhaitée en 1er + * @param alternativeNames Les noms de colonnes alternatifs à utiliser, peut être vide + * @return La valeur de la 1er colonne correctement mappée sur la ligne de CSV, {@code null} en absence de mapping + */ + default String getStringValueFromRecordDefaultEmpty(CSVRecord csvRecord, String mainName, String... alternativeNames) { + if (csvRecord.isMapped(mainName)) { + return StringUtils.trim(csvRecord.get(mainName)); + } + + for (String alternativeName : alternativeNames) { + if (csvRecord.isMapped(alternativeName)) { + return StringUtils.trim(csvRecord.get(alternativeName)); + } + } + return ""; + } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportCorrespondanceRefEquipementPortImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportCorrespondanceRefEquipementPortImpl.java index ae62e8d4b997e1e2801e5ac5a4e8ec634552960a..b84ceeadcb05334a5d878143c094e4c5fc9c5709 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportCorrespondanceRefEquipementPortImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportCorrespondanceRefEquipementPortImpl.java @@ -3,10 +3,10 @@ package org.mte.numecoeval.referentiel.domain.ports.input.impl; import lombok.extern.slf4j.Slf4j; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.mte.numecoeval.referentiel.domain.data.ResultatImport; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import java.io.InputStream; import java.io.InputStreamReader; @@ -19,20 +19,23 @@ import java.util.List; public class ImportCorrespondanceRefEquipementPortImpl implements ImportCSVReferentielPort<CorrespondanceRefEquipementDTO> { public static final String MODELE_EQUIPEMENT_SOURCE = "modeleEquipementSource"; public static final String REF_EQUIPEMENT_CIBLE = "refEquipementCible"; - private static final String[] HEADERS = new String[]{MODELE_EQUIPEMENT_SOURCE, REF_EQUIPEMENT_CIBLE}; + public static final String REF_NOM_ORGANISATION = "nomOrganisation"; + private static final String[] HEADERS = new String[]{MODELE_EQUIPEMENT_SOURCE, REF_EQUIPEMENT_CIBLE, REF_NOM_ORGANISATION}; + private static final String[] MANDATORY_HEADERS = new String[]{MODELE_EQUIPEMENT_SOURCE, REF_EQUIPEMENT_CIBLE}; public static String[] getHeaders() { return HEADERS; } - public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { - checkAllHeadersAreMapped(csvRecord, HEADERS); + public void checkCSVRecord(CSVRecord csvRecord, String nomOrganisation) throws ReferentielException { + checkAllHeadersAreMapped(csvRecord, MANDATORY_HEADERS); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, MODELE_EQUIPEMENT_SOURCE); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, REF_EQUIPEMENT_CIBLE); + checkNomOrganisation(csvRecord, nomOrganisation); } @Override - public ResultatImport<CorrespondanceRefEquipementDTO> importCSV(InputStream csvInputStream) { + public ResultatImport<CorrespondanceRefEquipementDTO> importCSV(InputStream csvInputStream, String nomOrganisation) { ResultatImport<CorrespondanceRefEquipementDTO> resultatImport = new ResultatImport<>(); List<CorrespondanceRefEquipementDTO> dtos = new ArrayList<>(); @@ -46,15 +49,15 @@ public class ImportCorrespondanceRefEquipementPortImpl implements ImportCSVRefer .build().parse(reader); records.forEach(csvRecord -> { try { - checkCSVRecord(csvRecord); + checkCSVRecord(csvRecord, nomOrganisation); dtos.add(CorrespondanceRefEquipementDTO.builder() .modeleEquipementSource(csvRecord.get(MODELE_EQUIPEMENT_SOURCE).trim()) .refEquipementCible(csvRecord.get(REF_EQUIPEMENT_CIBLE).trim()) + .nomOrganisation(getStringValueFromRecordDefaultEmpty(csvRecord, REF_NOM_ORGANISATION)) .build()); - } - catch (Exception e) { - log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber()+1, e.getMessage()); - resultatImport.getErreurs().add( e.getMessage() ); + } catch (Exception e) { + log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber() + 1, e.getMessage()); + resultatImport.getErreurs().add(e.getMessage()); } }); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportEtapePortImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportEtapePortImpl.java index 6358dcd6c7da0170cf6163cf17baa6accc46f8d3..5ae07f47750de7cfd1b5ab3db06c26c49b236ed0 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportEtapePortImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportEtapePortImpl.java @@ -3,10 +3,10 @@ package org.mte.numecoeval.referentiel.domain.ports.input.impl; import lombok.extern.slf4j.Slf4j; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.EtapeDTO; import org.mte.numecoeval.referentiel.domain.data.ResultatImport; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.EtapeDTO; import java.io.InputStream; import java.io.InputStreamReader; @@ -23,7 +23,6 @@ public class ImportEtapePortImpl implements ImportCSVReferentielPort<EtapeDTO> { return HEADERS; } - @Override public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { checkAllHeadersAreMapped(csvRecord, HEADERS); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, "code"); @@ -49,10 +48,9 @@ public class ImportEtapePortImpl implements ImportCSVReferentielPort<EtapeDTO> { .code(csvRecord.get("code").trim()) .libelle(csvRecord.get("libelle").trim()) .build()); - } - catch (Exception e) { - log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber()+1, e.getMessage()); - resultatImport.getErreurs().add( e.getMessage() ); + } catch (Exception e) { + log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber() + 1, e.getMessage()); + resultatImport.getErreurs().add(e.getMessage()); } }); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportFacteurCaracterisationPortImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportFacteurCaracterisationPortImpl.java index 0209c96a3a90dd44508fc5abe5624a25d296d06c..1726f7eebc4dd2f8bebad06d08377408647ba331 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportFacteurCaracterisationPortImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportFacteurCaracterisationPortImpl.java @@ -30,9 +30,11 @@ public class ImportFacteurCaracterisationPortImpl implements ImportCSVReferentie private static final String HEADER_VALEUR = "valeur"; private static final String HEADER_UNITE = "unite"; private static final String HEADER_SOURCE = "source"; + private static final String HEADER_NOM_ORGANISATION = "nomOrganisation"; + private static final String[] HEADERS = new String[]{HEADER_NOM, HEADER_ETAPEACV, HEADER_CRITERE, HEADER_DESCRIPTION, HEADER_NIVEAU, HEADER_TIERS, HEADER_CATEGORIE, HEADER_CONSO_ELEC_MOYENNE, HEADER_LOCALISATION, HEADER_VALEUR, - HEADER_UNITE, HEADER_SOURCE}; + HEADER_UNITE, HEADER_SOURCE, HEADER_NOM_ORGANISATION}; private static final String[] MANDATORY_HEADERS = new String[]{HEADER_NOM, HEADER_ETAPEACV, HEADER_CRITERE , HEADER_NIVEAU, HEADER_TIERS, HEADER_CATEGORIE, HEADER_CONSO_ELEC_MOYENNE, HEADER_LOCALISATION, HEADER_VALEUR, HEADER_UNITE, HEADER_SOURCE}; @@ -42,15 +44,17 @@ public class ImportFacteurCaracterisationPortImpl implements ImportCSVReferentie return HEADERS; } - public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { + public void checkCSVRecord(CSVRecord csvRecord, String nomOrganisation) throws ReferentielException { checkAllHeadersAreMapped(csvRecord, MANDATORY_HEADERS); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, HEADER_NOM); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, HEADER_ETAPEACV); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, HEADER_CRITERE); + checkNomOrganisation(csvRecord, nomOrganisation); + } @Override - public ResultatImport<FacteurCaracterisationDTO> importCSV(InputStream csvInputStream) { + public ResultatImport<FacteurCaracterisationDTO> importCSV(InputStream csvInputStream, String nomOrganisation) { ResultatImport<FacteurCaracterisationDTO> resultatImport = new ResultatImport<>(); List<FacteurCaracterisationDTO> dtos = new ArrayList<>(); @@ -64,20 +68,21 @@ public class ImportFacteurCaracterisationPortImpl implements ImportCSVReferentie .build().parse(reader); records.forEach(csvRecord -> { try { - checkCSVRecord(csvRecord); + checkCSVRecord(csvRecord, nomOrganisation); dtos.add(FacteurCaracterisationDTO.builder() .nom(csvRecord.get(HEADER_NOM).trim()) .etape(csvRecord.get(HEADER_ETAPEACV).trim()) .critere(csvRecord.get(HEADER_CRITERE).trim()) - .description(getStringValueFromRecord(csvRecord, "description")) - .niveau(getStringValueFromRecord(csvRecord, "niveau")) - .tiers(getStringValueFromRecord(csvRecord, "tiers")) - .categorie(getStringValueFromRecord(csvRecord, "categorie")) + .description(getStringValueFromRecord(csvRecord, HEADER_DESCRIPTION)) + .niveau(getStringValueFromRecord(csvRecord, HEADER_NIVEAU)) + .tiers(getStringValueFromRecord(csvRecord, HEADER_TIERS)) + .categorie(getStringValueFromRecord(csvRecord, HEADER_CATEGORIE)) .consoElecMoyenne(getDoubleValueFromRecord(csvRecord, HEADER_CONSO_ELEC_MOYENNE, null)) - .localisation(getStringValueFromRecord(csvRecord, "localisation")) + .localisation(getStringValueFromRecord(csvRecord, HEADER_LOCALISATION)) .valeur(getDoubleValueFromRecord(csvRecord, HEADER_VALEUR, null)) - .unite(getStringValueFromRecord(csvRecord, "unite")) - .source(getStringValueFromRecord(csvRecord, "source")) + .unite(getStringValueFromRecord(csvRecord, HEADER_UNITE)) + .source(getStringValueFromRecord(csvRecord, HEADER_SOURCE)) + .nomOrganisation(getStringValueFromRecordDefaultEmpty(csvRecord, HEADER_NOM_ORGANISATION)) .build()); } catch (Exception e) { log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber() + 1, e.getMessage()); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportHypothesePortImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportHypothesePortImpl.java index 925ad02f229a0a897d473fccff3a5919fff08d85..be785872f5a1ae5a48184eb573ca8df2341c1563 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportHypothesePortImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportHypothesePortImpl.java @@ -20,20 +20,21 @@ public class ImportHypothesePortImpl implements ImportCSVReferentielPort<Hypothe private static final String HEADER_VALEUR = "valeur"; private static final String[] MANDATORY_HEADERS = new String[]{"cle", HEADER_VALEUR, "source"}; - private static final String[] HEADERS = new String[]{"cle", HEADER_VALEUR, "source", "description"}; + private static final String[] HEADERS = new String[]{"cle", HEADER_VALEUR, "source", "description", "nomOrganisation"}; public static String[] getHeaders() { return HEADERS; } - public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { + public void checkCSVRecord(CSVRecord csvRecord, String nomOrganisation) throws ReferentielException { checkAllHeadersAreMapped(csvRecord, MANDATORY_HEADERS); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, "cle"); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, HEADER_VALEUR); + checkNomOrganisation(csvRecord, nomOrganisation); } @Override - public ResultatImport<HypotheseDTO> importCSV(InputStream csvInputStream) { + public ResultatImport<HypotheseDTO> importCSV(InputStream csvInputStream, String nomOrganisation) { ResultatImport<HypotheseDTO> resultatImport = new ResultatImport<>(); List<HypotheseDTO> dtos = new ArrayList<>(); @@ -47,12 +48,13 @@ public class ImportHypothesePortImpl implements ImportCSVReferentielPort<Hypothe .build().parse(reader); records.forEach(csvRecord -> { try { - checkCSVRecord(csvRecord); + checkCSVRecord(csvRecord, nomOrganisation); dtos.add(HypotheseDTO.builder() .valeur(csvRecord.get(HEADER_VALEUR).trim()) .code(csvRecord.get("cle").trim()) .source(csvRecord.get("source").trim()) .description(getStringValueFromRecord(csvRecord, "description")) + .nomOrganisation(getStringValueFromRecordDefaultEmpty(csvRecord, "nomOrganisation")) .build()); } catch (Exception e) { log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber() + 1, e.getMessage()); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportTypeItemPortImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportTypeItemPortImpl.java index 73182924f3cb27779e65767de59845065f55ab0d..13767ce137630270c18ee4561f1628e4a510d43b 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportTypeItemPortImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/input/impl/ImportTypeItemPortImpl.java @@ -19,33 +19,35 @@ import java.util.List; @Slf4j public class ImportTypeItemPortImpl implements ImportCSVReferentielPort<TypeItemDTO> { private static final String HEADER_TYPE = "type"; - private static final String[] HEADERS = new String[]{HEADER_TYPE, "categorie", "serveur", "commentaire", "dureeVieDefaut", "refHypothese", "source", "refItemParDefaut"}; + private static final String[] HEADERS = new String[]{HEADER_TYPE, "categorie", "serveur", "commentaire", "dureeVieDefaut", "refHypothese", "source", "refItemParDefaut", "nomOrganisation"}; + private static final String[] MANDATORY_HEADERS = new String[]{HEADER_TYPE, "categorie", "serveur", "commentaire", "dureeVieDefaut", "refHypothese", "source", "refItemParDefaut"}; public static String[] getHeaders() { return HEADERS; } - public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { - checkAllHeadersAreMapped(csvRecord, HEADERS); + public void checkCSVRecord(CSVRecord csvRecord, String nomOrganisation) throws ReferentielException { + checkAllHeadersAreMapped(csvRecord, MANDATORY_HEADERS); checkFieldIsMappedAndNotBlankInCSVRecord(csvRecord, HEADER_TYPE); + checkNomOrganisation(csvRecord, nomOrganisation); } @Override - public ResultatImport<TypeItemDTO> importCSV(InputStream csvInputStream) { + public ResultatImport<TypeItemDTO> importCSV(InputStream csvInputStream, String nomOrganisation) { ResultatImport<TypeItemDTO> resultatImport = new ResultatImport<>(); List<TypeItemDTO> dtos = new ArrayList<>(); try (Reader reader = new InputStreamReader(csvInputStream)) { Iterable<CSVRecord> records = CSVFormat.DEFAULT.builder() .setHeader() + .setAllowMissingColumnNames(true) .setDelimiter(CSV_SEPARATOR) .setTrim(true) - .setAllowMissingColumnNames(true) .setSkipHeaderRecord(true) .build().parse(reader); records.forEach(csvRecord -> { try { - checkCSVRecord(csvRecord); + checkCSVRecord(csvRecord, nomOrganisation); dtos.add(TypeItemDTO.builder() .type(csvRecord.get(HEADER_TYPE).trim()) .categorie(csvRecord.get("categorie").trim()) @@ -55,6 +57,7 @@ public class ImportTypeItemPortImpl implements ImportCSVReferentielPort<TypeItem .refHypothese(csvRecord.get("refHypothese").trim()) .source(csvRecord.get("source").trim()) .refItemParDefaut(getStringValueFromRecord(csvRecord, "refItemParDefaut")) + .nomOrganisation(getStringValueFromRecordDefaultEmpty(csvRecord, "nomOrganisation")) .build()); } catch (Exception e) { log.error("Erreur prévue lors de la lecture de la ligne {} : {}", csvRecord.getRecordNumber() + 1, e.getMessage()); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/output/ReferentielPersistencePort.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/output/ReferentielPersistencePort.java index 78061eaf1ff653614d3459b23294a5bafc30f95f..19c86d4b7dc0b922512b0b3bfc4f9eb15c38ffab 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/output/ReferentielPersistencePort.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/domain/ports/output/ReferentielPersistencePort.java @@ -38,6 +38,9 @@ public interface ReferentielPersistencePort<T extends AbstractReferentiel, P ext */ void purge(); + default void purgeByOrganisation(String nomOrganisation) { + } + /** * liste des elements d'une table * diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/CorrespondanceRefEquipemenetCsvExportService.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/CorrespondanceRefEquipemenetCsvExportService.java index c580f5be87c792a88ebbb3d344addcb07d73b29b..c7a51e7463dda85d378c52db385261ae80cb20b0 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/CorrespondanceRefEquipemenetCsvExportService.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/CorrespondanceRefEquipemenetCsvExportService.java @@ -1,7 +1,7 @@ package org.mte.numecoeval.referentiel.infrastructure.adapter.export; import org.apache.commons.csv.CSVPrinter; -import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportHypothesePortImpl; +import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportCorrespondanceRefEquipementPortImpl; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielCsvExportService; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRefEquipementEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.repository.CorrespondanceRefEquipementRepository; @@ -20,9 +20,8 @@ public class CorrespondanceRefEquipemenetCsvExportService extends ReferentielCsv this.repository = repository; } - @Override public String[] getHeaders() { - return ImportHypothesePortImpl.getHeaders(); + return ImportCorrespondanceRefEquipementPortImpl.getHeaders(); } @Override @@ -37,7 +36,7 @@ public class CorrespondanceRefEquipemenetCsvExportService extends ReferentielCsv @Override public void printRecord(CSVPrinter csvPrinter, CorrespondanceRefEquipementEntity objectToWrite) throws IOException { - csvPrinter.printRecord(objectToWrite.getModeleEquipementSource(),objectToWrite.getRefEquipementCible()); + csvPrinter.printRecord(objectToWrite.getModeleEquipementSource(), objectToWrite.getRefEquipementCible(), objectToWrite.getNomOrganisation()); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportService.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportService.java index df6bea8d1b8a040544d27c3e4e14c54c6c396f7d..b72f83b6607b028be98717138cb3bb18e29355da 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportService.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportService.java @@ -41,7 +41,7 @@ public class FacteurCaracterisationCsvExportService extends ReferentielCsvExport objectToWrite.getNiveau(), objectToWrite.getTiers(), objectToWrite.getCategorie(), formatDouble(objectToWrite.getConsoElecMoyenne()), objectToWrite.getLocalisation(), formatDouble(objectToWrite.getValeur()), objectToWrite.getUnite(), - objectToWrite.getSource() + objectToWrite.getSource(), objectToWrite.getNomOrganisation() ); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportService.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportService.java index e5a44db7d86b9daf4dced6adf94b789059357397..f6c419096c97273baf154a5469277ad929e54dcb 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportService.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportService.java @@ -37,7 +37,7 @@ public class HypotheseCsvExportService extends ReferentielCsvExportService<Hypot @Override public void printRecord(CSVPrinter csvPrinter, HypotheseEntity objectToWrite) throws IOException { - csvPrinter.printRecord(objectToWrite.getCode(), objectToWrite.getValeur(), objectToWrite.getSource(), objectToWrite.getDescription()); + csvPrinter.printRecord(objectToWrite.getCode(), objectToWrite.getValeur(), objectToWrite.getSource(), objectToWrite.getDescription(), objectToWrite.getNomOrganisation()); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportService.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportService.java index 851bba7b29e1f6cf504270b4fd76745036eef4e3..65e0b9104416cb67f8ae678837ef3b2263a981dd 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportService.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportService.java @@ -43,7 +43,8 @@ public class TypeItemCsvExportService extends ReferentielCsvExportService<TypeIt objectToWrite.getCommentaire(), formatDouble(objectToWrite.getDureeVieDefaut()), objectToWrite.getRefHypothese(), - objectToWrite.getSource(), objectToWrite.getRefItemParDefaut()); + objectToWrite.getSource(), objectToWrite.getRefItemParDefaut(), + objectToWrite.getNomOrganisation()); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/CorrespondanceRefEquipementJpaAdapter.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/CorrespondanceRefEquipementJpaAdapter.java index 39b3a471cf91b174f075d3ff3fc4011b597d344d..6234ecd2948dc7bfa5c948625269a37d1256d27e 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/CorrespondanceRefEquipementJpaAdapter.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/CorrespondanceRefEquipementJpaAdapter.java @@ -5,18 +5,21 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.ListUtils; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.CorrespondanceRefEquipement; +import org.mte.numecoeval.referentiel.domain.model.id.CorrespondanceRefEquipementId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRefEquipementEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.repository.CorrespondanceRefEquipementRepository; import org.mte.numecoeval.referentiel.infrastructure.mapper.CorrespondanceRefEquipementMapper; import org.springframework.stereotype.Service; import java.util.Collection; import java.util.List; +import java.util.Optional; @Service @Slf4j @AllArgsConstructor -public class CorrespondanceRefEquipementJpaAdapter implements ReferentielPersistencePort<CorrespondanceRefEquipement, String> { +public class CorrespondanceRefEquipementJpaAdapter implements ReferentielPersistencePort<CorrespondanceRefEquipement, CorrespondanceRefEquipementId> { CorrespondanceRefEquipementMapper mapper; CorrespondanceRefEquipementRepository repository; @@ -40,14 +43,10 @@ public class CorrespondanceRefEquipementJpaAdapter implements ReferentielPersist } @Override - public CorrespondanceRefEquipement get(String id) throws ReferentielException { - if (id != null) { - var entityOpt = repository.findById(id); - return entityOpt - .map(entity -> mapper.toDomain(entity)) - .orElseThrow(() -> new ReferentielException("Correspondance au RefEquipement " + id + " non trouvé")); - } - throw new ReferentielException("Correspondance au RefEquipement (id null) non trouvé"); + public CorrespondanceRefEquipement get(CorrespondanceRefEquipementId id) throws ReferentielException { + Optional<CorrespondanceRefEquipementEntity> correspondanceRefEquipementOpt = repository.findById(mapper.toEntityId(id)); + CorrespondanceRefEquipementEntity correspondanceRefEquipementEntity = correspondanceRefEquipementOpt.orElseThrow(() -> new ReferentielException("Correspondance au RefEquipement non trouvé pour l'id " + id)); + return mapper.toDomain(correspondanceRefEquipementEntity); } @Override @@ -55,6 +54,11 @@ public class CorrespondanceRefEquipementJpaAdapter implements ReferentielPersist repository.deleteAll(); } + @Override + public void purgeByOrganisation(String nomOrganisation) { + repository.deleteByNomOrganisation(nomOrganisation); + } + @Override public List<CorrespondanceRefEquipement> getAll() { diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/FacteurCaracterisationJpaAdapter.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/FacteurCaracterisationJpaAdapter.java index 9456a4818963fbb5f9b16c7ec1a61bcb8b6b2257..5746f690a40373948c59f428539c16a2820f983f 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/FacteurCaracterisationJpaAdapter.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/FacteurCaracterisationJpaAdapter.java @@ -57,7 +57,7 @@ public class FacteurCaracterisationJpaAdapter implements ReferentielPersistenceP @Override public List<FacteurCaracterisation> findByFilters(String... params) throws ReferentielException { List<FacteurCaracterisationEntity> facteurCaracterisationEntity = - repository.findByCritereAndEtapeAndNomAndLocalisationAndCategorie(params[0], params[1], params[2], params[3], params[4]); + repository.findByCritereAndEtapeAndNomAndLocalisationAndCategorieAndNomOrganisation(params[0], params[1], params[2], params[3], params[4], params[5]); return mapper.toDomains(facteurCaracterisationEntity); } @@ -67,6 +67,11 @@ public class FacteurCaracterisationJpaAdapter implements ReferentielPersistenceP repository.deleteAll(); } + @Override + public void purgeByOrganisation(String nomOrganisation) { + repository.deleteByNomOrganisation(nomOrganisation); + } + @Override public List<FacteurCaracterisation> getAll() { return ListUtils.emptyIfNull(mapper.toDomains(repository.findAll())); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/HypotheseJpaAdapter.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/HypotheseJpaAdapter.java index 1ec8b369edcb46a712ad02b4b79efa2381b32529..78052b9b07a5c9789b36a455907330742218e947 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/HypotheseJpaAdapter.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/HypotheseJpaAdapter.java @@ -43,7 +43,7 @@ public class HypotheseJpaAdapter implements ReferentielPersistencePort<Hypothese @Override public Hypothese get(HypotheseId id) throws ReferentielException { Optional<HypotheseEntity> hypotheseOpt = hypotheseRepository.findById(hypotheseMapper.toEntityId(id)); - HypotheseEntity hypotheseEntity = hypotheseOpt.orElseThrow(() -> new ReferentielException("Hypothèse non trouvé")); + HypotheseEntity hypotheseEntity = hypotheseOpt.orElseThrow(() -> new ReferentielException("Hypothèse non trouvée")); return hypotheseMapper.toDomain(hypotheseEntity); } @@ -52,6 +52,11 @@ public class HypotheseJpaAdapter implements ReferentielPersistencePort<Hypothese hypotheseRepository.deleteAll(); } + @Override + public void purgeByOrganisation(String nomOrganisation) { + hypotheseRepository.deleteByNomOrganisation(nomOrganisation); + } + @Override public List<Hypothese> getAll() { return hypotheseMapper.fromEntities(hypotheseRepository.findAll()); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeEquipementJpaAdapter.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeEquipementJpaAdapter.java index 34e623df3b4c0f15516616efe18cdcb7b429ef0b..1b8dad69f0170e8dab283aadfbe3b0e5cc0bf913 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeEquipementJpaAdapter.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeEquipementJpaAdapter.java @@ -7,6 +7,7 @@ import org.mte.numecoeval.referentiel.domain.model.TypeEquipement; import org.mte.numecoeval.referentiel.domain.model.TypeItem; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.TypeItemEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.TypeItemIdEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.repository.TypeItemRepository; import org.mte.numecoeval.referentiel.infrastructure.mapper.TypeEquipementMapper; import org.mte.numecoeval.referentiel.infrastructure.mapper.TypeItemMapper; @@ -43,11 +44,12 @@ public class TypeEquipementJpaAdapter implements ReferentielPersistencePort<Type typeItemRepository.saveAll(typeItemMapper.toEntities(typeItemList)); } + @Override public TypeEquipement get(String id) throws ReferentielException { if (id == null) throw new ReferentielException("Type Equipement non trouvé pour l'id null"); - - Optional<TypeItemEntity> typeItemEntities = typeItemRepository.findById(id); + TypeItemIdEntity typeItemIdEntity = new TypeItemIdEntity().setType(id); + Optional<TypeItemEntity> typeItemEntities = typeItemRepository.findById(typeItemIdEntity); if (typeItemEntities.isPresent()) { return typeEquipementMapper.toTypeEquipement(typeItemMapper.toDomain(typeItemEntities.get())); } else { diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeItemJpaAdapter.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeItemJpaAdapter.java index a2216c7b134a6b5cd77e8b8d533cdacb26713dfb..268a646d2c8f2ca83cc1a38393707468e9524947 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeItemJpaAdapter.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/adapter/TypeItemJpaAdapter.java @@ -4,18 +4,21 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.TypeItem; +import org.mte.numecoeval.referentiel.domain.model.id.TypeItemId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.TypeItemEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.repository.TypeItemRepository; import org.mte.numecoeval.referentiel.infrastructure.mapper.TypeItemMapper; import org.springframework.stereotype.Service; import java.util.Collection; import java.util.List; +import java.util.Optional; @Service @Slf4j @AllArgsConstructor -public class TypeItemJpaAdapter implements ReferentielPersistencePort<TypeItem, String> { +public class TypeItemJpaAdapter implements ReferentielPersistencePort<TypeItem, TypeItemId> { TypeItemMapper typeItemMapper; TypeItemRepository typeItemRepository; @@ -36,10 +39,10 @@ public class TypeItemJpaAdapter implements ReferentielPersistencePort<TypeItem, } @Override - public TypeItem get(String id) throws ReferentielException { - return typeItemRepository.findById(id) - .map(typeItemEntity -> typeItemMapper.toDomain(typeItemEntity)) - .orElse(null); + public TypeItem get(TypeItemId id) throws ReferentielException { + Optional<TypeItemEntity> typeItemOpt = typeItemRepository.findById(typeItemMapper.toEntityId(id)); + TypeItemEntity typeItemEntity = typeItemOpt.orElseThrow(() -> new ReferentielException("Type Item non trouvé pour l'id " + id)); + return typeItemMapper.toDomain(typeItemEntity); } @Override @@ -47,6 +50,11 @@ public class TypeItemJpaAdapter implements ReferentielPersistencePort<TypeItem, typeItemRepository.deleteAll(); } + @Override + public void purgeByOrganisation(String nomOrganisation) { + typeItemRepository.deleteByNomOrganisation(nomOrganisation); + } + @Override public List<TypeItem> getAll() { return typeItemRepository.findAll() diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/CorrespondanceRefEquipementEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/CorrespondanceRefEquipementEntity.java index c1c533dcfff0a24497c35f1c679f48974dfda8ba..9afcfdcaaa16fd70687b32f7b00da3b269cc1d15 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/CorrespondanceRefEquipementEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/CorrespondanceRefEquipementEntity.java @@ -2,6 +2,7 @@ package org.mte.numecoeval.referentiel.infrastructure.jpa.entity; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.IdClass; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; @@ -11,18 +12,22 @@ import lombok.experimental.Accessors; import lombok.experimental.FieldDefaults; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.CorrespondanceRefEquipementIdEntity; @Getter @Setter @Accessors(chain = true) @FieldDefaults(level = AccessLevel.PRIVATE) @NoArgsConstructor +@IdClass(CorrespondanceRefEquipementIdEntity.class) @Entity @Table(name = "REF_CORRESPONDANCE_REF_EQP") public class CorrespondanceRefEquipementEntity implements AbstractReferentielEntity { @Id String modeleEquipementSource; - + @Id + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; String refEquipementCible; @Override diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/FacteurCaracterisationEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/FacteurCaracterisationEntity.java index c679fa410b93ad92da1fa062e9f91d39982ecbfe..819c7ef4e1c2f884316774dea4d48b081b2e0672 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/FacteurCaracterisationEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/FacteurCaracterisationEntity.java @@ -26,6 +26,9 @@ public class FacteurCaracterisationEntity implements AbstractReferentielEntity { @Id @Column(name = "nomcritere") String critere; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + @Id + String nomOrganisation; String localisation; String description; String niveau; @@ -37,4 +40,5 @@ public class FacteurCaracterisationEntity implements AbstractReferentielEntity { String unite; String source; + } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/HypotheseEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/HypotheseEntity.java index 265d148edfe67fb9b6c112bd15bd3572885191d0..c2a05c110bd3b5e4defe0a76d63462eb284aa614 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/HypotheseEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/HypotheseEntity.java @@ -25,6 +25,9 @@ import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.HypotheseIdEn public class HypotheseEntity implements AbstractReferentielEntity { @Id String code; + @Id + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + String nomOrganisation; String valeur; String source; String description; diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/TypeItemEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/TypeItemEntity.java index 81ab071772f31a659c2f5e809678807bd04354df..71124aaff2dc20c7b7734ee0ee8f2905d6584d08 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/TypeItemEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/TypeItemEntity.java @@ -2,21 +2,27 @@ package org.mte.numecoeval.referentiel.infrastructure.jpa.entity; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.IdClass; import lombok.*; import lombok.experimental.Accessors; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.TypeItemIdEntity; @Builder @Getter @Setter @Accessors(chain = true) @NoArgsConstructor +@IdClass(TypeItemIdEntity.class) @AllArgsConstructor @Entity(name = "REF_TYPE_ITEM") public class TypeItemEntity implements AbstractReferentielEntity { @Id String type; + // Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation + @Id + String nomOrganisation; String categorie; boolean serveur; String commentaire; diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/CorrespondanceRefEquipementIdEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/CorrespondanceRefEquipementIdEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..498dbc43e6052a64bca8f3015dd06633c6a46244 --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/CorrespondanceRefEquipementIdEntity.java @@ -0,0 +1,17 @@ +package org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +@Getter +@Setter +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +@EqualsAndHashCode +public class CorrespondanceRefEquipementIdEntity implements AbstractReferentieIdEntity { + + String modeleEquipementSource; + String nomOrganisation; +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/FacteurCaracterisationIdEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/FacteurCaracterisationIdEntity.java index 448f4b349d13d23cad37b1b5c3d36cd610e3cacc..29fcd6990bdd9c65facd6ad213aec8fa54eb6ed7 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/FacteurCaracterisationIdEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/FacteurCaracterisationIdEntity.java @@ -18,6 +18,7 @@ public class FacteurCaracterisationIdEntity implements AbstractReferentieIdEntit String nom; String etape; String critere; + String nomOrganisation; @Override public boolean equals(Object o) { @@ -27,11 +28,11 @@ public class FacteurCaracterisationIdEntity implements AbstractReferentieIdEntit FacteurCaracterisationIdEntity that = (FacteurCaracterisationIdEntity) o; - return new EqualsBuilder().append(nom, that.nom).append(etape, that.etape).append(critere, that.critere).isEquals(); + return new EqualsBuilder().append(nom, that.nom).append(etape, that.etape).append(critere, that.critere).append(nomOrganisation, that.nomOrganisation).isEquals(); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37).append(nom).append(etape).append(critere).toHashCode(); + return new HashCodeBuilder(17, 37).append(nom).append(etape).append(critere).append(nomOrganisation).toHashCode(); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/HypotheseIdEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/HypotheseIdEntity.java index 9ee5948e6af68a28393798d280af37209ada53f5..1747a92348207fc50c9a2dcd18ef6ecb1133f340 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/HypotheseIdEntity.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/HypotheseIdEntity.java @@ -17,6 +17,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; public class HypotheseIdEntity implements AbstractReferentieIdEntity { String code; + String nomOrganisation; @Override public boolean equals(Object o) { @@ -26,11 +27,11 @@ public class HypotheseIdEntity implements AbstractReferentieIdEntity { HypotheseIdEntity that = (HypotheseIdEntity) o; - return new EqualsBuilder().append(code, that.code).isEquals(); + return new EqualsBuilder().append(code, that.code).append(nomOrganisation, that.nomOrganisation).isEquals(); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37).append(code).toHashCode(); + return new HashCodeBuilder(17, 37).append(code).append(nomOrganisation).toHashCode(); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/TypeItemIdEntity.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/TypeItemIdEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..fe02bf05efbdb53ab15ab827701f4a30c3b79871 --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/entity/id/TypeItemIdEntity.java @@ -0,0 +1,18 @@ +package org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +@Getter +@Setter +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +@EqualsAndHashCode +public class TypeItemIdEntity implements AbstractReferentieIdEntity { + + String type; + String nomOrganisation; + +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/CorrespondanceRefEquipementRepository.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/CorrespondanceRefEquipementRepository.java index 119bd61c0d87e04fb3b99026e2728b9b1773aceb..6523bf85cda0b29ad7aeb74290b313f2047b2090 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/CorrespondanceRefEquipementRepository.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/CorrespondanceRefEquipementRepository.java @@ -1,11 +1,21 @@ package org.mte.numecoeval.referentiel.infrastructure.jpa.repository; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.transaction.Transactional; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRefEquipementEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.CorrespondanceRefEquipementIdEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.rest.core.annotation.RepositoryRestResource; -@RepositoryRestResource(path = "CorrespondanceRefEquipement" , itemResourceRel = "CorrespondancesRefEquipement") +import java.util.Optional; + +@RepositoryRestResource(path = "CorrespondanceRefEquipement", itemResourceRel = "CorrespondancesRefEquipement") @Tag(name = "CorrespondanceRefEquipement") -public interface CorrespondanceRefEquipementRepository extends JpaRepository<CorrespondanceRefEquipementEntity,String> { +public interface CorrespondanceRefEquipementRepository extends JpaRepository<CorrespondanceRefEquipementEntity, CorrespondanceRefEquipementIdEntity> { + Optional<CorrespondanceRefEquipementEntity> findById(CorrespondanceRefEquipementIdEntity id); + + @Transactional + @Modifying + int deleteByNomOrganisation(String nomOrganisation); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/FacteurCaracterisationRepository.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/FacteurCaracterisationRepository.java index da8d00f777b6391be92df8d6dbfcbd17164bf48f..1d2363a0c21ce73cd9e2895add01db961ebf3ecf 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/FacteurCaracterisationRepository.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/FacteurCaracterisationRepository.java @@ -34,9 +34,10 @@ public interface FacteurCaracterisationRepository extends JpaRepository<FacteurC ((?2 IS NULL) OR (?2 IS NOT NULL AND fc.etape = ?2)) AND ((?3 IS NULL) OR (?3 IS NOT NULL AND fc.nom = ?3)) AND ((?4 IS NULL) OR (?4 IS NOT NULL AND fc.localisation = ?4)) AND - ((?5 IS NULL) OR (?5 IS NOT NULL AND fc.categorie = ?5)) + ((?5 IS NULL) OR (?5 IS NOT NULL AND fc.categorie = ?5)) AND + ((?6 IS NULL) OR (?6 IS NOT NULL AND fc.nomOrganisation = ?6)) """) - List<FacteurCaracterisationEntity> findByCritereAndEtapeAndNomAndLocalisationAndCategorie(String nomcritere, String etape, String nom, String localisation, String categorie); + List<FacteurCaracterisationEntity> findByCritereAndEtapeAndNomAndLocalisationAndCategorieAndNomOrganisation(String nomcritere, String etape, String nom, String localisation, String categorie, String nomOrganisation); List<FacteurCaracterisationEntity> findByNiveauAndCategorieAndLocalisationAndCritere(String niveau, String categorie, String localisation, String critere); @@ -47,4 +48,8 @@ public interface FacteurCaracterisationRepository extends JpaRepository<FacteurC List<FacteurCaracterisationEntity> findByNiveauAndTiers(String niveau, String tiers); List<FacteurCaracterisationEntity> findByNiveau(String niveau); + + @Transactional + @Modifying + int deleteByNomOrganisation(String nomOrganisation); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/HypotheseRepository.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/HypotheseRepository.java index 250786e94bbf543078b4ef032859080f867e4bf4..a151a6f6db48de6a842703d4ba5b3b3595ef7c18 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/HypotheseRepository.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/HypotheseRepository.java @@ -1,17 +1,23 @@ package org.mte.numecoeval.referentiel.infrastructure.jpa.repository; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.transaction.Transactional; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.HypotheseEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.HypotheseIdEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import java.util.Optional; -@RepositoryRestResource(path = "Hypothèses" , itemResourceRel = "Hypothèses") +@RepositoryRestResource(path = "Hypothèses", itemResourceRel = "Hypothèses") @Tag(name = "Hypothèse - CRUD/Spring Data REST") public interface HypotheseRepository extends JpaRepository<HypotheseEntity, HypotheseIdEntity> { Optional<HypotheseEntity> findById(HypotheseIdEntity id); + + @Transactional + @Modifying + int deleteByNomOrganisation(String nomOrganisation); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/TypeItemRepository.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/TypeItemRepository.java index f824bf685b2d8c6de84c01eed4f945e5f9bd3623..ba5ac9b25ea96e4ea93e295072eaa6b3f1df86ae 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/TypeItemRepository.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/jpa/repository/TypeItemRepository.java @@ -1,16 +1,25 @@ package org.mte.numecoeval.referentiel.infrastructure.jpa.repository; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.transaction.Transactional; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.TypeItemEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.TypeItemIdEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.rest.core.annotation.RepositoryRestResource; import java.util.List; +import java.util.Optional; @RepositoryRestResource(path = "TypeItem", itemResourceRel = "TypesEquipements") @Tag(name = "TypeItem - CRUD/Spring Data REST") -public interface TypeItemRepository extends JpaRepository<TypeItemEntity, String> { +public interface TypeItemRepository extends JpaRepository<TypeItemEntity, TypeItemIdEntity> { + Optional<TypeItemEntity> findById(TypeItemIdEntity id); List<TypeItemEntity> findByCategorie(String categorie); + @Transactional + @Modifying + int deleteByNomOrganisation(String nomOrganisation); + } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/CorrespondanceRefEquipementMapper.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/CorrespondanceRefEquipementMapper.java index 6501c7b5d37e791f964b28a4246179f14094d6da..0267c4335f1e2a069d3068493a853633cc2ebff5 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/CorrespondanceRefEquipementMapper.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/CorrespondanceRefEquipementMapper.java @@ -2,8 +2,11 @@ package org.mte.numecoeval.referentiel.infrastructure.mapper; import org.mapstruct.Mapper; import org.mte.numecoeval.referentiel.domain.model.CorrespondanceRefEquipement; +import org.mte.numecoeval.referentiel.domain.model.id.CorrespondanceRefEquipementId; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRefEquipementEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.CorrespondanceRefEquipementIdEntity; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.CorrespondanceRefEquipementIdDTO; import java.util.Collection; import java.util.List; @@ -13,10 +16,16 @@ public interface CorrespondanceRefEquipementMapper { CorrespondanceRefEquipement toDomain(CorrespondanceRefEquipementEntity entity); + CorrespondanceRefEquipementId toDomain(CorrespondanceRefEquipementIdDTO correspondanceRefEquipementIdDTO); + CorrespondanceRefEquipement toDomain(CorrespondanceRefEquipementDTO dto); + Collection<CorrespondanceRefEquipement> toDomains(List<CorrespondanceRefEquipementDTO> dtos); + CorrespondanceRefEquipementEntity toEntity(CorrespondanceRefEquipement domain); + CorrespondanceRefEquipementIdEntity toEntityId(CorrespondanceRefEquipementId id); + List<CorrespondanceRefEquipementEntity> toEntities(Collection<CorrespondanceRefEquipement> domains); CorrespondanceRefEquipementDTO toDto(CorrespondanceRefEquipement domain); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/FacteurCaracterisationMapper.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/FacteurCaracterisationMapper.java index 42df19c67a11f8140d857b6d83f57559277a2a3c..80469ff49b02cbf244fbe6fa2ee75ac89c5e1335 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/FacteurCaracterisationMapper.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/FacteurCaracterisationMapper.java @@ -25,6 +25,8 @@ public interface FacteurCaracterisationMapper { List<FacteurCaracterisation> toDomains(List<FacteurCaracterisationEntity> entities); + List<FacteurCaracterisation> toDomainsDTO(List<FacteurCaracterisationDTO> dtos); + FacteurCaracterisation toDomain(FacteurCaracterisationDTO dto); List<FacteurCaracterisation> toDomainsFromDTO(List<FacteurCaracterisationDTO> iesDTO); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/TypeItemMapper.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/TypeItemMapper.java index 16e9ec80b96b31bf8ad23d3ad69d0d78322bc19b..eba0748f7e81fa6de4ce08c8673dae3e963e92a0 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/TypeItemMapper.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/mapper/TypeItemMapper.java @@ -2,8 +2,11 @@ package org.mte.numecoeval.referentiel.infrastructure.mapper; import org.mapstruct.Mapper; import org.mte.numecoeval.referentiel.domain.model.TypeItem; +import org.mte.numecoeval.referentiel.domain.model.id.TypeItemId; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.TypeItemEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.TypeItemIdEntity; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.TypeItemDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.TypeItemIdDTO; import java.util.Collection; import java.util.List; @@ -13,12 +16,18 @@ public interface TypeItemMapper { TypeItem toDomain(TypeItemEntity TypeItemEntity); + TypeItemId toDomain(TypeItemIdDTO typeItemIdDTO); + List<TypeItem> toDomains(List<TypeItemEntity> TypeItemEntities); + List<TypeItem> toDomainsDTO(List<TypeItemDTO> TypeItemDTOs); + TypeItem toDomain(TypeItemDTO TypeItemDTO); TypeItemEntity toEntity(TypeItem TypeItem); + TypeItemIdEntity toEntityId(TypeItemId id); + List<TypeItemEntity> toEntities(Collection<TypeItem> TypeItems); TypeItemDTO toDTO(TypeItem TypeItem); diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielAdministrationCorrespondanceRefEquipementRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielAdministrationCorrespondanceRefEquipementRestApi.java index 8934b03eb58f1cf65ce4e063cdde8e69844bc7f0..2c05e55b26868b9dae8d5672b8ac3eec30ca02fb 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielAdministrationCorrespondanceRefEquipementRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielAdministrationCorrespondanceRefEquipementRestApi.java @@ -12,6 +12,7 @@ import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.RapportImportDT import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; @@ -38,7 +39,10 @@ public interface ReferentielAdministrationCorrespondanceRefEquipementRestApi { content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @PostMapping(path = "/referentiel/correspondanceRefEquipement/csv", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - RapportImportDTO importCSV(@RequestPart("file") MultipartFile file) throws IOException, ReferentielException; + RapportImportDTO importCSV(@RequestPart("file") MultipartFile file, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ) throws IOException, ReferentielException; @Operation( diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApi.java index 8952046333c6da220ed4c1fbd8f8f6b6d1d4969b..295cf4d0f2d7f4b0ee431bbac4559a1be4559bb3 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApi.java @@ -26,6 +26,10 @@ public interface ReferentielCorrespondanceRefEquipementRestApi { @ApiResponse(responseCode = "404", description = "Correspondance non trouvée", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @GetMapping(path = "/referentiel/correspondanceRefEquipement", produces = MediaType.APPLICATION_JSON_VALUE) - CorrespondanceRefEquipementDTO get(@RequestParam(name = "modele") final String modele); + CorrespondanceRefEquipementDTO get( + @RequestParam(name = "modele") final String modele, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImpl.java index a552e5286e1988887457bbff3aa2adf74434b7d4..3bc9c4ef7f48cdca5b315bebcb668284f3932240 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImpl.java @@ -11,6 +11,7 @@ import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRe import org.mte.numecoeval.referentiel.infrastructure.restapi.controller.BaseExportReferentiel; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.RapportImportDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.CorrespondanceRefEquipementIdDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.facade.CorrespondanceRefEquipementFacade; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RestController; @@ -28,12 +29,12 @@ public class ReferentielCorrespondanceRefEquipementRestApiImpl implements BaseEx private CorrespondanceRefEquipemenetCsvExportService csvExportService; @Override - public RapportImportDTO importCSV(MultipartFile fichier) throws IOException, ReferentielException { + public RapportImportDTO importCSV(MultipartFile fichier, String nomOrganisation) throws IOException, ReferentielException { if (fichier == null || fichier.isEmpty()) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le fichier n'existe pas ou alors il est vide"); } - var rapportImport = new ImportCorrespondanceRefEquipementPortImpl().importCSV(fichier.getInputStream()); - referentielFacade.purgeAndAddAll(rapportImport.getObjects()); + var rapportImport = new ImportCorrespondanceRefEquipementPortImpl().importCSV(fichier.getInputStream(), nomOrganisation); + referentielFacade.purgeByOrganisationAndAddAll(rapportImport.getObjects(), nomOrganisation); return new RapportImportDTO( fichier.getOriginalFilename(), @@ -44,8 +45,11 @@ public class ReferentielCorrespondanceRefEquipementRestApiImpl implements BaseEx @SneakyThrows @Override - public CorrespondanceRefEquipementDTO get(String modele) { - return referentielFacade.get(modele); + public CorrespondanceRefEquipementDTO get(String modele, String nomOrganisation) { + CorrespondanceRefEquipementIdDTO idDTO = new CorrespondanceRefEquipementIdDTO(); + idDTO.setModeleEquipementSource(modele); + idDTO.setNomOrganisation(nomOrganisation); + return referentielFacade.get(idDTO); } @Override diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielAdministrationFacteurCaracterisationRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielAdministrationFacteurCaracterisationRestApi.java index 1e184353ac958d1eee9c30e88e8e5208a4f57333..873626399a848a1c6326f896b80255a0c29b58a7 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielAdministrationFacteurCaracterisationRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielAdministrationFacteurCaracterisationRestApi.java @@ -42,7 +42,9 @@ public interface ReferentielAdministrationFacteurCaracterisationRestApi { @RequestPart("file") MultipartFile file, @RequestParam(value = "mode", defaultValue = "DELTA") @Schema(description = "Choix du mode d'insertion FULL (purge puis insertion des nouvelles données) ou " + - "DELTA (upsert : maj de la base de données existante)", defaultValue = "DELTA") String mode + "DELTA (upsert : maj de la base de données existante)", defaultValue = "DELTA") String mode, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation ) throws IOException, ReferentielException; diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApi.java index b172e0c1e562640bb270631991b38d3369fa767c..32bde86c8e5ee8f2b67d5b76126e86434c887a33 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApi.java @@ -49,7 +49,9 @@ public interface ReferentielFacteurCaracterisationRestApi { @RequestParam(required = false) @Schema(description = "Nom de la localisation") final String localisation, @RequestParam(required = false) - @Schema(description = "Nom de la catégorie") final String categorie + @Schema(description = "Nom de la catégorie") final String categorie, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation ); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImpl.java index 6ae975f47cf38c6c25868b1027a94eac3fdfe38a..d0b30b5e17602c044173ffecf59878ffa1d4fab5 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImpl.java @@ -30,20 +30,20 @@ public class ReferentielFacteurCaracterisationRestApiImpl implements BaseExportR @SneakyThrows @Override - public List<FacteurCaracterisationDTO> get(String critere, String etapeacv, String nom, String localisation, String categorie) { - String[] params = {critere, etapeacv, nom, localisation, categorie}; + public List<FacteurCaracterisationDTO> get(String critere, String etapeacv, String nom, String localisation, String categorie, String nomOrganisation) { + String[] params = {critere, etapeacv, nom, localisation, categorie, nomOrganisation}; return referentielFacade.getByFilters(params); } @Override - public RapportImportDTO importCSV(MultipartFile fichier, String mode) throws IOException, ReferentielException { + public RapportImportDTO importCSV(MultipartFile fichier, String mode, String nomOrganisation) throws IOException, ReferentielException { if (fichier == null || fichier.isEmpty()) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le fichier n'existe pas ou alors il est vide"); } - var rapportImport = new ImportFacteurCaracterisationPortImpl().importCSV(fichier.getInputStream()); + var rapportImport = new ImportFacteurCaracterisationPortImpl().importCSV(fichier.getInputStream(), nomOrganisation); if ("FULL".equals(mode)) { - referentielFacade.purgeAndAddAll(rapportImport.getObjects()); + referentielFacade.purgeByOrganisationAndAddAll(rapportImport.getObjects(), nomOrganisation); } else if ("DELTA".equals(mode)) { referentielFacade.upsert(rapportImport.getObjects()); } else { diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielAdministrationHypotheseRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielAdministrationHypotheseRestApi.java index c3d123dcc20f3e040cf16d71c862213287a03530..93a983fbd93521a522f47177200e8b85f5304021 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielAdministrationHypotheseRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielAdministrationHypotheseRestApi.java @@ -12,6 +12,7 @@ import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.RapportImportDT import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; @@ -37,7 +38,11 @@ public interface ReferentielAdministrationHypotheseRestApi { @ApiResponse(responseCode = "400", description = "Invalid request", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @PostMapping(path = "/referentiel/hypotheses/csv", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - RapportImportDTO importCSV(@RequestPart("file") MultipartFile file) throws IOException, ReferentielException; + RapportImportDTO importCSV( + @RequestPart("file") MultipartFile file, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ) throws IOException, ReferentielException; @Operation( diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApi.java index dc18fd8279a0d09ffbdb003ff424a4d93cc7e656..e06b2ac241fdd9430e89c7ca4f2e2a99e30a2028 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApi.java @@ -23,13 +23,17 @@ public interface ReferentielHypotheseRestApi { operationId = "getHypothese" ) @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Hypothèse trouvé", + @ApiResponse(responseCode = "200", description = "Hypothèse trouvée", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = HypotheseDTO.class))}), @ApiResponse(responseCode = "400", description = "Invalid request", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))}), - @ApiResponse(responseCode = "404", description = "Hypothèse non trouvé", content = {@Content(mediaType = "application/json", + @ApiResponse(responseCode = "404", description = "Hypothèse non trouvée", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @GetMapping(path = "/referentiel/hypothese", produces = MediaType.APPLICATION_JSON_VALUE) - HypotheseDTO get(@RequestParam @Schema(description = "Clé de l'hypothèse") final String cle); + HypotheseDTO get( + @RequestParam @Schema(description = "Clé de l'hypothèse") final String cle, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImpl.java index 9a021fb0e659763d0b860bca97010d2dbe842532..32373ecfe8da35fd9062ab15dd27057d6ee4b266 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImpl.java @@ -29,12 +29,12 @@ public class ReferentielHypotheseRestApiImpl implements BaseExportReferentiel<Hy private HypotheseCsvExportService csvExportService; @Override - public RapportImportDTO importCSV(MultipartFile fichier) throws IOException, ReferentielException { + public RapportImportDTO importCSV(MultipartFile fichier, String nomOrganisation) throws IOException, ReferentielException { if (fichier == null || fichier.isEmpty()) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le fichier n'existe pas ou alors il est vide"); } - var rapportImport = new ImportHypothesePortImpl().importCSV(fichier.getInputStream()); - referentielFacade.purgeAndAddAll(rapportImport.getObjects()); + var rapportImport = new ImportHypothesePortImpl().importCSV(fichier.getInputStream(), nomOrganisation); + referentielFacade.purgeByOrganisationAndAddAll(rapportImport.getObjects(), nomOrganisation); return new RapportImportDTO( fichier.getOriginalFilename(), @@ -45,9 +45,10 @@ public class ReferentielHypotheseRestApiImpl implements BaseExportReferentiel<Hy @SneakyThrows @Override - public HypotheseDTO get(String cle) { + public HypotheseDTO get(String cle, String nomOrganisation) { HypotheseIdDTO hypotheseIdDTO = new HypotheseIdDTO(); hypotheseIdDTO.setCode(cle); + hypotheseIdDTO.setNomOrganisation(nomOrganisation); return referentielFacade.get(hypotheseIdDTO); } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielAdministrationTypeItemRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielAdministrationTypeItemRestApi.java index 3c00bb6e5c7938e0d5389e03913fa49e5489e35a..388744ebe0dcdd3fdbbd4cf966e3cfd20e64e786 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielAdministrationTypeItemRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielAdministrationTypeItemRestApi.java @@ -12,6 +12,7 @@ import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.RapportImportDT import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; @@ -38,8 +39,10 @@ public interface ReferentielAdministrationTypeItemRestApi { content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @PostMapping(path = "/referentiel/typeItem/csv", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - RapportImportDTO importCSV(@RequestPart("file") MultipartFile file) throws IOException, ReferentielException; - + RapportImportDTO importCSV(@RequestPart("file") MultipartFile file, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ) throws IOException, ReferentielException; @Operation( summary = "Exporter les impacts des types d'items sous format csv", diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApi.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApi.java index bbdab44b4a800753bf5d79e44f6bba42dc37d4b9..29d75281f79b6c3d3b5d373387b9f39c91a0972e 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApi.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApi.java @@ -12,6 +12,7 @@ import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.TypeItemDTO; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -59,5 +60,9 @@ public interface ReferentielTypeItemRestApi { @ApiResponse(responseCode = "404", description = "Types Item non trouvé", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponseDTO.class))})}) @GetMapping(path = "/referentiel/typesItem/{type}", produces = MediaType.APPLICATION_JSON_VALUE) - TypeItemDTO getTypeItem(@PathVariable @Schema(description = "type recherché") String type) throws ReferentielException; + TypeItemDTO getTypeItem( + @PathVariable @Schema(description = "type recherché") String type, + @RequestParam(value = "nomOrganisation", defaultValue = "") + @Schema(description = "Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide", defaultValue = "") String nomOrganisation + ) throws ReferentielException; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImpl.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImpl.java index 50fb8d329aa5667969c8ef8a451ce8ecbad58a4c..7c23b90616edf6a1977c277c04064077d3176ae1 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImpl.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImpl.java @@ -2,6 +2,7 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.controller.typeite import jakarta.servlet.http.HttpServletResponse; import lombok.AllArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportTypeItemPortImpl; @@ -10,6 +11,7 @@ import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.TypeItemEntity; import org.mte.numecoeval.referentiel.infrastructure.restapi.controller.BaseExportReferentiel; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.RapportImportDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.TypeItemDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.TypeItemIdDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.facade.TypeItemFacade; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.RestController; @@ -24,17 +26,18 @@ import java.util.List; @AllArgsConstructor public class ReferentielTypeItemRestApiImpl implements BaseExportReferentiel<TypeItemEntity>, ReferentielTypeItemRestApi, ReferentielAdministrationTypeItemRestApi { - private TypeItemFacade TypeItemFacade; + private TypeItemFacade typeItemFacade; private TypeItemCsvExportService csvExportService; @Override - public RapportImportDTO importCSV(MultipartFile fichier) throws IOException, ReferentielException { + public RapportImportDTO importCSV(MultipartFile fichier, String nomOrganisation) throws IOException, ReferentielException { if (fichier == null || fichier.isEmpty()) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le fichier n'existe pas ou alors il est vide"); } - var rapportImport = new ImportTypeItemPortImpl().importCSV(fichier.getInputStream()); - TypeItemFacade.purgeAndAddAll(rapportImport.getObjects()); + var rapportImport = new ImportTypeItemPortImpl().importCSV(fichier.getInputStream(), nomOrganisation); + typeItemFacade.purgeByOrganisationAndAddAll(rapportImport.getObjects(), nomOrganisation); + return new RapportImportDTO( fichier.getOriginalFilename(), rapportImport.getErreurs(), @@ -42,14 +45,18 @@ public class ReferentielTypeItemRestApiImpl implements BaseExportReferentiel<Typ ); } + @SneakyThrows @Override - public TypeItemDTO getTypeItem(String type) throws ReferentielException { - return TypeItemFacade.getTypeItemForType(type); + public TypeItemDTO getTypeItem(String type, String nomOrganisation) { + TypeItemIdDTO typeItemIdDTO = new TypeItemIdDTO(); + typeItemIdDTO.setType(type); + typeItemIdDTO.setNomOrganisation(nomOrganisation); + return typeItemFacade.getTypeItemForType(typeItemIdDTO); } @Override public List<TypeItemDTO> getTypesItem() { - return TypeItemFacade.getAllTypesItem(); + return typeItemFacade.getAllTypesItem(); } @Override diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/CorrespondanceRefEquipementDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/CorrespondanceRefEquipementDTO.java index 3101e193f460916398a2c628269d6253bdafbd85..b95448c07c0d92f77d7570c85a5dc1430fef0e9c 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/CorrespondanceRefEquipementDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/CorrespondanceRefEquipementDTO.java @@ -27,4 +27,8 @@ public class CorrespondanceRefEquipementDTO implements Serializable { description = "Référence d'équipement correspondant au modèle de l'équipement" ) String refEquipementCible; + @Schema( + description = "Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation" + ) + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/FacteurCaracterisationDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/FacteurCaracterisationDTO.java index e1beb39ed41b429f121624ae460fc20466d3d00d..a382dbfc702ecb30bdb7f557b8e627d9ae9401b5 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/FacteurCaracterisationDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/FacteurCaracterisationDTO.java @@ -63,4 +63,8 @@ public class FacteurCaracterisationDTO { description = "Source de l'impact écologique pour ce facteur de caractérisation" ) String source; + @Schema( + description = "Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation" + ) + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/HypotheseDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/HypotheseDTO.java index 4fae57c7ad424360bd98e68a1016680d7652168e..1342b98028a8e5ac72604e92049d89ca93854767 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/HypotheseDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/HypotheseDTO.java @@ -34,4 +34,8 @@ public class HypotheseDTO implements Serializable { description = "Description de l'hypothèse" ) String description; + @Schema( + description = "Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation" + ) + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/TypeItemDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/TypeItemDTO.java index ddf50fe98d054369832457107c121025443033f4..3cf1361d69b62a395b171f2bdca837931098791d 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/TypeItemDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/TypeItemDTO.java @@ -51,4 +51,9 @@ public class TypeItemDTO implements Serializable { description = "Référence de l'item par défaut, permet des correspondances en cas d'absence de correspondance directe" ) String refItemParDefaut; + @Schema( + description = "Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation" + ) + String nomOrganisation; + } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/CorrespondanceRefEquipementIdDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/CorrespondanceRefEquipementIdDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..f4735a8dabb62f8fe611f6abeff6a05bd8e082a2 --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/CorrespondanceRefEquipementIdDTO.java @@ -0,0 +1,19 @@ +package org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +import java.io.Serializable; + +@Getter +@Setter +@EqualsAndHashCode +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +public class CorrespondanceRefEquipementIdDTO implements Serializable { + String modeleEquipementSource; + String nomOrganisation; + +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/FacteurCaracterisationIdDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/FacteurCaracterisationIdDTO.java index 1e17f24668cebc99da08369c7ec9b88508615b27..e2e393c7e1fa061445bbfdee4cb2474cacdda17c 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/FacteurCaracterisationIdDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/FacteurCaracterisationIdDTO.java @@ -14,4 +14,5 @@ public class FacteurCaracterisationIdDTO { String nom; String etape; String critere; + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/HypotheseIdDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/HypotheseIdDTO.java index ec20ee6b92a09a3a0b62c43fd8f791c74fab8997..0dbed7986a09d68ed428a270164623d828d1da3b 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/HypotheseIdDTO.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/HypotheseIdDTO.java @@ -18,4 +18,5 @@ import java.io.Serializable; @NoArgsConstructor public class HypotheseIdDTO implements Serializable { String code; + String nomOrganisation; } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/TypeItemIdDTO.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/TypeItemIdDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..7194fde6ace2cc1672440e8c0f93e3d27b99ba99 --- /dev/null +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/dto/id/TypeItemIdDTO.java @@ -0,0 +1,18 @@ +package org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id; + +import lombok.*; +import lombok.experimental.Accessors; +import lombok.experimental.FieldDefaults; + +import java.io.Serializable; + +@Getter +@Setter +@EqualsAndHashCode +@Accessors(chain = true) +@FieldDefaults(level = AccessLevel.PRIVATE) +@NoArgsConstructor +public class TypeItemIdDTO implements Serializable { + String type; + String nomOrganisation; +} diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacade.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacade.java index 007e5271f781e3704438f65cb4c82018d1351edf..37b98275ccf996628f5a8082c6e87559e79b46dd 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacade.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacade.java @@ -5,9 +5,11 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.CorrespondanceRefEquipement; +import org.mte.numecoeval.referentiel.domain.model.id.CorrespondanceRefEquipementId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; import org.mte.numecoeval.referentiel.infrastructure.mapper.CorrespondanceRefEquipementMapper; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.CorrespondanceRefEquipementIdDTO; import org.springframework.stereotype.Service; import java.util.List; @@ -16,15 +18,12 @@ import java.util.List; @Slf4j @AllArgsConstructor public class CorrespondanceRefEquipementFacade { - private ReferentielPersistencePort<CorrespondanceRefEquipement, String> persistencePort; + private ReferentielPersistencePort<CorrespondanceRefEquipement, CorrespondanceRefEquipementId> persistencePort; private CorrespondanceRefEquipementMapper mapper; - public CorrespondanceRefEquipementDTO get(String modeleEquipementSource) throws ReferentielException { - var correspondanceRefEquipement = persistencePort.get(modeleEquipementSource); - if (correspondanceRefEquipement != null) { - return mapper.toDto(correspondanceRefEquipement); - } - return null; + public CorrespondanceRefEquipementDTO get(CorrespondanceRefEquipementIdDTO correspondanceRefEquipementIdDTO) throws ReferentielException { + CorrespondanceRefEquipement correspondanceRefEquipement = persistencePort.get(mapper.toDomain(correspondanceRefEquipementIdDTO)); + return mapper.toDto(correspondanceRefEquipement); } public List<CorrespondanceRefEquipementDTO> getAll() { @@ -32,11 +31,9 @@ public class CorrespondanceRefEquipementFacade { return CollectionUtils.emptyIfNull(domains).stream().map(domain -> mapper.toDto(domain)).toList(); } - public void purgeAndAddAll(List<CorrespondanceRefEquipementDTO> correspondances) throws ReferentielException { - persistencePort.purge(); - persistencePort.saveAll(CollectionUtils.emptyIfNull(correspondances).stream() - .map(dto -> mapper.toDomain(dto)) - .toList()); + public void purgeByOrganisationAndAddAll(List<CorrespondanceRefEquipementDTO> correspondances, String nomOrganisation) throws ReferentielException { + persistencePort.purgeByOrganisation(nomOrganisation); + persistencePort.saveAll(mapper.toDomains(correspondances)); } } diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacade.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacade.java index f603f84ea3aa4c8bfe8c57fb8c9a98d194535fcf..4e933c051dbc7f809b3884c1583ef647ed01b272 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacade.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacade.java @@ -31,13 +31,13 @@ public class FacteurCaracterisationFacade { } public List<FacteurCaracterisationDTO> getByFilters(String... params) throws ReferentielException { - List<FacteurCaracterisation> facteurCaracterisation = persistencePort.findByFilters(params[0], params[1], params[2], params[3], params[4]); + List<FacteurCaracterisation> facteurCaracterisation = persistencePort.findByFilters(params[0], params[1], params[2], params[3], params[4], params[5]); return mapper.toDTOs(facteurCaracterisation); } - public void purgeAndAddAll(List<FacteurCaracterisationDTO> fcsDTO) throws ReferentielException { - persistencePort.purge(); - persistencePort.saveAll(mapper.toDomainsFromDTO(fcsDTO)); + public void purgeByOrganisationAndAddAll(List<FacteurCaracterisationDTO> fcsDTO, String nomOrganisation) throws ReferentielException { + persistencePort.purgeByOrganisation(nomOrganisation); + persistencePort.saveAll(mapper.toDomainsDTO(fcsDTO)); } public void upsert(List<FacteurCaracterisationDTO> fcsDTO) throws ReferentielException { diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacade.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacade.java index ceeb6491fcf33d705b8147b34bcfa732a15e7cd1..277743d81351f56cfb57d2703c16aaa3c7de461f 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacade.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacade.java @@ -2,12 +2,12 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.facade; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.Hypothese; import org.mte.numecoeval.referentiel.domain.model.id.HypotheseId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; import org.mte.numecoeval.referentiel.infrastructure.mapper.HypotheseMapper; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.HypotheseIdDTO; import org.springframework.stereotype.Service; @@ -23,14 +23,10 @@ public class HypotheseFacade { private HypotheseMapper mapper; - /** - * Ajout des hypotheses depuis un fichier csv - * - * @param hypotheses - */ - public void purgeAndAddAll(List<HypotheseDTO> hypotheses) throws ReferentielException { - persistencePort.purge(); + public void purgeByOrganisationAndAddAll(List<HypotheseDTO> hypotheses, String nomOrganisation) throws ReferentielException { + persistencePort.purgeByOrganisation(nomOrganisation); persistencePort.saveAll(mapper.toDomains(hypotheses)); + } /** diff --git a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/TypeItemFacade.java b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/TypeItemFacade.java index b15e0ec8cd7c00c19783e87ce2d0258c05b3c2c0..2fa967a4d489f05d92cfc69b6d174c202c93585c 100644 --- a/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/TypeItemFacade.java +++ b/services/api-referentiel/src/main/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/TypeItemFacade.java @@ -4,9 +4,11 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.TypeItem; +import org.mte.numecoeval.referentiel.domain.model.id.TypeItemId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; import org.mte.numecoeval.referentiel.infrastructure.mapper.TypeItemMapper; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.TypeItemDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.TypeItemIdDTO; import org.springframework.stereotype.Service; import java.util.List; @@ -16,15 +18,12 @@ import java.util.List; @AllArgsConstructor public class TypeItemFacade { - private ReferentielPersistencePort<TypeItem, String> persistencePort; + private ReferentielPersistencePort<TypeItem, TypeItemId> persistencePort; private TypeItemMapper mapper; - public TypeItemDTO getTypeItemForType(String type) throws ReferentielException { - var TypeItem = persistencePort.get(type); - if (TypeItem != null) { - return mapper.toDTO(TypeItem); - } - return null; + public TypeItemDTO getTypeItemForType(TypeItemIdDTO typeItemIdDTO) throws ReferentielException { + TypeItem typeItem = persistencePort.get(mapper.toDomain(typeItemIdDTO)); + return mapper.toDTO(typeItem); } public List<TypeItemDTO> getAllTypesItem() { @@ -33,12 +32,9 @@ public class TypeItemFacade { .toList(); } - public void purgeAndAddAll(List<TypeItemDTO> types) throws ReferentielException { - if (types == null) return; - persistencePort.purge(); - persistencePort.saveAll(types.stream() - .map(TypeItemDTO -> mapper.toDomain(TypeItemDTO)) - .toList()); + public void purgeByOrganisationAndAddAll(List<TypeItemDTO> typeItems, String nomOrganisation) throws ReferentielException { + persistencePort.purgeByOrganisation(nomOrganisation); + persistencePort.saveAll(mapper.toDomainsDTO(typeItems)); } } diff --git a/services/api-referentiel/src/main/resources/schema.sql b/services/api-referentiel/src/main/resources/schema.sql index d81d8dde24fa93687f803a52b0e38c6f16e14a2d..ebd66c09c0dd200fc78e56d9754e6b682898e9c1 100644 --- a/services/api-referentiel/src/main/resources/schema.sql +++ b/services/api-referentiel/src/main/resources/schema.sql @@ -1,3 +1,18 @@ +create or replace function create_constraint_if_not_exists ( + t_name text, c_name text, constraint_sql text +) +returns void AS +' +begin + -- Look for our constraint + if not exists (select constraint_name + from information_schema.constraint_column_usage + where table_name = t_name and constraint_name = c_name) then + execute ''ALTER TABLE '' || t_name || '' ADD CONSTRAINT '' || c_name || '' '' || constraint_sql; + end if; +end; +' language 'plpgsql'; + CREATE TABLE IF NOT EXISTS ref_etapeacv ( code varchar(255) NOT NULL, @@ -19,7 +34,8 @@ CREATE TABLE IF NOT EXISTS ref_hypothese "source" varchar(255) NULL, valeur varchar(255) NULL, description varchar(255) NULL, - CONSTRAINT ref_hypothese_pkey PRIMARY KEY (code) + nom_organisation varchar(255) NOT NULL, + CONSTRAINT ref_hypothese_pkey PRIMARY KEY (code, nom_organisation) ); CREATE TABLE IF NOT EXISTS ref_type_item @@ -32,7 +48,8 @@ CREATE TABLE IF NOT EXISTS ref_type_item serveur bool NOT NULL, "source" varchar(255) NULL, ref_item_par_defaut varchar(255) NULL, - CONSTRAINT ref_type_item_pkey PRIMARY KEY (type) + nom_organisation varchar(255) NOT NULL, + CONSTRAINT ref_type_item_pkey PRIMARY KEY (type, nom_organisation) ); CREATE TABLE IF NOT EXISTS ref_impact_messagerie @@ -48,7 +65,8 @@ CREATE TABLE IF NOT EXISTS ref_correspondance_ref_eqp ( modele_equipement_source varchar(255) NOT NULL, ref_equipement_cible varchar(255) NULL, - CONSTRAINT ref_correspondance_ref_eqp_pkey PRIMARY KEY (modele_equipement_source) + nom_organisation varchar(255) NOT NULL, + CONSTRAINT ref_correspondance_ref_eqp_pkey PRIMARY KEY (modele_equipement_source, nom_organisation) ); CREATE TABLE IF NOT EXISTS ref_facteurcaracterisation ( @@ -64,7 +82,23 @@ CREATE TABLE IF NOT EXISTS ref_correspondance_ref_eqp valeur float8 NULL, unite varchar(255) NULL, source varchar(255) NULL, - CONSTRAINT ref_facteurcaracterisation_pkey PRIMARY KEY (nom, etapeacv, nomcritere) + nom_organisation varchar(255) NOT NULL, + CONSTRAINT ref_facteurcaracterisation_pkey PRIMARY KEY (nom, etapeacv, nomcritere, nom_organisation) ); -- suppression des contraintes de clés étrangères ALTER TABLE ref_impact_messagerie DROP CONSTRAINT IF EXISTS fkohnlpwfp0ebk7dswmfbe5l3k0; +ALTER TABLE IF EXISTS ref_type_item ADD COLUMN IF NOT EXISTS nom_organisation varchar(255) DEFAULT ''; +ALTER TABLE IF EXISTS ref_facteurcaracterisation ADD COLUMN IF NOT EXISTS nom_organisation varchar(255) DEFAULT ''; +ALTER TABLE IF EXISTS ref_hypothese ADD COLUMN IF NOT EXISTS nom_organisation varchar(255) DEFAULT ''; +ALTER TABLE IF EXISTS ref_correspondance_ref_eqp ADD COLUMN IF NOT EXISTS nom_organisation varchar(255) DEFAULT ''; + +-- suppression des anciennes clés primaires et ajout du nom_organisation à la clé + +ALTER TABLE ref_hypothese DROP CONSTRAINT IF EXISTS ref_hypothese_pkey; +SELECT create_constraint_if_not_exists('ref_hypothese', 'ref_hypothese_org_pkey', 'PRIMARY KEY (code, nom_organisation);'); +ALTER TABLE ref_type_item DROP CONSTRAINT IF EXISTS ref_type_item_pkey; +SELECT create_constraint_if_not_exists('ref_type_item', 'ref_type_item_org_pkey', 'PRIMARY KEY (type, nom_organisation);'); +ALTER TABLE ref_correspondance_ref_eqp DROP CONSTRAINT IF EXISTS ref_correspondance_ref_eqp_pkey; +SELECT create_constraint_if_not_exists('ref_correspondance_ref_eqp', 'ref_correspondance_ref_eqp_org_pkey', 'PRIMARY KEY (modele_equipement_source, nom_organisation);'); +ALTER TABLE ref_facteurcaracterisation DROP CONSTRAINT IF EXISTS ref_facteurcaracterisation_pkey; +SELECT create_constraint_if_not_exists('ref_facteurcaracterisation', 'ref_facteurcaracterisation_org_pkey', 'PRIMARY KEY (nom, etapeacv, nomcritere, nom_organisation);'); \ No newline at end of file diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCSVReferentielPortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCSVReferentielPortTest.java index 77fc8f59d79374343b1a1f8171021ae994f6ffbb..bbaef94c40690a46b2c6ae68bd76ff19f4df02d4 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCSVReferentielPortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCSVReferentielPortTest.java @@ -5,10 +5,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportCorrespondanceRefEquipementPortImpl; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCorrespondanceRefEquipementPortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCorrespondanceRefEquipementPortTest.java index c5579678341e5c552cf31decab306b02b7fc5d99..e2ab744973dd4b5280d80c9cb91b9d52f3b28291 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCorrespondanceRefEquipementPortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportCorrespondanceRefEquipementPortTest.java @@ -1,16 +1,12 @@ package org.mte.numecoeval.referentiel.domain.port.input; import org.junit.jupiter.api.Test; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportCorrespondanceRefEquipementPortImpl; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.springframework.util.ResourceUtils; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.io.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -23,35 +19,34 @@ class ImportCorrespondanceRefEquipementPortTest { @Test void importCSV_shouldImportAllDatas() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/correspondanceRefEquipement.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(3, resultatImport.getNbrLignesImportees()); assertEquals(0, resultatImport.getErreurs().size()); assertEquals(3, resultatImport.getObjects().size()); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele01".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele02".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele03".equals(etapeDTO.getModeleEquipementSource()) && "refCible02".equals(etapeDTO.getRefEquipementCible()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele01".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()) && "ADEO".equals(etapeDTO.getNomOrganisation()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele02".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()) && "ADEO".equals(etapeDTO.getNomOrganisation()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele03".equals(etapeDTO.getModeleEquipementSource()) && "refCible02".equals(etapeDTO.getRefEquipementCible()) && "ADEO".equals(etapeDTO.getNomOrganisation()))); } @Test void importCSV_whenErrorInMiddleOfFile_shouldImportDatasWithErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/correspondanceRefEquipement_errorInMiddle.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(3, resultatImport.getNbrLignesImportees()); assertEquals(2, resultatImport.getErreurs().size()); assertTrue(resultatImport.getErreurs().stream().anyMatch("La ligne n°4 est invalide : La colonne modeleEquipementSource ne peut être vide"::equals)); assertTrue(resultatImport.getErreurs().stream().anyMatch("La ligne n°5 est invalide : La colonne refEquipementCible ne peut être vide"::equals)); assertEquals(3, resultatImport.getObjects().size()); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele01".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele01".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele03".equals(etapeDTO.getModeleEquipementSource()) && "refCible02".equals(etapeDTO.getRefEquipementCible()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele01".equals(etapeDTO.getModeleEquipementSource()) && "refCible01".equals(etapeDTO.getRefEquipementCible()) && "ADEO".equals(etapeDTO.getNomOrganisation()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(etapeDTO -> "modele03".equals(etapeDTO.getModeleEquipementSource()) && "refCible02".equals(etapeDTO.getRefEquipementCible()) && "ADEO".equals(etapeDTO.getNomOrganisation()))); } @Test void importCSV_whenWrongFile_shouldReturnOnlyErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/wrongCSVFile.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(0, resultatImport.getNbrLignesImportees()); assertEquals(1, resultatImport.getErreurs().size()); @@ -63,7 +58,7 @@ class ImportCorrespondanceRefEquipementPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doNothing().when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); @@ -76,7 +71,7 @@ class ImportCorrespondanceRefEquipementPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doThrow(new FileNotFoundException("start Read csv etape")).when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportFacteurCaracterisationPortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportFacteurCaracterisationPortTest.java index 3054d4c1cd8722e7d0b58478070a155890260bb8..ef593894aabbb89006a7b885a8748680d0ca9cc6 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportFacteurCaracterisationPortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportFacteurCaracterisationPortTest.java @@ -19,7 +19,7 @@ public class ImportFacteurCaracterisationPortTest { @Test void importCSV_shouldImportAllDatas() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/facteurCaracterisation.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(4, resultatImport.getNbrLignesImportees()); assertEquals(0, resultatImport.getErreurs().size()); @@ -35,7 +35,7 @@ public class ImportFacteurCaracterisationPortTest { && Double.valueOf(0.0813225).equals(dto.getValeur()) && "kWh".equals(dto.getUnite()) && "BaseImpact".equals(dto.getSource()) - + && "ADEO".equals(dto.getNomOrganisation()) ) ); @@ -51,6 +51,7 @@ public class ImportFacteurCaracterisationPortTest { && Double.valueOf(0.000882).equals(dto.getValeur()) && "Item".equals(dto.getUnite()) && "NegaOctet".equals(dto.getSource()) + && "ADEO".equals(dto.getNomOrganisation()) ) ); @@ -64,16 +65,15 @@ public class ImportFacteurCaracterisationPortTest { && Double.valueOf(0.00000159).equals(dto.getValeur()) && "GB".equals(dto.getUnite()) && "NegaOctet".equals(dto.getSource()) + && "ADEO".equals(dto.getNomOrganisation()) ) ); - - } @Test void importCSV_whenErrorInMiddleOfFile_shouldImportDatasWithErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/facteurCaracterisation_errorInMiddle.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(4, resultatImport.getNbrLignesImportees()); assertEquals(3, resultatImport.getErreurs().size()); @@ -92,7 +92,7 @@ public class ImportFacteurCaracterisationPortTest { && Double.valueOf(0.0813225).equals(dto.getValeur()) && "kWh".equals(dto.getUnite()) && "BaseImpact".equals(dto.getSource()) - + && "ADEO".equals(dto.getNomOrganisation()) ) ); } @@ -100,7 +100,7 @@ public class ImportFacteurCaracterisationPortTest { @Test void importCSV_whenWrongFile_shouldReturnOnlyErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/wrongCSVFile.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(0, resultatImport.getNbrLignesImportees()); assertEquals(1, resultatImport.getErreurs().size()); @@ -112,7 +112,7 @@ public class ImportFacteurCaracterisationPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doNothing().when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); @@ -125,7 +125,7 @@ public class ImportFacteurCaracterisationPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doThrow(new FileNotFoundException("start Read csv etape")).when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportHypothesePortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportHypothesePortTest.java index aba280bcc8301480942af84247390b9b63eb0d4b..1521a51a3d2f00778ec84c329739408352db3b92 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportHypothesePortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportHypothesePortTest.java @@ -1,16 +1,12 @@ package org.mte.numecoeval.referentiel.domain.port.input; import org.junit.jupiter.api.Test; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; import org.mte.numecoeval.referentiel.domain.ports.input.impl.ImportHypothesePortImpl; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.springframework.util.ResourceUtils; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.io.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -23,33 +19,33 @@ class ImportHypothesePortTest { @Test void importCSV_shouldImportAllDatas() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/hypothese.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(2, resultatImport.getNbrLignesImportees()); assertEquals(0, resultatImport.getErreurs().size()); assertEquals(2, resultatImport.getObjects().size()); - assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "PUEPardDfault".equals(dto.getCode()) && "1.6".equals(dto.getValeur()) && "expertise IJO".equals(dto.getSource()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "DureeVieServeurParDefaut".equals(dto.getCode()) && "3".equals(dto.getValeur()) && "US 46".equals(dto.getSource()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "PUEPardDfault".equals(dto.getCode()) && "1.6".equals(dto.getValeur()) && "expertise IJO".equals(dto.getSource()) && "ADEO".equals(dto.getNomOrganisation()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "DureeVieServeurParDefaut".equals(dto.getCode()) && "3".equals(dto.getValeur()) && "US 46".equals(dto.getSource()) && "ADEO".equals(dto.getNomOrganisation()))); } @Test void importCSV_whenErrorInMiddleOfFile_shouldImportDatasWithErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/hypothese_errorInMiddle.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(2, resultatImport.getNbrLignesImportees()); assertEquals(2, resultatImport.getErreurs().size()); assertTrue(resultatImport.getErreurs().stream().anyMatch("La ligne n°3 est invalide : La colonne cle ne peut être vide"::equals)); assertTrue(resultatImport.getErreurs().stream().anyMatch("La ligne n°4 est invalide : La colonne valeur ne peut être vide"::equals)); assertEquals(2, resultatImport.getObjects().size()); - assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "PUEPardDfault".equals(dto.getCode()) && "1.6".equals(dto.getValeur()) && "expertise IJO".equals(dto.getSource()))); - assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "DureeVieServeurParDefaut".equals(dto.getCode()) && "3".equals(dto.getValeur()) && "US 46".equals(dto.getSource()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "PUEPardDfault".equals(dto.getCode()) && "1.6".equals(dto.getValeur()) && "expertise IJO".equals(dto.getSource()) && "ADEO".equals(dto.getNomOrganisation()))); + assertTrue(resultatImport.getObjects().stream().anyMatch(dto -> "DureeVieServeurParDefaut".equals(dto.getCode()) && "3".equals(dto.getValeur()) && "US 46".equals(dto.getSource()) && "ADEO".equals(dto.getNomOrganisation()))); } @Test void importCSV_whenWrongFile_shouldReturnOnlyErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/wrongCSVFile.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(0, resultatImport.getNbrLignesImportees()); assertEquals(1, resultatImport.getErreurs().size()); @@ -61,7 +57,7 @@ class ImportHypothesePortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doNothing().when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); @@ -74,7 +70,7 @@ class ImportHypothesePortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doThrow(new FileNotFoundException("start Read csv etape")).when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportTypeItemPortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportTypeItemPortTest.java index cf5bb6a02d7702e9fbbd37ac1bb9bf905c91d7ac..0c403eedb6675274cdf86d85d1d961f001cab0f2 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportTypeItemPortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/domain/port/input/ImportTypeItemPortTest.java @@ -19,7 +19,7 @@ class ImportTypeItemPortTest { @Test void importCSV_shouldImportAllDatas() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/typeItem.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(2, resultatImport.getNbrLignesImportees()); assertEquals(0, resultatImport.getErreurs().size()); @@ -32,6 +32,7 @@ class ImportTypeItemPortTest { && Double.valueOf(6.0).equals(typeItemDTO.getDureeVieDefaut()) && "NegaOctet".equals(typeItemDTO.getSource()) && "serveur_par_defaut".equals(typeItemDTO.getRefItemParDefaut()) + && "ADEO".equals(typeItemDTO.getNomOrganisation()) ) ); assertTrue(resultatImport.getObjects().stream().anyMatch(typeItemDTO -> @@ -42,6 +43,7 @@ class ImportTypeItemPortTest { && Double.valueOf(50.0).equals(typeItemDTO.getDureeVieDefaut()) && "SSG".equals(typeItemDTO.getSource()) && "deplacement_voiture_hybride".equals(typeItemDTO.getRefItemParDefaut()) + && "ADEO".equals(typeItemDTO.getNomOrganisation()) ) ); } @@ -49,7 +51,7 @@ class ImportTypeItemPortTest { @Test void importCSV_whenErrorInMiddleOfFile_shouldImportDatasWithErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/typeItem_errorInMiddle.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(2, resultatImport.getNbrLignesImportees()); assertEquals(1, resultatImport.getErreurs().size()); @@ -63,6 +65,7 @@ class ImportTypeItemPortTest { && Double.valueOf(6.0).equals(typeItemDTO.getDureeVieDefaut()) && "NegaOctet".equals(typeItemDTO.getSource()) && "serveur_par_defaut".equals(typeItemDTO.getRefItemParDefaut()) + && "ADEO".equals(typeItemDTO.getNomOrganisation()) ) ); assertTrue(resultatImport.getObjects().stream().anyMatch(typeItemDTO -> @@ -73,6 +76,7 @@ class ImportTypeItemPortTest { && Double.valueOf(50.0).equals(typeItemDTO.getDureeVieDefaut()) && "SSG".equals(typeItemDTO.getSource()) && "deplacement_voiture_hybride".equals(typeItemDTO.getRefItemParDefaut()) + && "ADEO".equals(typeItemDTO.getNomOrganisation()) ) ); } @@ -80,7 +84,7 @@ class ImportTypeItemPortTest { @Test void importCSV_whenWrongFile_shouldReturnOnlyErrors() throws Exception { File file = ResourceUtils.getFile("classpath:csv/unit/wrongCSVFile.csv"); - var resultatImport = importPortToTest.importCSV(new FileInputStream(file)); + var resultatImport = importPortToTest.importCSV(new FileInputStream(file), "ADEO"); assertEquals(0, resultatImport.getNbrLignesImportees()); assertEquals(1, resultatImport.getErreurs().size()); @@ -92,7 +96,7 @@ class ImportTypeItemPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doNothing().when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); @@ -105,7 +109,7 @@ class ImportTypeItemPortTest { DataInputStream dataInputStream = mock(DataInputStream.class); doThrow(new FileNotFoundException("start Read csv etape")).when(dataInputStream).close(); - var resultatImport = importPortToTest.importCSV(dataInputStream); + var resultatImport = importPortToTest.importCSV(dataInputStream, "ADEO"); verify(dataInputStream).close(); assertEquals(0, resultatImport.getNbrLignesImportees()); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/factory/TestDataFactory.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/factory/TestDataFactory.java index 62338a5db3275c4ad5f0f5771b6a87e796efc568..dd873193f8ac949873fd84cb8903f4304936b966 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/factory/TestDataFactory.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/factory/TestDataFactory.java @@ -3,9 +3,7 @@ package org.mte.numecoeval.referentiel.factory; import org.mte.numecoeval.referentiel.domain.model.*; import org.mte.numecoeval.referentiel.domain.model.id.*; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.*; -import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.CritereIdEntity; -import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.EtapeIdEntity; -import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.HypotheseIdEntity; +import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.id.*; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.*; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.*; @@ -84,39 +82,44 @@ public class TestDataFactory { } public static class HypotheseFactory { - public static HypotheseDTO dto(String code, String valeur, String source, String description) { - return new HypotheseDTO(code, valeur, source, description); + public static HypotheseDTO dto(String code, String valeur, String source, String description, String nomOrganisation) { + return new HypotheseDTO(code, valeur, source, description, nomOrganisation); } - public static Hypothese domain(String code, String valeur, String source, String description) { + public static Hypothese domain(String code, String valeur, String source, String description, String nomOrganisation) { return new Hypothese() .setCode(code) .setValeur(valeur) .setSource(source) - .setDescription(description); + .setDescription(description) + .setNomOrganisation(nomOrganisation); } - public static HypotheseEntity entity(String code, String valeur, String source, String description) { + public static HypotheseEntity entity(String code, String valeur, String source, String description, String nomOrganisation) { return new HypotheseEntity() .setCode(code) .setValeur(valeur) .setSource(source) - .setDescription(description); + .setDescription(description) + .setNomOrganisation(nomOrganisation); } - public static HypotheseIdDTO idDTO(String code) { + public static HypotheseIdDTO idDTO(String code, String nomOrganisation) { return new HypotheseIdDTO() - .setCode(code); + .setCode(code) + .setNomOrganisation(nomOrganisation); } - public static HypotheseId idDomain(String code) { + public static HypotheseId idDomain(String code, String nomOrganisation) { return new HypotheseId() - .setCode(code); + .setCode(code) + .setNomOrganisation(nomOrganisation); } - public static HypotheseIdEntity idEntity(String code) { + public static HypotheseIdEntity idEntity(String code, String nomOrganisation) { return new HypotheseIdEntity() - .setCode(code); + .setCode(code) + .setNomOrganisation(nomOrganisation); } } @@ -146,7 +149,7 @@ public class TestDataFactory { } public static class TypeItemFactory { - public static TypeItemDTO dto(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut) { + public static TypeItemDTO dto(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut, String nomOrganisation) { return TypeItemDTO.builder() .type(type) .categorie(categorie) @@ -156,10 +159,11 @@ public class TestDataFactory { .source(source) .commentaire(commentaire) .refItemParDefaut(refItemParDefaut) + .nomOrganisation(nomOrganisation) .build(); } - public static TypeItem domain(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut) { + public static TypeItem domain(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut, String nomOrganisation) { return TypeItem.builder() .type(type) .categorie(categorie) @@ -169,11 +173,30 @@ public class TestDataFactory { .source(source) .commentaire(commentaire) .refItemParDefaut(refItemParDefaut) + .nomOrganisation(nomOrganisation) .build(); } - public static TypeItemEntity entity(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut) { - return new TypeItemEntity(type, categorie, estUnServeur, commentaire, dureeVieDefaut, refHypothese, source, refItemParDefaut); + public static TypeItemEntity entity(String type, String categorie, boolean estUnServeur, String commentaire, Double dureeVieDefaut, String refHypothese, String source, String refItemParDefaut, String nomOrganisation) { + return new TypeItemEntity(type, nomOrganisation, categorie, estUnServeur, commentaire, dureeVieDefaut, refHypothese, source, refItemParDefaut); + } + + public static TypeItemIdDTO idDTO(String type, String nomOrganisation) { + return new TypeItemIdDTO() + .setType(type) + .setNomOrganisation(nomOrganisation); + } + + public static TypeItemId idDomain(String type, String nomOrganisation) { + return new TypeItemId() + .setType(type) + .setNomOrganisation(nomOrganisation); + } + + public static TypeItemIdEntity idEntity(String type, String nomOrganisation) { + return new TypeItemIdEntity() + .setType(type) + .setNomOrganisation(nomOrganisation); } } @@ -260,7 +283,7 @@ public class TestDataFactory { public static class FacteurCaracterisationFactory { - public static FacteurCaracterisationDTO dto(String nom, String etape, String critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source) { + public static FacteurCaracterisationDTO dto(String nom, String etape, String critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source, String nomOrganisation) { return new FacteurCaracterisationDTO( nom, etape, @@ -273,11 +296,12 @@ public class TestDataFactory { localisation, valeur, unite, - source + source, + nomOrganisation ); } - public static FacteurCaracterisation domain(String nom, Etape etape, Critere critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source) { + public static FacteurCaracterisation domain(String nom, Etape etape, Critere critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source, String nomOrganisation) { return new FacteurCaracterisation() .setNom(nom) .setEtape(etape.getCode()) @@ -290,10 +314,11 @@ public class TestDataFactory { .setLocalisation(localisation) .setValeur(valeur) .setUnite(unite) - .setSource(source); + .setSource(source) + .setNomOrganisation(nomOrganisation); } - public static FacteurCaracterisationEntity entity(String nom, EtapeEntity etape, CritereEntity critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source) { + public static FacteurCaracterisationEntity entity(String nom, EtapeEntity etape, CritereEntity critere, String description, String niveau, String tiers, String categorie, Double consoElecMoyenne, String localisation, Double valeur, String unite, String source, String nomOrganisation) { return new FacteurCaracterisationEntity() .setNom(nom) .setEtape(etape.getCode()) @@ -306,23 +331,26 @@ public class TestDataFactory { .setLocalisation(localisation) .setValeur(valeur) .setUnite(unite) - .setSource(source); + .setSource(source) + .setNomOrganisation(nomOrganisation); } - public static FacteurCaracterisationIdDTO idDTO(String nom, String etapeIdDTO, String critereId) { + public static FacteurCaracterisationIdDTO idDTO(String nom, String etapeIdDTO, String critereId, String nomOrganisation) { return FacteurCaracterisationIdDTO .builder() .nom(nom) .etape(etapeIdDTO) .critere(critereId) + .nomOrganisation(nomOrganisation) .build(); } - public static FacteurCaracterisationId idDomain(String nom, String etapeId, String critereId) { + public static FacteurCaracterisationId idDomain(String nom, String etapeId, String critereId, String nomOrganisation) { return new FacteurCaracterisationId() .setNom(nom) .setEtape(etapeId) - .setCritere(critereId); + .setCritere(critereId) + .setNomOrganisation(nomOrganisation); } @@ -398,24 +426,45 @@ public class TestDataFactory { } public static class CorrespondanceRefEquipementFactory { - public static CorrespondanceRefEquipementDTO dto(String modeleSource, String refEquipementCible) { + public static CorrespondanceRefEquipementDTO dto(String modeleSource, String refEquipementCible, String nomOrganisation) { return CorrespondanceRefEquipementDTO.builder() .modeleEquipementSource(modeleSource) .refEquipementCible(refEquipementCible) + .nomOrganisation(nomOrganisation) .build(); } - public static CorrespondanceRefEquipement domain(String modeleSource, String refEquipementCible) { + public static CorrespondanceRefEquipement domain(String modeleSource, String refEquipementCible, String nomOrganisation) { return CorrespondanceRefEquipement.builder() .modeleEquipementSource(modeleSource) .refEquipementCible(refEquipementCible) + .nomOrganisation(nomOrganisation) .build(); } - public static CorrespondanceRefEquipementEntity entity(String modeleSource, String refEquipementCible) { + public static CorrespondanceRefEquipementEntity entity(String modeleSource, String refEquipementCible, String nomOrganisation) { return new CorrespondanceRefEquipementEntity() .setModeleEquipementSource(modeleSource) - .setRefEquipementCible(refEquipementCible); + .setRefEquipementCible(refEquipementCible) + .setNomOrganisation(nomOrganisation); + } + + public static CorrespondanceRefEquipementIdDTO idDTO(String modeleSource, String nomOrganisation) { + return new CorrespondanceRefEquipementIdDTO() + .setModeleEquipementSource(modeleSource) + .setNomOrganisation(nomOrganisation); + } + + public static CorrespondanceRefEquipementId idDomain(String modeleSource, String nomOrganisation) { + return new CorrespondanceRefEquipementId() + .setModeleEquipementSource(modeleSource) + .setNomOrganisation(nomOrganisation); + } + + public static CorrespondanceRefEquipementIdEntity idEntity(String modeleSource, String nomOrganisation) { + return new CorrespondanceRefEquipementIdEntity() + .setModeleEquipementSource(modeleSource) + .setNomOrganisation(nomOrganisation); } } } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportServiceTest.java index cdc55bbdc8d15f737d8b2734a6846d7fba4ef0dc..123768ae18522a44943db89c2395ca7534d7ebd5 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/FacteurCaracterisationCsvExportServiceTest.java @@ -53,13 +53,13 @@ public class FacteurCaracterisationCsvExportServiceTest { TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), "description", Constants.EQUIPEMENT_NIVEAU, "tiers", "Monitor", 0.01, "France", 0.02, "kgCO2e", - "NegaOctet"), + "NegaOctet", "ADEO"), TestDataFactory.FacteurCaracterisationFactory.entity( "Ecran 27 pouces", TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), "description", Constants.EQUIPEMENT_NIVEAU, "tiers", "Monitor", 0.01, "France", 0.02, "kgCO2e", - "NegaOctet") + "NegaOctet", "ADEO") ); when(repository.findAll()).thenReturn(entities); @@ -73,7 +73,7 @@ public class FacteurCaracterisationCsvExportServiceTest { TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), "description", Constants.EQUIPEMENT_NIVEAU, "tiers", "Monitor", 0.01, "France", 0.02, "kgCO2e", - "NegaOctet"); + "NegaOctet", "ADEO"); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(340); @@ -82,7 +82,7 @@ public class FacteurCaracterisationCsvExportServiceTest { Mockito.verify(csvPrinter, times(1)).printRecord(entity.getNom(), entity.getEtape(), entity.getCritere(), entity.getDescription(), entity.getNiveau(), entity.getTiers(), entity.getCategorie(), df.format(entity.getConsoElecMoyenne()), entity.getLocalisation(), df.format(entity.getValeur()), - entity.getUnite(), entity.getSource()); + entity.getUnite(), entity.getSource(), entity.getNomOrganisation()); } @Test @@ -92,7 +92,7 @@ public class FacteurCaracterisationCsvExportServiceTest { TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), "description", Constants.EQUIPEMENT_NIVEAU, "tiers", "Monitor", 0.01, "France", 0.02, "kgCO2e", - "NegaOctet"); + "NegaOctet", "ADEO"); assertDoesNotThrow(() -> exportService.logRecordError(entity, new Exception("Test"))); } @@ -116,7 +116,7 @@ public class FacteurCaracterisationCsvExportServiceTest { TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), "description", Constants.EQUIPEMENT_NIVEAU, "tiers", "Monitor", 0.01, "France", 0.02, "kgCO2e", - "NegaOctet") + "NegaOctet", "ADEO") ); when(repository.findAll()).thenReturn(entities); StringWriter stringWriter = new StringWriter(); @@ -127,8 +127,8 @@ public class FacteurCaracterisationCsvExportServiceTest { // Then String result = stringWriter.toString(); assertEquals( - "nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source\r\n" + - "Ecran 27 pouces;DISTRIBUTION;Changement climatique;description;2-Equipement;tiers;Monitor;0.01;France;0.02;kgCO2e;NegaOctet\r\n", + "nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source;nomOrganisation\r\n" + + "Ecran 27 pouces;DISTRIBUTION;Changement climatique;description;2-Equipement;tiers;Monitor;0.01;France;0.02;kgCO2e;NegaOctet;ADEO\r\n", result ); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportServiceTest.java index 0e8a555dd124edf043feb6d085b81da0056d5524..6e8449b9ce009c5f9a7ecb5fe0578deb0faa5d29 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/HypotheseCsvExportServiceTest.java @@ -44,8 +44,8 @@ class HypotheseCsvExportServiceTest { @Test void getObjectsToWriteShouldReturnRepositoryFindAll() { var entities = List.of( - TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description"), - TestDataFactory.HypotheseFactory.entity("clé2", "1.0", "Source", "exemple de description") + TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description", "ADEO"), + TestDataFactory.HypotheseFactory.entity("clé2", "1.0", "Source", "exemple de description", "ADEO") ); when(repository.findAll()).thenReturn(entities); @@ -54,16 +54,16 @@ class HypotheseCsvExportServiceTest { @Test void printRecordShouldUseEntityAttributes() throws IOException { - var entity = TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description"); + var entity = TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description", "ADEO"); assertDoesNotThrow(() -> exportService.printRecord(csvPrinter, entity)); - Mockito.verify(csvPrinter, times(1)).printRecord(entity.getCode(), entity.getValeur(), entity.getSource(), entity.getDescription()); + Mockito.verify(csvPrinter, times(1)).printRecord(entity.getCode(), entity.getValeur(), entity.getSource(), entity.getDescription(), entity.getNomOrganisation()); } @Test void logRecordErrorShouldLogSpecificErrorForRecord() { - var entity = TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description"); + var entity = TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description", "ADEO"); assertDoesNotThrow(() -> exportService.logRecordError(entity, new Exception("Test"))); } @@ -82,7 +82,7 @@ class HypotheseCsvExportServiceTest { void writeToCsvShouldReturnCSV() { // given var entities = List.of( - TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description") + TestDataFactory.HypotheseFactory.entity("clé", "0.0", "Source", "exemple de description", "ADEO") ); when(repository.findAll()).thenReturn(entities); StringWriter stringWriter = new StringWriter(); @@ -93,7 +93,7 @@ class HypotheseCsvExportServiceTest { // Then String result = stringWriter.toString(); assertEquals( - "cle;valeur;source;description\r\nclé;0.0;Source;exemple de description\r\n", + "cle;valeur;source;description;nomOrganisation\r\nclé;0.0;Source;exemple de description;ADEO\r\n", result ); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactEquipementCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactEquipementCsvExportServiceTest.java index 175cfa440807c53da57d931ecbfe13d89a4ec4d2..432004cc749e29178572fa7de798e84e6f43eb1a 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactEquipementCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactEquipementCsvExportServiceTest.java @@ -58,12 +58,12 @@ class ImpactEquipementCsvExportServiceTest { TestDataFactory.FacteurCaracterisationFactory.entity("Laptop", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ), TestDataFactory.FacteurCaracterisationFactory.entity("Ecran", TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.01, "", 0.002, "", "" + "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.01, "", 0.002, "", "", "ADEO" ) ); } @@ -88,7 +88,7 @@ class ImpactEquipementCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Laptop", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); @@ -109,7 +109,7 @@ class ImpactEquipementCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Laptop", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.EQUIPEMENT_NIVEAU, "", "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ); assertDoesNotThrow(() -> exportService.logRecordError(equipementMapper.toImpactEquipement(facteurCaracterisationMapper.toDomain(entity)), new Exception("Test"))); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactMixElectriqueCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactMixElectriqueCsvExportServiceTest.java index 2ef28e593a5d4b3582cbdfca2e4cca475bdc0c3e..10c97b4e3c5bad869f20d5fa8d6f7ffb0afa86be 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactMixElectriqueCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactMixElectriqueCsvExportServiceTest.java @@ -57,12 +57,12 @@ class ImpactMixElectriqueCsvExportServiceTest { TestDataFactory.FacteurCaracterisationFactory.entity("Electricity mix FR", TestDataFactory.EtapeFactory.entity("FABRICATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet" + "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet", "ADEO" ), TestDataFactory.FacteurCaracterisationFactory.entity("Electricity mix ES", TestDataFactory.EtapeFactory.entity("FABRICATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "Espagne", 0.1, "", "" + "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "Espagne", 0.1, "", "", "ADEO" ) ); } @@ -86,7 +86,7 @@ class ImpactMixElectriqueCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Electricity mix FR", TestDataFactory.EtapeFactory.entity("FABRICATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet" + "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet", "ADEO" ); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); @@ -107,7 +107,7 @@ class ImpactMixElectriqueCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Electricity mix FR", TestDataFactory.EtapeFactory.entity("FABRICATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet" + "", Constants.MIXELEC_NIVEAU, "", Constants.MIXELEC_CATEGORIE, 0.0, "France", 0.2, "", "NegaOctet", "ADEO" ); assertDoesNotThrow(() -> exportService.logRecordError(mixElectriqueMapper.toMixElectrique(facteurCaracterisationMapper.toDomain(entity)), new Exception("Test"))); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactReseauCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactReseauCsvExportServiceTest.java index 008e8f047ef5eceaa7df61d5b7746b506b66caf1..ca527e3a573899dd052a6f28bb16fb1f7994df0e 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactReseauCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/ImpactReseauCsvExportServiceTest.java @@ -56,12 +56,12 @@ class ImpactReseauCsvExportServiceTest { TestDataFactory.FacteurCaracterisationFactory.entity("Fixed-line network", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ), TestDataFactory.FacteurCaracterisationFactory.entity("Mobile network", TestDataFactory.EtapeFactory.entity("DISTRIBUTION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.01, "", 0.002, "", "" + "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.01, "", 0.002, "", "", "ADEO" ) ); } @@ -87,7 +87,7 @@ class ImpactReseauCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Fixed-line network", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); @@ -106,7 +106,7 @@ class ImpactReseauCsvExportServiceTest { var entity = TestDataFactory.FacteurCaracterisationFactory.entity("Fixed-line network", TestDataFactory.EtapeFactory.entity("UTILISATION", ""), TestDataFactory.CritereFactory.entity("Changement climatique", "", ""), - "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet" + "", Constants.RESEAU_NIVEAU, Constants.RESEAU_TIERS, "Ecran", 0.1, "", 0.2, "", "NegaOctet", "ADEO" ); assertDoesNotThrow(() -> exportService.logRecordError(reseauMapper.toImpactReseau(facteurCaracterisationMapper.toDomain(entity)), new Exception("Test"))); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeEquipementCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeEquipementCsvExportServiceTest.java index 434e3a8488c6ebbf4f8b2d798524cebea8864b8e..22131ab99ce6c01eb00f9b218ba27758c2d3f359 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeEquipementCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeEquipementCsvExportServiceTest.java @@ -56,15 +56,15 @@ class TypeEquipementCsvExportServiceTest { private List<TypeItemEntity> typeItemEntities() { return List.of( TestDataFactory.TypeItemFactory.entity( - "Serveur", CATEGORIE_EQUIPEMENT_PHYSIQUE, true, null, 6.0, null, "", "Test"), + "Serveur", CATEGORIE_EQUIPEMENT_PHYSIQUE, true, null, 6.0, null, "", "Test", null), TestDataFactory.TypeItemFactory.entity( "Communication Device", CATEGORIE_EQUIPEMENT_PHYSIQUE, false, "commentaires", 4.0, null, "SSG", - "refItem") + "refItem", null) ); } private TypeItemEntity typeItemEntity() { - return TestDataFactory.TypeItemFactory.entity("Serveur", CATEGORIE_EQUIPEMENT_PHYSIQUE, true, null, 6.0, null, "", "Test"); + return TestDataFactory.TypeItemFactory.entity("Serveur", CATEGORIE_EQUIPEMENT_PHYSIQUE, true, null, 6.0, null, "", "Test", null); } @Test @@ -85,7 +85,7 @@ class TypeEquipementCsvExportServiceTest { void printRecordShouldUseEntityAttributes() throws IOException { var entity = TestDataFactory.TypeItemFactory.entity( "Serveur", null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut"); + 6.0, null, "NegaOctet", "serveur_par_defaut", null); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(340); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportServiceTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportServiceTest.java index 1d800d1810b2c4c2e51bcb2e86775469ec32cac2..553edf384c1cfc4cbf2281d4c3506814c11aa9ff 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportServiceTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/adapter/export/TypeItemCsvExportServiceTest.java @@ -50,10 +50,10 @@ class TypeItemCsvExportServiceTest { var entities = List.of( TestDataFactory.TypeItemFactory.entity( "Serveur", null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut"), + 6.0, null, "NegaOctet", "serveur_par_defaut", null), TestDataFactory.TypeItemFactory.entity( "deplacement voiture hybride", "deplacement_hybride", false, - "Exemple d'opération non it", 50.0, "CONSO_MOYENNE_VOITURE_HYBRIDE", "SSG", "deplacement_voiture_hybride" + "Exemple d'opération non it", 50.0, "CONSO_MOYENNE_VOITURE_HYBRIDE", "SSG", "deplacement_voiture_hybride", null ) ); when(repository.findAll()).thenReturn(entities); @@ -65,7 +65,7 @@ class TypeItemCsvExportServiceTest { void printRecordShouldUseEntityAttributes() throws IOException { var entity = TestDataFactory.TypeItemFactory.entity( "Serveur", null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut"); + 6.0, null, "NegaOctet", "serveur_par_defaut", null); DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); df.setMaximumFractionDigits(340); @@ -79,14 +79,15 @@ class TypeItemCsvExportServiceTest { df.format(entity.getDureeVieDefaut()), entity.getRefHypothese(), entity.getSource(), - entity.getRefItemParDefaut()); + entity.getRefItemParDefaut(), + entity.getNomOrganisation()); } @Test void logRecordErrorShouldLogSpecificErrorForRecord() { var entity = TestDataFactory.TypeItemFactory.entity( "Serveur", null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut"); + 6.0, null, "NegaOctet", "serveur_par_defaut", null); assertDoesNotThrow(() -> exportService.logRecordError(entity, new Exception("Test"))); } @@ -107,7 +108,7 @@ class TypeItemCsvExportServiceTest { var entities = List.of( TestDataFactory.TypeItemFactory.entity( "Serveur", null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut") + 6.0, null, "NegaOctet", "serveur_par_defaut", "ADEO") ); when(repository.findAll()).thenReturn(entities); StringWriter stringWriter = new StringWriter(); @@ -119,8 +120,8 @@ class TypeItemCsvExportServiceTest { String result = stringWriter.toString(); assertEquals( """ - type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut - Serveur;;true;Exemple de serveur basique;6;;NegaOctet;serveur_par_defaut + type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut;nomOrganisation + Serveur;;true;Exemple de serveur basique;6;;NegaOctet;serveur_par_defaut;ADEO """, result.replaceAll("\r\n", "\n") ); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/csv/ImportCSVReferentielPortTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/csv/ImportCSVReferentielPortTest.java index 1b1993fd422cb9a866b5f30bad4c276012b0c45b..848a0ac060983eeabb77bb02dde0d3c35237dc2f 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/csv/ImportCSVReferentielPortTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/csv/ImportCSVReferentielPortTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.mockito.MockitoAnnotations; import org.mte.numecoeval.referentiel.domain.data.ResultatImport; -import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.ports.input.ImportCSVReferentielPort; import java.io.InputStream; @@ -20,10 +19,6 @@ class ImportCSVReferentielPortTest { CSVRecord csvRecord; ImportCSVReferentielPort csvReferentielPort = new ImportCSVReferentielPort() { - @Override - public void checkCSVRecord(CSVRecord csvRecord) throws ReferentielException { - // Nothing to do - } @Override public ResultatImport importCSV(InputStream csvInputStream) { diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/CorrespondanceRefEquipementJpaAdapterTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/CorrespondanceRefEquipementJpaAdapterTest.java index 3d9f08d295565bd6f7fec8f19509d2252292d6f2..8832a067ec9e23dc036fd219431e23383c892bb7 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/CorrespondanceRefEquipementJpaAdapterTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/CorrespondanceRefEquipementJpaAdapterTest.java @@ -10,6 +10,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.CorrespondanceRefEquipement; +import org.mte.numecoeval.referentiel.domain.model.id.CorrespondanceRefEquipementId; import org.mte.numecoeval.referentiel.infrastructure.jpa.adapter.CorrespondanceRefEquipementJpaAdapter; import org.mte.numecoeval.referentiel.infrastructure.jpa.entity.CorrespondanceRefEquipementEntity; import org.mte.numecoeval.referentiel.infrastructure.jpa.repository.CorrespondanceRefEquipementRepository; @@ -28,7 +29,7 @@ class CorrespondanceRefEquipementJpaAdapterTest { private CorrespondanceRefEquipementJpaAdapter jpaAdapter; @Mock - CorrespondanceRefEquipementRepository hypotheseRepository; + CorrespondanceRefEquipementRepository repository; CorrespondanceRefEquipementMapper mapper = new CorrespondanceRefEquipementMapperImpl(); @@ -43,11 +44,13 @@ class CorrespondanceRefEquipementJpaAdapterTest { var expectedEntity = new CorrespondanceRefEquipementEntity() .setModeleEquipementSource("source") .setRefEquipementCible("cible"); - var wantedId = "source"; + var wantedId = new CorrespondanceRefEquipementId() + .setModeleEquipementSource(expectedEntity.getModeleEquipementSource()); + var wantedEntityId = mapper.toEntityId(wantedId); - Mockito.when(hypotheseRepository.findById(wantedId)).thenReturn(Optional.of(expectedEntity)); + Mockito.when(repository.findById(wantedEntityId)).thenReturn(Optional.of(expectedEntity)); - var expectedDomain = assertDoesNotThrow( () -> jpaAdapter.get(wantedId) ); + var expectedDomain = assertDoesNotThrow(() -> jpaAdapter.get(wantedId)); assertEquals(expectedEntity.getModeleEquipementSource(), expectedDomain.getModeleEquipementSource()); assertEquals(expectedEntity.getRefEquipementCible(), expectedDomain.getRefEquipementCible()); @@ -55,38 +58,35 @@ class CorrespondanceRefEquipementJpaAdapterTest { @Test void get_shouldThrowException() { - var wantedId = "notExisting"; - - Mockito.when(hypotheseRepository.findById(wantedId)).thenReturn(Optional.empty()); - - ReferentielException expectedException = assertThrows(ReferentielException.class, () -> jpaAdapter.get(wantedId) ); + var expectedEntity = new CorrespondanceRefEquipementEntity() + .setModeleEquipementSource("source") + .setRefEquipementCible("cible") + .setNomOrganisation("ADEO"); - assertEquals("Correspondance au RefEquipement "+ wantedId +" non trouvé",expectedException.getMessage()); - } + var wantedId = new CorrespondanceRefEquipementId() + .setModeleEquipementSource(expectedEntity.getModeleEquipementSource()); - @Test - void get_withNullValueShouldThrowException() { - String wantedId = null; + var wantedEntityId = mapper.toEntityId(wantedId); - Mockito.when(hypotheseRepository.findById(wantedId)).thenReturn(Optional.empty()); + Mockito.when(repository.findById(wantedEntityId)).thenReturn(Optional.empty()); - ReferentielException expectedException = assertThrows(ReferentielException.class, () -> jpaAdapter.get(wantedId) ); + ReferentielException expectedException = assertThrows(ReferentielException.class, () -> jpaAdapter.get(wantedId)); - assertEquals("Correspondance au RefEquipement (id null) non trouvé",expectedException.getMessage()); + assertEquals("Correspondance au RefEquipement non trouvé pour l'id " + wantedId, expectedException.getMessage()); } @Test void purge_shouldCallDeleteAll() { jpaAdapter.purge(); - Mockito.verify(hypotheseRepository, Mockito.times(1)).deleteAll(); + Mockito.verify(repository, Mockito.times(1)).deleteAll(); } @Test void getAll_shouldCallfindAll() { jpaAdapter.getAll(); - Mockito.verify(hypotheseRepository, Mockito.times(1)).findAll(); + Mockito.verify(repository, Mockito.times(1)).findAll(); } @Test @@ -99,7 +99,7 @@ class CorrespondanceRefEquipementJpaAdapterTest { assertDoesNotThrow(() -> jpaAdapter.saveAll(Collections.singletonList(domainToSave))); - Mockito.verify(hypotheseRepository, Mockito.times(1)).saveAll(Collections.singletonList(entityToSave)); + Mockito.verify(repository, Mockito.times(1)).saveAll(Collections.singletonList(entityToSave)); } @Test @@ -110,9 +110,9 @@ class CorrespondanceRefEquipementJpaAdapterTest { .build(); var expectedEntity = mapper.toEntities(Collections.singletonList(wantedDomain)).get(0); - Mockito.when(hypotheseRepository.save(expectedEntity)).thenReturn(expectedEntity); + Mockito.when(repository.save(expectedEntity)).thenReturn(expectedEntity); - var expectedDomain = assertDoesNotThrow( () -> jpaAdapter.save(wantedDomain) ); + var expectedDomain = assertDoesNotThrow(() -> jpaAdapter.save(wantedDomain)); assertEquals(expectedEntity.getModeleEquipementSource(), expectedDomain.getModeleEquipementSource()); assertEquals(expectedEntity.getRefEquipementCible(), expectedDomain.getRefEquipementCible()); @@ -121,7 +121,7 @@ class CorrespondanceRefEquipementJpaAdapterTest { @ParameterizedTest @NullSource void save_shouldSaveAndReturnNull(CorrespondanceRefEquipement nullValue) { - var expectedDomain = assertDoesNotThrow( () -> jpaAdapter.save(nullValue) ); + var expectedDomain = assertDoesNotThrow(() -> jpaAdapter.save(nullValue)); assertNull(expectedDomain); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/HypotheseJpaAdapterTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/HypotheseJpaAdapterTest.java index c76fc171cfcf23d62a1e3bab54e1df86b7d1bf30..85070b608877234bafb7d24e55ecafb8117b072c 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/HypotheseJpaAdapterTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/jpa/HypotheseJpaAdapterTest.java @@ -52,7 +52,7 @@ class HypotheseJpaAdapterTest { Mockito.when(hypotheseRepository.findById(wantedEntityId)).thenReturn(Optional.of(expectedEntity)); - var expectedDomain = assertDoesNotThrow( () -> hypotheseJpaAdapter.get(wantedId) ); + var expectedDomain = assertDoesNotThrow(() -> hypotheseJpaAdapter.get(wantedId)); Assertions.assertEquals(expectedEntity.getCode(), expectedDomain.getCode()); Assertions.assertEquals(expectedEntity.getValeur(), expectedDomain.getValeur()); @@ -71,9 +71,9 @@ class HypotheseJpaAdapterTest { Mockito.when(hypotheseRepository.findById(wantedEntityId)).thenReturn(Optional.empty()); - ReferentielException expectedException = assertThrows(ReferentielException.class, () -> hypotheseJpaAdapter.get(wantedId) ); + ReferentielException expectedException = assertThrows(ReferentielException.class, () -> hypotheseJpaAdapter.get(wantedId)); - assertEquals("Hypothèse non trouvé",expectedException.getMessage()); + assertEquals("Hypothèse non trouvée", expectedException.getMessage()); } @Test @@ -113,7 +113,7 @@ class HypotheseJpaAdapterTest { Mockito.when(hypotheseRepository.save(expectedEntity)).thenReturn(expectedEntity); - var expectedDomain = assertDoesNotThrow( () -> hypotheseJpaAdapter.save(wantedDomain) ); + var expectedDomain = assertDoesNotThrow(() -> hypotheseJpaAdapter.save(wantedDomain)); Assertions.assertEquals(wantedDomain.getCode(), expectedDomain.getCode()); Assertions.assertEquals(wantedDomain.getValeur(), expectedDomain.getValeur()); @@ -123,7 +123,7 @@ class HypotheseJpaAdapterTest { @ParameterizedTest @NullSource void save_shouldSaveAndReturnNull(Hypothese nullValue) { - var expectedDomain = assertDoesNotThrow( () -> hypotheseJpaAdapter.save(nullValue) ); + var expectedDomain = assertDoesNotThrow(() -> hypotheseJpaAdapter.save(nullValue)); assertNull(expectedDomain); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImplTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImplTest.java index c3ac93f29b05b7686c65425b76321af816b81bde..b99fc31e38c03b6c6aec580f2179799e501c287b 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImplTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/correspondance/ReferentielCorrespondanceRefEquipementRestApiImplTest.java @@ -2,9 +2,10 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.controller.corresp import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.infrastructure.adapter.export.CorrespondanceRefEquipemenetCsvExportService; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.CorrespondanceRefEquipementDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.CorrespondanceRefEquipementIdDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.facade.CorrespondanceRefEquipementFacade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -37,37 +38,37 @@ class ReferentielCorrespondanceRefEquipementRestApiImplTest { @Test void get_shouldCallFacadeGetAndReturnCorrespondingDTO() throws ReferentielException { - var wantedId = "modeleSource"; - CorrespondanceRefEquipementDTO expectedDto = CorrespondanceRefEquipementDTO.builder() - .modeleEquipementSource(wantedId) - .refEquipementCible("test") - .build(); - when(referentielFacade.get(wantedId)).thenReturn(expectedDto); - CorrespondanceRefEquipementDTO resultDto = referentielRestApi.get(wantedId); - assertSame(expectedDto, resultDto); - verify(referentielFacade).get(wantedId); + String modele = "modeleSource"; + String nomOrganisation = "nomOrga"; + CorrespondanceRefEquipementIdDTO idDTO = new CorrespondanceRefEquipementIdDTO().setModeleEquipementSource(modele).setNomOrganisation(nomOrganisation); + var expectedDTO = CorrespondanceRefEquipementDTO.builder().modeleEquipementSource(modele).nomOrganisation(nomOrganisation).refEquipementCible("cible").build(); + + when(referentielFacade.get(idDTO)).thenReturn(expectedDTO); + var receivedDTO = referentielRestApi.get(modele, nomOrganisation); + assertSame(expectedDTO, receivedDTO); + verify(referentielFacade).get(idDTO); } @Test - void importCSV_shouldCallPurgeAndAddAll() throws IOException, ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8))); - verify(referentielFacade).purgeAndAddAll(any()); + void importCSV_shouldCallPurgeByOrganisationAndAddAll() throws IOException, ReferentielException { + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "nomOrga"); + verify(referentielFacade).purgeByOrganisationAndAddAll(any(), eq("nomOrga")); } @Test void importCSV_whenEmptyFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); MockMultipartFile file = new MockMultipartFile("Name", (byte[]) null); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file)); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file, "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } @Test void importCSV_whenNullFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null)); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null, "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImplTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImplTest.java index 8fd5ec7e0923d0e9f2f4a95bb9ca47ef7020c672..89ec9b5257f2039d6193e9c079b01cbb529d5c51 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImplTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/facteurcaracterisation/ReferentielFacteurCaracterisationRestApiImplTest.java @@ -41,69 +41,72 @@ public class ReferentielFacteurCaracterisationRestApiImplTest { @Test void get_shouldCallFacadeGetAndReturnMatchingDTO() throws ReferentielException { String nom = "Ordinateur Portable"; + String nomOrganisation = "nomOrga"; String nomCritere = "Changement Climatique"; String codeEtapeACV = "UTILISATION"; var fc = FacteurCaracterisationDTO.builder() .nom(nom) .etape(codeEtapeACV) + .nomOrganisation(nomOrganisation) .critere(nomCritere) .niveau(Constants.EQUIPEMENT_NIVEAU) .valeur(1.0).build(); var expectedDTO = List.of(fc); - when(referentielFacade.getByFilters(nomCritere, codeEtapeACV, nom, null, null)).thenReturn(expectedDTO); + when(referentielFacade.getByFilters(nomCritere, codeEtapeACV, nom, null, null, nomOrganisation)).thenReturn(expectedDTO); - var actualDTO = referentielRestApi.get(nomCritere, codeEtapeACV, nom, null, null); + var actualDTO = referentielRestApi.get(nomCritere, codeEtapeACV, nom, null, null, nomOrganisation); assertSame(expectedDTO, actualDTO); - verify(referentielFacade).getByFilters(nomCritere, codeEtapeACV, nom, null, null); + verify(referentielFacade).getByFilters(nomCritere, codeEtapeACV, nom, null, null, nomOrganisation); } @Test void get_whenNotFound_thenShouldThrowReferentielException() throws ReferentielException { String nom = "Ordinateur Portable"; + String nomOrganisation = "nomOrga"; String nomCritere = "Changement Climatique"; String codeEtapeACV = "UTILISATION"; - when(referentielFacade.getByFilters(nomCritere, codeEtapeACV, nom, null, null)).thenThrow(new ReferentielException("Impact Equipement non trouvé")); + when(referentielFacade.getByFilters(nomCritere, codeEtapeACV, nom, null, null, nomOrganisation)).thenThrow(new ReferentielException("Impact Equipement non trouvé")); - var exception = assertThrows(ReferentielException.class, () -> referentielRestApi.get(nomCritere, codeEtapeACV, nom, null, null)); + var exception = assertThrows(ReferentielException.class, () -> referentielRestApi.get(nomCritere, codeEtapeACV, nom, null, null, nomOrganisation)); assertEquals("Impact Equipement non trouvé", exception.getMessage()); } @Test - void importCSV_shouldCallPurgeAndAddAll() throws IOException, ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "FULL"); - verify(referentielFacade).purgeAndAddAll(any()); + void importCSV_shouldCallPurgeByOrganisationAndAddAll() throws IOException, ReferentielException { + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "FULL", "nomOrga"); + verify(referentielFacade).purgeByOrganisationAndAddAll(any(), eq("nomOrga")); } @Test void importCSV_shouldCallUpsert() throws IOException, ReferentielException { - referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "DELTA"); + referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "DELTA", "nomOrga"); verify(referentielFacade).upsert(any()); } @Test void importCSV_withWrongModeShouldThrowException() throws IOException, ReferentielException { - var exception = assertThrows(ReferentielException.class, () -> referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "WRONG")); + var exception = assertThrows(ReferentielException.class, () -> referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "WRONG", "nomOrga")); assertEquals("Le mode d'import indiqué n'est pas valide", exception.getMessage()); } @Test void importCSV_whenEmptyFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); MockMultipartFile file = new MockMultipartFile("Name", (byte[]) null); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file, "FULL")); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file, "FULL", "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } @Test void importCSV_whenNullFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null, "FULL")); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null, "FULL", "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImplTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImplTest.java index 3afe264b8e77ffbc8ec048e80c7328f3988d187b..61ce5f6269b26f89a41a3eb0de251719deaf937c 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImplTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/hypothese/ReferentielHypotheseRestApiImplTest.java @@ -2,9 +2,9 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.controller.hypothe import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.infrastructure.adapter.export.HypotheseCsvExportService; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.HypotheseDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.HypotheseIdDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.facade.HypotheseFacade; import org.springframework.beans.factory.annotation.Autowired; @@ -38,46 +38,47 @@ class ReferentielHypotheseRestApiImplTest { @Test void get_shouldCallFacadeGetAndReturnMatchingDTO() throws ReferentielException { String cle = "cle"; - HypotheseIdDTO idDTO = new HypotheseIdDTO().setCode(cle); - var expectedDTO = HypotheseDTO.builder().code(cle).valeur("test").build(); - + String nomOrganisation = "nomOrga"; + HypotheseIdDTO idDTO = new HypotheseIdDTO().setCode(cle).setNomOrganisation(nomOrganisation); + var expectedDTO = HypotheseDTO.builder().code(cle).nomOrganisation(nomOrganisation).valeur("test").build(); when(referentielFacade.get(idDTO)).thenReturn(expectedDTO); - var receivedDTO = referentielRestApi.get(cle); - assertSame(receivedDTO, receivedDTO); + var receivedDTO = referentielRestApi.get(cle, nomOrganisation); + assertSame(expectedDTO, receivedDTO); verify(referentielFacade).get(idDTO); } @Test void get_whenNotFound_thenShouldThrowReferentielException() throws ReferentielException { String cle = "cle"; - HypotheseIdDTO idDTO = new HypotheseIdDTO().setCode(cle); + String nomOrganisation = "nomOrga"; + HypotheseIdDTO idDTO = new HypotheseIdDTO().setCode(cle).setNomOrganisation(nomOrganisation); - when(referentielFacade.get(idDTO)).thenThrow(new ReferentielException("Hypothèse non trouvé")); - var exception = assertThrows(ReferentielException.class,() -> referentielRestApi.get(cle)); - assertEquals("Hypothèse non trouvé", exception.getMessage()); + when(referentielFacade.get(idDTO)).thenThrow(new ReferentielException("Hypothèse non trouvée")); + var exception = assertThrows(ReferentielException.class, () -> referentielRestApi.get(cle, nomOrganisation)); + assertEquals("Hypothèse non trouvée", exception.getMessage()); } @Test - void importCSV_shouldCallPurgeAndAddAll() throws IOException, ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8))); - verify(referentielFacade).purgeAndAddAll(any()); + void importCSV_shouldCallPurgeByOrganisationAndAddAll() throws IOException, ReferentielException { + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "nomOrga"); + verify(referentielFacade).purgeByOrganisationAndAddAll(any(), eq("nomOrga")); } @Test void importCSV_whenEmptyFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); MockMultipartFile file = new MockMultipartFile("Name", (byte[]) null); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file)); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(file, "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } @Test void importCSV_whenNullFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); - ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null)); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); + ResponseStatusException responseStatusException = assertThrows(ResponseStatusException.class, () -> referentielRestApi.importCSV(null, "nomOrga")); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); assertEquals("Le fichier n'existe pas ou alors il est vide", responseStatusException.getReason()); } diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImplTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImplTest.java index 82f74fa2118fdf7dfba934ed9b30a58e8327ac55..710e738185cc14520166ee19b2da2e3e2ea3e072 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImplTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/controller/typeitem/ReferentielTypeItemRestApiImplTest.java @@ -3,9 +3,9 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.controller.typeite import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; -import org.mte.numecoeval.referentiel.factory.TestDataFactory; import org.mte.numecoeval.referentiel.infrastructure.adapter.export.TypeItemCsvExportService; import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.TypeItemDTO; +import org.mte.numecoeval.referentiel.infrastructure.restapi.dto.id.TypeItemIdDTO; import org.mte.numecoeval.referentiel.infrastructure.restapi.facade.TypeItemFacade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -51,35 +51,34 @@ class ReferentielTypeItemRestApiImplTest { @Test void getTypeItem_shouldCallFacadeGetAndReturnDTO() throws ReferentielException { - String expectedType = "Serveur"; - TypeItemDTO expectedDTO = TestDataFactory.TypeItemFactory.dto(expectedType, null, true, "Exemple de serveur basique", - 6.0, null, "NegaOctet", "serveur_par_defaut"); - when(referentielFacade.getTypeItemForType(expectedType)).thenReturn(expectedDTO); - - TypeItemDTO actualResponse = referentielRestApi.getTypeItem(expectedType); + String nomOrganisation = "nomOrga"; + TypeItemIdDTO idDTO = new TypeItemIdDTO().setType(expectedType).setNomOrganisation(nomOrganisation); + var expectedDTO = TypeItemDTO.builder().type(expectedType).nomOrganisation("nomOrga").source("NegaOctet").build(); + when(referentielFacade.getTypeItemForType(idDTO)).thenReturn(expectedDTO); + var receivedDTO = referentielRestApi.getTypeItem(expectedType, nomOrganisation); + assertSame(expectedDTO, receivedDTO); + verify(referentielFacade).getTypeItemForType(idDTO); - assertSame(expectedDTO, actualResponse); - verify(referentielFacade).getTypeItemForType(expectedType); } @Test - void importCSV_shouldCallPurgeAndAddAll() throws IOException, ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + void importCSV_shouldCallPurgeByOrganisationAndAddAll() throws IOException, ReferentielException { + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); - referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8))); + referentielRestApi.importCSV(new MockMultipartFile("Name", "AAAAAAAA".getBytes(StandardCharsets.UTF_8)), "nomOrga"); - verify(referentielFacade).purgeAndAddAll(any()); + verify(referentielFacade).purgeByOrganisationAndAddAll(any(), eq("nomOrga")); } @Test void importCSV_whenEmptyFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); MockMultipartFile file = new MockMultipartFile("Name", (byte[]) null); ResponseStatusException responseStatusException = assertThrows( ResponseStatusException.class, - () -> referentielRestApi.importCSV(file) + () -> referentielRestApi.importCSV(file, "nomOrga") ); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); @@ -88,11 +87,11 @@ class ReferentielTypeItemRestApiImplTest { @Test void importCSV_whenNullFileThenShouldThrowException() throws ReferentielException { - doNothing().when(referentielFacade).purgeAndAddAll(any()); + doNothing().when(referentielFacade).purgeByOrganisationAndAddAll(any(), any()); ResponseStatusException responseStatusException = assertThrows( ResponseStatusException.class, - () -> referentielRestApi.importCSV(null) + () -> referentielRestApi.importCSV(null, "nomOrga") ); assertEquals(HttpStatus.BAD_REQUEST, responseStatusException.getStatusCode()); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacadeTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacadeTest.java index b43464fbe9ee4533f4d3989e806e00cacea12b27..1bb9b7ae5ae9083815ab97729f584ba88ca7cb04 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacadeTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/CorrespondanceRefEquipementFacadeTest.java @@ -3,13 +3,10 @@ package org.mte.numecoeval.referentiel.infrastructure.restapi.facade; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.*; import org.mte.numecoeval.referentiel.domain.exception.ReferentielException; import org.mte.numecoeval.referentiel.domain.model.CorrespondanceRefEquipement; +import org.mte.numecoeval.referentiel.domain.model.id.CorrespondanceRefEquipementId; import org.mte.numecoeval.referentiel.domain.ports.output.ReferentielPersistencePort; import org.mte.numecoeval.referentiel.factory.TestDataFactory; import org.mte.numecoeval.referentiel.infrastructure.mapper.CorrespondanceRefEquipementMapper; @@ -27,7 +24,7 @@ class CorrespondanceRefEquipementFacadeTest { CorrespondanceRefEquipementFacade facadeToTest; @Mock - private ReferentielPersistencePort<CorrespondanceRefEquipement, String> persistencePort; + private ReferentielPersistencePort<CorrespondanceRefEquipement, CorrespondanceRefEquipementId> persistencePort; private CorrespondanceRefEquipementMapper mapper = new CorrespondanceRefEquipementMapperImpl(); @@ -39,10 +36,9 @@ class CorrespondanceRefEquipementFacadeTest { @Test void get_shouldReturnMatchingDTO() throws ReferentielException { - var wantedDTOId = "modele"; - var expectedDomainID = "modele"; - var expectedDomain = TestDataFactory.CorrespondanceRefEquipementFactory.domain( - "modele", "refCible"); + var wantedDTOId = TestDataFactory.CorrespondanceRefEquipementFactory.idDTO("modeleSource", "ADEO"); + var expectedDomainID = TestDataFactory.CorrespondanceRefEquipementFactory.idDomain("modeleSource", "ADEO"); + var expectedDomain = TestDataFactory.CorrespondanceRefEquipementFactory.domain("modeleSource", "refCible", "ADEO"); Mockito.when(persistencePort.get(expectedDomainID)).thenReturn(expectedDomain); @@ -50,13 +46,14 @@ class CorrespondanceRefEquipementFacadeTest { assertEquals(expectedDomain.getModeleEquipementSource(), result.getModeleEquipementSource()); assertEquals(expectedDomain.getRefEquipementCible(), result.getRefEquipementCible()); + assertEquals(expectedDomain.getNomOrganisation(), result.getNomOrganisation()); } @Test void get_withNonMachingDTOShouldReturnNull() throws ReferentielException { - var wantedDTOId = "modele"; - var expectedDomainID = "modele"; + var wantedDTOId = TestDataFactory.CorrespondanceRefEquipementFactory.idDTO("modeleSource", "ADEO"); + var expectedDomainID = TestDataFactory.CorrespondanceRefEquipementFactory.idDomain("modeleSource", "ADEO"); Mockito.when(persistencePort.get(expectedDomainID)).thenReturn(null); var result = Assertions.assertDoesNotThrow(() -> facadeToTest.get(wantedDTOId)); @@ -67,9 +64,9 @@ class CorrespondanceRefEquipementFacadeTest { @Test void getAll_shouldReturnMatchingAllDTOs() throws ReferentielException { var expectedDomains = Arrays.asList( - TestDataFactory.CorrespondanceRefEquipementFactory.domain("modele", "refCible"), - TestDataFactory.CorrespondanceRefEquipementFactory.domain("modele2", "refCible") - ); + TestDataFactory.CorrespondanceRefEquipementFactory.domain("modele", "refCible", "ADEO"), + TestDataFactory.CorrespondanceRefEquipementFactory.domain("modele2", "refCible", "ADEO") + ); Mockito.when(persistencePort.getAll()).thenReturn(expectedDomains); @@ -79,20 +76,20 @@ class CorrespondanceRefEquipementFacadeTest { } @Test - void purgeAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { + void purgeByOrganisationAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { var dtosToSave = Arrays.asList( TestDataFactory.CorrespondanceRefEquipementFactory.dto( - "modele01", "refCible" + "modele01", "refCible", "ADEO" ), TestDataFactory.CorrespondanceRefEquipementFactory.dto( - "modele02", "refCible" + "modele02", "refCible", "ADEO" ) ); ArgumentCaptor<Collection<CorrespondanceRefEquipement>> valueCapture = ArgumentCaptor.forClass(Collection.class); - assertDoesNotThrow(() -> facadeToTest.purgeAndAddAll(dtosToSave)); + assertDoesNotThrow(() -> facadeToTest.purgeByOrganisationAndAddAll(dtosToSave, "ADEO")); - Mockito.verify(persistencePort, Mockito.times(1)).purge(); + Mockito.verify(persistencePort, Mockito.times(1)).purgeByOrganisation("ADEO"); Mockito.verify(persistencePort, Mockito.times(1)).saveAll(valueCapture.capture()); var expectedDomains = valueCapture.getValue(); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacadeTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacadeTest.java index 84ca5ec83bf97335b63feba5afd24d70fbe18984..aeba245e888ae7c4013291677f5cf755fadc9226 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacadeTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/FacteurCaracterisationFacadeTest.java @@ -38,19 +38,19 @@ public class FacteurCaracterisationFacadeTest { var wantedDTOId = TestDataFactory.FacteurCaracterisationFactory.idDTO( "Ecran 27 pouces", TestDataFactory.DEFAULT_ETAPE, - TestDataFactory.DEFAULT_CRITERE - + TestDataFactory.DEFAULT_CRITERE, + "ADEO" ); var expectedDomainID = TestDataFactory.FacteurCaracterisationFactory.idDomain( "Ecran 27 pouces", TestDataFactory.DEFAULT_ETAPE, - TestDataFactory.DEFAULT_CRITERE - + TestDataFactory.DEFAULT_CRITERE, + "ADEO" ); var expectedDomain = TestDataFactory.FacteurCaracterisationFactory.domain("Ecran 27 pouces", TestDataFactory.EtapeFactory.domain(TestDataFactory.DEFAULT_ETAPE, "Test"), TestDataFactory.CritereFactory.domain(TestDataFactory.DEFAULT_CRITERE, TestDataFactory.DEFAULT_UNITE, TestDataFactory.DEFAULT_CRITERE), - "", Constants.EQUIPEMENT_NIVEAU, "", "", 0.01, "France", 0.02, "", "NegaOctet" + "", Constants.EQUIPEMENT_NIVEAU, "", "", 0.01, "France", 0.02, "", "NegaOctet", "ADEO" ); Mockito.when(persistencePort.get(expectedDomainID)).thenReturn(expectedDomain); @@ -63,27 +63,27 @@ public class FacteurCaracterisationFacadeTest { } @Test - void purgeAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { + void purgeByOrganisationAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { var dtosToSave = Arrays.asList( TestDataFactory.FacteurCaracterisationFactory.dto( "Ecran 27 pouces", TestDataFactory.DEFAULT_ETAPE, TestDataFactory.DEFAULT_CRITERE, "", Constants.EQUIPEMENT_NIVEAU, "", "", 0.01, "France", 0.02, "", - "NegaOctet"), + "NegaOctet", "ADEO"), TestDataFactory.FacteurCaracterisationFactory.dto( "Ecran 27 pouces", "FIN_DE_VIE", "Acidification", "", Constants.EQUIPEMENT_NIVEAU, "", "", 0.01, "France", 0.02, "", - "NegaOctet") + "NegaOctet", "ADEO") ); ArgumentCaptor<Collection<FacteurCaracterisation>> valueCapture = ArgumentCaptor.forClass(Collection.class); - assertDoesNotThrow(() -> facadeToTest.purgeAndAddAll(dtosToSave)); + assertDoesNotThrow(() -> facadeToTest.purgeByOrganisationAndAddAll(dtosToSave, "ADEO")); - Mockito.verify(persistencePort, Mockito.times(1)).purge(); + Mockito.verify(persistencePort, Mockito.times(1)).purgeByOrganisation("ADEO"); Mockito.verify(persistencePort, Mockito.times(1)).saveAll(valueCapture.capture()); var expectedDomains = valueCapture.getValue(); diff --git a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacadeTest.java b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacadeTest.java index 1fea959937cc93c35e017dee9c282e711c3a9a15..edf03fa306603b12ede9f560a69ed6c384635a8c 100644 --- a/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacadeTest.java +++ b/services/api-referentiel/src/test/java/org/mte/numecoeval/referentiel/infrastructure/restapi/facade/HypotheseFacadeTest.java @@ -35,9 +35,9 @@ class HypotheseFacadeTest { @Test void get_shouldReturnMatchingDTO() throws ReferentielException { - var wantedDTOId = TestDataFactory.HypotheseFactory.idDTO("code"); - var expectedDomainID = TestDataFactory.HypotheseFactory.idDomain("code"); - var expectedDomain = TestDataFactory.HypotheseFactory.domain("code", "1.1", "Test", "exemple de description"); + var wantedDTOId = TestDataFactory.HypotheseFactory.idDTO("code", "ADEO"); + var expectedDomainID = TestDataFactory.HypotheseFactory.idDomain("code", "ADEO"); + var expectedDomain = TestDataFactory.HypotheseFactory.domain("code", "1.1", "Test", "exemple de description", "ADEO"); Mockito.when(persistencePort.get(expectedDomainID)).thenReturn(expectedDomain); @@ -51,8 +51,8 @@ class HypotheseFacadeTest { @Test void getAll_ShouldAllReturnMatchingDTO() { var expectedDomains = Arrays.asList( - TestDataFactory.HypotheseFactory.domain("code", "2.0", "Test", "exemple de description"), - TestDataFactory.HypotheseFactory.domain("code2", "3.0", "Test", "exemple de description") + TestDataFactory.HypotheseFactory.domain("code", "2.0", "Test", "exemple de description", "ADEO"), + TestDataFactory.HypotheseFactory.domain("code2", "3.0", "Test", "exemple de description", "ADEO") ); Mockito.when(persistencePort.getAll()).thenReturn(expectedDomains); @@ -76,16 +76,16 @@ class HypotheseFacadeTest { } @Test - void purgeAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { + void purgeByOrganisationAndAddAll_ShouldCallPurgeThenSaveAll() throws ReferentielException { var dtosToSave = Arrays.asList( - TestDataFactory.HypotheseFactory.dto("hyp", "1.0", "Test", "exemple de description"), - TestDataFactory.HypotheseFactory.dto("hyp2", "m3", "Autre Test", "exemple de description") + TestDataFactory.HypotheseFactory.dto("hyp", "1.0", "Test", "exemple de description", "ADEO"), + TestDataFactory.HypotheseFactory.dto("hyp2", "m3", "Autre Test", "exemple de description", "ADEO") ); ArgumentCaptor<Collection<Hypothese>> valueCapture = ArgumentCaptor.forClass(Collection.class); - assertDoesNotThrow(() -> facadeToTest.purgeAndAddAll(dtosToSave)); + assertDoesNotThrow(() -> facadeToTest.purgeByOrganisationAndAddAll(dtosToSave, "ADEO")); - Mockito.verify(persistencePort, Mockito.times(1)).purge(); + Mockito.verify(persistencePort, Mockito.times(1)).purgeByOrganisation("ADEO"); Mockito.verify(persistencePort, Mockito.times(1)).saveAll(valueCapture.capture()); var expectedDomains = valueCapture.getValue(); diff --git a/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement.csv b/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement.csv index 2e13fbcde325ad0fa0bb08e77fdfddb1f03e7447..f6984522d77f4ce4b23d7f90faf1494d979d4e5d 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement.csv @@ -1,4 +1,4 @@ -modeleEquipementSource;refEquipementCible -modele01;refCible01 -modele02;refCible01 -modele03;refCible02 \ No newline at end of file +modeleEquipementSource;refEquipementCible;nomOrganisation +modele01;refCible01;ADEO +modele02;refCible01;ADEO +modele03;refCible02;ADEO \ No newline at end of file diff --git a/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement_errorInMiddle.csv b/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement_errorInMiddle.csv index 47834cbafb0974bdee5d1ab36d65a2a2e10434a5..35bd3754ccd04981d12631240b153c234b701b2d 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement_errorInMiddle.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/correspondanceRefEquipement_errorInMiddle.csv @@ -1,6 +1,6 @@ -modeleEquipementSource;refEquipementCible -modele01;refCible01 -modele02;refCible01 -;;Ceci;N'estPas;UneLigne;Valide -Tests;;Ceci;N'estPasNonPlus;UneLigne;Valide -modele03;refCible02 \ No newline at end of file +modeleEquipementSource;refEquipementCible;nomOrganisation +modele01;refCible01;ADEO +modele02;refCible01;ADEO +;;Ceci;N'estPas;UneLigne;Valide; +Tests;;Ceci;N'estPasNonPlus;UneLigne;Valide; +modele03;refCible02;ADEO \ No newline at end of file diff --git a/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation.csv b/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation.csv index e9611bb43993df1da7a6ae5e307cece533f7b53e..7dfdaad95f51721d47e4623f42ae6fe4f6b1dd58 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation.csv @@ -1,6 +1,6 @@ -nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source -Electricity Mix/ Production mix/ Low voltage/ FR;FABRICATION;Changement climatique;;0-Base data;;electricity-mix;;France;0.0813225;kWh;BaseImpact -Laptop;DISTRIBUTION;Ressources use, minerals and metals;HP;2-Equipement;End-user/Terminals;Consultation;0.4;Allemagne;0.000882;Item;NegaOctet -Blade server;DISTRIBUTION;Climate change;;2-Equipement;Datacenter;IT equipment;0.4;Allemagne;0.0092;Item;NegaOctet -Mobile network;FABRICATION;Climate change;;3-System;Network;;0.8;;0.00000159;GB;NegaOctet +nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source;nomOrganisation +Electricity Mix/ Production mix/ Low voltage/ FR;FABRICATION;Changement climatique;;0-Base data;;electricity-mix;;France;0.0813225;kWh;BaseImpact;ADEO +Laptop;DISTRIBUTION;Ressources use, minerals and metals;HP;2-Equipement;End-user/Terminals;Consultation;0.4;Allemagne;0.000882;Item;NegaOctet;ADEO +Blade server;DISTRIBUTION;Climate change;;2-Equipement;Datacenter;IT equipment;0.4;Allemagne;0.0092;Item;NegaOctet;ADEO +Mobile network;FABRICATION;Climate change;;3-System;Network;;0.8;;0.00000159;GB;NegaOctet;ADEO diff --git a/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation_errorInMiddle.csv b/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation_errorInMiddle.csv index a98bd5aa438cc6e1d384b3c532a8ce47e38f277a..79a3461a6f689e7e00acb02194e47fc54ea4ff47 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation_errorInMiddle.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/facteurCaracterisation_errorInMiddle.csv @@ -1,9 +1,9 @@ -nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source -Electricity Mix/ Production mix/ Low voltage/ FR;FABRICATION;Changement climatique;;0-Base data;;electricity-mix;;France;0.0813225;kWh;BaseImpact -Laptop;DISTRIBUTION;Ressources use, minerals and metals;HP;2-Equipement;End-user/Terminals;Consultation;0.4;Allemagne;0.000882;Item;NegaOctet -;SansRefEquipement;Critère inconnu;;;;;;;;; -SansEtape;;Critère inconnu;;;;;;;;; -SansCritere;SansCritere;;;;;;;;;; -Blade server;DISTRIBUTION;Climate change;;2-Equipement;Datacenter;IT equipment;0.4;Allemagne;0.0092;Item;NegaOctet -Mobile network;FABRICATION;Climate change;;3-System;Network;;0.8;;0.00000159;GB;NegaOctet +nom;etapeacv;critere;description;niveau;tiers;categorie;consoElecMoyenne;localisation;valeur;unite;source;nomOrganisation +Electricity Mix/ Production mix/ Low voltage/ FR;FABRICATION;Changement climatique;;0-Base data;;electricity-mix;;France;0.0813225;kWh;BaseImpact;ADEO +Laptop;DISTRIBUTION;Ressources use, minerals and metals;HP;2-Equipement;End-user/Terminals;Consultation;0.4;Allemagne;0.000882;Item;NegaOctet;ADEO +;SansRefEquipement;Critère inconnu;;;;;;;;;; +SansEtape;;Critère inconnu;;;;;;;;;; +SansCritere;SansCritere;;;;;;;;;;; +Blade server;DISTRIBUTION;Climate change;;2-Equipement;Datacenter;IT equipment;0.4;Allemagne;0.0092;Item;NegaOctet;ADEO +Mobile network;FABRICATION;Climate change;;3-System;Network;;0.8;;0.00000159;GB;NegaOctet;ADEO diff --git a/services/api-referentiel/src/test/resources/csv/unit/hypothese.csv b/services/api-referentiel/src/test/resources/csv/unit/hypothese.csv index 4093f137d0cbd94d4f21de122f35e37bd84bb5f0..855fa410c654855ed004c95f0750bb68f37b2767 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/hypothese.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/hypothese.csv @@ -1,3 +1,3 @@ -cle;valeur;source;description -PUEPardDfault;1.6;expertise IJO; -DureeVieServeurParDefaut;3;US 46;unité: années +cle;valeur;source;description;nomOrganisation +PUEPardDfault;1.6;expertise IJO;;ADEO +DureeVieServeurParDefaut;3;US 46;unité: années;ADEO diff --git a/services/api-referentiel/src/test/resources/csv/unit/hypothese_errorInMiddle.csv b/services/api-referentiel/src/test/resources/csv/unit/hypothese_errorInMiddle.csv index b4a98ebda2b87f76584eebc9133d1b207783c7df..00825115ec64055ceb04fd8360a68e0dea24f2d2 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/hypothese_errorInMiddle.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/hypothese_errorInMiddle.csv @@ -1,5 +1,5 @@ -cle;valeur;source;description -PUEPardDfault;1.6;expertise IJO; -;PasUnChiffreMaisPasGrave;Test;Pas;Le;Bon;Nombre;De;Colonne; -ErreurValeur;;Test;Pas;Le;Bon;Nombre;De;Colonne; -DureeVieServeurParDefaut;3;US 46;unité: années \ No newline at end of file +cle;valeur;source;description;nomOrganisation +PUEPardDfault;1.6;expertise IJO;description;ADEO +;PasUnChiffreMaisPasGrave;Test;Pas;Le;Bon;Nombre;De;Colonne;; +ErreurValeur;;Test;Pas;Le;Bon;Nombre;De;Colonne;; +DureeVieServeurParDefaut;3;US 46;unité: années;ADEO \ No newline at end of file diff --git a/services/api-referentiel/src/test/resources/csv/unit/typeItem.csv b/services/api-referentiel/src/test/resources/csv/unit/typeItem.csv index f96c37285188c75bee2e5495bc1b73b29f74dd2d..28e0054b6888b46a438366e741b520685e3b5ec5 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/typeItem.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/typeItem.csv @@ -1,3 +1,3 @@ -type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut -Serveur;;true;Exemple de serveur basique;6.0;;NegaOctet;serveur_par_defaut -deplacement voiture hybride;deplacement_hybride;false;Exemple d'opération non it;50.0;CONSO_MOYENNE_VOITURE_HYBRIDE;SSG;deplacement_voiture_hybride +type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut;nomOrganisation +Serveur;;true;Exemple de serveur basique;6.0;;NegaOctet;serveur_par_defaut;ADEO +deplacement voiture hybride;deplacement_hybride;false;Exemple d'opération non it;50.0;CONSO_MOYENNE_VOITURE_HYBRIDE;SSG;deplacement_voiture_hybride;ADEO diff --git a/services/api-referentiel/src/test/resources/csv/unit/typeItem_errorInMiddle.csv b/services/api-referentiel/src/test/resources/csv/unit/typeItem_errorInMiddle.csv index e690069c2d67ed3b32e6938bc0d31aadc1055458..973fdcdf7a6aaa26c765cfb5950b2daded721621 100644 --- a/services/api-referentiel/src/test/resources/csv/unit/typeItem_errorInMiddle.csv +++ b/services/api-referentiel/src/test/resources/csv/unit/typeItem_errorInMiddle.csv @@ -1,4 +1,4 @@ -type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut -Serveur;;true;Exemple de serveur basique;6.0;;NegaOctet;serveur_par_defaut -;;TypeAbsent;"est une erreur";complete;"Sur toute";"La";"Ligne"; -deplacement voiture hybride;deplacement_hybride;false;Exemple d'opération non it;50.0;CONSO_MOYENNE_VOITURE_HYBRIDE;SSG;deplacement_voiture_hybride \ No newline at end of file +type;categorie;serveur;commentaire;dureeVieDefaut;refHypothese;source;refItemParDefaut;nomOrganisation +Serveur;;true;Exemple de serveur basique;6.0;;NegaOctet;serveur_par_defaut;ADEO +;;TypeAbsent;"est une erreur";complete;"Sur toute";"La";"Ligne";; +deplacement voiture hybride;deplacement_hybride;false;Exemple d'opération non it;50.0;CONSO_MOYENNE_VOITURE_HYBRIDE;SSG;deplacement_voiture_hybride;ADEO \ No newline at end of file diff --git a/services/common/src/main/resources/static/api-referentiels-openapi.yaml b/services/common/src/main/resources/static/api-referentiels-openapi.yaml index 9a754523437ec3bbb716886b1a673e2104e081d5..d54e47de85e61029ad6cc1e1138735dfc4290a38 100644 --- a/services/common/src/main/resources/static/api-referentiels-openapi.yaml +++ b/services/common/src/main/resources/static/api-referentiels-openapi.yaml @@ -19,6 +19,9 @@ info: externalDocs: description: NumEcoEval Documentation url: https://gitlab-forge.din.developpement-durable.gouv.fr/pub/numeco/m4g/docs +servers: + - url: http://localhost:18080 + description: Generated server url paths: /referentiel/typeItem/csv: get: @@ -64,6 +67,14 @@ paths: <li>Sortie : Rapport du fichier CSV (nombre de lignes totales, nombre de lignes en erreur, nombre de lignes traitées, liste des erreurs par lignes).</li> </ul> operationId: importTypeItemCSV + parameters: + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide requestBody: content: multipart/form-data: @@ -544,6 +555,14 @@ paths: <li>Sortie : Rapport du fichier CSV (nombre de lignes totales, nombre de lignes en erreur, nombre de lignes traitées, liste des erreurs par lignes).</li> </ul> operationId: importHypothesesCSV + parameters: + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide requestBody: content: multipart/form-data: @@ -633,6 +652,13 @@ paths: type: string description: 'Choix du mode d''insertion FULL (purge puis insertion des nouvelles données) ou DELTA (upsert : maj de la base de données existante)' default: DELTA + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide requestBody: content: multipart/form-data: @@ -873,6 +899,14 @@ paths: <li>Sortie : Rapport du fichier CSV (nombre de lignes totales, nombre de lignes en erreur, nombre de lignes traitées, liste des erreurs par lignes).</li> </ul> operationId: importCorrespondanceRefEquipementCSV + parameters: + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut importer des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide requestBody: content: multipart/form-data: @@ -997,6 +1031,13 @@ paths: schema: type: string description: type recherché + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide responses: '200': description: Types Item @@ -1423,9 +1464,16 @@ paths: schema: type: string description: Clé de l'hypothèse + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide responses: '200': - description: Hypothèse trouvé + description: Hypothèse trouvée content: application/json: schema: @@ -1437,7 +1485,7 @@ paths: schema: $ref: '#/components/schemas/ErrorResponseDTO' '404': - description: Hypothèse non trouvé + description: Hypothèse non trouvée content: application/json: schema: @@ -1501,6 +1549,13 @@ paths: schema: type: string description: Nom de la catégorie + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide responses: '200': description: Liste des Facteurs de Caractérisation trouvés @@ -1611,6 +1666,13 @@ paths: required: true schema: type: string + - name: nomOrganisation + in: query + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide + required: false + schema: + type: string + description: Choix de l'organisation pour laquelle on veut exporter des hypothèses, si ce sont des références par défaut, communes à toutes les organisations, laisser le paramètre vide responses: '200': description: Correspondance trouvée @@ -1773,6 +1835,9 @@ components: refItemParDefaut: type: string description: Référence de l'item par défaut, permet des correspondances en cas d'absence de correspondance directe + nomOrganisation: + type: string + description: Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation description: Référentiel des types d'items utilisables dans le système. La clé du référentiel est le champ type. TypeEquipementDTO: type: object @@ -1908,6 +1973,9 @@ components: description: type: string description: Description de l'hypothèse + nomOrganisation: + type: string + description: Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation description: Référentiel des hypothèses utilisées pour les calculs FacteurCaracterisationDTO: type: object @@ -1950,6 +2018,9 @@ components: source: type: string description: Source de l'impact écologique pour ce facteur de caractérisation + nomOrganisation: + type: string + description: Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation description: Référentiel de l'impact écologique d'un facteur de caractérisation. La clé est composé des champs nom, etape et critere. EtapeDTO: type: object @@ -1984,4 +2055,7 @@ components: refEquipementCible: type: string description: Référence d'équipement correspondant au modèle de l'équipement + nomOrganisation: + type: string + description: Nom de l'organisation dans le cas où cette dernière à des références customisées, propres à son organisation description: Référentiel de correspondance entre un modèle d'équipement physique et une référence d'équipement dans les référentiels.