@Override
    public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
        final Map<Path, List<Long>> regular = new HashMap<>();
        final Map<Path, List<Long>> trashed = new HashMap<>();
        for(Path file : files.keySet()) {
            final Map<Path, List<Long>> set = file.attributes().isDuplicate() ? trashed : regular;
            if(set.containsKey(file.getParent())) {
                set.get(file.getParent()).add(Long.parseLong(nodeid.getVersionId(file)));
            }
            else {
                final List<Long> nodes = new ArrayList<>();
                nodes.add(Long.parseLong(nodeid.getVersionId(file)));
                set.put(file.getParent(), nodes);
            }
            callback.delete(file);
            nodeid.cache(file, null);
        }
        for(List<Long> nodes : regular.values()) {
            try {
                new NodesApi(session.getClient()).removeNodes(new DeleteNodesRequest().nodeIds(nodes), StringUtils.EMPTY);
            }
            catch(ApiException e) {
                switch(e.getCode()) {
                    case 400:
                        log.warn(String.format("Ignore failure %s", e));
                        new SDSDeleteFeature(session, nodeid).delete(files, prompt, callback);
                        break;
                    default:
                        throw new SDSExceptionMappingService(nodeid).map("Cannot delete {0}", e, files.keySet().iterator().next());
                }
            }
        }
        for(List<Long> nodes : trashed.values()) {
            try {
                new NodesApi(session.getClient()).removeDeletedNodes(new DeleteDeletedNodesRequest().deletedNodeIds(nodes), StringUtils.EMPTY);
            }
            catch(ApiException e) {
                throw new SDSExceptionMappingService(nodeid).map("Cannot delete {0}", e, files.keySet().iterator().next());
            }
        }
    }
@Test
    public void testDeleteFolderRoomWithContent() throws Exception {
        final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session);
        final Path room = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(
                new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
        final Path folder = new SDSDirectoryFeature(session, nodeid).mkdir(new Path(room,
                new AlphanumericRandomStringService().random().toLowerCase(), EnumSet.of(Path.Type.directory)), new TransferStatus());
        assertTrue(new SDSFindFeature(session, nodeid).find(folder));
        final Path file = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        new SDSTouchFeature(session, nodeid).touch(file, new TransferStatus());
        assertTrue(new SDSFindFeature(session, nodeid).find(file));
        new SDSBatchDeleteFeature(session, nodeid).delete(Collections.singletonList(folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
        assertFalse(new SDSFindFeature(session, nodeid).find(folder));
        new SDSBatchDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
        assertFalse(new SDSFindFeature(session, nodeid).find(room));
    }