-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send Update Queries to seperate endpoint (#281)
* Add QueryData class * Check for update queries * Move responsibility of QueryData to QueryHandler * Remove unused methods * Add tests * Fix authentication * Cleanup * Remove unused import statements * Add chained update request as test case for Update queries distinction Closes #229
- Loading branch information
Showing
6 changed files
with
225 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.aksw.iguana.cc.query; | ||
|
||
import org.apache.jena.update.UpdateFactory; | ||
|
||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* This class stores extra information about a query. | ||
* At the moment, it only stores if the query is an update query or not. | ||
* | ||
* @param queryId The id of the query | ||
* @param update If the query is an update query | ||
*/ | ||
public record QueryData(int queryId, boolean update) { | ||
public static List<QueryData> generate(Collection<InputStream> queries) { | ||
final var queryData = new ArrayList<QueryData>(); | ||
int i = 0; | ||
for (InputStream query : queries) { | ||
boolean update = true; | ||
try { | ||
UpdateFactory.read(query); // Throws an exception if the query is not an update query | ||
} catch (Exception e) { | ||
update = false; | ||
} | ||
queryData.add(new QueryData(i++, update)); | ||
} | ||
return queryData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.aksw.iguana.cc.query; | ||
|
||
import org.aksw.iguana.cc.query.source.QuerySource; | ||
import org.aksw.iguana.cc.query.source.impl.FileSeparatorQuerySource; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class QueryDataTest { | ||
|
||
private static Path tempFile = null; | ||
|
||
@BeforeAll | ||
public static void setup() throws IOException { | ||
tempFile = Files.createTempFile("test", "txt"); | ||
Files.writeString(tempFile, """ | ||
SELECT ?s ?p ?o WHERE { | ||
?s ?p ?o | ||
} | ||
INSERT DATA { | ||
<http://example.org/s> <http://example.org/p> <http://example.org/o> | ||
} | ||
DELETE DATA { | ||
<http://example.org/s> <http://example.org/p> <http://example.org/o> | ||
} | ||
SELECT ?s ?p ?o WHERE { | ||
?s ?p ?o | ||
} | ||
INSERT DATA { | ||
<http://example.org/s> <http://example.org/p> <http://example.org/o> | ||
}; INSERT DATA { | ||
<http://example.org/s> <http://example.org/p> <http://example.org/o> | ||
} | ||
"""); | ||
} | ||
|
||
@AfterAll | ||
public static void teardown() throws IOException { | ||
Files.deleteIfExists(tempFile); | ||
} | ||
|
||
@Test | ||
void testGeneration() throws IOException { | ||
final QuerySource querySource = new FileSeparatorQuerySource(tempFile, ""); | ||
final var testStrings = querySource.getAllQueries(); | ||
|
||
List<List<QueryData>> generations = List.of( | ||
QueryData.generate(testStrings.stream().map(s -> (InputStream) new ByteArrayInputStream(s.getBytes())).toList()) | ||
); | ||
for (List<QueryData> generation : generations) { | ||
assertEquals(5, generation.size()); | ||
assertFalse(generation.get(0).update()); | ||
assertTrue(generation.get(1).update()); | ||
assertTrue(generation.get(2).update()); | ||
assertFalse(generation.get(3).update()); | ||
assertTrue(generation.get(4).update()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters