@Test public void getChangesGeneratesNqudForTheGivenChangeVersion() throws Exception { when(dataSetRepository.getDataSet(null, "u1", "ds1")).thenReturn(Optional.of(dataSet)); UpdatedPerPatchStore updatedPerPatchStore = mock(UpdatedPerPatchStore.class); given(updatedPerPatchStore.getVersions()).willReturn(Stream.of(1)); given(updatedPerPatchStore.ofVersion(1)).willReturn(Stream.of("s1", "s2")); BdbTruePatchStore truePatchStore = mock(BdbTruePatchStore.class); CursorQuad cursorQuad1 = mock(CursorQuad.class); given(cursorQuad1.getSubject()).willReturn("s1"); given(cursorQuad1.getPredicate()).willReturn("p1"); given(cursorQuad1.getChangeType()).willReturn(ChangeType.ASSERTED); given(cursorQuad1.getObject()).willReturn("o1"); given(cursorQuad1.getDirection()).willReturn(Direction.OUT); CursorQuad cursorQuad2 = mock(CursorQuad.class); given(cursorQuad2.getSubject()).willReturn("s2"); given(cursorQuad2.getPredicate()).willReturn("p2"); given(cursorQuad2.getChangeType()).willReturn(ChangeType.RETRACTED); given(cursorQuad2.getObject()).willReturn("o2"); given(cursorQuad2.getDirection()).willReturn(Direction.OUT); given(truePatchStore.getChangesOfVersion(1, true)).willReturn(Stream.of(cursorQuad1, cursorQuad2)); DataSetMetaData dataSetMetaData = mock(DataSetMetaData.class); given(dataSetMetaData.getBaseUri()).willReturn("uri"); given(dataSetMetaData.getGraph()).willReturn("graph"); given(dataSetMetaData.getOwnerId()).willReturn("u1"); given(dataSetMetaData.getDataSetId()).willReturn("ds1"); ChangesRetriever changesRetriever = new ChangesRetriever(truePatchStore, updatedPerPatchStore); given(dataSet.getUpdatedPerPatchStore()).willReturn(updatedPerPatchStore); given(dataSet.getTruePatchStore()).willReturn(truePatchStore); given(dataSet.getChangesRetriever()).willReturn(changesRetriever); given(dataSet.getMetadata()).willReturn(dataSetMetaData); Optional<Stream<String>> changes = rsDocumentBuilder.getChanges(null, "u1", "ds1", "changes1.nqud"); assertThat(changes.isPresent(), is(true)); assertThat(changes.get().collect(Collectors.toList()), Matchers.contains( "+<s1> <p1> <o1> <graph> .\n", "-<s2> <p2> <o2> <graph> .\n" )); }
public Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId) { Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSet dataSet = maybeDataSet.get(); DataSetMetaData dataSetMetaData = dataSet.getMetadata(); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); Integer version = getVersionFromFileId(fileId); if (dataSet.getChangesRetriever().versionExists(version)) { return Optional.of(changeListBuilder.retrieveChanges(dataSet.getChangesRetriever(), version)); } } return Optional.empty(); }
RsDocumentBuilder { public Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId) { Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSet dataSet = maybeDataSet.get(); DataSetMetaData dataSetMetaData = dataSet.getMetadata(); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); Integer version = getVersionFromFileId(fileId); if (dataSet.getChangesRetriever().versionExists(version)) { return Optional.of(changeListBuilder.retrieveChanges(dataSet.getChangesRetriever(), version)); } } return Optional.empty(); } }
RsDocumentBuilder { public Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId) { Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSet dataSet = maybeDataSet.get(); DataSetMetaData dataSetMetaData = dataSet.getMetadata(); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); Integer version = getVersionFromFileId(fileId); if (dataSet.getChangesRetriever().versionExists(version)) { return Optional.of(changeListBuilder.retrieveChanges(dataSet.getChangesRetriever(), version)); } } return Optional.empty(); } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); }
RsDocumentBuilder { public Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId) { Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSet dataSet = maybeDataSet.get(); DataSetMetaData dataSetMetaData = dataSet.getMetadata(); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); Integer version = getVersionFromFileId(fileId); if (dataSet.getChangesRetriever().versionExists(version)) { return Optional.of(changeListBuilder.retrieveChanges(dataSet.getChangesRetriever(), version)); } } return Optional.empty(); } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); Urlset getSourceDescription(@Nullable User user); Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getResourceList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId); Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<Stream<String>> getResourceData(@Nullable User user, String ownerId, String dataSetId); Optional<CachedFile> getCachedFile(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<File> getDataSetDescription(@Nullable User user, String ownerId, String dataSetId); }
RsDocumentBuilder { public Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId) { Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSet dataSet = maybeDataSet.get(); DataSetMetaData dataSetMetaData = dataSet.getMetadata(); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); Integer version = getVersionFromFileId(fileId); if (dataSet.getChangesRetriever().versionExists(version)) { return Optional.of(changeListBuilder.retrieveChanges(dataSet.getChangesRetriever(), version)); } } return Optional.empty(); } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); Urlset getSourceDescription(@Nullable User user); Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getResourceList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId); Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<Stream<String>> getResourceData(@Nullable User user, String ownerId, String dataSetId); Optional<CachedFile> getCachedFile(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<File> getDataSetDescription(@Nullable User user, String ownerId, String dataSetId); static final String SOURCE_DESCRIPTION_PATH; }