Skip to content

Commit

Permalink
Merge pull request #96 from feup-infolab/Jena-Fuseki-Middleware
Browse files Browse the repository at this point in the history
Summary Fix
  • Loading branch information
nunofreitas96 committed Feb 6, 2021
2 parents 71e9424 + a43c5a8 commit 68d1ca1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

public class ResponseClass {

private final String id;
//private final String id;

private final String $schema;
//private final String $schema;

private final String description;
//private final String description;

private final String type;
//private final String type;

private final Map<String,Object> properties;

Expand All @@ -20,22 +20,25 @@ public class ResponseClass {


public ResponseClass( Map<String,Object> properties) {
this.id = "https://example.com/arrays.schema.json";
//this.id = "https://example.com/arrays.schema.json";
this.properties = properties;
this.$schema = "http://json-schema.org/draft-07/schema#summaryDoc";
this.description = "The document summary representation.";
this.type = "object";

}

public String getId() {
return id;
}

//public String getId() {
// return id;
//}

public Map<String,Object> getProperties() {
return properties;
}

public void putProperties(String key, Object ob) {
this.properties.put(key,ob);
}


public void addContent(String key,Map<String,String> value) {
properties.put(key,value);
}
Expand All @@ -44,7 +47,7 @@ public void addList(String key,List<Map<String,String>> value) {
properties.put(key,value);
}

public String get$schema() {
/*public String get$schema() {
return $schema;
}
Expand All @@ -54,5 +57,5 @@ public String getDescription() {
public String getType() {
return type;
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.concurrent.atomic.AtomicLong;

import cclasses.ResponseClass;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -19,7 +21,7 @@ public class MainController {
private final Queries queries =new Queries();

@GetMapping("/doc")
public ResponseClass document(@RequestParam(value = "id", defaultValue = "") String uuid) {
public String document(@RequestParam(value = "id", defaultValue = "") String uuid) {
Connection conn = new Connection();
HashMap<String,Object> list = new HashMap<>();

Expand All @@ -34,11 +36,18 @@ public ResponseClass document(@RequestParam(value = "id", defaultValue = "") Str
rep = conn.obtainGeneralResponse(queries.getUuid(docid),"episaIdentifier",rep);
rep = conn.obtainGeneralResponse(queries.getReference_codes_query(docid),"dglabIdentifier",rep);

return rep;
ObjectMapper mapper = new ObjectMapper();
String json = "";
try {
json = mapper.writeValueAsString(rep.getProperties());
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return json;
}

@GetMapping("/searchdoc")
public ResponseClass documentSummary(@RequestParam(value = "refcode", defaultValue = "") String refcode) {
public String documentSummary(@RequestParam(value = "refcode", defaultValue = "") String refcode) {
Connection conn = new Connection();
HashMap<String,Object> list0 = new HashMap<>() ;
ResponseClass uuidrep = new ResponseClass(list0);
Expand All @@ -49,11 +58,18 @@ public ResponseClass documentSummary(@RequestParam(value = "refcode", defaultVal

HashMap<String,Object> list = new HashMap<>() ;
ResponseClass rep = new ResponseClass( list);
rep = conn.obtainGeneralResponse(queries.getTitle_query(uuid),"title",rep);
rep = conn.obtainGeneralResponse(queries.getUuid(uuid),"episaIdentifier",rep);
rep = conn.obtainGeneralResponse(queries.getReference_codes_query(uuid),"dglabIdentifier",rep);

return rep;
rep = conn.obtainSummaryResponse(queries.getTitle_query(uuid),"title",rep);
rep = conn.obtainSummaryResponse(queries.getUuid(uuid),"episaIdentifier",rep);
rep = conn.obtainSummaryResponse(queries.getReference_codes_query(uuid),"dglabIdentifier",rep);

ObjectMapper mapper = new ObjectMapper();
String json = "";
try {
json = mapper.writeValueAsString(rep.getProperties());
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return json;
}

@GetMapping("/person")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@
public class Connection {
Queries querier = new Queries();


public ResponseClass obtainSummaryResponse(Query query,String key,ResponseClass r){
RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
.destination("http://localhost:3030/name/sparql");


try ( RDFConnectionFuseki conn = (RDFConnectionFuseki)builder.build() ) {
ResultSet rs = conn.query(query).execSelect();
QuerySolution stmt;
if(rs.hasNext()){
stmt = rs.next();
Iterator<String> b = stmt.varNames();

while(b.hasNext()){
String current = b.next();
RDFNode res = stmt.get(current);
r.putProperties(key,res.toString());

}
}else{
return r;
}
}


return r;
}


public ResponseClass obtainGeneralResponse(Query query,String key,ResponseClass r){
RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create()
.destination("http://localhost:3030/name/sparql");
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 68d1ca1

Please sign in to comment.