Skip to content

Commit

Permalink
big ugly refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Apr 3, 2023
1 parent a8ed1ab commit 64e664a
Show file tree
Hide file tree
Showing 48 changed files with 689 additions and 437 deletions.
18 changes: 7 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>fr.insee.knowledge</groupId>
<artifactId>knowledge</artifactId>
<version>0.4.7</version>
<version>0.5.0</version>
<packaging>jar</packaging>
<name>Knowledge-Back-Office</name>
<description>Back-office services for Knowledge</description>
Expand All @@ -25,6 +25,12 @@
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -49,16 +55,6 @@
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.mongodb</groupId>-->
<!-- <artifactId>mongodb-driver-core</artifactId>-->
<!-- <version>4.7.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mongodb</groupId>-->
<!-- <artifactId>bson</artifactId>-->
<!-- <version>4.7.1</version>-->
<!-- </dependency>-->

<!-- Commons -->
<dependency>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/fr/insee/knowledge/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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<HierarchyProduct> getProducts() {
HierarchyProduct result = hierarchyProductSvc.getProducts();
return new ResponseEntity<HierarchyProduct>(result, HttpStatus.OK);
}

@Operation(summary = "Get Gsbpm")
@GetMapping(path = "/gsbpm")
public ResponseEntity<HierarchyGsbpm> getGsbpm() {
HierarchyGsbpm result = hierarchyGsbpmSvc.getGsbpm();
return new ResponseEntity<HierarchyGsbpm>(result, HttpStatus.OK);
}

@Operation(summary = "Get Hierarchy by id")
@GetMapping(path = "/{id}")
public ResponseEntity<Hierarchy> getHierarchyById(@PathVariable(value = "id") String id) {
Hierarchy result = hierarchyService.getHierarchyById(id);
return new ResponseEntity<Hierarchy>(result, HttpStatus.OK);
@Operation(summary = "Get Services")
@GetMapping(path = "/services")
public ResponseEntity<HierarchyService> getServices() {
HierarchyService result = hierarchyServiceSvc.getService();
return new ResponseEntity<HierarchyService>(result, HttpStatus.OK);
}

@Operation(summary = "Get all hierarchies")
@GetMapping(path = "/all")
public ResponseEntity<List<Hierarchy>> getAllHierarchies() {
List<Hierarchy> result = hierarchyService.getAllHierarchies();
return new ResponseEntity<List<Hierarchy>>(result, HttpStatus.OK);
@Operation(summary = "Get Users")
@GetMapping(path = "/users")
public ResponseEntity<HierarchyUser> getUsers() {
HierarchyUser result = hierarchyUserSvc.getUser();
return new ResponseEntity<HierarchyUser>(result, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> importFunctions() throws IOException {
String result = importService.importListFunctions(Constants.GithubFunctionFile);
String result = functionService.importListFunctions();
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import GSBPM")
@GetMapping(path = "/hierarchy/gsbpm")
public ResponseEntity<String> importGsbpm() throws IOException {
String result = importService.importHierarchy(Constants.GithubGsbpmFile);
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import Status")
@GetMapping(path = "/hierarchy/status")
public ResponseEntity<String> importStatus() throws IOException {
String result = importService.importHierarchy(Constants.GithubStatusFile);
String result = hierarchyGsbpmSvc.importGsbpm();
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import Services")
@GetMapping(path = "/hierarchy/services")
public ResponseEntity<String> importServices() throws IOException {
String result = importService.importHierarchy(Constants.GithubServicesFile);
String result = hierarchyServiceSvc.importService();
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import Products")
@GetMapping(path = "/hierarchy/products")
public ResponseEntity<String> importProducts() throws IOException {
String result = importService.importHierarchy(Constants.GithubProductsFile);
String result = hierarchyProductSvc.importProduct();
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import Users")
@GetMapping(path = "/hierarchy/user")
public ResponseEntity<String> importUsers() throws IOException {
String result = importService.importHierarchy(Constants.GithubUserFile);
String result = hierarchyUserSvc.importUser();
return new ResponseEntity<String>(result, HttpStatus.OK);
}

@Operation(summary = "Import All")
@GetMapping(path = "/import-hierarchy-and-functions")
public ResponseEntity<String> importHierarchyAndFunction() throws IOException {
List<String> results = importService.importHierarchyAndFunction();
return new ResponseEntity<String>(results.toString(), HttpStatus.OK);
String results = importService.importHierarchyAndFunction();
return new ResponseEntity<String>(results, HttpStatus.OK);
}
}
7 changes: 0 additions & 7 deletions src/main/java/fr/insee/knowledge/dao/HierarchyDAO.java

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/java/fr/insee/knowledge/dao/HierarchyDAOImpl.java

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/fr/insee/knowledge/dao/HierarchyGsbpmDAO.java
Original file line number Diff line number Diff line change
@@ -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<HierarchyGsbpm> {
}

9 changes: 9 additions & 0 deletions src/main/java/fr/insee/knowledge/dao/HierarchyProductDAO.java
Original file line number Diff line number Diff line change
@@ -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<HierarchyProduct> {
}

8 changes: 8 additions & 0 deletions src/main/java/fr/insee/knowledge/dao/HierarchyServiceDAO.java
Original file line number Diff line number Diff line change
@@ -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<HierarchyService> {
}

9 changes: 9 additions & 0 deletions src/main/java/fr/insee/knowledge/dao/HierarchyUserDAO.java
Original file line number Diff line number Diff line change
@@ -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<HierarchyUser> {
}

6 changes: 3 additions & 3 deletions src/main/java/fr/insee/knowledge/dao/generic/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -83,7 +83,7 @@ public FindIterable<T> findByKeyValue(String key, String value) {
return iterable;
}

public T FindById(String value) {
public T findById(String value) {
return findByKeyValue("_id", value).first();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/knowledge/dao/generic/IDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IDao<T extends GenericIDLabel> {

FindIterable<T> findByKeyValue(String key, String value);

T FindById(String idValue);
T findById(String idValue);

List<T> getAllDocuments();
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HierarchyGsbpm> implements HierarchyGsbpmDAO {
public HierarchyGsbpmDAOImpl() {
super(HierarchyGsbpm.class, Constants.CollectionHierarchy);
}

}
Original file line number Diff line number Diff line change
@@ -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<HierarchyProduct> implements HierarchyProductDAO {
public HierarchyProductDAOImpl() {
super(HierarchyProduct.class, Constants.CollectionHierarchy);
}

}
Original file line number Diff line number Diff line change
@@ -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<HierarchyService> implements HierarchyServiceDAO {
public HierarchyServiceDAOImpl() {
super(HierarchyService.class, Constants.CollectionHierarchy);
}

}
Original file line number Diff line number Diff line change
@@ -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<HierarchyUser> implements HierarchyUserDAO {
public HierarchyUserDAOImpl() {
super(HierarchyUser.class, Constants.CollectionHierarchy);
}

}
Loading

0 comments on commit 64e664a

Please sign in to comment.