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-consultation/fdxconsultation-core-impl/src/main/java/com/megatim/fdxconsultation/core/impl/documents/DocumentManageImpl.java |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/fdx-consultation/fdxconsultation-core-impl/src/main/java/com/megatim/fdxconsultation/core/impl/documents/DocumentManageImpl.java b/fdx-consultation/fdxconsultation-core-impl/src/main/java/com/megatim/fdxconsultation/core/impl/documents/DocumentManageImpl.java
new file mode 100644
index 0000000..0d5b28b
--- /dev/null
+++ b/fdx-consultation/fdxconsultation-core-impl/src/main/java/com/megatim/fdxconsultation/core/impl/documents/DocumentManageImpl.java
@@ -0,0 +1,85 @@
+package com.megatim.fdxconsultation.core.impl.documents;
+
+import com.bekosoftware.genericdaolayer.dao.ifaces.GenericDAO;
+import com.bekosoftware.genericmanagerlayer.core.impl.AbstractGenericManager;
+import com.megatim.commons.tools.exceptions.ApplicationServerException;
+import com.megatim.fdxconsultation.core.ifaces.documents.DocumentManager;
+import com.megatim.fdxconsultation.dao.ifaces.documents.CategoryDAO;
+import com.megatim.fdxconsultation.dao.ifaces.documents.DocumentDAO;
+import com.megatim.fdxconsultation.dao.impl.utils.BaseEntityUtil;
+import com.megatim.fdxconsultation.model.administration.User;
+import com.megatim.fdxconsultation.model.documents.Category;
+import com.megatim.fdxconsultation.model.documents.Document;
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
+import javax.transaction.Transactional;
+
+/**
+ *
+ * @author Gabuntu
+ */
+@Dependent
+public class DocumentManageImpl extends AbstractGenericManager<Document, Long> implements DocumentManager {
+
+    @Inject
+    private DocumentDAO dao;
+
+    @Inject
+    private CategoryDAO categoryDAO;
+
+    @Override
+    public GenericDAO<Document, Long> getDao() {
+        return dao;
+    }
+
+    @Override
+    public String getEntityIdName() {
+        return "id";
+    }
+
+    @Transactional
+    @Override
+    public Document add(Long CategoryId, Document document, User connectedUser) {
+
+        Category category = categoryDAO.getById(CategoryId);
+        if (category == null) {
+            throw new ApplicationServerException("La catégorie à associer au document à enregistrer est introuvable");
+        }
+
+        document.setCategory(category);
+
+        BaseEntityUtil.setBaseEntityFieldsForAdd(document, connectedUser);
+        return dao.save(document);
+    }
+
+    @Transactional
+    @Override
+    public Document update(Long id, Document document, User connectedUser) {
+
+        Document doc = getById(id);
+        doc.setLabel(document.getLabel());
+        doc.setVersion(document.getVersion());
+        doc.setPosition(document.getPosition());
+        doc.setItemFile(document.getItemFile());
+
+        BaseEntityUtil.setBaseEntityFieldsForUpdate(doc, connectedUser);
+        return dao.save(doc);
+    }
+
+    @Transactional
+    @Override
+    public Document delete(Long id, User connectedUser) {
+        Document document = getById(id);
+        BaseEntityUtil.setBaseEntityFieldsForDelete(document, connectedUser);
+        return dao.save(document);
+    }
+
+    private Document getById(Long id) {
+        Document document = dao.getById(id);
+        if (document == null) {
+            throw new ApplicationServerException("Document introuvable");
+        }
+        return document;
+    }
+
+}

--
Gitblit v1.10.0