Skip to content
Snippets Groups Projects
Commit 8118ae7d authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

wip

parent 26f06a01
No related branches found
No related tags found
1 merge request!11Feature/get values
package com.smartharvester.controller;
import java.util.List;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.smartharvester.model.Path;
import com.smartharvester.service.MappingFromIsoService;
import com.smartharvester.service.MappingService;
import io.swagger.v3.oas.annotations.tags.Tag;
......@@ -16,18 +23,37 @@ import io.swagger.v3.oas.annotations.tags.Tag;
@RequestMapping("/harvester/api/transform")
@Tag(name = "Harvest",description = "transform xml iso 19115 to RDF")
@RestController
public class SmartHarvesterTransformerController {
public class SmartHarvesterMappingController {
@Autowired
private MappingFromIsoService mappingFromIsoService;
@Autowired
private MappingFromIsoService mappingService;
private MappingService mappingService;
@GetMapping
public ResponseEntity<String> transformXmlToRdf(@RequestParam (value="url") String url, @RequestParam (value="catalogId") String catalogId) {
try {
return ResponseEntity.ok().body(this.mappingService.mapfromCWStoRDF(url, catalogId));
return ResponseEntity.ok().body(this.mappingFromIsoService.mapfromCWStoRDF(url, catalogId));
} catch (Exception e) {
return ResponseEntity.badRequest().body("ERROR " + e.getMessage());
}
}
@PostMapping
public ResponseEntity<String> map(@RequestBody Path[] paths, @RequestBody List<String> urlRepos, @RequestParam String catalogId, @RequestParam String fdpUrl) {
urlRepos.stream().forEach(url -> {
try {
String dataset = this.mappingService.createRDF(url, paths, catalogId, fdpUrl);
return ResponseEntity.ok().body(url);
} catch (JSONException e) {
return ResponseEntity.badRequest().body("ERROR " + e.getMessage());
}
});
}
}
......@@ -24,12 +24,14 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.stream.JsonReader;
import com.smartharvester.model.Path;
import io.swagger.util.Json;
@Service
public class MappingService {
public static String getDatasetString(String catId, String properties, String fdpUrl) {
String dataset = "@prefix dcat: <http://www.w3.org/ns/dcat#>. \n"
......@@ -94,7 +96,7 @@ public class MappingService {
return property;
}
public static String createRDF(String urlRepo, Path[] paths, String catalogId, String fdpUrl) throws JSONException {
public String createRDF(String urlRepo, Path[] paths, String catalogId, String fdpUrl) throws JSONException {
String properties = "";
JSONObject json = null;
......@@ -167,7 +169,7 @@ public class MappingService {
}
private static String readStream(InputStream input) throws IOException {
private static String readStream(InputStream input) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(input), 1000);
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
......@@ -177,29 +179,6 @@ public class MappingService {
return sb.toString();
}
public static void main(String[] args) throws IOException {
Path path1 = new Path();
Path path2 = new Path();
Path path3 = new Path();
Path path4 = new Path();
path1.setProperty("dct:title");
path1.setPath("response : docs : 0 : title");
path2.setProperty("dct:description");
path2.setPath("mresponse : docs : 0 : further_info_url : 0");
path3.setProperty("dct:publisher");
path3.setPath("response : docs : 0 : data_node");
path4.setPath("response : docs : 0 : geo");
path4.setProperty("dct:spatial");
Path[] paths = { path1, path2, path3, path4 };
try {
System.out.println(createRDF(
"https://esgf-data.dkrz.de/esg-search//search?format=application%2Fsolr%2Bjson&id=CMIP6.ScenarioMIP.DKRZ.MPI-ESM1-2-HR.ssp585.r1i1p1f1.Amon.tasmin.gn.v20190710%7Cesgf3.dkrz.de",
paths, "121321231231231", "https://f2ds.eosc-pillar.eu"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment