From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation
---
fdx-commons/fdxcommons-core-impl/src/main/java/com/megatim/fdxcommons/core/impl/helper/referentiel/ReferentielToImportDataReaderImpl.java | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/fdx-commons/fdxcommons-core-impl/src/main/java/com/megatim/fdxcommons/core/impl/helper/referentiel/ReferentielToImportDataReaderImpl.java b/fdx-commons/fdxcommons-core-impl/src/main/java/com/megatim/fdxcommons/core/impl/helper/referentiel/ReferentielToImportDataReaderImpl.java
new file mode 100644
index 0000000..8df963a
--- /dev/null
+++ b/fdx-commons/fdxcommons-core-impl/src/main/java/com/megatim/fdxcommons/core/impl/helper/referentiel/ReferentielToImportDataReaderImpl.java
@@ -0,0 +1,76 @@
+package com.megatim.fdxcommons.core.impl.helper.referentiel;
+
+import com.megatim.fdxcommons.core.ifaces.db.ImportZipValidatorIfaces;
+import com.megatim.fdxcommons.core.ifaces.helper.referentiel.ReferentielToImportDataReader;
+import com.megatim.fdxcommons.core.ifaces.helper.referentiel.ReferentielXmlDataReader;
+import com.megatim.fdxcommons.tools.exceptions.ImportReferentielException;
+import com.megatim.fdxcommons.model.enumeration.StatutReferentiel;
+import com.megatim.fdxcommons.model.pojo.ReferentielToImportData;
+import com.megatim.fdxcommons.model.integration.TableDefinition;
+import com.megatim.fdxcommons.model.referentiel.Referentiel;
+import com.megatim.fdxcommons.tools.CommonAppContext;
+import com.megatim.fdxcommons.tools.AppFileUtils;
+import java.io.File;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
+
+/**
+ *
+ * @author lenovo
+ */
+@Dependent
+public class ReferentielToImportDataReaderImpl implements ReferentielToImportDataReader {
+
+ @Inject
+ private ReferentielXmlDataReader referentielXmlDataReader;
+
+ @Inject
+ private ImportZipValidatorIfaces importValidator;
+
+ @Override
+ public ReferentielToImportData getData(File referentielFile) throws Exception {
+
+ //On décompresse le fichier zip du référentiel dans le répertoire temporaire du serveur
+ File unzipDirectory = AppFileUtils.unzipFileInDirectory(referentielFile.getAbsolutePath(), CommonAppContext.TEMP_DIR);
+
+ //Dans le répertoire décompressé, on décompresse encore le fichier contenant les fichiers xml des entités du référentiel
+ File unzipReferentielDirectory = AppFileUtils.unzipFileInDirectory((unzipDirectory + File.separator + CommonAppContext.REFERENTIEL_ZIP_FILE_NAME), unzipDirectory.getAbsolutePath());
+
+ //Indique le répertoire des validateurs du référentiel
+ File validateursDirectory = new File(unzipDirectory + File.separator + CommonAppContext.UNZIP_REFERENTIEL_VALIDATEUR_DIR_NAME);
+
+ ReferentielToImportData referentielToImportData = new ReferentielToImportData();
+ referentielToImportData.setFileName(referentielFile.getName());
+ referentielXmlDataReader.readData(unzipReferentielDirectory, referentielToImportData);
+
+ Referentiel referentielEncours = getReferentielEncours(referentielToImportData);
+ referentielToImportData.setReferentielEnCours(referentielEncours);
+
+ //On extrait la définition des tables associées aux validateur (structures lignes) du référentiel EN COURS
+ List<TableDefinition> tableDefinitions = importValidator.getTableDefinitions(validateursDirectory, referentielToImportData);
+ referentielToImportData.setTableDefinitions(tableDefinitions);
+
+ return referentielToImportData;
+
+ }
+
+ private Referentiel getReferentielEncours(ReferentielToImportData referentielToImportData) throws Exception {
+ List<Referentiel> referentiels = referentielToImportData.getReferentiels()
+ .stream()
+ .filter(p -> p.getStatutReferentiel().equals(StatutReferentiel.EN_COURS))
+ .collect(Collectors.toList());
+
+ if (referentiels == null || referentiels.isEmpty()) {
+ throw new ImportReferentielException("Cette archive n'a pas de referentiel avec le statut EN COURS");
+ }
+
+ if (referentiels.size() > 1) {
+ throw new ImportReferentielException(referentiels.size() + " réferentiels en cours trouvés");
+ }
+
+ return referentiels.get(0);
+ }
+
+}
--
Gitblit v1.10.0