Skip to content

Commit

Permalink
Merge pull request #11 from ddecrulle/new-data-model
Browse files Browse the repository at this point in the history
New data model
  • Loading branch information
ddecrulle authored May 31, 2023
2 parents fe6e30f + c9189db commit 8d5384a
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 100 deletions.
2 changes: 1 addition & 1 deletion 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.6.0</version>
<version>0.7.0</version>
<packaging>jar</packaging>
<name>Knowledge-Back-Office</name>
<description>Back-office services for Knowledge</description>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/insee/knowledge/StarterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ public static SpringApplicationBuilder configureApplicationBuilder(SpringApplica
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() throws IOException {
initializer.createCollections();
initializer.importDataFromGithub();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.insee.knowledge.controller.errors;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@RequiredArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ErrorResponse {
private final int status;
private final String message;
private final List<String> errors;
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
@RestController
@RequestMapping(path = "/function")
public class FunctionController {

private final static Logger logger = LoggerFactory.getLogger(FunctionController.class);

@Autowired
private FunctionService functionService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import org.springframework.web.bind.annotation.RestController;

public class GenericHierarchyController<T extends Hierarchy> {

private final static Logger logger = LoggerFactory.getLogger(GenericHierarchyController.class);

private final GenericHierarchyService<T> hierarchyService;

public GenericHierarchyController(GenericHierarchyService<T> hierarchyService) {
Expand All @@ -30,4 +27,6 @@ public GenericHierarchyController(GenericHierarchyService<T> hierarchyService) {
public ResponseEntity<T> getHierarchy() {
return new ResponseEntity<T>(hierarchyService.getHierarchy(), HttpStatus.OK);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.LoggerFactory;
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,4 +25,12 @@ public HierarchyGsbpmController(HierarchyGsbpmServiceImpl hierarchyService) {
public ResponseEntity<HierarchyGsbpm> getGsbpm() {
return getHierarchy();
}

@Operation(summary = "Get a Sub Gsbpm by Id")
@GetMapping(path = "/gsbpm/{id}")
public ResponseEntity<HierarchyGsbpm> getGsbpmChildById(@PathVariable(value = "id") String id) {
return getHierarchy();
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fr.insee.knowledge.controller.importdata;

import fr.insee.knowledge.service.*;
import fr.insee.knowledge.controller.errors.ErrorResponse;
import fr.insee.knowledge.service.FunctionService;
import fr.insee.knowledge.service.ImportService;
import fr.insee.knowledge.service.exceptions.FunctionValidationException;
import fr.insee.knowledge.service.impl.HierarchyGsbpmServiceImpl;
import fr.insee.knowledge.service.impl.HierarchyProductServiceImpl;
import fr.insee.knowledge.service.impl.HierarchySvcServiceImpl;
Expand All @@ -9,24 +12,21 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Tag(name = "Import Data", description = "Import Data from Github")
@RestController
@Slf4j
@RequestMapping(path = "/import")
public class ImportGithubController {
private ImportService importService;
private HierarchyProductServiceImpl hierarchyProductSvc;
private HierarchyGsbpmServiceImpl hierarchyGsbpmSvc;
private HierarchyUserServiceImpl hierarchyUserSvc;
private HierarchySvcServiceImpl hierarchyServiceSvc;
private final ImportService importService;
private final HierarchyProductServiceImpl hierarchyProductSvc;
private final HierarchyGsbpmServiceImpl hierarchyGsbpmSvc;
private final HierarchyUserServiceImpl hierarchyUserSvc;
private final HierarchySvcServiceImpl hierarchyServiceSvc;
private final FunctionService functionService;

public ImportGithubController(ImportService importService, HierarchyProductServiceImpl hierarchyProductSvc, HierarchyGsbpmServiceImpl hierarchyGsbpmSvc,
HierarchyUserServiceImpl hierarchyUserSvc, HierarchySvcServiceImpl hierarchyServiceSvc, FunctionService functionService) {
Expand All @@ -38,47 +38,45 @@ public ImportGithubController(ImportService importService, HierarchyProductServi
this.functionService = functionService;
}

private FunctionService functionService;

@Operation(summary = "Import Functions")
@GetMapping(path = "/functions")
public ResponseEntity<String> importFunctions() throws IOException {
String result = functionService.importListFunctions();
return new ResponseEntity<String>(result, HttpStatus.OK);
public String importFunctions() throws IOException {
return functionService.importListFunctions();
}

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

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

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

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

@Operation(summary = "Import All")
@GetMapping(path = "/import-hierarchy-and-functions")
public ResponseEntity<String> importHierarchyAndFunction() throws IOException {
String results = importService.importHierarchyAndFunction();
return new ResponseEntity<String>(results, HttpStatus.OK);
public String importHierarchyAndFunction() throws IOException {
return importService.importHierarchyAndFunction();
}

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(FunctionValidationException.class)
public ErrorResponse handleFunctionValidationException(FunctionValidationException ex) {
return new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage(), ex.getErrorMessages());
}
}
1 change: 0 additions & 1 deletion src/main/java/fr/insee/knowledge/dao/generic/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public String insertOrReplaceOne(T document) {
}
}


public String insertOrReplaceMany(List<T> documents) {
try {
List<WriteModel<T>> bulkOperations = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class HierarchyDAOImpl<T extends Hierarchy> extends DAO<T> {
public HierarchyDAOImpl() {
super(Constants.CollectionHierarchy);
}

}
8 changes: 4 additions & 4 deletions src/main/java/fr/insee/knowledge/domain/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Function extends GenericIDLabel {
private int dispo;
private Boolean dispo;
private GenericIDLabel gsbpm;
private String idProduct;
private List<GenericIDLabel> users;
private List<GenericIDLabel> products;
private List<Task> tasks;
private Service service;

public Function(String id, String label, String description, int dispo, Gsbpm gsbpm, String idProduct, List<GenericIDLabel> users, List<Gsbpm> tools, List<Task> tasks, Service service) {
public Function(String id, String label, String description, Boolean dispo, Gsbpm gsbpm, String idProduct, List<GenericIDLabel> users, List<Gsbpm> tools, List<Task> tasks, Service service) {
super(id, label, description);
this.dispo = dispo;
this.gsbpm = gsbpm;
Expand All @@ -28,11 +28,11 @@ public Function() {
super();
}

public int getDispo() {
public Boolean getDispo() {
return dispo;
}

public void setDispo(int dispo) {
public void setDispo(Boolean dispo) {
this.dispo = dispo;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/GenericIDLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public String getLabel() {
public void setLabel(String label) {
this.label = label;
}

public boolean hasId(String targetId) {
return id.equals(targetId);
}
}
83 changes: 83 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/RawFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package fr.insee.knowledge.domain;

import java.util.List;

public class RawFunction extends GenericIDLabel {
private Boolean dispo;
private String gsbpm;
private String idProduct;
private List<String> users;
private List<String> products;
private List<Task> tasks;
private Service service;

public RawFunction(String id, String label, String description, Boolean dispo, String gsbpm, String idProduct, List<String> users, List<String> products, List<Task> 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;
}

public RawFunction() {
}

public Boolean getDispo() {
return dispo;
}

public void setDispo(Boolean dispo) {
this.dispo = dispo;
}

public String getGsbpm() {
return gsbpm;
}

public void setGsbpm(String gsbpm) {
this.gsbpm = gsbpm;
}

public String getIdProduct() {
return idProduct;
}

public void setIdProduct(String idProduct) {
this.idProduct = idProduct;
}

public List<String> getUsers() {
return users;
}

public void setUsers(List<String> users) {
this.users = users;
}

public List<String> getProducts() {
return products;
}

public void setProducts(List<String> products) {
this.products = products;
}

public List<Task> getTasks() {
return tasks;
}

public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}

public Service getService() {
return service;
}

public void setService(Service service) {
this.service = service;
}
}
15 changes: 15 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/hierarchy/Hierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ public List<T> getChildren() {
public void setChildren(List<T> children) {
this.children = children;
}

public Hierarchy<T> getChildrenById(String targetId) {
if (hasId(targetId)) {
return this;
}
if (this.children != null) {
for (T child : this.children) {
Hierarchy<T> found = child.getChildrenById(targetId);
if (found != null) {
return found;
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface GenericHierarchyService<T extends Hierarchy> {
String importHierarchy() throws IOException;

T findHierarchyById(String id);

Hierarchy<T> findChildrenById(String idChildren);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
public interface InitializerService {

void createCollections();

void importDataFromGithub() throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fr.insee.knowledge.service.exceptions;

import lombok.Getter;

import java.util.List;

@Getter
public class FunctionValidationException extends RuntimeException {
private final List<String> errorMessages;

public FunctionValidationException(String message, List<String> errorMessages) {
super(message);
this.errorMessages = errorMessages;
}
}
Loading

0 comments on commit 8d5384a

Please sign in to comment.