diff --git a/pom.xml b/pom.xml index 4b68f59..4c294de 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ fr.insee.knowledge knowledge - 0.4.7 + 0.5.0 jar Knowledge-Back-Office Back-office services for Knowledge @@ -25,6 +25,12 @@ + + + org.springframework.boot + spring-boot-starter-data-mongodb + + org.springframework.boot spring-boot-starter-web @@ -49,16 +55,6 @@ org.mongodb mongodb-driver-sync - - - - - - - - - - diff --git a/src/main/java/fr/insee/knowledge/constants/Constants.java b/src/main/java/fr/insee/knowledge/constants/Constants.java index 3b9c53b..64315de 100644 --- a/src/main/java/fr/insee/knowledge/constants/Constants.java +++ b/src/main/java/fr/insee/knowledge/constants/Constants.java @@ -26,8 +26,12 @@ private Constants() { //Function JsonFields public static final String functionField = "function"; public static final String idField = "id"; - public static final String idProductFiled = "products"; - public static final String gsbpmField = "gsbpm"; + public static final String idProductsDocument = "products"; + public static final String idGsbpmDocument = "gsbpm"; + public static final String idServicesDocument = "services"; + public static final String idUsersDocument = "users"; + public static final String idStatusDocument = "status"; + public static final String labelField = "label"; public static final String serviceField = "service"; public static final String descriptionField = "description"; diff --git a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java index d32eae3..20538f1 100644 --- a/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java +++ b/src/main/java/fr/insee/knowledge/controller/hierarchy/HierarchyController.java @@ -1,7 +1,10 @@ package fr.insee.knowledge.controller.hierarchy; -import fr.insee.knowledge.domain.Hierarchy; -import fr.insee.knowledge.service.HierarchyService; +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; @@ -10,7 +13,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -24,19 +26,39 @@ public class HierarchyController { private final static Logger logger = LoggerFactory.getLogger(HierarchyController.class); @Autowired - private HierarchyService hierarchyService; + 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 Hierarchy by id") - @GetMapping(path = "/{id}") - public ResponseEntity getHierarchyById(@PathVariable(value = "id") String id) { - Hierarchy result = hierarchyService.getHierarchyById(id); - 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 all hierarchies") - @GetMapping(path = "/all") - public ResponseEntity> getAllHierarchies() { - List result = hierarchyService.getAllHierarchies(); - 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/importdata/ImportGithubController.java b/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java index e808dfe..95c401a 100644 --- a/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java +++ b/src/main/java/fr/insee/knowledge/controller/importdata/ImportGithubController.java @@ -1,12 +1,9 @@ package fr.insee.knowledge.controller.importdata; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.service.facade.ImportServiceFacade; +import fr.insee.knowledge.service.*; 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 lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -18,59 +15,65 @@ @Tag(name = "Import Data", description = "Import Data from Github") @RestController +@Slf4j @RequestMapping(path = "/import") public class ImportGithubController { - @Autowired - private ImportServiceFacade importService; + private ImportService importService; + private HierarchyProductSvc hierarchyProductSvc; + private HierarchyGsbpmSvc hierarchyGsbpmSvc; + private HierarchyUserSvc hierarchyUserSvc; + private HierarchyServiceSvc hierarchyServiceSvc; - private final static Logger logger = LoggerFactory.getLogger(ImportGithubController.class); + public ImportGithubController(ImportService importService, HierarchyProductSvc hierarchyProductSvc, HierarchyGsbpmSvc hierarchyGsbpmSvc, HierarchyUserSvc hierarchyUserSvc, HierarchyServiceSvc hierarchyServiceSvc, FunctionService functionService) { + this.importService = importService; + this.hierarchyProductSvc = hierarchyProductSvc; + this.hierarchyGsbpmSvc = hierarchyGsbpmSvc; + this.hierarchyUserSvc = hierarchyUserSvc; + this.hierarchyServiceSvc = hierarchyServiceSvc; + this.functionService = functionService; + } + + private FunctionService functionService; @Operation(summary = "Import Functions") @GetMapping(path = "/functions") public ResponseEntity importFunctions() throws IOException { - String result = importService.importListFunctions(Constants.GithubFunctionFile); + String result = functionService.importListFunctions(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import GSBPM") @GetMapping(path = "/hierarchy/gsbpm") public ResponseEntity importGsbpm() throws IOException { - String result = importService.importHierarchy(Constants.GithubGsbpmFile); - return new ResponseEntity(result, HttpStatus.OK); - } - - @Operation(summary = "Import Status") - @GetMapping(path = "/hierarchy/status") - public ResponseEntity importStatus() throws IOException { - String result = importService.importHierarchy(Constants.GithubStatusFile); + String result = hierarchyGsbpmSvc.importGsbpm(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Services") @GetMapping(path = "/hierarchy/services") public ResponseEntity importServices() throws IOException { - String result = importService.importHierarchy(Constants.GithubServicesFile); + String result = hierarchyServiceSvc.importService(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Products") @GetMapping(path = "/hierarchy/products") public ResponseEntity importProducts() throws IOException { - String result = importService.importHierarchy(Constants.GithubProductsFile); + String result = hierarchyProductSvc.importProduct(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import Users") @GetMapping(path = "/hierarchy/user") public ResponseEntity importUsers() throws IOException { - String result = importService.importHierarchy(Constants.GithubUserFile); + String result = hierarchyUserSvc.importUser(); return new ResponseEntity(result, HttpStatus.OK); } @Operation(summary = "Import All") @GetMapping(path = "/import-hierarchy-and-functions") public ResponseEntity importHierarchyAndFunction() throws IOException { - List results = importService.importHierarchyAndFunction(); - return new ResponseEntity(results.toString(), HttpStatus.OK); + String results = importService.importHierarchyAndFunction(); + return new ResponseEntity(results, HttpStatus.OK); } } diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyDAO.java deleted file mode 100644 index e2722f4..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyDAO.java +++ /dev/null @@ -1,7 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.dao.generic.IDao; -import fr.insee.knowledge.domain.Hierarchy; - -public interface HierarchyDAO extends IDao { -} diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/HierarchyDAOImpl.java deleted file mode 100644 index 7c478da..0000000 --- a/src/main/java/fr/insee/knowledge/dao/HierarchyDAOImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insee.knowledge.dao; - -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.generic.DAO; -import fr.insee.knowledge.domain.Hierarchy; -import org.springframework.stereotype.Component; - -@Component -public class HierarchyDAOImpl extends DAO implements HierarchyDAO { - public HierarchyDAOImpl() { - super(Hierarchy.class, Constants.CollectionHierarchy); - } - -} diff --git a/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java b/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java new file mode 100644 index 0000000..9f27a4b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000..a8281e2 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..962497a --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000..03018a6 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java @@ -0,0 +1,9 @@ +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 c06ac86..6db2cc7 100644 --- a/src/main/java/fr/insee/knowledge/dao/generic/DAO.java +++ b/src/main/java/fr/insee/knowledge/dao/generic/DAO.java @@ -9,6 +9,7 @@ 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; @@ -51,8 +52,7 @@ protected void init() { public String insertOrReplaceOne(T document) { try { - mongoCollection.replaceOne(eq("_id", document.getId()), document, new ReplaceOptions().upsert(true)); - return ("Success! The document is imported in the database \n"); + return mongoCollection.replaceOne(eq("_id", document.getId()), document, new ReplaceOptions().upsert(true)).toString() + "\n"; } catch (MongoException exception) { return ("Error ! Unable to insert document : " + document.getId() + " to an error: " + exception); @@ -83,7 +83,7 @@ public FindIterable findByKeyValue(String key, String value) { return iterable; } - public T FindById(String value) { + public T findById(String value) { return findByKeyValue("_id", value).first(); } diff --git a/src/main/java/fr/insee/knowledge/dao/generic/IDao.java b/src/main/java/fr/insee/knowledge/dao/generic/IDao.java index 8f5ab96..dc282dd 100644 --- a/src/main/java/fr/insee/knowledge/dao/generic/IDao.java +++ b/src/main/java/fr/insee/knowledge/dao/generic/IDao.java @@ -13,7 +13,7 @@ public interface IDao { FindIterable findByKeyValue(String key, String value); - T FindById(String idValue); + T findById(String idValue); List getAllDocuments(); } \ No newline at end of file diff --git a/src/main/java/fr/insee/knowledge/dao/FunctionDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java similarity index 82% rename from src/main/java/fr/insee/knowledge/dao/FunctionDAOImpl.java rename to src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java index d403b60..2790e54 100644 --- a/src/main/java/fr/insee/knowledge/dao/FunctionDAOImpl.java +++ b/src/main/java/fr/insee/knowledge/dao/impl/FunctionDAOImpl.java @@ -1,6 +1,7 @@ -package fr.insee.knowledge.dao; +package fr.insee.knowledge.dao.impl; import fr.insee.knowledge.constants.Constants; +import fr.insee.knowledge.dao.FunctionDAO; import fr.insee.knowledge.dao.generic.DAO; import fr.insee.knowledge.domain.Function; import org.springframework.stereotype.Component; diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java new file mode 100644 index 0000000..eabcc4a --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyGsbpmDAOImpl.java @@ -0,0 +1,17 @@ +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); + } + +} diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java new file mode 100644 index 0000000..c68a7ea --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyProductDAOImpl.java @@ -0,0 +1,15 @@ +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 org.springframework.stereotype.Component; + +@Component +public class HierarchyProductDAOImpl extends DAO implements HierarchyProductDAO { + public HierarchyProductDAOImpl() { + super(HierarchyProduct.class, Constants.CollectionHierarchy); + } + +} diff --git a/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java new file mode 100644 index 0000000..f272d7c --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyServiceDAOImpl.java @@ -0,0 +1,15 @@ +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/HierarchyUserDAOImpl.java b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java new file mode 100644 index 0000000..031e38b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/dao/impl/HierarchyUserDAOImpl.java @@ -0,0 +1,15 @@ +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); + } + +} diff --git a/src/main/java/fr/insee/knowledge/domain/Function.java b/src/main/java/fr/insee/knowledge/domain/Function.java index 9a57e82..72d5498 100644 --- a/src/main/java/fr/insee/knowledge/domain/Function.java +++ b/src/main/java/fr/insee/knowledge/domain/Function.java @@ -3,23 +3,20 @@ import java.util.List; public class Function extends GenericIDLabel { - private String description; private int dispo; - private ProductOrGsbpm gsbpm; + private GenericIDLabel gsbpm; private String idProduct; private List users; - private List products; + private List products; private List tasks; private Service service; - public Function(String id, String label, String description, int dispo, ProductOrGsbpm gsbpm, String idProduct, List users, List tools, List tasks, Service service) { - super(id, label); - this.description = description; + public Function(String id, String label, String description, int dispo, Gsbpm gsbpm, String idProduct, List users, List tools, List tasks, Service service) { + super(id, label, description); this.dispo = dispo; this.gsbpm = gsbpm; this.idProduct = idProduct; this.users = users; - this.products = products; this.tasks = tasks; this.service = service; } @@ -28,14 +25,6 @@ public Function() { super(); } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - public int getDispo() { return dispo; } @@ -44,11 +33,11 @@ public void setDispo(int dispo) { this.dispo = dispo; } - public ProductOrGsbpm getGsbpm() { + public GenericIDLabel getGsbpm() { return gsbpm; } - public void setGsbpm(ProductOrGsbpm gsbpm) { + public void setGsbpm(GenericIDLabel gsbpm) { this.gsbpm = gsbpm; } @@ -68,11 +57,11 @@ public void setUsers(List users) { this.users = users; } - public List getProducts() { + public List getProducts() { return products; } - public void setProducts(List products) { + public void setProducts(List products) { this.products = products; } diff --git a/src/main/java/fr/insee/knowledge/domain/GenericIDLabel.java b/src/main/java/fr/insee/knowledge/domain/GenericIDLabel.java index 0fd7a53..d563d3a 100644 --- a/src/main/java/fr/insee/knowledge/domain/GenericIDLabel.java +++ b/src/main/java/fr/insee/knowledge/domain/GenericIDLabel.java @@ -4,6 +4,22 @@ public class GenericIDLabel { private String id; private String label; + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public GenericIDLabel(String id, String label, String description) { + this.id = id; + this.label = label; + this.description = description; + } + public GenericIDLabel() { } diff --git a/src/main/java/fr/insee/knowledge/domain/ProductOrGsbpm.java b/src/main/java/fr/insee/knowledge/domain/Gsbpm.java similarity index 62% rename from src/main/java/fr/insee/knowledge/domain/ProductOrGsbpm.java rename to src/main/java/fr/insee/knowledge/domain/Gsbpm.java index 3edfe7f..bc0f384 100644 --- a/src/main/java/fr/insee/knowledge/domain/ProductOrGsbpm.java +++ b/src/main/java/fr/insee/knowledge/domain/Gsbpm.java @@ -1,16 +1,16 @@ package fr.insee.knowledge.domain; -public class ProductOrGsbpm extends GenericIDLabel { +public class Gsbpm extends GenericIDLabel { private String description; - public ProductOrGsbpm() { + public Gsbpm() { } - public ProductOrGsbpm(String id, String label) { + public Gsbpm(String id, String label) { super(id, label); } - public ProductOrGsbpm(String id, String label, String description) { + public Gsbpm(String id, String label, String description) { super(id, label); this.description = description; } diff --git a/src/main/java/fr/insee/knowledge/domain/Hierarchy.java b/src/main/java/fr/insee/knowledge/domain/Hierarchy.java deleted file mode 100644 index 8c5b5b7..0000000 --- a/src/main/java/fr/insee/knowledge/domain/Hierarchy.java +++ /dev/null @@ -1,56 +0,0 @@ -package fr.insee.knowledge.domain; - -import java.util.List; - -public class Hierarchy extends GenericIDLabel { - private List children; - private String description; - - public Hierarchy() { - super(); - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Hierarchy(String id, String label) { - super(id, label); - } - - public Hierarchy(String id, String label, String description) { - super(id, label); - this.description = description; - } - - public Hierarchy(String id, String label, List children) { - super(id, label); - this.children = children; - } - - public Hierarchy(String id, String label, String description, List children) { - super(id, label); - this.children = children; - this.description = description; - } - - @Override - public String toString() { - return "Hierarchy{" + - "children=" + children + - ", description='" + description + '\'' + - "} " + super.toString(); - } - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } -} diff --git a/src/main/java/fr/insee/knowledge/domain/Service.java b/src/main/java/fr/insee/knowledge/domain/Service.java index ac00ec6..e78e885 100644 --- a/src/main/java/fr/insee/knowledge/domain/Service.java +++ b/src/main/java/fr/insee/knowledge/domain/Service.java @@ -3,12 +3,10 @@ public class Service extends GenericIDLabel { private Service service; - private String description; public Service(Service service, String description, String id, String label) { - super(id, label); + super(id, label, description); this.service = service; - this.description = description; } public Service() { @@ -21,13 +19,4 @@ public Service getService() { public void setService(Service service) { this.service = service; } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - } diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/Hierarchy.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/Hierarchy.java new file mode 100644 index 0000000..25aac79 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/Hierarchy.java @@ -0,0 +1,47 @@ +package fr.insee.knowledge.domain.hierarchy; + +import fr.insee.knowledge.domain.GenericIDLabel; + +import java.util.List; + +public class Hierarchy extends GenericIDLabel { + private List children; + + public Hierarchy() { + super(); + } + + public Hierarchy(String id, String label) { + super(id, label); + } + + public Hierarchy(String id, String label, String description) { + super(id, label, description); + } + + public Hierarchy(String id, String label, List children) { + super(id, label); + this.children = children; + } + + public Hierarchy(String id, String label, String description, List children) { + super(id, label, description); + this.children = children; + } + + @Override + public String toString() { + return "Hierarchy{" + + "children=" + children + + ", description='" + this.getDescription() + '\'' + + "} " + super.toString(); + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyGsbpm.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyGsbpm.java new file mode 100644 index 0000000..a5fad89 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyGsbpm.java @@ -0,0 +1,24 @@ +package fr.insee.knowledge.domain.hierarchy; + +import java.util.List; + +public class HierarchyGsbpm extends Hierarchy { + public HierarchyGsbpm() { + } + + public HierarchyGsbpm(String id, String label) { + super(id, label); + } + + public HierarchyGsbpm(String id, String label, String description) { + super(id, label, description); + } + + public HierarchyGsbpm(String id, String label, List children) { + super(id, label, children); + } + + public HierarchyGsbpm(String id, String label, String description, List children) { + super(id, label, description, children); + } +} diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyProduct.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyProduct.java new file mode 100644 index 0000000..71d28a8 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyProduct.java @@ -0,0 +1,50 @@ +package fr.insee.knowledge.domain.hierarchy; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import java.util.List; + +public class HierarchyProduct extends Hierarchy { + + private String iconUrl; + private String color; + + public HierarchyProduct() { + } + + public HierarchyProduct(String id, String label, String description) { + super(id, label, description); + } + + public HierarchyProduct(String id, String label, String description, String iconUrl, String color) { + super(id, label, description); + this.iconUrl = iconUrl; + this.color = color; + } + + public HierarchyProduct(String id, String label, String description, List children, String iconUrl, String color) { + super(id, label, description, children); + this.iconUrl = iconUrl; + this.color = color; + } + + public HierarchyProduct(String id, String label, String description, List children) { + super(id, label, description, children); + } + + public String getIconUrl() { + return iconUrl; + } + + public void setIconUrl(String iconUrl) { + this.iconUrl = iconUrl; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} diff --git a/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java new file mode 100644 index 0000000..2c7864b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyService.java @@ -0,0 +1,25 @@ +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/HierarchyUser.java b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyUser.java new file mode 100644 index 0000000..413845b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/domain/hierarchy/HierarchyUser.java @@ -0,0 +1,25 @@ +package fr.insee.knowledge.domain.hierarchy; + +import java.util.List; + +public class HierarchyUser extends Hierarchy { + + public HierarchyUser() { + } + + public HierarchyUser(String id, String label) { + super(id, label); + } + + public HierarchyUser(String id, String label, String description) { + super(id, label, description); + } + + public HierarchyUser(String id, String label, List children) { + super(id, label, children); + } + + public HierarchyUser(String id, String label, String description, List children) { + super(id, label, description, children); + } +} diff --git a/src/main/java/fr/insee/knowledge/service/FunctionService.java b/src/main/java/fr/insee/knowledge/service/FunctionService.java index c6ded73..909f2bc 100644 --- a/src/main/java/fr/insee/knowledge/service/FunctionService.java +++ b/src/main/java/fr/insee/knowledge/service/FunctionService.java @@ -2,6 +2,7 @@ import fr.insee.knowledge.domain.Function; +import java.io.IOException; import java.util.List; public interface FunctionService { @@ -9,4 +10,7 @@ public interface FunctionService { Function getFunctionById(String id); List getAllFunctions(); + + String importListFunctions() throws IOException; + } diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java new file mode 100644 index 0000000..d751a30 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/HierarchyGsbpmSvc.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..f25337f --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/HierarchyProductSvc.java @@ -0,0 +1,14 @@ +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/HierarchyService.java b/src/main/java/fr/insee/knowledge/service/HierarchyService.java deleted file mode 100644 index a4d3035..0000000 --- a/src/main/java/fr/insee/knowledge/service/HierarchyService.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.insee.knowledge.service; - -import fr.insee.knowledge.domain.Hierarchy; - -import java.util.List; - -public interface HierarchyService { - - Hierarchy getHierarchyById(String id); - - List getAllHierarchies(); - - Boolean isServiceExist(String id); -} diff --git a/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java b/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java new file mode 100644 index 0000000..d9c728d --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/HierarchyServiceSvc.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..ee85c0b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/HierarchyUserSvc.java @@ -0,0 +1,15 @@ +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/ImportFunctionService.java b/src/main/java/fr/insee/knowledge/service/ImportFunctionService.java deleted file mode 100644 index a16ab3d..0000000 --- a/src/main/java/fr/insee/knowledge/service/ImportFunctionService.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.insee.knowledge.service; - -import java.io.IOException; - -public interface ImportFunctionService { - - String importListFunctions(String pathName) throws IOException; - -} diff --git a/src/main/java/fr/insee/knowledge/service/ImportHierarchyService.java b/src/main/java/fr/insee/knowledge/service/ImportHierarchyService.java deleted file mode 100644 index 90c51bf..0000000 --- a/src/main/java/fr/insee/knowledge/service/ImportHierarchyService.java +++ /dev/null @@ -1,9 +0,0 @@ -package fr.insee.knowledge.service; - -import java.io.IOException; - -public interface ImportHierarchyService { - - String importHierarchy(String pathName) throws IOException; - -} diff --git a/src/main/java/fr/insee/knowledge/service/ImportService.java b/src/main/java/fr/insee/knowledge/service/ImportService.java index 97b446b..5fb8b03 100644 --- a/src/main/java/fr/insee/knowledge/service/ImportService.java +++ b/src/main/java/fr/insee/knowledge/service/ImportService.java @@ -4,6 +4,6 @@ import java.util.List; public interface ImportService { - List importHierarchyAndFunction() throws IOException; + String importHierarchyAndFunction() throws IOException; } diff --git a/src/main/java/fr/insee/knowledge/service/facade/ImportServiceFacade.java b/src/main/java/fr/insee/knowledge/service/facade/ImportServiceFacade.java deleted file mode 100644 index b493d80..0000000 --- a/src/main/java/fr/insee/knowledge/service/facade/ImportServiceFacade.java +++ /dev/null @@ -1,47 +0,0 @@ -package fr.insee.knowledge.service.facade; - -import fr.insee.knowledge.dao.FunctionDAO; -import fr.insee.knowledge.dao.HierarchyDAO; -import fr.insee.knowledge.service.ImportFunctionService; -import fr.insee.knowledge.service.ImportHierarchyService; -import fr.insee.knowledge.service.ImportService; -import fr.insee.knowledge.service.impl.ImportFunctionServiceImpl; -import fr.insee.knowledge.service.impl.ImportHierarchyServiceImpl; -import fr.insee.knowledge.service.impl.ImportServiceImpl; -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.util.List; - -@Service -public class ImportServiceFacade implements ImportHierarchyService, ImportFunctionService, ImportService { - - @Autowired - private FunctionDAO functionDAO; - - @Autowired - private HierarchyDAO hierarchyDAO; - - @Value("${fr.insee.knowledge.git.access.rawrepository}") - private String githubRepository; - - @Override - public String importHierarchy(String pathName) throws IOException { - ImportHierarchyService importHierarchyService = new ImportHierarchyServiceImpl(hierarchyDAO, githubRepository); - return importHierarchyService.importHierarchy(pathName); - } - - @Override - public String importListFunctions(String pathName) throws IOException { - ImportFunctionService importFunctionService = new ImportFunctionServiceImpl(functionDAO, githubRepository); - return importFunctionService.importListFunctions(pathName); - } - - @Override - public List importHierarchyAndFunction() throws IOException { - ImportService importService = new ImportServiceImpl(functionDAO, hierarchyDAO, githubRepository); - return importService.importHierarchyAndFunction(); - } -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/FunctionServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/FunctionServiceImpl.java index 1a600ef..9aa71ae 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/FunctionServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/FunctionServiceImpl.java @@ -1,5 +1,9 @@ package fr.insee.knowledge.service.impl; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import fr.insee.knowledge.constants.Constants; import fr.insee.knowledge.dao.FunctionDAO; import fr.insee.knowledge.domain.Function; import fr.insee.knowledge.service.FunctionService; @@ -7,24 +11,66 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; import java.util.List; +import static fr.insee.knowledge.constants.Constants.GithubFunctionFile; + @Service public class FunctionServiceImpl implements FunctionService { @Value("${fr.insee.knowledge.git.access.rawrepository}") private String githubRepository; - @Autowired private FunctionDAO functionDAO; + private final ObjectMapper mapper = new ObjectMapper(); public Function getFunctionById(String idValue) { - return functionDAO.FindById(idValue); + return functionDAO.findById(idValue); } public List getAllFunctions() { return functionDAO.getAllDocuments(); } + public String importListFunctions() throws IOException { + JsonNode jsonNode = mapper.readTree(new URL(githubRepository + GithubFunctionFile)); + List listFunctions = getListFunctionsFromJsonNode(jsonNode); + return functionDAO.insertOrReplaceMany(listFunctions); + } + private List getListFunctionsFromJsonNode(JsonNode rootNode) throws JsonProcessingException { + List listFunction = new ArrayList<>(); + if (rootNode.isArray()) { + for (JsonNode node : rootNode) { + recursiveMapping(listFunction, node, new fr.insee.knowledge.domain.Service()); + } + } + return listFunction; + } + + private void recursiveMapping(List functionList, JsonNode jsonNode, fr.insee.knowledge.domain.Service currentService) throws JsonProcessingException { + currentService.setId(jsonNode.get(Constants.idField).asText()); + currentService.setLabel(jsonNode.get(Constants.labelField).asText()); + + JsonNode functionNodeArray = jsonNode.get(Constants.functionField); + if (functionNodeArray != null) { + for (JsonNode functionNode : functionNodeArray) { + Function function = mapper.treeToValue(functionNode, Function.class); + function.setService(currentService); + functionList.add(function); + } + } + JsonNode node = jsonNode.get(Constants.serviceField); + if (node != null) { + for (JsonNode serviceNode : node) { + fr.insee.knowledge.domain.Service service = new fr.insee.knowledge.domain.Service(); + //TODO test if service exist in database + service.setService(currentService); + recursiveMapping(functionList, serviceNode, service); + } + } + } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java new file mode 100644 index 0000000..e4e19a2 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyGsbpmSvcImpl.java @@ -0,0 +1,46 @@ +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/HierarchyProductSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java new file mode 100644 index 0000000..fde94b4 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyProductSvcImpl.java @@ -0,0 +1,40 @@ +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/HierarchyServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceImpl.java deleted file mode 100644 index 1b0211e..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import fr.insee.knowledge.dao.HierarchyDAO; -import fr.insee.knowledge.domain.Hierarchy; -import fr.insee.knowledge.service.HierarchyService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class HierarchyServiceImpl implements HierarchyService { - @Autowired - private HierarchyDAO hierarchyDAO; - - public Hierarchy getHierarchyById(String idValue) { - return hierarchyDAO.FindById(idValue); - } - - public List getAllHierarchies() { - return hierarchyDAO.getAllDocuments(); - } - - public Boolean isServiceExist(String id) { - //TODO: implement - 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 new file mode 100644 index 0000000..aa9c3e3 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyServiceSvcImpl.java @@ -0,0 +1,45 @@ +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/HierarchyUserSvcImpl.java b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java new file mode 100644 index 0000000..03c8136 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/service/impl/HierarchyUserSvcImpl.java @@ -0,0 +1,45 @@ +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/ImportFunctionServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/ImportFunctionServiceImpl.java deleted file mode 100644 index 07183a3..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/ImportFunctionServiceImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.FunctionDAO; -import fr.insee.knowledge.domain.Function; -import fr.insee.knowledge.domain.Service; -import fr.insee.knowledge.service.ImportFunctionService; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -//TODO Catch and log all exception - - -public class ImportFunctionServiceImpl implements ImportFunctionService { - private final FunctionDAO functionDAO; - private final String githubRepository; - private final ObjectMapper mapper = new ObjectMapper(); - - public ImportFunctionServiceImpl(FunctionDAO functionDAO, String githubRepository) { - this.functionDAO = functionDAO; - this.githubRepository = githubRepository; - } - - public String importListFunctions(String filename) throws IOException { - JsonNode jsonNode = mapper.readTree(new URL(githubRepository + filename)); - List listFunctions = getListFunctionsFromJsonNode(jsonNode); - return functionDAO.insertOrReplaceMany(listFunctions); - } - - private List getListFunctionsFromJsonNode(JsonNode rootNode) throws JsonProcessingException { - List listFunction = new ArrayList<>(); - if (rootNode.isArray()) { - for (JsonNode node : rootNode) { - recursiveMapping(listFunction, node, new Service()); - } - } - return listFunction; - } - - private void recursiveMapping(List functionList, JsonNode jsonNode, Service currentService) throws JsonProcessingException { - currentService.setId(jsonNode.get(Constants.idField).asText()); - currentService.setLabel(jsonNode.get(Constants.labelField).asText()); - - JsonNode functionNodeArray = jsonNode.get(Constants.functionField); - if (functionNodeArray != null) { - for (JsonNode functionNode : functionNodeArray) { - Function function = mapper.treeToValue(functionNode, Function.class); - function.setService(currentService); - functionList.add(function); - } - } - JsonNode node = jsonNode.get(Constants.serviceField); - if (node != null) { - for (JsonNode serviceNode : node) { - Service service = new Service(); - //TODO test if service exist in database - service.setService(currentService); - recursiveMapping(functionList, serviceNode, service); - } - } - } - - -} diff --git a/src/main/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImpl.java deleted file mode 100644 index adc72fc..0000000 --- a/src/main/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import fr.insee.knowledge.dao.HierarchyDAO; -import fr.insee.knowledge.domain.Hierarchy; -import fr.insee.knowledge.service.ImportHierarchyService; -import lombok.extern.slf4j.Slf4j; - -import java.io.IOException; -import java.net.URL; - -@Slf4j -public class ImportHierarchyServiceImpl implements ImportHierarchyService { - private final HierarchyDAO hierarchyDAO; - private final String githubRepository; - private final ObjectMapper mapper = new ObjectMapper(); - - public ImportHierarchyServiceImpl(HierarchyDAO hierarchyDAO, String githubRepository) { - this.hierarchyDAO = hierarchyDAO; - this.githubRepository = githubRepository; - } - - public String importHierarchy(String filename) throws IOException { - Hierarchy hierarchy = mapper.readValue(new URL(githubRepository + filename), Hierarchy.class); - return hierarchyDAO.insertOrReplaceOne(hierarchy); - } - -} \ No newline at end of file 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 174fca3..1171233 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/ImportServiceImpl.java @@ -1,47 +1,37 @@ package fr.insee.knowledge.service.impl; -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.FunctionDAO; -import fr.insee.knowledge.dao.HierarchyDAO; -import fr.insee.knowledge.service.ImportFunctionService; -import fr.insee.knowledge.service.ImportHierarchyService; -import fr.insee.knowledge.service.ImportService; +import fr.insee.knowledge.service.*; +import org.springframework.stereotype.Service; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; //TODO Catch and log all exception - +@Service public class ImportServiceImpl implements ImportService { - private final FunctionDAO functionDAO; - private final HierarchyDAO hierarchyDAO; - private final String githubRepository; - - private final ImportFunctionService importFunctionService; - private final ImportHierarchyService importHierarchyService; - - public ImportServiceImpl(FunctionDAO functionDAO, HierarchyDAO hierarchyDAO, String githubRepository) { - this.functionDAO = functionDAO; - this.hierarchyDAO = hierarchyDAO; - this.githubRepository = githubRepository; - this.importFunctionService = new ImportFunctionServiceImpl(functionDAO, githubRepository); - this.importHierarchyService = new ImportHierarchyServiceImpl(hierarchyDAO, githubRepository); + private final FunctionService functionService; + private final HierarchyServiceSvc hierarchyServiceSvc; + private final HierarchyUserSvc hierarchyUserSvc; + private final HierarchyGsbpmSvc hierarchyGsbpmSvc; + private final HierarchyProductSvc hierarchyProductSvc; + + public ImportServiceImpl(FunctionService functionService, HierarchyServiceSvc hierarchyServiceSvc, HierarchyUserSvc hierarchyUserSvc, HierarchyGsbpmSvc hierarchyGsbpmSvc, HierarchyProductSvc hierarchyProductSvc) { + this.functionService = functionService; + this.hierarchyServiceSvc = hierarchyServiceSvc; + this.hierarchyUserSvc = hierarchyUserSvc; + this.hierarchyGsbpmSvc = hierarchyGsbpmSvc; + this.hierarchyProductSvc = hierarchyProductSvc; } - public List importHierarchyAndFunction() throws IOException { - List results = new ArrayList(); - Constants.ListHierarchy.forEach(filename -> { - try { - results.add(filename + " " + importHierarchyService.importHierarchy(filename)); - } catch (IOException e) { - e.printStackTrace(); - } - }); - results.add(Constants.GithubFunctionFile + " " + importFunctionService.importListFunctions(Constants.GithubFunctionFile)); - return results; + 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(functionService.importListFunctions()); + return stringBuilder.toString(); } } diff --git a/src/main/java/fr/insee/knowledge/service/impl/InitializerServiceImpl.java b/src/main/java/fr/insee/knowledge/service/impl/InitializerServiceImpl.java index 3095e6f..6c11d17 100644 --- a/src/main/java/fr/insee/knowledge/service/impl/InitializerServiceImpl.java +++ b/src/main/java/fr/insee/knowledge/service/impl/InitializerServiceImpl.java @@ -7,8 +7,8 @@ import com.mongodb.client.model.ValidationLevel; import com.mongodb.client.model.ValidationOptions; import fr.insee.knowledge.constants.Constants; +import fr.insee.knowledge.service.ImportService; import fr.insee.knowledge.service.InitializerService; -import fr.insee.knowledge.service.facade.ImportServiceFacade; import fr.insee.knowledge.utils.Utils; import org.bson.Document; import org.slf4j.Logger; @@ -26,7 +26,7 @@ public class InitializerServiceImpl implements InitializerService { private MongoDatabase mongoDatabase; @Autowired - private ImportServiceFacade importService; + private ImportService importService; private final static Logger logger = LoggerFactory.getLogger(InitializerServiceImpl.class); @@ -53,10 +53,10 @@ public void createCollections() { public void importDataFromGithub() throws IOException { logger.info("Import Data from Github"); try { - List result = importService.importHierarchyAndFunction(); + String result = importService.importHierarchyAndFunction(); logger.info(String.valueOf(result)); } catch (Exception e) { - logger.error("Error could not import data from github. Execption occured " + e); + logger.error("Error could not import data from github. Execption occured ", e); } } } diff --git a/src/test/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImplTest.java b/src/test/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImplTest.java deleted file mode 100644 index 2874ccf..0000000 --- a/src/test/java/fr/insee/knowledge/service/impl/ImportHierarchyServiceImplTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package fr.insee.knowledge.service.impl; - -import fr.insee.knowledge.constants.Constants; -import fr.insee.knowledge.dao.HierarchyDAO; -import fr.insee.knowledge.service.ImportHierarchyService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.io.IOException; - -import static org.assertj.core.api.Assertions.assertThat; - -@ExtendWith(MockitoExtension.class) -public class ImportHierarchyServiceImplTest { - - @Mock - private HierarchyDAO hierarchyDAO; - - public void importHierarchyTest() throws IOException { - ImportHierarchyService importHierarchy = new ImportHierarchyServiceImpl(hierarchyDAO, "https://raw.githubusercontent.com/ddecrulle/Knowledge-Data/main/"); - String result = importHierarchy.importHierarchy(Constants.GithubProductsFile); - assertThat(result).isNotEmpty(); - } -}