From fec1362d3f8a4982acda520c053eee91dddffa89 Mon Sep 17 00:00:00 2001 From: David Darras Date: Mon, 3 Apr 2023 22:48:35 +0200 Subject: [PATCH 1/3] feat: use generics and no generics :p --- .../hierarchy/GenericHierarchyController.java | 33 ++++++++++ .../hierarchy/HierarchyController.java | 64 ------------------- .../hierarchy/HierarchyGsbpmController.java | 30 +++++++++ .../hierarchy/HierarchyProductController.java | 30 +++++++++ .../hierarchy/HierarchyServiceController.java | 30 +++++++++ .../hierarchy/HierarchyUserController.java | 33 ++++++++++ .../importdata/ImportGithubController.java | 23 ++++--- .../knowledge/dao/HierarchyGsbpmDAO.java | 8 --- .../knowledge/dao/HierarchyProductDAO.java | 9 --- .../knowledge/dao/HierarchyServiceDAO.java | 8 --- .../insee/knowledge/dao/HierarchyUserDAO.java | 9 --- .../fr/insee/knowledge/dao/generic/DAO.java | 7 +- .../knowledge/dao/impl/FunctionDAOImpl.java | 2 +- .../knowledge/dao/impl/HierarchyDAOImpl.java | 13 ++++ .../dao/impl/HierarchyGsbpmDAOImpl.java | 11 +--- .../dao/impl/HierarchyProductDAOImpl.java | 10 +-- .../dao/impl/HierarchyServiceDAOImpl.java | 15 ----- .../dao/impl/HierarchySvcDAOImpl.java | 8 +++ .../dao/impl/HierarchyUserDAOImpl.java | 9 +-- .../domain/hierarchy/HierarchyService.java | 25 -------- .../domain/hierarchy/HierarchySvc.java | 25 ++++++++ .../service/GenericHierarchyService.java | 13 ++++ .../knowledge/service/HierarchyGsbpmSvc.java | 14 ---- .../service/HierarchyProductSvc.java | 14 ---- .../service/HierarchyServiceSvc.java | 14 ---- .../knowledge/service/HierarchyUserSvc.java | 15 ----- .../impl/GenericHierarchyServiceImpl.java | 43 +++++++++++++ .../impl/HierarchyGsbpmServiceImpl.java | 15 +++++ .../service/impl/HierarchyGsbpmSvcImpl.java | 46 ------------- .../impl/HierarchyProductServiceImpl.java | 13 ++++ .../service/impl/HierarchyProductSvcImpl.java | 40 ------------ .../service/impl/HierarchyServiceSvcImpl.java | 45 ------------- .../service/impl/HierarchySvcServiceImpl.java | 13 ++++ .../impl/HierarchyUserServiceImpl.java | 13 ++++ .../service/impl/HierarchyUserSvcImpl.java | 45 ------------- .../service/impl/ImportServiceImpl.java | 19 +++--- 36 files changed, 344 insertions(+), 420 deletions(-) create mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java delete mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java create mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java create mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java create mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java create mode 100644 src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java delete mode 100644 src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java delete mode 100644 src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java delete mode 100644 src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java delete mode 100644 src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java create mode 100644 src/main/java/fr/insee/knowledge/dao/impl/HierarchyDAOImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java create mode 100644 src/main/java/fr/insee/knowledge/dao/impl/HierarchySvcDAOImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java create mode 100644 src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchySvc.java create mode 100644 src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java delete mode 100644 src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java delete mode 100644 src/main/java/fr/insee/knowledge/service/HierarchyProductSvc.java delete mode 100644 src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java delete mode 100644 src/main/java/fr/insee/knowledge/service/HierarchyUserSvc.java create mode 100644 src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java create mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java create mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceSvcImpl.java create mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java create mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java delete mode 100644 src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java new file mode 100644 index 0000000..7118873 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java @@ -0,0 +1,33 @@ +package fr.insee.knowledge.controller.hierarchy; + +import fr.insee.knowledge.domain.hierarchy.*; +import fr.insee.knowledge.service.GenericHierarchyService; +import fr.insee.knowledge.service.impl.HierarchyGsbpmServiceImpl; +import fr.insee.knowledge.service.impl.HierarchyProductServiceImpl; +import fr.insee.knowledge.service.impl.HierarchySvcServiceImpl; +import fr.insee.knowledge.service.impl.HierarchyUserServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +public class GenericHierarchyController { + + private final static Logger logger = LoggerFactory.getLogger(GenericHierarchyController.class); + + private GenericHierarchyService hierarchyService; + + public GenericHierarchyController(GenericHierarchyService hierarchyService) { + this.hierarchyService = hierarchyService; + } + + public ResponseEntity getHierarchy() { + return new ResponseEntity(hierarchyService.getHierarchy(), HttpStatus.OK); + } +} diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java deleted file mode 100644 index 20538f1..0000000 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java +++ /dev/null @@ -1,64 +0,0 @@ -package fr.insee.knowledge.controller.hierarchy; - -import fr.insee.knowledge.domain.hierarchy.*; -import fr.insee.knowledge.service.HierarchyGsbpmSvc; -import fr.insee.knowledge.service.HierarchyProductSvc; -import fr.insee.knowledge.service.HierarchyServiceSvc; -import fr.insee.knowledge.service.HierarchyUserSvc; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@Tag(name = "Hierarchy", description = "") -@RestController -@RequestMapping(path = "/hierarchy") -public class HierarchyController { - - private final static Logger logger = LoggerFactory.getLogger(HierarchyController.class); - - @Autowired - private HierarchyProductSvc hierarchyProductSvc; - @Autowired - private HierarchyUserSvc hierarchyUserSvc; - @Autowired - private HierarchyGsbpmSvc hierarchyGsbpmSvc; - @Autowired - private HierarchyServiceSvc hierarchyServiceSvc; - - @Operation(summary = "Get Products") - @GetMapping(path = "/products") - public ResponseEntity getProducts() { - HierarchyProduct result = hierarchyProductSvc.getProducts(); - return new ResponseEntity(result, HttpStatus.OK); - } - - @Operation(summary = "Get Gsbpm") - @GetMapping(path = "/gsbpm") - public ResponseEntity getGsbpm() { - HierarchyGsbpm result = hierarchyGsbpmSvc.getGsbpm(); - return new ResponseEntity(result, HttpStatus.OK); - } - - @Operation(summary = "Get Services") - @GetMapping(path = "/services") - public ResponseEntity getServices() { - HierarchyService result = hierarchyServiceSvc.getService(); - return new ResponseEntity(result, HttpStatus.OK); - } - - @Operation(summary = "Get Users") - @GetMapping(path = "/users") - public ResponseEntity getUsers() { - HierarchyUser result = hierarchyUserSvc.getUser(); - return new ResponseEntity(result, HttpStatus.OK); - } -} diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java new file mode 100644 index 0000000..c3fa76d --- /dev/null +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java @@ -0,0 +1,30 @@ +package fr.insee.knowledge.controller.hierarchy; + +import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; +import fr.insee.knowledge.service.impl.HierarchyGsbpmServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Hierarchy", description = "") +@RestController +@RequestMapping(path = "/hierarchy") +public class HierarchyGsbpmController extends GenericHierarchyController{ + + private final static Logger logger = LoggerFactory.getLogger(HierarchyGsbpmController.class); + + public HierarchyGsbpmController(HierarchyGsbpmServiceImpl hierarchyService) { + super(hierarchyService); + } + + @Operation(summary = "Get Gsbpm") + @GetMapping(path = "/gsbpm") + public ResponseEntity getGsbpm() { + return getHierarchy(); + } +} diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java new file mode 100644 index 0000000..ca48df7 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java @@ -0,0 +1,30 @@ +package fr.insee.knowledge.controller.hierarchy; + +import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; +import fr.insee.knowledge.service.impl.HierarchyProductServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Hierarchy", description = "") +@RestController +@RequestMapping(path = "/hierarchy") +public class HierarchyProductController extends GenericHierarchyController{ + + private final static Logger logger = LoggerFactory.getLogger(HierarchyProductController.class); + + public HierarchyProductController(HierarchyProductServiceImpl hierarchyService) { + super(hierarchyService); + } + + @Operation(summary = "Get Products") + @GetMapping(path = "/products") + public ResponseEntity getProducts() { + return getHierarchy(); + } +} diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java new file mode 100644 index 0000000..f2dfe2f --- /dev/null +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java @@ -0,0 +1,30 @@ +package fr.insee.knowledge.controller.hierarchy; + +import fr.insee.knowledge.domain.hierarchy.HierarchySvc; +import fr.insee.knowledge.service.impl.HierarchySvcServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Hierarchy", description = "") +@RestController +@RequestMapping(path = "/hierarchy") +public class HierarchyServiceController extends GenericHierarchyController{ + + private final static Logger logger = LoggerFactory.getLogger(HierarchyServiceController.class); + + public HierarchyServiceController(HierarchySvcServiceImpl hierarchyService) { + super(hierarchyService); + } + + @Operation(summary = "Get Services") + @GetMapping(path = "/services") + public ResponseEntity getServices() { + return getHierarchy(); + } +} diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java new file mode 100644 index 0000000..21c9ea1 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java @@ -0,0 +1,33 @@ +package fr.insee.knowledge.controller.hierarchy; + +import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; +import fr.insee.knowledge.domain.hierarchy.HierarchyUser; +import fr.insee.knowledge.service.impl.HierarchyProductServiceImpl; +import fr.insee.knowledge.service.impl.HierarchyUserServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "Hierarchy", description = "") +@RestController +@RequestMapping(path = "/hierarchy") +public class HierarchyUserController extends GenericHierarchyController{ + + private final static Logger logger = LoggerFactory.getLogger(HierarchyUserController.class); + + public HierarchyUserController(HierarchyUserServiceImpl hierarchyService) { + super(hierarchyService); + } + + @Operation(summary = "Get Users") + @GetMapping(path = "/users") + public ResponseEntity getUsers() { + return getHierarchy(); + } +} diff --git a/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java b/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java index 95c401a..c33214d 100644 --- a/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java +++ b/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java @@ -1,6 +1,10 @@ package fr.insee.knowledge.controller.importdata; import fr.insee.knowledge.service.*; +import fr.insee.knowledge.service.impl.HierarchyGsbpmServiceImpl; +import fr.insee.knowledge.service.impl.HierarchyProductServiceImpl; +import fr.insee.knowledge.service.impl.HierarchySvcServiceImpl; +import fr.insee.knowledge.service.impl.HierarchyUserServiceImpl; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -19,12 +23,13 @@ @RequestMapping(path = "/import") public class ImportGithubController { private ImportService importService; - private HierarchyProductSvc hierarchyProductSvc; - private HierarchyGsbpmSvc hierarchyGsbpmSvc; - private HierarchyUserSvc hierarchyUserSvc; - private HierarchyServiceSvc hierarchyServiceSvc; + private HierarchyProductServiceImpl hierarchyProductSvc; + private HierarchyGsbpmServiceImpl hierarchyGsbpmSvc; + private HierarchyUserServiceImpl hierarchyUserSvc; + private HierarchySvcServiceImpl hierarchyServiceSvc; - public ImportGithubController(ImportService importService, HierarchyProductSvc hierarchyProductSvc, HierarchyGsbpmSvc hierarchyGsbpmSvc, HierarchyUserSvc hierarchyUserSvc, HierarchyServiceSvc hierarchyServiceSvc, FunctionService functionService) { + public ImportGithubController(ImportService importService, HierarchyProductServiceImpl hierarchyProductSvc, HierarchyGsbpmServiceImpl hierarchyGsbpmSvc, + HierarchyUserServiceImpl hierarchyUserSvc, HierarchySvcServiceImpl hierarchyServiceSvc, FunctionService functionService) { this.importService = importService; this.hierarchyProductSvc = hierarchyProductSvc; this.hierarchyGsbpmSvc = hierarchyGsbpmSvc; @@ -45,28 +50,28 @@ public ResponseEntity importFunctions() throws IOException { @Operation(summary = "Import GSBPM") @GetMapping(path = "/hierarchy/gsbpm") public ResponseEntity importGsbpm() throws IOException { - String result = hierarchyGsbpmSvc.importGsbpm(); + String result = hierarchyGsbpmSvc.importHierarchy(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Services") @GetMapping(path = "/hierarchy/services") public ResponseEntity importServices() throws IOException { - String result = hierarchyServiceSvc.importService(); + String result = hierarchyServiceSvc.importHierarchy(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Products") @GetMapping(path = "/hierarchy/products") public ResponseEntity importProducts() throws IOException { - String result = hierarchyProductSvc.importProduct(); + String result = hierarchyProductSvc.importHierarchy(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Users") @GetMapping(path = "/hierarchy/user") public ResponseEntity importUsers() throws IOException { - String result = hierarchyUserSvc.importUser(); + String result = hierarchyUserSvc.importHierarchy(); return new ResponseEntity(result, HttpStatus.OK); } diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java deleted file mode 100644 index 9f27a4b..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java +++ /dev/null @@ -1,8 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.dao.generic.IDao; -import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; - -public interface HierarchyGsbpmDAO extends IDao { -} - diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java deleted file mode 100644 index a8281e2..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.dao.generic.IDao; -import fr.insee.knowledge.domain.hierarchy.Hierarchy; -import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; - -public interface HierarchyProductDAO extends IDao { -} - diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java deleted file mode 100644 index 962497a..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java +++ /dev/null @@ -1,8 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.dao.generic.IDao; -import fr.insee.knowledge.domain.hierarchy.HierarchyService; - -public interface HierarchyServiceDAO extends IDao { -} - diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java deleted file mode 100644 index 03018a6..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.dao.generic.IDao; -import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; -import fr.insee.knowledge.domain.hierarchy.HierarchyUser; - -public interface HierarchyUserDAO extends IDao { -} - diff --git a/src/main/java/fr/insee/knowledge/dao/generic/DAO.java b/src/main/java/fr/insee/knowledge/dao/generic/DAO.java index 6db2cc7..f3ffd5e 100644 --- a/src/main/java/fr/insee/knowledge/dao/generic/DAO.java +++ b/src/main/java/fr/insee/knowledge/dao/generic/DAO.java @@ -9,11 +9,11 @@ import com.mongodb.client.model.ReplaceOneModel; import com.mongodb.client.model.ReplaceOptions; import com.mongodb.client.model.WriteModel; -import com.mongodb.client.result.UpdateResult; import fr.insee.knowledge.domain.GenericIDLabel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.GenericTypeResolver; import javax.annotation.PostConstruct; import java.util.ArrayList; @@ -37,11 +37,10 @@ public class DAO implements IDao { /** * Create a new BasicDAO * - * @param entityClass the class of the POJO to persist using this DAO * @param collectionName the name of the collection to persist entity */ - public DAO(final Class entityClass, final String collectionName) { - this.entityClass = entityClass; + public DAO(final String collectionName) { + this.entityClass = (Class) GenericTypeResolver.resolveTypeArgument(getClass(), DAO.class); this.collectionName = collectionName; } diff --git a/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java index 2790e54..2dc6e57 100644 --- a/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java +++ b/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java @@ -9,7 +9,7 @@ @Component public class FunctionDAOImpl extends DAO implements FunctionDAO { public FunctionDAOImpl() { - super(Function.class, Constants.CollectionFunctions); + super(Constants.CollectionFunctions); } } diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyDAOImpl.java new file mode 100644 index 0000000..668266d --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyDAOImpl.java @@ -0,0 +1,13 @@ +package fr.insee.knowledge.dao.impl; + +import fr.insee.knowledge.constants.Constants; +import fr.insee.knowledge.dao.generic.DAO; +import fr.insee.knowledge.domain.hierarchy.Hierarchy; +import org.springframework.stereotype.Component; + +public class HierarchyDAOImpl extends DAO { + public HierarchyDAOImpl() { + super(Constants.CollectionHierarchy); + } + +} diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java index eabcc4a..fe7e8ee 100644 --- a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java @@ -1,17 +1,8 @@ package fr.insee.knowledge.dao.impl; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.HierarchyGsbpmDAO; -import fr.insee.knowledge.dao.HierarchyProductDAO; -import fr.insee.knowledge.dao.generic.DAO; import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; -import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; import org.springframework.stereotype.Component; @Component -public class HierarchyGsbpmDAOImpl extends DAO implements HierarchyGsbpmDAO { - public HierarchyGsbpmDAOImpl() { - super(HierarchyGsbpm.class, Constants.CollectionHierarchy); - } - +public class HierarchyGsbpmDAOImpl extends HierarchyDAOImpl { } diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java index c68a7ea..abaab3d 100644 --- a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java @@ -1,15 +1,9 @@ package fr.insee.knowledge.dao.impl; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.HierarchyProductDAO; -import fr.insee.knowledge.dao.generic.DAO; import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; +import fr.insee.knowledge.domain.hierarchy.HierarchyUser; import org.springframework.stereotype.Component; @Component -public class HierarchyProductDAOImpl extends DAO implements HierarchyProductDAO { - public HierarchyProductDAOImpl() { - super(HierarchyProduct.class, Constants.CollectionHierarchy); - } - +public class HierarchyProductDAOImpl extends HierarchyDAOImpl { } diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java deleted file mode 100644 index f272d7c..0000000 --- a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package fr.insee.knowledge.dao.impl; - -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.HierarchyServiceDAO; -import fr.insee.knowledge.dao.generic.DAO; -import fr.insee.knowledge.domain.hierarchy.HierarchyService; -import org.springframework.stereotype.Component; - -@Component -public class HierarchyServiceDAOImpl extends DAO implements HierarchyServiceDAO { - public HierarchyServiceDAOImpl() { - super(HierarchyService.class, Constants.CollectionHierarchy); - } - -} diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchySvcDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchySvcDAOImpl.java new file mode 100644 index 0000000..b99456b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchySvcDAOImpl.java @@ -0,0 +1,8 @@ +package fr.insee.knowledge.dao.impl; + +import fr.insee.knowledge.domain.hierarchy.HierarchySvc; +import org.springframework.stereotype.Component; + +@Component +public class HierarchySvcDAOImpl extends HierarchyDAOImpl { +} diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java index 031e38b..50646f9 100644 --- a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java @@ -1,15 +1,8 @@ package fr.insee.knowledge.dao.impl; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.HierarchyUserDAO; -import fr.insee.knowledge.dao.generic.DAO; import fr.insee.knowledge.domain.hierarchy.HierarchyUser; import org.springframework.stereotype.Component; @Component -public class HierarchyUserDAOImpl extends DAO implements HierarchyUserDAO { - public HierarchyUserDAOImpl() { - super(HierarchyUser.class, Constants.CollectionHierarchy); - } - +public class HierarchyUserDAOImpl extends HierarchyDAOImpl { } diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java deleted file mode 100644 index 2c7864b..0000000 --- a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java +++ /dev/null @@ -1,25 +0,0 @@ -package fr.insee.knowledge.domain.hierarchy; - -import java.util.List; - -public class HierarchyService extends Hierarchy { - - public HierarchyService() { - } - - public HierarchyService(String id, String label) { - super(id, label); - } - - public HierarchyService(String id, String label, String description) { - super(id, label, description); - } - - public HierarchyService(String id, String label, List children) { - super(id, label, children); - } - - public HierarchyService(String id, String label, String description, List children) { - super(id, label, description, children); - } -} diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchySvc.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchySvc.java new file mode 100644 index 0000000..b2b0dfe --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchySvc.java @@ -0,0 +1,25 @@ +package fr.insee.knowledge.domain.hierarchy; + +import java.util.List; + +public class HierarchySvc extends Hierarchy { + + public HierarchySvc() { + } + + public HierarchySvc(String id, String label) { + super(id, label); + } + + public HierarchySvc(String id, String label, String description) { + super(id, label, description); + } + + public HierarchySvc(String id, String label, List children) { + super(id, label, children); + } + + public HierarchySvc(String id, String label, String description, List children) { + super(id, label, description, children); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java b/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java new file mode 100644 index 0000000..3018f63 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java @@ -0,0 +1,13 @@ +package fr.insee.knowledge.service; + +import fr.insee.knowledge.domain.hierarchy.Hierarchy; + +import java.io.IOException; + +public interface GenericHierarchyService { + T getHierarchy(); + + String importHierarchy() throws IOException; + + Boolean isHierarchyExist(String id); +} diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java deleted file mode 100644 index d751a30..0000000 --- a/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insee.knowledge.service; - -import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; - -import java.io.IOException; - -public interface HierarchyGsbpmSvc { - - HierarchyGsbpm getGsbpm(); - - String importGsbpm() throws IOException; - - Boolean isGsbpmExist(String id); -} diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyProductSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyProductSvc.java deleted file mode 100644 index f25337f..0000000 --- a/src/main/java/fr/insee/knowledge/service/HierarchyProductSvc.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insee.knowledge.service; - -import fr.insee.knowledge.domain.hierarchy.*; - -import java.io.IOException; - -public interface HierarchyProductSvc { - - HierarchyProduct getProducts(); - - String importProduct() throws IOException; - - Boolean isProductExist(String id); -} diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java deleted file mode 100644 index d9c728d..0000000 --- a/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insee.knowledge.service; - -import fr.insee.knowledge.domain.hierarchy.HierarchyService; - -import java.io.IOException; - -public interface HierarchyServiceSvc { - - HierarchyService getService(); - - String importService() throws IOException; - - Boolean isServiceExist(String id); -} diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyUserSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyUserSvc.java deleted file mode 100644 index ee85c0b..0000000 --- a/src/main/java/fr/insee/knowledge/service/HierarchyUserSvc.java +++ /dev/null @@ -1,15 +0,0 @@ -package fr.insee.knowledge.service; - -import fr.insee.knowledge.domain.hierarchy.HierarchyUser; - -import java.io.IOException; -import java.net.MalformedURLException; - -public interface HierarchyUserSvc { - - HierarchyUser getUser(); - - String importUser() throws IOException; - - Boolean isUserExist(String id); -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java new file mode 100644 index 0000000..ec14dbd --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java @@ -0,0 +1,43 @@ +package fr.insee.knowledge.service.impl; + +import com.fasterxml.jackson.databind.ObjectMapper; +import fr.insee.knowledge.constants.Constants; +import fr.insee.knowledge.dao.generic.DAO; +import fr.insee.knowledge.domain.hierarchy.Hierarchy; +import fr.insee.knowledge.service.GenericHierarchyService; +import org.springframework.core.GenericTypeResolver; + +import java.io.IOException; +import java.net.URL; + +public class GenericHierarchyServiceImpl implements GenericHierarchyService { + private DAO hierarchyDAO; + + private final ObjectMapper mapper; + + private String githubRepository; + + public GenericHierarchyServiceImpl(DAO hierarchyDAO, String githubRepository) { + this.hierarchyDAO = hierarchyDAO; + this.githubRepository = githubRepository; + this.mapper = new ObjectMapper(); + } + + @Override + public T getHierarchy() { + return hierarchyDAO.findById(Constants.idUsersDocument); + } + + @Override + public String importHierarchy() throws IOException { + Class tClass = (Class) GenericTypeResolver.resolveTypeArgument(getClass(), GenericHierarchyServiceImpl.class); + T hierarchy = mapper.readValue(new URL(githubRepository + Constants.GithubUserFile), tClass); + return hierarchyDAO.insertOrReplaceOne(hierarchy); + } + + //TODO + @Override + public Boolean isHierarchyExist(String id) { + return null; + } +} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java new file mode 100644 index 0000000..2ed5413 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java @@ -0,0 +1,15 @@ +package fr.insee.knowledge.service.impl; + +import fr.insee.knowledge.dao.generic.DAO; +import fr.insee.knowledge.dao.impl.HierarchyGsbpmDAOImpl; +import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; +import fr.insee.knowledge.domain.hierarchy.HierarchyUser; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class HierarchyGsbpmServiceImpl extends GenericHierarchyServiceImpl { + public HierarchyGsbpmServiceImpl(HierarchyGsbpmDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { + super(hierarchyDAO, githubRepository); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java deleted file mode 100644 index e4e19a2..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.dao.HierarchyGsbpmDAO; -import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; -import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; -import fr.insee.knowledge.domain.hierarchy.HierarchyUser; -import fr.insee.knowledge.service.HierarchyGsbpmSvc; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -import static fr.insee.knowledge.constants.Constants.*; - -@Service -public class HierarchyGsbpmSvcImpl implements HierarchyGsbpmSvc { - - @Autowired - private HierarchyGsbpmDAO hierarchyGsbpmDAO; - - private final ObjectMapper mapper = new ObjectMapper(); - - @Value("${fr.insee.knowledge.git.access.rawrepository}") - private String githubRepository; - - @Override - public HierarchyGsbpm getGsbpm() { - return hierarchyGsbpmDAO.findById(idServicesDocument); - } - - @Override - public String importGsbpm() throws IOException { - HierarchyGsbpm hierarchyGsbpm = mapper.readValue(new URL(githubRepository + GithubGsbpmFile), HierarchyGsbpm.class); - return hierarchyGsbpmDAO.insertOrReplaceOne(hierarchyGsbpm); - } - - //TODO - @Override - public Boolean isGsbpmExist(String id) { - return null; - } -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java new file mode 100644 index 0000000..b1aae04 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java @@ -0,0 +1,13 @@ +package fr.insee.knowledge.service.impl; + +import fr.insee.knowledge.dao.impl.HierarchyProductDAOImpl; +import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class HierarchyProductServiceImpl extends GenericHierarchyServiceImpl { + public HierarchyProductServiceImpl(HierarchyProductDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { + super(hierarchyDAO, githubRepository); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java deleted file mode 100644 index fde94b4..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.dao.HierarchyProductDAO; -import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; -import fr.insee.knowledge.service.HierarchyProductSvc; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.net.URL; - -import static fr.insee.knowledge.constants.Constants.*; - -@Service -public class HierarchyProductSvcImpl implements HierarchyProductSvc { - @Autowired - private HierarchyProductDAO hierarchyProductDAO; - private final ObjectMapper mapper = new ObjectMapper(); - - @Value("${fr.insee.knowledge.git.access.rawrepository}") - private String githubRepository; - - public HierarchyProduct getProducts() { - return hierarchyProductDAO.findById(idProductsDocument); - } - - @Override - public String importProduct() throws IOException { - HierarchyProduct hierarchyProduct = mapper.readValue(new URL(githubRepository + GithubProductsFile), HierarchyProduct.class); - return hierarchyProductDAO.insertOrReplaceOne(hierarchyProduct); - } - - //TODO - @Override - public Boolean isProductExist(String id) { - return true; - } -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceSvcImpl.java deleted file mode 100644 index aa9c3e3..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceSvcImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.dao.HierarchyServiceDAO; -import fr.insee.knowledge.domain.hierarchy.HierarchyService; -import fr.insee.knowledge.service.HierarchyServiceSvc; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.net.URL; - -import static fr.insee.knowledge.constants.Constants.GithubServicesFile; -import static fr.insee.knowledge.constants.Constants.idServicesDocument; - -@Service -public class HierarchyServiceSvcImpl implements HierarchyServiceSvc { - - @Autowired - private HierarchyServiceDAO hierarchyServiceDAO; - - private final ObjectMapper mapper = new ObjectMapper(); - - @Value("${fr.insee.knowledge.git.access.rawrepository}") - private String githubRepository; - - @Override - public HierarchyService getService() { - return hierarchyServiceDAO.findById(idServicesDocument); - } - - @Override - public String importService() throws IOException { - HierarchyService hierarchyService = mapper.readValue(new URL(githubRepository + GithubServicesFile), HierarchyService.class); - return hierarchyServiceDAO.insertOrReplaceOne(hierarchyService); - } - - - //TODO - @Override - public Boolean isServiceExist(String id) { - return true; - } -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java new file mode 100644 index 0000000..ad88438 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java @@ -0,0 +1,13 @@ +package fr.insee.knowledge.service.impl; + +import fr.insee.knowledge.dao.impl.HierarchySvcDAOImpl; +import fr.insee.knowledge.domain.hierarchy.HierarchySvc; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class HierarchySvcServiceImpl extends GenericHierarchyServiceImpl { + public HierarchySvcServiceImpl(HierarchySvcDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { + super(hierarchyDAO, githubRepository); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java new file mode 100644 index 0000000..13dfb2c --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java @@ -0,0 +1,13 @@ +package fr.insee.knowledge.service.impl; + +import fr.insee.knowledge.dao.impl.HierarchyUserDAOImpl; +import fr.insee.knowledge.domain.hierarchy.HierarchyUser; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class HierarchyUserServiceImpl extends GenericHierarchyServiceImpl { + public HierarchyUserServiceImpl(HierarchyUserDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { + super(hierarchyDAO, githubRepository); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java deleted file mode 100644 index 03c8136..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.dao.HierarchyUserDAO; -import fr.insee.knowledge.domain.hierarchy.HierarchyUser; -import fr.insee.knowledge.service.HierarchyUserSvc; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -import static fr.insee.knowledge.constants.Constants.GithubUserFile; -import static fr.insee.knowledge.constants.Constants.idUsersDocument; - -@Service -public class HierarchyUserSvcImpl implements HierarchyUserSvc { - - @Autowired - private HierarchyUserDAO hierarchyUserDAO; - - private final ObjectMapper mapper = new ObjectMapper(); - - @Value("${fr.insee.knowledge.git.access.rawrepository}") - private String githubRepository; - - @Override - public HierarchyUser getUser() { - return hierarchyUserDAO.findById(idUsersDocument); - } - - @Override - public String importUser() throws IOException { - HierarchyUser hierarchyUser = mapper.readValue(new URL(githubRepository + GithubUserFile), HierarchyUser.class); - return hierarchyUserDAO.insertOrReplaceOne(hierarchyUser); - } - - //TODO - @Override - public Boolean isUserExist(String id) { - return null; - } -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java index 1171233..d771da7 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java @@ -11,12 +11,13 @@ public class ImportServiceImpl implements ImportService { private final FunctionService functionService; - private final HierarchyServiceSvc hierarchyServiceSvc; - private final HierarchyUserSvc hierarchyUserSvc; - private final HierarchyGsbpmSvc hierarchyGsbpmSvc; - private final HierarchyProductSvc hierarchyProductSvc; + private final HierarchySvcServiceImpl hierarchyServiceSvc; + private final HierarchyUserServiceImpl hierarchyUserSvc; + private final HierarchyGsbpmServiceImpl hierarchyGsbpmSvc; + private final HierarchyProductServiceImpl hierarchyProductSvc; - public ImportServiceImpl(FunctionService functionService, HierarchyServiceSvc hierarchyServiceSvc, HierarchyUserSvc hierarchyUserSvc, HierarchyGsbpmSvc hierarchyGsbpmSvc, HierarchyProductSvc hierarchyProductSvc) { + public ImportServiceImpl(FunctionService functionService, HierarchySvcServiceImpl hierarchyServiceSvc, HierarchyUserServiceImpl hierarchyUserSvc, + HierarchyGsbpmServiceImpl hierarchyGsbpmSvc, HierarchyProductServiceImpl hierarchyProductSvc) { this.functionService = functionService; this.hierarchyServiceSvc = hierarchyServiceSvc; this.hierarchyUserSvc = hierarchyUserSvc; @@ -26,10 +27,10 @@ public ImportServiceImpl(FunctionService functionService, HierarchyServiceSvc hi public String importHierarchyAndFunction() throws IOException { StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(hierarchyGsbpmSvc.importGsbpm()); - stringBuilder.append(hierarchyProductSvc.importProduct()); - stringBuilder.append(hierarchyUserSvc.importUser()); - stringBuilder.append(hierarchyServiceSvc.importService()); + stringBuilder.append(hierarchyGsbpmSvc.importHierarchy()); + stringBuilder.append(hierarchyProductSvc.importHierarchy()); + stringBuilder.append(hierarchyUserSvc.importHierarchy()); + stringBuilder.append(hierarchyServiceSvc.importHierarchy()); stringBuilder.append(functionService.importListFunctions()); return stringBuilder.toString(); } From c99f6efcaa1c02b6aedcd1bceb821cbf7d7b09c2 Mon Sep 17 00:00:00 2001 From: Dylan Decrulle <81740200+ddecrulle@users.noreply.github.com> Date: Wed, 24 May 2023 17:18:13 +0200 Subject: [PATCH 2/3] end of refactor --- pom.xml | 6 ++++++ .../configuration/MongoConfiguration.java | 8 ++++---- .../configuration/PropertiesLogger.java | 9 ++++----- .../hierarchy/GenericHierarchyController.java | 2 +- .../hierarchy/HierarchyGsbpmController.java | 5 +---- .../hierarchy/HierarchyProductController.java | 5 +---- .../hierarchy/HierarchyServiceController.java | 5 +---- .../hierarchy/HierarchyUserController.java | 5 +---- .../fr/insee/knowledge/dao/generic/DAO.java | 3 --- .../service/GenericHierarchyService.java | 3 ++- .../impl/GenericHierarchyServiceImpl.java | 20 +++++++++++-------- .../impl/HierarchyGsbpmServiceImpl.java | 6 +++--- .../impl/HierarchyProductServiceImpl.java | 3 ++- .../service/impl/HierarchySvcServiceImpl.java | 3 ++- .../impl/HierarchyUserServiceImpl.java | 3 ++- 15 files changed, 42 insertions(+), 44 deletions(-) diff --git a/pom.xml b/pom.xml index dcd0360..65fa8da 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,12 @@ test + + org.springframework.boot + spring-boot-devtools + true + + org.springdoc diff --git a/src/main/java/fr/insee/knowledge/configuration/MongoConfiguration.java b/src/main/java/fr/insee/knowledge/configuration/MongoConfiguration.java index ba4231f..018873f 100644 --- a/src/main/java/fr/insee/knowledge/configuration/MongoConfiguration.java +++ b/src/main/java/fr/insee/knowledge/configuration/MongoConfiguration.java @@ -3,6 +3,7 @@ import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; +import lombok.extern.slf4j.Slf4j; import org.bson.codecs.configuration.CodecProvider; import org.bson.codecs.configuration.CodecRegistry; import org.bson.codecs.pojo.PojoCodecProvider; @@ -17,9 +18,8 @@ import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; @Configuration +@Slf4j public class MongoConfiguration { - private static final Logger logger = LoggerFactory.getLogger(MongoConfiguration.class); - private CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build(); private CodecRegistry pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider)); @@ -29,14 +29,14 @@ public class MongoConfiguration { private String mongoUri; private MongoClient mongoClient() { - logger.info("Create mongoClient"); + log.info("Create mongoClient"); //we don't auth as admin return MongoClients.create(mongoUri + "?authSource=" + database); } @Bean(name = "mongoDatabase") public MongoDatabase mongoDatabase() { - logger.info("Connection to database"); + log.info("Connection to database"); return mongoClient().getDatabase(database).withCodecRegistry(pojoCodecRegistry); } diff --git a/src/main/java/fr/insee/knowledge/configuration/PropertiesLogger.java b/src/main/java/fr/insee/knowledge/configuration/PropertiesLogger.java index 99227c9..fa33fa4 100644 --- a/src/main/java/fr/insee/knowledge/configuration/PropertiesLogger.java +++ b/src/main/java/fr/insee/knowledge/configuration/PropertiesLogger.java @@ -16,13 +16,12 @@ @Slf4j public class PropertiesLogger implements ApplicationListener { - private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesLogger.class); @Override public void onApplicationEvent(@NonNull ApplicationEnvironmentPreparedEvent event) { final Environment env = event.getEnvironment(); - LOGGER.info("====== Environment and configuration ======"); - LOGGER.info("Active profiles: {}", Arrays.toString(env.getActiveProfiles())); + log.info("====== Environment and configuration ======"); + log.info("Active profiles: {}", Arrays.toString(env.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) env).getPropertySources(); StreamSupport.stream(sources.spliterator(), false) .filter(ps -> ps instanceof EnumerablePropertySource) @@ -31,8 +30,8 @@ public void onApplicationEvent(@NonNull ApplicationEnvironmentPreparedEvent even .distinct() .filter(prop -> !(prop.contains("credentials") || prop.contains("password"))) .sorted() - .forEach(prop -> LOGGER.info("{}: {}", prop, env.getProperty(prop))); - LOGGER.info("==========================================="); + .forEach(prop -> log.info("{}: {}", prop, env.getProperty(prop))); + log.info("==========================================="); } } diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java index 7118873..fa87720 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/GenericHierarchyController.java @@ -21,7 +21,7 @@ public class GenericHierarchyController { private final static Logger logger = LoggerFactory.getLogger(GenericHierarchyController.class); - private GenericHierarchyService hierarchyService; + private final GenericHierarchyService hierarchyService; public GenericHierarchyController(GenericHierarchyService hierarchyService) { this.hierarchyService = hierarchyService; diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java index c3fa76d..ddc6c33 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyGsbpmController.java @@ -14,10 +14,7 @@ @Tag(name = "Hierarchy", description = "") @RestController @RequestMapping(path = "/hierarchy") -public class HierarchyGsbpmController extends GenericHierarchyController{ - - private final static Logger logger = LoggerFactory.getLogger(HierarchyGsbpmController.class); - +public class HierarchyGsbpmController extends GenericHierarchyController { public HierarchyGsbpmController(HierarchyGsbpmServiceImpl hierarchyService) { super(hierarchyService); } diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java index ca48df7..9e393b1 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyProductController.java @@ -14,10 +14,7 @@ @Tag(name = "Hierarchy", description = "") @RestController @RequestMapping(path = "/hierarchy") -public class HierarchyProductController extends GenericHierarchyController{ - - private final static Logger logger = LoggerFactory.getLogger(HierarchyProductController.class); - +public class HierarchyProductController extends GenericHierarchyController { public HierarchyProductController(HierarchyProductServiceImpl hierarchyService) { super(hierarchyService); } diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java index f2dfe2f..0166010 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyServiceController.java @@ -14,10 +14,7 @@ @Tag(name = "Hierarchy", description = "") @RestController @RequestMapping(path = "/hierarchy") -public class HierarchyServiceController extends GenericHierarchyController{ - - private final static Logger logger = LoggerFactory.getLogger(HierarchyServiceController.class); - +public class HierarchyServiceController extends GenericHierarchyController { public HierarchyServiceController(HierarchySvcServiceImpl hierarchyService) { super(hierarchyService); } diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java index 21c9ea1..ce1bc9f 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyUserController.java @@ -17,10 +17,7 @@ @Tag(name = "Hierarchy", description = "") @RestController @RequestMapping(path = "/hierarchy") -public class HierarchyUserController extends GenericHierarchyController{ - - private final static Logger logger = LoggerFactory.getLogger(HierarchyUserController.class); - +public class HierarchyUserController extends GenericHierarchyController { public HierarchyUserController(HierarchyUserServiceImpl hierarchyService) { super(hierarchyService); } diff --git a/src/main/java/fr/insee/knowledge/dao/generic/DAO.java b/src/main/java/fr/insee/knowledge/dao/generic/DAO.java index f3ffd5e..91c3ca2 100644 --- a/src/main/java/fr/insee/knowledge/dao/generic/DAO.java +++ b/src/main/java/fr/insee/knowledge/dao/generic/DAO.java @@ -25,9 +25,6 @@ * @param the type of the entity, it extends GenericIDLabel */ public class DAO implements IDao { - - private final static Logger LOGGER = LoggerFactory.getLogger(DAO.class); - @Autowired private MongoDatabase mongoDatabase; protected MongoCollection mongoCollection; diff --git a/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java b/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java index 3018f63..6c2a4cd 100644 --- a/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java +++ b/src/main/java/fr/insee/knowledge/service/GenericHierarchyService.java @@ -3,11 +3,12 @@ import fr.insee.knowledge.domain.hierarchy.Hierarchy; import java.io.IOException; +import java.util.Optional; public interface GenericHierarchyService { T getHierarchy(); String importHierarchy() throws IOException; - Boolean isHierarchyExist(String id); + T findHierarchyById(String id); } diff --git a/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java index ec14dbd..8f952bf 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/GenericHierarchyServiceImpl.java @@ -1,7 +1,6 @@ package fr.insee.knowledge.service.impl; import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.generic.DAO; import fr.insee.knowledge.domain.hierarchy.Hierarchy; import fr.insee.knowledge.service.GenericHierarchyService; @@ -9,35 +8,40 @@ import java.io.IOException; import java.net.URL; +import java.util.Optional; public class GenericHierarchyServiceImpl implements GenericHierarchyService { - private DAO hierarchyDAO; + private final DAO hierarchyDAO; + + private final String idHierarchy; private final ObjectMapper mapper; + private final String githubFileName; private String githubRepository; - public GenericHierarchyServiceImpl(DAO hierarchyDAO, String githubRepository) { + public GenericHierarchyServiceImpl(DAO hierarchyDAO, String idHierarchy, String githubFileName, String githubRepository) { this.hierarchyDAO = hierarchyDAO; + this.idHierarchy = idHierarchy; + this.githubFileName = githubFileName; this.githubRepository = githubRepository; this.mapper = new ObjectMapper(); } @Override public T getHierarchy() { - return hierarchyDAO.findById(Constants.idUsersDocument); + return findHierarchyById(idHierarchy); } @Override public String importHierarchy() throws IOException { Class tClass = (Class) GenericTypeResolver.resolveTypeArgument(getClass(), GenericHierarchyServiceImpl.class); - T hierarchy = mapper.readValue(new URL(githubRepository + Constants.GithubUserFile), tClass); + T hierarchy = mapper.readValue(new URL(githubRepository + githubFileName), tClass); return hierarchyDAO.insertOrReplaceOne(hierarchy); } - //TODO @Override - public Boolean isHierarchyExist(String id) { - return null; + public T findHierarchyById(String id) { + return hierarchyDAO.findById(id); } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java index 2ed5413..4d4edc5 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmServiceImpl.java @@ -1,15 +1,15 @@ package fr.insee.knowledge.service.impl; -import fr.insee.knowledge.dao.generic.DAO; +import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.impl.HierarchyGsbpmDAOImpl; import fr.insee.knowledge.domain.hierarchy.HierarchyGsbpm; -import fr.insee.knowledge.domain.hierarchy.HierarchyUser; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service public class HierarchyGsbpmServiceImpl extends GenericHierarchyServiceImpl { + public HierarchyGsbpmServiceImpl(HierarchyGsbpmDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { - super(hierarchyDAO, githubRepository); + super(hierarchyDAO, Constants.idGsbpmDocument, Constants.GithubGsbpmFile, githubRepository); } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java index b1aae04..4dd99ac 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductServiceImpl.java @@ -1,5 +1,6 @@ package fr.insee.knowledge.service.impl; +import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.impl.HierarchyProductDAOImpl; import fr.insee.knowledge.domain.hierarchy.HierarchyProduct; import org.springframework.beans.factory.annotation.Value; @@ -8,6 +9,6 @@ @Service public class HierarchyProductServiceImpl extends GenericHierarchyServiceImpl { public HierarchyProductServiceImpl(HierarchyProductDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { - super(hierarchyDAO, githubRepository); + super(hierarchyDAO, Constants.idProductsDocument, Constants.GithubProductsFile, githubRepository); } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java index ad88438..91055b9 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchySvcServiceImpl.java @@ -1,5 +1,6 @@ package fr.insee.knowledge.service.impl; +import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.impl.HierarchySvcDAOImpl; import fr.insee.knowledge.domain.hierarchy.HierarchySvc; import org.springframework.beans.factory.annotation.Value; @@ -8,6 +9,6 @@ @Service public class HierarchySvcServiceImpl extends GenericHierarchyServiceImpl { public HierarchySvcServiceImpl(HierarchySvcDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { - super(hierarchyDAO, githubRepository); + super(hierarchyDAO, Constants.idServicesDocument, Constants.GithubServicesFile, githubRepository); } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java index 13dfb2c..601c5da 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserServiceImpl.java @@ -1,5 +1,6 @@ package fr.insee.knowledge.service.impl; +import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.impl.HierarchyUserDAOImpl; import fr.insee.knowledge.domain.hierarchy.HierarchyUser; import org.springframework.beans.factory.annotation.Value; @@ -8,6 +9,6 @@ @Service public class HierarchyUserServiceImpl extends GenericHierarchyServiceImpl { public HierarchyUserServiceImpl(HierarchyUserDAOImpl hierarchyDAO, @Value("${fr.insee.knowledge.git.access.rawrepository}") String githubRepository) { - super(hierarchyDAO, githubRepository); + super(hierarchyDAO, Constants.idUsersDocument, Constants.GithubUserFile, githubRepository); } } From 354284198b8591900153aaad56975d5cc0b27935 Mon Sep 17 00:00:00 2001 From: Dylan Decrulle <81740200+ddecrulle@users.noreply.github.com> Date: Wed, 24 May 2023 17:19:23 +0200 Subject: [PATCH 3/3] bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65fa8da..7281847 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ fr.insee.knowledge knowledge - 0.5.1 + 0.6.0 jar Knowledge-Back-Office Back-office services for Knowledge