Skip to content

Commit

Permalink
Issue #334
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed Feb 8, 2023
1 parent e055e51 commit 35bdde3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,30 @@ private QueryIterator catchUnboundVariableException(Op op, OpBGP opBGP, QueryIte

private QueryIterator executeMagicProperties(QueryIterator input, List<Triple> propFuncTriples) {
QueryIterator input2 = input;

for (Triple t : propFuncTriples) {
input2 = QC.execute(Utils.getOpPropFuncAnySlot(t), input2, execCxt);
}
return input2;
}

protected QueryIterator execute(final OpBGP opBGP, QueryIterator input) {
logger.trace("Execute OpBGP {}", opBGP.getPattern().toString());
// check that the BGP is within a FacadeX-SERVICE clause
if (this.execCxt.getClass() == FacadeXExecutionContext.class) {
// check that the BGP contains FacadeX Magic properties
logger.trace("FacadeX Execution context");
List<Triple> magicPropertyTriples = Utils.getFacadeXMagicPropertyTriples(opBGP.getPattern());
if (!magicPropertyTriples.isEmpty()) {
// execute magic properties and bgp without FacadeX magic properties
logger.trace("BGP has magic properties");
return super.execute(Utils.excludeMagicPropertyTriples(Utils.excludeFXProperties(opBGP)), executeMagicProperties(input, magicPropertyTriples));
} else {
// execute BGP by excluding FX properties
logger.trace("Execute BGP by excluding FX properties");
//return QC.execute(Utils.excludeFXProperties(opBGP), input, new ExecutionContext(this.execCxt.getDataset()));
return QC.execute(Utils.excludeFXProperties(opBGP), input, new ExecutionContext(execCxt));
}
}
logger.trace("Execute with default Jena execution");
// go with the default Jena execution
return super.execute(opBGP, input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.QueryIterator;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.iterator.QueryIterDefaulting;
import org.apache.jena.sparql.engine.iterator.QueryIterRepeatApply;
import org.apache.jena.sparql.engine.iterator.QueryIterSingleton;
import org.apache.jena.sparql.engine.iterator.*;
import org.apache.jena.sparql.engine.main.QC;
import org.apache.jena.sparql.pfunction.PropFuncArg;
import org.slf4j.Logger;
Expand Down Expand Up @@ -69,6 +67,12 @@ static String queryIteratorToString(QueryIterator q) {
return sb.toString();
}

static String printDatasetGraph(DatasetGraph dg){
StringBuilder sb = new StringBuilder();
dg.find().forEachRemaining(q-> sb.append(q.toString()).append("\n"));
return sb.toString();
}

static String bindingToString(Binding binding) {
StringBuilder sb = new StringBuilder();
Iterator<Var> vars = binding.vars();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,11 @@ public void testIssue334() throws URISyntaxException, IOException {

query = QueryFactory.create(queryStr);



QueryExecution qExec = QueryExecutionFactory.create(query, ds);
assertTrue(!qExec.execConstruct().isEmpty());


qExec.execConstruct().write(System.out, "TTL");
// qExec.execConstruct().write(System.out, "TTL");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ construct {
service <x-sparql-anything:> {
bind(coalesce(?__file,".*") as ?pattern)
fx:properties fx:location "%%%LOCATION%%%" .
fx:properties fx:archive.matches ?pattern.
fx:properties fx:archive.matches ".*".
[] fx:anySlot ?file
service <x-sparql-anything:media-type=application/json> {
bind(str(bsdd:) as ?bsdd)
Expand Down
Binary file modified sparql-anything-it/src/test/resources/issues/issue334.tar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;

public class ResourceManager {

private Logger logger = LoggerFactory.getLogger(ResourceManager.class);

private static ResourceManager instance;

public static final String tmpFolder = "tmp";
private final static Logger logger = LoggerFactory.getLogger(ResourceManager.class);
private static ResourceManager instance;

private ResourceManager() {
new File(tmpFolder).mkdir();
Expand All @@ -54,8 +48,7 @@ public static ResourceManager getInstance() {
return instance;
}

public InputStream getInputStreamFromArchive(URL archiveLocation, String entryName, Charset charset)
throws ArchiveException, IOException {
public InputStream getInputStreamFromArchive(URL archiveLocation, String entryName, Charset charset) throws ArchiveException, IOException {

logger.trace("Archive location {} entry {}", archiveLocation.toString(), entryName);

Expand All @@ -69,14 +62,12 @@ public InputStream getInputStreamFromArchive(URL archiveLocation, String entryNa

if (!fileToRead.exists()) {

logger.trace("Extracting content from {}", archiveLocation.toString());
logger.trace("Extracting content from {}", archiveLocation);
// extract
File destinationDir = new File(folder);
new File(folder).mkdir();

ArchiveInputStream i = new ArchiveStreamFactory().createArchiveInputStream(
FilenameUtils.getExtension(archiveLocation.toString()), archiveLocation.openStream(),
charset.toString());
ArchiveInputStream i = new ArchiveStreamFactory().createArchiveInputStream(FilenameUtils.getExtension(archiveLocation.toString()), archiveLocation.openStream(), charset.toString());
ArchiveEntry entry = null;
while ((entry = i.getNextEntry()) != null) {

Expand Down Expand Up @@ -105,7 +96,13 @@ public InputStream getInputStreamFromArchive(URL archiveLocation, String entryNa
}
}

return new FileInputStream(new File(folder + "/" + entryName));
if (!fileToRead.exists() || fileToRead.isDirectory()){
logger.error(fileToRead.getAbsolutePath() + " does not exist!");
return new ByteArrayInputStream(new byte[]{});
// throw new RuntimeException(fileToRead.getAbsolutePath() + " does not exist!");
}

return new FileInputStream(fileToRead);
}

}

0 comments on commit 35bdde3

Please sign in to comment.