class B2FileidProvider implements IdProvider {

    @Override
    public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException {
        if(StringUtils.isNotBlank(file.attributes().getVersionId())) {
            return file.attributes().getVersionId();
        }
        try {
            if(cache.isCached(file.getParent())) {
                final AttributedList<Path> list = cache.get(file.getParent());
                final Path found = list.find(new SimplePathPredicate(file));
                if(null != found) {
                    if(StringUtils.isNotBlank(found.attributes().getVersionId())) {
                        // Cache in file attributes
                        return set(file, found.attributes().getVersionId());
                    }
                }
            }
            if(containerService.isContainer(file)) {
                final B2BucketResponse info = session.getClient().listBucket(file.getName());
                // Cache in file attributes
                return this.set(file, info.getBucketId());
            }
            if(cache.isCached(file.getParent())) {
                final AttributedList<Path> list = cache.get(file.getParent());
                final Path found = list.find(new SimplePathPredicate(file));
                if(null != found) {
                    if(StringUtils.isNotBlank(found.attributes().getVersionId())) {
                        // Cache in file attributes
                        return this.set(file, found.attributes().getVersionId());
                    }
                }
            }
            final B2ListFilesResponse response = session.getClient().listFileNames(
                this.getFileid(containerService.getContainer(file), listener),
                containerService.getKey(file), 2);
            for(B2FileInfoResponse info : response.getFiles()) {
                if(StringUtils.equals(containerService.getKey(file), info.getFileName())) {
                    // Cache in file attributes
                    return this.set(file, info.getFileId());
                }
            }
            throw new NotfoundException(file.getAbsolute());
        }
        catch(B2ApiException e) {
            throw new B2ExceptionMappingService().map(e);
        }
        catch(IOException e) {
            throw new DefaultIOExceptionMappingService().map(e);
        }
    }

    public  B2FileidProvider(final B2Session session);

}