ConstructProjection { public RyaStatement projectBindingSet(VisibilityBindingSet vBs, Map<String, BNode> bNodes) { Preconditions.checkNotNull(vBs); Preconditions.checkNotNull(bNodes); Value subj = getValue(subjName, subjValue, vBs, bNodes); Value pred = getValue(predName, predValue, vBs, bNodes); Value obj = getValue(objName, objValue, vBs, bNodes); Preconditions.checkNotNull(subj); Preconditions.checkNotNull(pred); Preconditions.checkNotNull(obj); Preconditions.checkArgument(subj instanceof Resource); Preconditions.checkArgument(pred instanceof IRI); RyaIRI subjType = RdfToRyaConversions.convertResource((Resource) subj); RyaIRI predType = RdfToRyaConversions.convertIRI((IRI) pred); RyaType objectType = RdfToRyaConversions.convertValue(obj); RyaStatement statement = new RyaStatement(subjType, predType, objectType); try { statement.setColumnVisibility(vBs.getVisibility().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { log.trace("Unable to decode column visibility. RyaStatement being created without column visibility."); } return statement; } ConstructProjection(Var subjectVar, Var predicateVar, Var objectVar);  ConstructProjection(StatementPattern pattern); String getSubjectSourceName(); String getPredicateSourceName(); String getObjectSourceName(); Optional<Value> getSubjValue(); Optional<Value> getPredValue(); Optional<Value> getObjValue(); StatementPattern getStatementPatternRepresentation(); RyaStatement projectBindingSet(VisibilityBindingSet vBs, Map<String, BNode> bNodes); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testConstructProjectionProjectSubj() throws MalformedQueryException, UnsupportedEncodingException { String query = "select ?x where { ?x <uri:talksTo> <uri:Bob> }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("x", VF.createIRI("uri:Joe")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs, "FOUO"); RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>()); RyaStatement expected = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); expected.setColumnVisibility("FOUO".getBytes("UTF-8")); expected.setTimestamp(statement.getTimestamp()); assertEquals(expected, statement); }
@Test public void testConstructProjectionProjPred() throws MalformedQueryException { String query = "select ?p where { <uri:Joe> ?p <uri:Bob> }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("p", VF.createIRI("uri:worksWith")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs); RyaStatement statement = projection.projectBindingSet(vBs, new HashMap<>()); RyaStatement expected = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:worksWith"), new RyaIRI("uri:Bob")); expected.setTimestamp(statement.getTimestamp()); expected.setColumnVisibility(new byte[0]); assertEquals(expected, statement); }
@Test public void testConstructProjectionBNodes() throws MalformedQueryException { String query = "select ?o where { _:b <uri:talksTo> ?o }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructProjection projection = new ConstructProjection(patterns.get(0)); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("o", VF.createIRI("uri:Bob")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs); BNode bNode = VF.createBNode(); Map<String, BNode> bNodeMap = new HashMap<>(); bNodeMap.put(VarNameUtils.prependAnonymous("1"), bNode); RyaStatement statement = projection.projectBindingSet(vBs,bNodeMap); RyaStatement expected = new RyaStatement(RdfToRyaConversions.convertResource(bNode), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); expected.setTimestamp(statement.getTimestamp()); expected.setColumnVisibility(new byte[0]); assertEquals(expected, statement); }