Revision 56987
Added by Alessia Bardi over 4 years ago
VirtuosoReadAPI.java | ||
---|---|---|
4 | 4 |
import java.io.OutputStream; |
5 | 5 |
import java.io.StringWriter; |
6 | 6 |
import java.util.HashMap; |
7 |
import java.util.Iterator; |
|
8 | 7 |
import java.util.List; |
9 | 8 |
import java.util.Map; |
10 | 9 |
|
... | ... | |
74 | 73 |
log.debug("SPARQL query: "+q); |
75 | 74 |
final QueryEngineHTTP serviceRequest = new QueryEngineHTTP(sparqlUrl, q); |
76 | 75 |
ResultSet subjects = serviceRequest.execSelect(); |
77 |
Iterator<String> s = Iterators.transform(subjects, qs -> qs.getResource("s").getURI()); |
|
78 |
List<String> res = Lists.newArrayList(s); |
|
76 |
List<String> res = Lists.newArrayList(Iterators.filter(Iterators.transform(subjects, qs -> qs.getResource("s").getURI()), input -> input.startsWith("http"))); |
|
79 | 77 |
serviceRequest.close(); |
80 | 78 |
return res; |
81 | 79 |
} |
... | ... | |
85 | 83 |
@ResponseStatus(value = HttpStatus.OK) |
86 | 84 |
public void getSubject(@RequestParam final String subjectURL, @RequestParam final String typeName, @RequestParam(name="timeout") final String timeoutMs, final OutputStream responseStream) |
87 | 85 |
throws IOException, TemplateException, ParthenosPublisherException { |
86 |
|
|
87 |
sendConstructResponse(generateQuery(subjectURL, typeName), timeoutMs, responseStream); |
|
88 |
} |
|
89 |
|
|
90 |
public String getRDF(final String subjectURL, final String typeName, final String apiId, final String timeoutMs) |
|
91 |
throws IOException, TemplateException, ParthenosPublisherException { |
|
92 |
|
|
93 |
return executeSparqlPost(generateQuery(subjectURL, typeName), timeoutMs); |
|
94 |
} |
|
95 |
|
|
96 |
protected String generateQuery(final String subjectURL, final String typeName) throws IOException, TemplateException { |
|
88 | 97 |
String templateName = typeName+".sparql"; |
89 | 98 |
Template temp = freemarkerConfig.getTemplate(templateName); |
90 | 99 |
Map<String, String> values = new HashMap<>(); |
... | ... | |
94 | 103 |
temp.process(values, sw); |
95 | 104 |
String q = sw.toString(); |
96 | 105 |
log.debug("Querying for "+subjectURL+" with query "+templateName); |
97 |
sendConstructResponse(q, timeoutMs, responseStream);
|
|
106 |
return q;
|
|
98 | 107 |
} |
99 | 108 |
|
100 | 109 |
|
Also available in: Unified diff
refactoring for proper publishing on JRR