@Test public void getChangeListGeneratesChangeListWithChangeFileNames() throws Exception { when(dataSetRepository.getDataSet(null, "u1", "ds1")).thenReturn(Optional.of(dataSet)); UpdatedPerPatchStore updatedPerPatchStore = mock(UpdatedPerPatchStore.class); given(updatedPerPatchStore.getVersions()).willReturn(Stream.of(0, 1)); LogList logList = new LogList(); logList.setLastImportDate("2018-03-21T10:11:53.811Z"); ImportManager importManager = mock(ImportManager.class); given(importManager.getLogList()).willReturn(logList); EntryImportStatus entryImportStatus1 = new EntryImportStatus(); entryImportStatus1.setDate("2018-02-21T10:11:53.811Z"); LogEntry logEntry1 = mock(LogEntry.class); given(logEntry1.getImportStatus()).willReturn(entryImportStatus1); EntryImportStatus entryImportStatus2 = new EntryImportStatus(); entryImportStatus2.setDate("2018-01-21T10:11:53.811Z"); LogEntry logEntry2 = mock(LogEntry.class); given(logEntry2.getImportStatus()).willReturn(entryImportStatus2); logList.addEntry(logEntry1); logList.addEntry(logEntry2); DataSetMetaData dataSetMetaData = mock(DataSetMetaData.class); given(dataSetMetaData.getBaseUri()).willReturn("http: given(dataSetMetaData.getGraph()).willReturn("http: given(dataSetMetaData.getOwnerId()).willReturn("u1"); given(dataSetMetaData.getDataSetId()).willReturn("ds1"); given(dataSet.getUpdatedPerPatchStore()).willReturn(updatedPerPatchStore); given(dataSet.getMetadata()).willReturn(dataSetMetaData); given(dataSet.getImportManager()).willReturn(importManager); given(dataSet.getChangesRetriever()).willReturn(new ChangesRetriever(null, updatedPerPatchStore)); Urlset changeList = rsDocumentBuilder.getChangeList(null, "u1", "ds1").get(); String xml = rsBuilder.toXml(changeList, true); rsBuilder.setXmlString(xml).build(); Urlset changeListSet = rsBuilder.getUrlset().get(); assertThat(changeListSet.getCapability().get(), is(Capability.CHANGELIST)); assertThat(changeList.getItemList().size(), is(2)); assertThat(changeList.getItemList().get(0).getLoc(), is("http: assertThat(changeList.getItemList().get(0).getLink(ResourceSyncConstants.PATCH_LINK).get().getHref(), is("http: assertThat(changeList.getItemList().get(1).getLink(ResourceSyncConstants.PATCH_LINK).get().getHref(), is("http: }
public Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId) throws IOException { Urlset changeList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); LogList loglist = maybeDataSet.get().getImportManager().getLogList(); RsMd rsMd = new RsMd(Capability.CHANGELIST.xmlValue) .withFrom(ZonedDateTime.parse(loglist.getLastImportDate())); List<LogEntry> logEntries = loglist.getEntries(); changeList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST))); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); ChangesRetriever changesRetriever = maybeDataSet.get().getChangesRetriever(); List<String> changeFileNames = changeListBuilder.retrieveChangeFileNames( changesRetriever.getVersions() ); boolean isFirst = true; for (String changeFileName : changeFileNames) { LogEntry logEntry = logEntries.get(getVersionFromFileId(changeFileName)); UrlItem item = new UrlItem(rsUriHelper.uriForRsDataSet(dataSetMetaData)) .addLink(new RsLn(ResourceSyncConstants.PATCH_LINK, rsUriHelper.uriForChanges(dataSetMetaData, changeFileName)) .withType("application/vnd.timbuctoo-rdf.nquads_unified_diff")) .withMetadata(new RsMd() .withChange(isFirst ? "created" : "updated") .withType("application/n-quads") .withDateTime(ZonedDateTime.parse(logEntry.getImportStatus().getDate()))); changeList.addItem(item); isFirst = false; } } return Optional.ofNullable(changeList); }
RsDocumentBuilder { public Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId) throws IOException { Urlset changeList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); LogList loglist = maybeDataSet.get().getImportManager().getLogList(); RsMd rsMd = new RsMd(Capability.CHANGELIST.xmlValue) .withFrom(ZonedDateTime.parse(loglist.getLastImportDate())); List<LogEntry> logEntries = loglist.getEntries(); changeList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST))); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); ChangesRetriever changesRetriever = maybeDataSet.get().getChangesRetriever(); List<String> changeFileNames = changeListBuilder.retrieveChangeFileNames( changesRetriever.getVersions() ); boolean isFirst = true; for (String changeFileName : changeFileNames) { LogEntry logEntry = logEntries.get(getVersionFromFileId(changeFileName)); UrlItem item = new UrlItem(rsUriHelper.uriForRsDataSet(dataSetMetaData)) .addLink(new RsLn(ResourceSyncConstants.PATCH_LINK, rsUriHelper.uriForChanges(dataSetMetaData, changeFileName)) .withType("application/vnd.timbuctoo-rdf.nquads_unified_diff")) .withMetadata(new RsMd() .withChange(isFirst ? "created" : "updated") .withType("application/n-quads") .withDateTime(ZonedDateTime.parse(logEntry.getImportStatus().getDate()))); changeList.addItem(item); isFirst = false; } } return Optional.ofNullable(changeList); } }
RsDocumentBuilder { public Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId) throws IOException { Urlset changeList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); LogList loglist = maybeDataSet.get().getImportManager().getLogList(); RsMd rsMd = new RsMd(Capability.CHANGELIST.xmlValue) .withFrom(ZonedDateTime.parse(loglist.getLastImportDate())); List<LogEntry> logEntries = loglist.getEntries(); changeList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST))); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); ChangesRetriever changesRetriever = maybeDataSet.get().getChangesRetriever(); List<String> changeFileNames = changeListBuilder.retrieveChangeFileNames( changesRetriever.getVersions() ); boolean isFirst = true; for (String changeFileName : changeFileNames) { LogEntry logEntry = logEntries.get(getVersionFromFileId(changeFileName)); UrlItem item = new UrlItem(rsUriHelper.uriForRsDataSet(dataSetMetaData)) .addLink(new RsLn(ResourceSyncConstants.PATCH_LINK, rsUriHelper.uriForChanges(dataSetMetaData, changeFileName)) .withType("application/vnd.timbuctoo-rdf.nquads_unified_diff")) .withMetadata(new RsMd() .withChange(isFirst ? "created" : "updated") .withType("application/n-quads") .withDateTime(ZonedDateTime.parse(logEntry.getImportStatus().getDate()))); changeList.addItem(item); isFirst = false; } } return Optional.ofNullable(changeList); } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); }
RsDocumentBuilder { public Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId) throws IOException { Urlset changeList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); LogList loglist = maybeDataSet.get().getImportManager().getLogList(); RsMd rsMd = new RsMd(Capability.CHANGELIST.xmlValue) .withFrom(ZonedDateTime.parse(loglist.getLastImportDate())); List<LogEntry> logEntries = loglist.getEntries(); changeList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST))); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); ChangesRetriever changesRetriever = maybeDataSet.get().getChangesRetriever(); List<String> changeFileNames = changeListBuilder.retrieveChangeFileNames( changesRetriever.getVersions() ); boolean isFirst = true; for (String changeFileName : changeFileNames) { LogEntry logEntry = logEntries.get(getVersionFromFileId(changeFileName)); UrlItem item = new UrlItem(rsUriHelper.uriForRsDataSet(dataSetMetaData)) .addLink(new RsLn(ResourceSyncConstants.PATCH_LINK, rsUriHelper.uriForChanges(dataSetMetaData, changeFileName)) .withType("application/vnd.timbuctoo-rdf.nquads_unified_diff")) .withMetadata(new RsMd() .withChange(isFirst ? "created" : "updated") .withType("application/n-quads") .withDateTime(ZonedDateTime.parse(logEntry.getImportStatus().getDate()))); changeList.addItem(item); isFirst = false; } } return Optional.ofNullable(changeList); } 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<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId) throws IOException { Urlset changeList = null; Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId); if (maybeDataSet.isPresent()) { DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata(); LogList loglist = maybeDataSet.get().getImportManager().getLogList(); RsMd rsMd = new RsMd(Capability.CHANGELIST.xmlValue) .withFrom(ZonedDateTime.parse(loglist.getLastImportDate())); List<LogEntry> logEntries = loglist.getEntries(); changeList = new Urlset(rsMd) .addLink(new RsLn(REL_UP, rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST))); ChangeListBuilder changeListBuilder = new ChangeListBuilder(dataSetMetaData.getGraph()); ChangesRetriever changesRetriever = maybeDataSet.get().getChangesRetriever(); List<String> changeFileNames = changeListBuilder.retrieveChangeFileNames( changesRetriever.getVersions() ); boolean isFirst = true; for (String changeFileName : changeFileNames) { LogEntry logEntry = logEntries.get(getVersionFromFileId(changeFileName)); UrlItem item = new UrlItem(rsUriHelper.uriForRsDataSet(dataSetMetaData)) .addLink(new RsLn(ResourceSyncConstants.PATCH_LINK, rsUriHelper.uriForChanges(dataSetMetaData, changeFileName)) .withType("application/vnd.timbuctoo-rdf.nquads_unified_diff")) .withMetadata(new RsMd() .withChange(isFirst ? "created" : "updated") .withType("application/n-quads") .withDateTime(ZonedDateTime.parse(logEntry.getImportStatus().getDate()))); changeList.addItem(item); isFirst = false; } } return Optional.ofNullable(changeList); } 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; }