@Test public void retrieveChangesReturnsQuadsForGivenVersionAndSubjects() throws Exception { UpdatedPerPatchStore updatedPerPatchStore = mock(UpdatedPerPatchStore.class); when(updatedPerPatchStore.getVersions()).thenReturn(IntStream.of(1).boxed()); BdbNonPersistentEnvironmentCreator dataStoreFactory = new BdbNonPersistentEnvironmentCreator(); BdbTruePatchStore bdbTruePatchStore = new BdbTruePatchStore(version -> dataStoreFactory.getDatabase( "user", "dataSet", "schema" + version, false, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler() ), updatedPerPatchStore); int version = 1; bdbTruePatchStore.put("s1", version, "p1", Direction.OUT, true, "o1", null, null); bdbTruePatchStore.put("s2", version, "p2", Direction.OUT, false, "o2", null, null); bdbTruePatchStore.put("s3", version, "p3", Direction.OUT, true, "o3", RdfConstants.STRING, null); bdbTruePatchStore.put("s4", version, "p4", Direction.OUT, false, "o4", RdfConstants.STRING, null); bdbTruePatchStore.put("s5", version, "p5", Direction.OUT, true, "o5", RdfConstants.LANGSTRING, "en"); bdbTruePatchStore.put("s6", version, "p6", Direction.OUT, false, "o6", RdfConstants.LANGSTRING, "en"); ChangeListBuilder changeListBuilder = new ChangeListBuilder("graph"); ChangesRetriever changesRetriever = new ChangesRetriever(bdbTruePatchStore, null); List<String> changes = changeListBuilder.retrieveChanges(changesRetriever, version).collect(Collectors.toList()); assertThat(changes, containsInAnyOrder( "+<s1> <p1> <o1> <graph> .\n", "-<s2> <p2> <o2> <graph> .\n", "+<s3> <p3> \"o3\"^^<http: "-<s4> <p4> \"o4\"^^<http: "+<s5> <p5> \"o5\"@en <graph> .\n", "-<s6> <p6> \"o6\"@en <graph> .\n" )); }
public Stream<String> retrieveChanges(ChangesRetriever changesRetriever, Integer version) { Stream<CursorQuad> quads = changesRetriever.retrieveChanges(version); return quads.map(quad -> { Optional<String> dataType = quad.getValuetype(); if (dataType == null || !dataType.isPresent()) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } } else { Optional<String> language = quad.getLanguage(); if (language != null && language.isPresent() && dataType.get().equals(RdfConstants.LANGSTRING)) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } } else { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } } } return ""; }); }
ChangeListBuilder { public Stream<String> retrieveChanges(ChangesRetriever changesRetriever, Integer version) { Stream<CursorQuad> quads = changesRetriever.retrieveChanges(version); return quads.map(quad -> { Optional<String> dataType = quad.getValuetype(); if (dataType == null || !dataType.isPresent()) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } } else { Optional<String> language = quad.getLanguage(); if (language != null && language.isPresent() && dataType.get().equals(RdfConstants.LANGSTRING)) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } } else { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } } } return ""; }); } }
ChangeListBuilder { public Stream<String> retrieveChanges(ChangesRetriever changesRetriever, Integer version) { Stream<CursorQuad> quads = changesRetriever.retrieveChanges(version); return quads.map(quad -> { Optional<String> dataType = quad.getValuetype(); if (dataType == null || !dataType.isPresent()) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } } else { Optional<String> language = quad.getLanguage(); if (language != null && language.isPresent() && dataType.get().equals(RdfConstants.LANGSTRING)) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } } else { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } } } return ""; }); } ChangeListBuilder(String graph); }
ChangeListBuilder { public Stream<String> retrieveChanges(ChangesRetriever changesRetriever, Integer version) { Stream<CursorQuad> quads = changesRetriever.retrieveChanges(version); return quads.map(quad -> { Optional<String> dataType = quad.getValuetype(); if (dataType == null || !dataType.isPresent()) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } } else { Optional<String> language = quad.getLanguage(); if (language != null && language.isPresent() && dataType.get().equals(RdfConstants.LANGSTRING)) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } } else { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } } } return ""; }); } ChangeListBuilder(String graph); List<String> retrieveChangeFileNames(Supplier<List<Integer>> versions); Stream<String> retrieveChanges(ChangesRetriever changesRetriever,
                                        Integer version); }
ChangeListBuilder { public Stream<String> retrieveChanges(ChangesRetriever changesRetriever, Integer version) { Stream<CursorQuad> quads = changesRetriever.retrieveChanges(version); return quads.map(quad -> { Optional<String> dataType = quad.getValuetype(); if (dataType == null || !dataType.isPresent()) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delRelation(quad.getSubject(), quad.getPredicate(), quad.getObject(), graph); } } else { Optional<String> language = quad.getLanguage(); if (language != null && language.isPresent() && dataType.get().equals(RdfConstants.LANGSTRING)) { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delLanguageTaggedString( quad.getSubject(), quad.getPredicate(), quad.getObject(), language.get(), graph ); } } else { if (quad.getChangeType() == ChangeType.ASSERTED) { return changesQuadGenerator.onValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } else if (quad.getChangeType() == ChangeType.RETRACTED) { return changesQuadGenerator.delValue( quad.getSubject(), quad.getPredicate(), quad.getObject(), dataType.get(), graph ); } } } return ""; }); } ChangeListBuilder(String graph); List<String> retrieveChangeFileNames(Supplier<List<Integer>> versions); Stream<String> retrieveChanges(ChangesRetriever changesRetriever,
                                        Integer version);  }