diff --git a/pom.xml b/pom.xml index 5c308e3..7d7782f 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,11 @@ jackson-databind 2.12.3 + + com.fasterxml.jackson.core + jackson-core + 2.12.3 + com.fasterxml.jackson.core jackson-annotations @@ -81,6 +86,12 @@ + + io.springfox diff --git a/src/main/java/fr/insee/knowledge/controller/KnowledgeResourcesAPI.java b/src/main/java/fr/insee/knowledge/controller/KnowledgeResourcesAPI.java index 1ef062f..4211639 100644 --- a/src/main/java/fr/insee/knowledge/controller/KnowledgeResourcesAPI.java +++ b/src/main/java/fr/insee/knowledge/controller/KnowledgeResourcesAPI.java @@ -1,7 +1,11 @@ package fr.insee.knowledge.controller; -import fr.insee.knowledge.data.access.ServiceDataAccess; +import fr.insee.knowledge.git.access.GsbpmDataAccess; +import fr.insee.knowledge.git.access.ProductDataAccess; +import fr.insee.knowledge.git.access.ServiceDataAccess; +import fr.insee.knowledge.domain.Gsbpm; import fr.insee.knowledge.domain.KnowledgeFile; +import fr.insee.knowledge.domain.Product; import fr.insee.knowledge.domain.Service; import io.swagger.annotations.ApiOperation; import org.apache.commons.io.filefilter.NotFileFilter; @@ -28,7 +32,7 @@ import java.util.Locale; @RestController -@RequestMapping(path = "/api") +@RequestMapping(path = "/git") public class KnowledgeResourcesAPI { private final static Logger LOGGER = LoggerFactory.getLogger(KnowledgeResourcesAPI.class); @@ -36,6 +40,12 @@ public class KnowledgeResourcesAPI { @Autowired ServiceDataAccess serviceDataAccess; + @Autowired + GsbpmDataAccess gsbpmDataAccess; + + @Autowired + ProductDataAccess productDataAccess; + /** * This method is using to get all files from git repo with JSON extensions * @@ -67,11 +77,11 @@ public ResponseEntity getFiles() throws IOException, GitAPIException { } /** - * This method is using to get services JSON representation + * This method is using to get services JSON representation from git repo * * @return List of all {@link fr.insee.knowledge.domain.Service} */ - @ApiOperation(value = "Get services") + @ApiOperation(value = "Get services from git repo") @GetMapping(path = "/services") public ResponseEntity getServices() throws IOException, GitAPIException { List services = null; @@ -98,6 +108,70 @@ public ResponseEntity getServices() throws IOException, GitAPIException return new ResponseEntity<>(services, HttpStatus.OK); } + /** + * This method is using to get GSBPM JSON representation from git repo + * + * @return List of all {@link fr.insee.knowledge.domain.Gsbpm} + */ + @ApiOperation(value = "Get GSBPM Phases from git repo") + @GetMapping(path = "/gsbpm") + public ResponseEntity getGSBPM() throws IOException, GitAPIException { + List gsbpms = 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 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("gsbpm.json")){ + gsbpms = gsbpmDataAccess.serializeFromFile(file); + LOGGER.info("gsbpm.json serialized"); + } + } + LOGGER.info("GET gsbpm resulting in 200"); + return new ResponseEntity<>(gsbpms, HttpStatus.OK); + } + + /** + * This method is using to get produit JSON representation from git repo + * + * @return List of all {@link fr.insee.knowledge.domain.Product} + */ + @ApiOperation(value = "Get Product from git repo") + @GetMapping(path = "/products") + public ResponseEntity getProducts() throws IOException, GitAPIException { + List products = 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 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("produits.json")){ + products = productDataAccess.serializeFromFile(file); + LOGGER.info("produits.json serialized"); + } + } + LOGGER.info("GET produit resulting in 200"); + return new ResponseEntity<>(products, HttpStatus.OK); + } + } diff --git a/src/main/java/fr/insee/knowledge/domain/Gsbpm.java b/src/main/java/fr/insee/knowledge/domain/Gsbpm.java index e4d18b4..6c9c49c 100644 --- a/src/main/java/fr/insee/knowledge/domain/Gsbpm.java +++ b/src/main/java/fr/insee/knowledge/domain/Gsbpm.java @@ -1,13 +1,20 @@ package fr.insee.knowledge.domain; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + import java.util.List; public class Gsbpm { + @JsonProperty("id") private String id; + @JsonProperty("label") private String label; + @JsonProperty("description") private String description; - private List children; + @JsonDeserialize(contentAs=Gsbpm.class) + private List processus; public String getId() { return id; @@ -33,11 +40,11 @@ public void setDescription(String description) { this.description = description; } - public List getChildren() { - return children; + public List getProcessus() { + return processus; } - public void setChildren(List children) { - this.children = children; + public void setProcessus(List processus) { + this.processus = processus; } } diff --git a/src/main/java/fr/insee/knowledge/domain/Product.java b/src/main/java/fr/insee/knowledge/domain/Product.java index 16ff2aa..49e3e92 100644 --- a/src/main/java/fr/insee/knowledge/domain/Product.java +++ b/src/main/java/fr/insee/knowledge/domain/Product.java @@ -1,14 +1,19 @@ package fr.insee.knowledge.domain; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; public class Product { + @JsonProperty("nom") private String name; + @JsonProperty("description") private String description; + @JsonProperty("mode") private String mode; + @JsonProperty("utilisation") private String usage; - private List relatedProducts; + @JsonProperty("produits") + private String relatedProducts; public String getName() { return name; @@ -42,11 +47,11 @@ public void setUsage(String usage) { this.usage = usage; } - public List getRelatedProducts() { + public String getRelatedProducts() { return relatedProducts; } - public void setRelatedProducts(List relatedProducts) { + public void setRelatedProducts(String relatedProducts) { this.relatedProducts = relatedProducts; } } diff --git a/src/main/java/fr/insee/knowledge/git/access/GsbpmDataAccess.java b/src/main/java/fr/insee/knowledge/git/access/GsbpmDataAccess.java new file mode 100644 index 0000000..c4fcc1b --- /dev/null +++ b/src/main/java/fr/insee/knowledge/git/access/GsbpmDataAccess.java @@ -0,0 +1,26 @@ +package fr.insee.knowledge.git.access; + + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import fr.insee.knowledge.domain.Gsbpm; +import fr.insee.knowledge.domain.KnowledgeFile; + + +import java.io.File; +import java.io.IOException; +import java.util.List; + +@org.springframework.stereotype.Service +public class GsbpmDataAccess { + + public List serializeFromFile(KnowledgeFile resource) throws IOException { + + ObjectMapper objectMapper = new ObjectMapper(); + List gsbpms; + gsbpms = objectMapper.readValue(new File(resource.getPath()), new TypeReference>() {}); + return gsbpms; + + } + +} diff --git a/src/main/java/fr/insee/knowledge/git/access/ProductDataAccess.java b/src/main/java/fr/insee/knowledge/git/access/ProductDataAccess.java new file mode 100644 index 0000000..8e625a2 --- /dev/null +++ b/src/main/java/fr/insee/knowledge/git/access/ProductDataAccess.java @@ -0,0 +1,25 @@ +package fr.insee.knowledge.git.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.Product; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +@org.springframework.stereotype.Service +public class ProductDataAccess { + + public List serializeFromFile(KnowledgeFile resource) throws IOException { + + ObjectMapper objectMapper = new ObjectMapper(); + List products; + products = objectMapper.readValue(new File(resource.getPath()), new TypeReference>() {}); + return products; + + } + +} diff --git a/src/main/java/fr/insee/knowledge/data/access/ServiceDataAccess.java b/src/main/java/fr/insee/knowledge/git/access/ServiceDataAccess.java similarity index 94% rename from src/main/java/fr/insee/knowledge/data/access/ServiceDataAccess.java rename to src/main/java/fr/insee/knowledge/git/access/ServiceDataAccess.java index cf272de..65ce220 100644 --- a/src/main/java/fr/insee/knowledge/data/access/ServiceDataAccess.java +++ b/src/main/java/fr/insee/knowledge/git/access/ServiceDataAccess.java @@ -1,4 +1,4 @@ -package fr.insee.knowledge.data.access; +package fr.insee.knowledge.git.access; import com.fasterxml.jackson.core.type.TypeReference;