@Test public void testRevert() throws Exception { final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session).withCache(cache); final Path room = new SDSDirectoryFeature(session, nodeid).mkdir( new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.triplecrypt)), null, new TransferStatus()); final SDSAttributesFinderFeature f = new SDSAttributesFinderFeature(session, nodeid); final Path test = new SDSTouchFeature(session, nodeid).touch(new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); final byte[] content = RandomUtils.nextBytes(32769); final TransferStatus status = new TransferStatus(); status.setLength(content.length); final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session, nodeid); final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); final VersionId version = out.getStatus(); assertNotNull(version); assertNotEquals(version.id, test.attributes().getVersionId()); final PathAttributes updated = new SDSAttributesFinderFeature(session, nodeid, true).find( new Path(test.getParent(), test.getName(), test.getType(), new PathAttributes().withVersionId(version.id))); assertFalse(updated.getVersions().isEmpty()); assertEquals(1, updated.getVersions().size()); assertEquals(test, updated.getVersions().get(0)); assertTrue(new SDSFindFeature(nodeid).find(updated.getVersions().get(0))); assertEquals(test.attributes().getVersionId(), new SDSAttributesFinderFeature(session, nodeid).find(updated.getVersions().get(0)).getVersionId()); new SDSVersioningFeature(session, nodeid).revert(test); final Path reverted = new SDSListService(session, nodeid, true).list(room, new DisabledListProgressListener()).find(new DefaultPathPredicate(test)); assertEquals(test.attributes().getVersionId(), reverted.attributes().getVersionId()); assertEquals(1, reverted.attributes().getVersions().size()); assertEquals(new Path(test.getParent(), test.getName(), test.getType(), new PathAttributes().withVersionId(version.id)), reverted.attributes().getVersions().get(0)); new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public void revert(final Path file) throws BackgroundException { try { new NodesApi(session.getClient()).restoreNodes( new RestoreDeletedNodesRequest() .resolutionStrategy(RestoreDeletedNodesRequest.ResolutionStrategyEnum.OVERWRITE) .keepShareLinks(PreferencesFactory.get().getBoolean("sds.upload.sharelinks.keep")) .addDeletedNodeIdsItem(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))) .parentId(Long.parseLong(nodeid.getFileid(file.getParent(), new DisabledListProgressListener()))), StringUtils.EMPTY); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
SDSVersioningFeature implements Versioning { @Override public void revert(final Path file) throws BackgroundException { try { new NodesApi(session.getClient()).restoreNodes( new RestoreDeletedNodesRequest() .resolutionStrategy(RestoreDeletedNodesRequest.ResolutionStrategyEnum.OVERWRITE) .keepShareLinks(PreferencesFactory.get().getBoolean("sds.upload.sharelinks.keep")) .addDeletedNodeIdsItem(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))) .parentId(Long.parseLong(nodeid.getFileid(file.getParent(), new DisabledListProgressListener()))), StringUtils.EMPTY); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }
SDSVersioningFeature implements Versioning { @Override public void revert(final Path file) throws BackgroundException { try { new NodesApi(session.getClient()).restoreNodes( new RestoreDeletedNodesRequest() .resolutionStrategy(RestoreDeletedNodesRequest.ResolutionStrategyEnum.OVERWRITE) .keepShareLinks(PreferencesFactory.get().getBoolean("sds.upload.sharelinks.keep")) .addDeletedNodeIdsItem(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))) .parentId(Long.parseLong(nodeid.getFileid(file.getParent(), new DisabledListProgressListener()))), StringUtils.EMPTY); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } SDSVersioningFeature(final SDSSession session, final SDSNodeIdProvider nodeid); }
SDSVersioningFeature implements Versioning { @Override public void revert(final Path file) throws BackgroundException { try { new NodesApi(session.getClient()).restoreNodes( new RestoreDeletedNodesRequest() .resolutionStrategy(RestoreDeletedNodesRequest.ResolutionStrategyEnum.OVERWRITE) .keepShareLinks(PreferencesFactory.get().getBoolean("sds.upload.sharelinks.keep")) .addDeletedNodeIdsItem(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))) .parentId(Long.parseLong(nodeid.getFileid(file.getParent(), new DisabledListProgressListener()))), StringUtils.EMPTY); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } SDSVersioningFeature(final SDSSession session, final SDSNodeIdProvider nodeid); @Override VersioningConfiguration getConfiguration(final Path container); @Override void setConfiguration(final Path container, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override void revert(final Path file); @Override boolean isRevertable(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback); @Override Versioning withCache(final LRUCache<Path, VersioningConfiguration> cache); }
SDSVersioningFeature implements Versioning { @Override public void revert(final Path file) throws BackgroundException { try { new NodesApi(session.getClient()).restoreNodes( new RestoreDeletedNodesRequest() .resolutionStrategy(RestoreDeletedNodesRequest.ResolutionStrategyEnum.OVERWRITE) .keepShareLinks(PreferencesFactory.get().getBoolean("sds.upload.sharelinks.keep")) .addDeletedNodeIdsItem(Long.parseLong(nodeid.getFileid(file, new DisabledListProgressListener()))) .parentId(Long.parseLong(nodeid.getFileid(file.getParent(), new DisabledListProgressListener()))), StringUtils.EMPTY); } catch(ApiException e) { throw new SDSExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } SDSVersioningFeature(final SDSSession session, final SDSNodeIdProvider nodeid); @Override VersioningConfiguration getConfiguration(final Path container); @Override void setConfiguration(final Path container, final PasswordCallback prompt, final VersioningConfiguration configuration); @Override void revert(final Path file); @Override boolean isRevertable(final Path file); @Override Credentials getToken(final String mfaSerial, final PasswordCallback callback); @Override Versioning withCache(final LRUCache<Path, VersioningConfiguration> cache);  }