Skip to content

Commit

Permalink
add mapping for services, product and gsbpm
Browse files Browse the repository at this point in the history
  • Loading branch information
bwerquin committed Jan 17, 2022
1 parent 06906b2 commit 2dfd017
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 14 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down Expand Up @@ -81,6 +86,12 @@
</exclusion>
</exclusions>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>-->

<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -28,14 +32,20 @@
import java.util.Locale;

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

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

@Autowired
ServiceDataAccess serviceDataAccess;

@Autowired
GsbpmDataAccess gsbpmDataAccess;

@Autowired
ProductDataAccess productDataAccess;

/**
* This method is using to get all files from git repo with JSON extensions
*
Expand Down Expand Up @@ -67,11 +77,11 @@ public ResponseEntity<Object> 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<Object> getServices() throws IOException, GitAPIException {
List<Service> services = null;
Expand All @@ -98,6 +108,70 @@ public ResponseEntity<Object> 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<Object> getGSBPM() throws IOException, GitAPIException {
List<Gsbpm> 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<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("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<Object> getProducts() throws IOException, GitAPIException {
List<Product> 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<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("produits.json")){
products = productDataAccess.serializeFromFile(file);
LOGGER.info("produits.json serialized");
}
}
LOGGER.info("GET produit resulting in 200");
return new ResponseEntity<>(products, HttpStatus.OK);
}


}

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/fr/insee/knowledge/domain/Gsbpm.java
Original file line number Diff line number Diff line change
@@ -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<Gsbpm> children;
@JsonDeserialize(contentAs=Gsbpm.class)
private List<Gsbpm> processus;

public String getId() {
return id;
Expand All @@ -33,11 +40,11 @@ public void setDescription(String description) {
this.description = description;
}

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

public void setChildren(List<Gsbpm> children) {
this.children = children;
public void setProcessus(List<Gsbpm> processus) {
this.processus = processus;
}
}
13 changes: 9 additions & 4 deletions src/main/java/fr/insee/knowledge/domain/Product.java
Original file line number Diff line number Diff line change
@@ -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<Product> relatedProducts;
@JsonProperty("produits")
private String relatedProducts;

public String getName() {
return name;
Expand Down Expand Up @@ -42,11 +47,11 @@ public void setUsage(String usage) {
this.usage = usage;
}

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

public void setRelatedProducts(List<Product> relatedProducts) {
public void setRelatedProducts(String relatedProducts) {
this.relatedProducts = relatedProducts;
}
}
26 changes: 26 additions & 0 deletions src/main/java/fr/insee/knowledge/git/access/GsbpmDataAccess.java
Original file line number Diff line number Diff line change
@@ -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<Gsbpm> serializeFromFile(KnowledgeFile resource) throws IOException {

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

}

}
25 changes: 25 additions & 0 deletions src/main/java/fr/insee/knowledge/git/access/ProductDataAccess.java
Original file line number Diff line number Diff line change
@@ -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<Product> serializeFromFile(KnowledgeFile resource) throws IOException {

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

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.insee.knowledge.data.access;
package fr.insee.knowledge.git.access;


import com.fasterxml.jackson.core.type.TypeReference;
Expand Down

0 comments on commit 2dfd017

Please sign in to comment.