Skip to content

Commit

Permalink
Fix to enable streaming upload of TTL files to Fuseki via uploadTurtl…
Browse files Browse the repository at this point in the history
…e endpoint (Issue #464)
  • Loading branch information
weisenje committed Mar 10, 2023
1 parent d34ffaf commit 2a1cc0f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void buildParametersJSON() throws Exception {

// everyone except syncOwl uses this
if (! this.conf.getServiceEndpoint().endsWith("syncOwl")) {
parametersJSON.put("dataset", ((SparqlQueryClientConfig)this.conf).getSparqlDataset());
parametersJSON.put("graph", ((SparqlQueryClientConfig)this.conf).getSparqlDataset());
}

// auth queries will have these as well
Expand Down Expand Up @@ -131,9 +131,11 @@ public SimpleResultSet clearAll() throws Exception{
}
}

/**
* Upload an OWL file
*/
public SimpleResultSet uploadOwl(File owlFile) throws Exception{
this.overrideConfEndpoint("uploadOwl");

try {
this.fileParameter = owlFile;
this.fileParameterName = "owlFile";
Expand All @@ -146,6 +148,24 @@ public SimpleResultSet uploadOwl(File owlFile) throws Exception{
this.restoreConfEndpoint();
}
}

/**
* Upload a TTL file
*/
public SimpleResultSet uploadTurtle(File ttlFile) throws Exception{
this.overrideConfEndpoint("uploadTurtle");
try {
this.fileParameter = ttlFile;
this.fileParameterName = "ttlFile";

JSONObject resultJSON = (JSONObject)super.execute();
SimpleResultSet retval = new SimpleResultSet(true);
retval.readJson(resultJSON);
return retval;
} finally {
this.restoreConfEndpoint();
}
}

public SimpleResultSet syncOwl(File owlFile) throws Exception{
this.overrideConfEndpoint("syncOwl");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
** Copyright 2023 General Electric Company
**
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/


package com.ge.research.semtk.sparqlX.test;

import static org.junit.Assert.*;

import java.io.File;

import org.junit.BeforeClass;
import org.junit.Test;

import com.ge.research.semtk.resultSet.SimpleResultSet;
import com.ge.research.semtk.sparqlX.client.SparqlQueryClient;
import com.ge.research.semtk.test.IntegrationTestUtility;
import com.ge.research.semtk.test.TestGraph;
import com.ge.research.semtk.utility.Utility;

public class SparqlQueryClientTest_IT {

@BeforeClass
public static void setup() throws Exception {
IntegrationTestUtility.authenticateJunit();
}

@Test
public void testUploadOwl() throws Exception {
try {
TestGraph.clearGraph();
File owlFile = Utility.getResourceAsTempFile(this, "Pet.owl");
SparqlQueryClient client = IntegrationTestUtility.getSparqlQueryAuthClient("/sparqlQueryService/uploadOwl", TestGraph.getSparqlServer(), TestGraph.getDataset());
SimpleResultSet result = client.uploadOwl(owlFile);
assertTrue(result.getSuccess());
assertEquals("Number of triples loaded via OWL file", 53, TestGraph.getNumTriples());
}finally {
TestGraph.clearGraph();
}
}

@Test
public void testUploadTurtle() throws Exception {
try {
TestGraph.clearGraph();
File ttlFile = Utility.getResourceAsTempFile(this, "musicTestDataset_2017.q2.ttl");
SparqlQueryClient client = IntegrationTestUtility.getSparqlQueryAuthClient("/sparqlQueryService/uploadTurtle", TestGraph.getSparqlServer(), TestGraph.getDataset());
SimpleResultSet result = client.uploadTurtle(ttlFile);
assertTrue(result.getSuccess());
assertEquals("Number of triples loaded via TTL file", 215, TestGraph.getNumTriples());
}finally{
TestGraph.clearGraph();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,7 @@ public JSONObject uploadOwl(@RequestParam("serverAndPort") String serverAndPort,
@RequestParam(value="password", required=false) String password,
@RequestParam("owlFile") MultipartFile owlFile,
@RequestHeader HttpHeaders headers) {

return this.uploadFile("uploadTurtle", serverAndPort, serverType, (dataset!=null)?dataset:graph, user, password, owlFile, headers);
return this.uploadFile("uploadOwl", serverAndPort, serverType, (dataset!=null)?dataset:graph, user, password, owlFile, headers);
}


Expand Down Expand Up @@ -646,7 +645,6 @@ private JSONObject uploadFile(String endpointName,
SparqlEndpointInterface sei = null;
LocalLogger.logToStdOut("Sparql Query Service start uploadTurtle");


try {
if (serverAndPort == null || serverAndPort.trim().isEmpty() ) throw new Exception("serverAndPort is empty.");
if (serverType == null || serverType.trim().isEmpty() ) throw new Exception("serverType is empty.");
Expand All @@ -655,8 +653,8 @@ private JSONObject uploadFile(String endpointName,
String nonEmptyUser = (user==null || user.isBlank()) ? "no-user" : user;
String nonEmptyPassword = (password==null || password.isBlank()) ? "no-password" : password;
sei = SparqlEndpointInterface.getInstance(serverType, serverAndPort, graph, nonEmptyUser, nonEmptyPassword);
SimpleResultSet sResult = this.uploadFile(sei, multiFile.getInputStream(), multiFile.getName());

SimpleResultSet sResult = this.uploadFile(sei, multiFile.getInputStream(), multiFile.getOriginalFilename());
return sResult.toJson();

} catch (Exception e) {
Expand Down

0 comments on commit 2a1cc0f

Please sign in to comment.