public RyaStatementBuilder setColumnVisibility(final byte[] columnVisibility) { ryaStatement.setColumnVisibility(columnVisibility); return this; }
public RyaStatementBuilder setColumnVisibility(final byte[] columnVisibility) { ryaStatement.setColumnVisibility(columnVisibility); return this; }
@Override public Optional<RyaStatement> merge(final Optional<RyaStatement> parent, final Optional<RyaStatement> child) throws MergerException { if(parent.isPresent()) { final RyaStatement parentStatement = parent.get(); if(child.isPresent()) { final RyaStatement childStatement = child.get(); final String pVis = new String(parentStatement.getColumnVisibility(), StandardCharsets.UTF_8); final String cVis = new String(childStatement.getColumnVisibility(), StandardCharsets.UTF_8); String visibility = ""; final Joiner join = Joiner.on(")&("); if(pVis.isEmpty() || cVis.isEmpty()) { visibility = (pVis + cVis).trim(); } else { visibility = "(" + join.join(pVis, cVis) + ")"; } parentStatement.setColumnVisibility(visibility.getBytes(StandardCharsets.UTF_8)); return Optional.of(parentStatement); } return parent; } else if(child.isPresent()) { return child; } return Optional.absent(); } }
@Override public Optional<RyaStatement> merge(final Optional<RyaStatement> parent, final Optional<RyaStatement> child) throws MergerException { if(parent.isPresent()) { final RyaStatement parentStatement = parent.get(); if(child.isPresent()) { final RyaStatement childStatement = child.get(); final String pVis = new String(parentStatement.getColumnVisibility(), StandardCharsets.UTF_8); final String cVis = new String(childStatement.getColumnVisibility(), StandardCharsets.UTF_8); String visibility = ""; final Joiner join = Joiner.on(")&("); if(pVis.isEmpty() || cVis.isEmpty()) { visibility = (pVis + cVis).trim(); } else { visibility = "(" + join.join(pVis, cVis) + ")"; } parentStatement.setColumnVisibility(visibility.getBytes(StandardCharsets.UTF_8)); return Optional.of(parentStatement); } return parent; } else if(child.isPresent()) { return child; } return Optional.absent(); } }
private void simplifyVisibilities(final RyaSubGraph subgraph) throws UnsupportedEncodingException { final Set<RyaStatement> statements = subgraph.getStatements(); if (statements.size() > 0) { final byte[] visibilityBytes = statements.iterator().next().getColumnVisibility(); // Simplify the result's visibilities and cache new simplified // visibilities final String visibility = new String(visibilityBytes, "UTF-8"); if (!simplifiedVisibilities.containsKey(visibility)) { final String simplified = VisibilitySimplifier.simplify(visibility); simplifiedVisibilities.put(visibility, simplified); } for (final RyaStatement statement : statements) { statement.setColumnVisibility(simplifiedVisibilities.get(visibility).getBytes("UTF-8")); } subgraph.setStatements(statements); } }
private void simplifyVisibilities(final RyaSubGraph subgraph) throws UnsupportedEncodingException { final Set<RyaStatement> statements = subgraph.getStatements(); if (statements.size() > 0) { final byte[] visibilityBytes = statements.iterator().next().getColumnVisibility(); // Simplify the result's visibilities and cache new simplified // visibilities final String visibility = new String(visibilityBytes, "UTF-8"); if (!simplifiedVisibilities.containsKey(visibility)) { final String simplified = VisibilitySimplifier.simplify(visibility); simplifiedVisibilities.put(visibility, simplified); } for (final RyaStatement statement : statements) { statement.setColumnVisibility(simplifiedVisibilities.get(visibility).getBytes("UTF-8")); } subgraph.setStatements(statements); } }
private static RyaStatement makeRyaStatement(final Statement statement, final String visibility) throws UnsupportedEncodingException { final RyaStatement ryaStatement = RdfToRyaConversions.convertStatement(statement); ryaStatement.setColumnVisibility(visibility.getBytes("UTF-8")); return ryaStatement; } }
private void writeRyaMutations(final RyaStatement ryaStatement, final Context context, final boolean isDelete) throws IOException, InterruptedException { if (ryaStatement.getColumnVisibility() == null) { ryaStatement.setColumnVisibility(AccumuloRdfConstants.EMPTY_CV.getExpression()); } final Map<TABLE_LAYOUT, Collection<Mutation>> mutationMap = ryaTableMutationFactory.serialize(ryaStatement); final Collection<Mutation> spoMutations = mutationMap.get(TABLE_LAYOUT.SPO); final Collection<Mutation> poMutations = mutationMap.get(TABLE_LAYOUT.PO); final Collection<Mutation> ospMutations = mutationMap.get(TABLE_LAYOUT.OSP); for (final Mutation mutation : spoMutations) { writeMutation(spoTable, mutation, context, isDelete); } for (final Mutation mutation : poMutations) { writeMutation(poTable, mutation, context, isDelete); } for (final Mutation mutation : ospMutations) { writeMutation(ospTable, mutation, context, isDelete); } }
/** * Writes a (key,value) pair to Rya. Adds the statement to a buffer, and * flushes the statement buffer to the database if full. * @param key Arbitrary Writable, not used. * @param value Contains statement to insert to Rya. * @throws IOException if writing to Accumulo fails. */ @Override public void write(final Writable key, final RyaStatementWritable value) throws IOException { final RyaStatement ryaStatement = value.getRyaStatement(); if (ryaStatement.getColumnVisibility() == null) { ryaStatement.setColumnVisibility(cv); } if (ryaStatement.getContext() == null) { ryaStatement.setContext(defaultContext); } buffer.add(ryaStatement); bufferCurrentSize += statementSize(ryaStatement); if (bufferCurrentSize >= bufferSizeLimit) { flushBuffer(); } }
/** * Writes a (key,value) pair to Rya. Adds the statement to a buffer, and * flushes the statement buffer to the database if full. * @param key Arbitrary Writable, not used. * @param value Contains statement to insert to Rya. * @throws IOException if writing to Accumulo fails. */ @Override public void write(final Writable key, final RyaStatementWritable value) throws IOException { final RyaStatement ryaStatement = value.getRyaStatement(); if (ryaStatement.getColumnVisibility() == null) { ryaStatement.setColumnVisibility(cv); } if (ryaStatement.getContext() == null) { ryaStatement.setContext(defaultContext); } buffer.add(ryaStatement); bufferCurrentSize += statementSize(ryaStatement); if (bufferCurrentSize >= bufferSizeLimit) { flushBuffer(); } }
/** * Loads a RyaStatementWritable by reading data from an input stream. * Creates a new RyaStatement and assigns it to this RyaStatementWritable. * @param dataInput An stream containing serialized statement data. */ @Override public void readFields(DataInput dataInput) throws IOException { byte[] row = read(dataInput); byte[] columnFamily = read(dataInput); byte[] columnQualifier = read(dataInput); byte[] columnVisibility = read(dataInput); byte[] value = read(dataInput); boolean b = dataInput.readBoolean(); Long timestamp = null; if (b) { timestamp = dataInput.readLong(); } try { ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row, columnFamily, columnQualifier)); ryaStatement.setColumnVisibility(columnVisibility); ryaStatement.setValue(value); ryaStatement.setTimestamp(timestamp); } catch (TripleRowResolverException e) { throw new IOException(e); } } }
/** * Loads a RyaStatementWritable by reading data from an input stream. * Creates a new RyaStatement and assigns it to this RyaStatementWritable. * @param dataInput An stream containing serialized statement data. */ @Override public void readFields(DataInput dataInput) throws IOException { byte[] row = read(dataInput); byte[] columnFamily = read(dataInput); byte[] columnQualifier = read(dataInput); byte[] columnVisibility = read(dataInput); byte[] value = read(dataInput); boolean b = dataInput.readBoolean(); Long timestamp = null; if (b) { timestamp = dataInput.readLong(); } try { ryaStatement = ryaContext.deserializeTriple(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new TripleRow(row, columnFamily, columnQualifier)); ryaStatement.setColumnVisibility(columnVisibility); ryaStatement.setValue(value); ryaStatement.setTimestamp(timestamp); } catch (TripleRowResolverException e) { throw new IOException(e); } } }
statement.setColumnVisibility(documentVisibility.flatten()); if(timestamp != null) { statement.setTimestamp(timestamp);
RyaStatement statement2 = new RyaStatement(new RyaIRI("urn:Bob"), new RyaIRI("urn:livesIn"), new RyaIRI("urn:London")); RyaStatement statement3 = new RyaStatement(new RyaIRI("urn:Bob"), new RyaIRI("urn:worksAt"), new RyaIRI("urn:burgerShack")); statement1.setColumnVisibility("U&W".getBytes("UTF-8")); statement2.setColumnVisibility("V".getBytes("UTF-8")); statement3.setColumnVisibility("W".getBytes("UTF-8")); statement4.setColumnVisibility("U&V&W".getBytes("UTF-8")); statement5.setColumnVisibility("U&V&W".getBytes("UTF-8"));
RyaStatement statement5 = new RyaStatement(new RyaIRI("urn:Evan"), new RyaIRI("urn:livesIn"), new RyaIRI("urn:SanFrancisco")); RyaStatement statement6 = new RyaStatement(new RyaIRI("urn:Evan"), new RyaIRI("urn:worksAt"), new RyaIRI("urn:burgerShack")); statement1.setColumnVisibility("U&W".getBytes("UTF-8")); statement2.setColumnVisibility("V".getBytes("UTF-8")); statement3.setColumnVisibility("W".getBytes("UTF-8")); statement4.setColumnVisibility("A&B".getBytes("UTF-8")); statement5.setColumnVisibility("B".getBytes("UTF-8")); statement6.setColumnVisibility("C".getBytes("UTF-8")); RyaStatement statement9 = new RyaStatement(new RyaIRI("urn:John"), new RyaIRI("urn:travelsTo"), new RyaIRI("urn:SanFrancisco")); RyaStatement statement10 = new RyaStatement(new RyaIRI("urn:John"), new RyaIRI("urn:friendsWith"), new RyaIRI("urn:Evan")); statement7.setColumnVisibility("U&V&W".getBytes("UTF-8")); statement8.setColumnVisibility("U&V&W".getBytes("UTF-8")); statement9.setColumnVisibility("A&B&C".getBytes("UTF-8")); statement10.setColumnVisibility("A&B&C".getBytes("UTF-8"));
@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); }
statement1.setColumnVisibility(new byte[0]); statement2.setColumnVisibility(new byte[0]);
@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); }
@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 testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException { String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq = parser.parseQuery(query, null); List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr()); ConstructGraph graph = new ConstructGraph(patterns); QueryBindingSet bs = new QueryBindingSet(); bs.addBinding("x", VF.createIRI("uri:Joe")); bs.addBinding("y", VF.createIRI("uri:Bob")); bs.addBinding("z", VF.createIRI("uri:BurgerShack")); VisibilityBindingSet vBs = new VisibilityBindingSet(bs,"FOUO"); Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs); RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob")); RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Bob"), new RyaIRI("uri:worksAt"), new RyaIRI("uri:BurgerShack")); Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2)); expected.forEach(x-> x.setColumnVisibility("FOUO".getBytes())); ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements); }