Skip to content

Commit

Permalink
implement model
Browse files Browse the repository at this point in the history
  • Loading branch information
bwerquin committed Dec 21, 2021
1 parent 12c1ed2 commit 06906b2
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 5 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
<version>2.11.0</version>
</dependency>

<!-- JSON serialization -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.3</version>
</dependency>

<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package fr.insee.knowledge.controller;

import fr.insee.knowledge.data.access.ServiceDataAccess;
import fr.insee.knowledge.domain.KnowledgeFile;
import fr.insee.knowledge.domain.Service;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.eclipse.jgit.api.errors.GitAPIException;
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;
Expand All @@ -19,21 +22,22 @@
import java.io.File;
import java.nio.file.Files;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import java.util.Locale;

@RestController
@RequestMapping(path = "/api")
public class KnowledgeResourcesAPI {

private final static Logger LOGGER = LoggerFactory.getLogger(KnowledgeResourcesAPI.class);

@Autowired
ServiceDataAccess serviceDataAccess;

/**
* This method is using to get all files from git repo
* This method is using to get all files from git repo with JSON extensions
*
* @return List of all {@link KnowledgeFile}
*/
Expand All @@ -48,7 +52,7 @@ public ResponseEntity<Object> getFiles() throws IOException, GitAPIException {
.setURI("https://github.com/bwerquin/Knowledge-Data.git")
.setDirectory(localPath)
.call();
NotFileFilter suffixFileFilterFileFilter=new NotFileFilter(new SuffixFileFilter(new String[] { "txt", "java" }));
NotFileFilter suffixFileFilterFileFilter=new NotFileFilter(new SuffixFileFilter(new String[] { "md", "MD", ".git",".pack","idx" }));
Collection<File> files = FileUtils.listFiles(localPath, suffixFileFilterFileFilter, TrueFileFilter.INSTANCE);
for(File file2 : files){
KnowledgeFile file = new KnowledgeFile();
Expand All @@ -62,6 +66,39 @@ public ResponseEntity<Object> getFiles() throws IOException, GitAPIException {
return new ResponseEntity<>(resp, HttpStatus.OK);
}

/**
* This method is using to get services JSON representation
*
* @return List of all {@link fr.insee.knowledge.domain.Service}
*/
@ApiOperation(value = "Get services")
@GetMapping(path = "/services")
public ResponseEntity<Object> getServices() throws IOException, GitAPIException {
List<Service> services = null;
File localPath = File.createTempFile("GitRepositoryKnowledge", "");
Files.delete(localPath.toPath());

Git git = Git.cloneRepository()
.setURI("https://github.com/bwerquin/Knowledge-Data.git")
.setDirectory(localPath)
.call();
NotFileFilter suffixFileFilterFileFilter=new NotFileFilter(new SuffixFileFilter(new String[] { "md", "MD", ".git",".pack","idx"}));
Collection<File> files = FileUtils.listFiles(localPath, suffixFileFilterFileFilter, TrueFileFilter.INSTANCE);
for(File file2 : files){
KnowledgeFile file = new KnowledgeFile();
file.setFileName(file2.getName());
file.setFolder(file2.isDirectory());
file.setPath(file2.getPath());
if(file2.getName().toUpperCase(Locale.ROOT).equalsIgnoreCase("services.json")){
services = serviceDataAccess.serializeFromFile(file);
LOGGER.info("services.json serialized");
}
}
LOGGER.info("GET services resulting in 200");
return new ResponseEntity<>(services, HttpStatus.OK);
}


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fr.insee.knowledge.data.access;


import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insee.knowledge.domain.KnowledgeFile;
import fr.insee.knowledge.domain.Service;

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

@org.springframework.stereotype.Service
public class ServiceDataAccess {

public List<Service> serializeFromFile(KnowledgeFile resource) throws IOException {

ObjectMapper objectMapper = new ObjectMapper();
List<Service> services;
services = objectMapper.readValue(new File(resource.getPath()), new TypeReference<List<Service>>() {});
return services;

}

}
80 changes: 80 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/Function.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package fr.insee.knowledge.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.List;

public class Function {

@JsonProperty("label")
public String label;
@JsonProperty("utilisateurs")
public String users;
@JsonProperty("dispo")
public int available;
@JsonProperty("description")
public String description;
@JsonProperty("gsbpm")
public String gsbpm;
@JsonDeserialize(contentAs = Task.class)
public List<Task> taches;
@JsonProperty("produit")
public String products;

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getUsers() {
return users;
}

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

public int getAvailable() {
return available;
}

public void setAvailable(int available) {
this.available = available;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getGsbpm() {
return gsbpm;
}

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

public List<Task> getTaches() {
return taches;
}

public void setTaches(List<Task> taches) {
this.taches = taches;
}

public String getProducts() {
return products;
}

public void setProducts(String products) {
this.products = products;
}
}
43 changes: 43 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/Gsbpm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fr.insee.knowledge.domain;

import java.util.List;

public class Gsbpm {

private String id;
private String label;
private String description;
private List<Gsbpm> children;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public List<Gsbpm> getChildren() {
return children;
}

public void setChildren(List<Gsbpm> children) {
this.children = children;
}
}
52 changes: 52 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package fr.insee.knowledge.domain;

import java.util.List;

public class Product {

private String name;
private String description;
private String mode;
private String usage;
private List<Product> relatedProducts;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getMode() {
return mode;
}

public void setMode(String mode) {
this.mode = mode;
}

public String getUsage() {
return usage;
}

public void setUsage(String usage) {
this.usage = usage;
}

public List<Product> getRelatedProducts() {
return relatedProducts;
}

public void setRelatedProducts(List<Product> relatedProducts) {
this.relatedProducts = relatedProducts;
}
}
80 changes: 80 additions & 0 deletions src/main/java/fr/insee/knowledge/domain/Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package fr.insee.knowledge.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.util.List;

public class Service {

@JsonProperty("id")
public String id;
@JsonProperty("label")
public String label;
@JsonProperty("description")
public String description;
@JsonProperty("niveau")
public int level;
@JsonProperty("gsbpm")
public String gsbpm;
@JsonDeserialize(contentAs=Service.class)
public List<Service> service;
@JsonDeserialize(contentAs=Function.class)
public List<Function> fonction;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public int getLevel() {
return level;
}

public void setLevel(int level) {
this.level = level;
}

public String getGsbpm() {
return gsbpm;
}

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

public List<Service> getService() {
return service;
}

public void setService(List<Service> service) {
this.service = service;
}

public List<Function> getFonction() {
return fonction;
}

public void setFonction(List<Function> fonction) {
this.fonction = fonction;
}
}
Loading

0 comments on commit 06906b2

Please sign in to comment.