Filtering (text search and max result size) works now for file lists.
1 files added
4 files modified
| | |
| | | |
| | | import de.micromata.borgbutler.config.BorgRepoConfig; |
| | | import de.micromata.borgbutler.data.Archive; |
| | | import de.micromata.borgbutler.data.FileSystemFilter; |
| | | import de.micromata.borgbutler.json.borg.BorgFilesystemItem; |
| | | import de.micromata.borgbutler.utils.ReplaceUtils; |
| | | import lombok.Getter; |
| | |
| | | /** |
| | | * Will load and touch the archive file if exist. The file will be touched (last modified time will be set to now) |
| | | * for pruning oldest cache files. The last modified time will be the time of the last usage. |
| | | * |
| | | * @param repoConfig |
| | | * @param archive |
| | | * @param filter If given, only file items matching this filter are returned. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive, int maxSize) { |
| | | public List<BorgFilesystemItem> load(BorgRepoConfig repoConfig, Archive archive, FileSystemFilter filter) { |
| | | File file = getFile(repoConfig, archive); |
| | | if (!file.exists()) { |
| | | return null; |
| | | } |
| | | return load(file, maxSize); |
| | | return load(file, filter); |
| | | } |
| | | |
| | | public List<BorgFilesystemItem> load(File file, int maxSize) { |
| | | /** |
| | | * @param file |
| | | * @param filter If given, only file items matching this filter are returned. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> load(File file, FileSystemFilter filter) { |
| | | if (file.exists() == false) { |
| | | log.error("File '" + file.getAbsolutePath() + "' doesn't exist. Can't get archive content files."); |
| | | return null; |
| | |
| | | return null; |
| | | } |
| | | int size = (Integer) obj; |
| | | if (maxSize > 0 && maxSize < size) { |
| | | size = maxSize; |
| | | } |
| | | int maxSize = filter != null ? filter.getMaxResultSize() : -1; |
| | | list = new ArrayList<>(); |
| | | int counter = 0; |
| | | for (int i = 0; i < size; i++) { |
| | | obj = inputStream.readObject(); |
| | | if (obj instanceof BorgFilesystemItem) { |
| | | list.add((BorgFilesystemItem) obj); |
| | | if (filter == null || filter.matches(((BorgFilesystemItem) obj))) { |
| | | list.add((BorgFilesystemItem) obj); |
| | | if (maxSize > 0 && counter++ >= maxSize) break; |
| | | } |
| | | } else { |
| | | log.error("Can't load archive content. FilesystemItem expected, but received: " |
| | | + (obj != null ? obj.getClass() : "null") |
| | |
| | | |
| | | File getFile(BorgRepoConfig repoConfig, Archive archive) { |
| | | return new File(cacheDir, ReplaceUtils.encodeFilename(CACHE_ARCHIVE_LISTS_BASENAME + archive.getTime() |
| | | + "-" + repoConfig.getRepo() + "-" + archive.getName() + CACHE_FILE_GZIP_EXTENSION, |
| | | + "-" + repoConfig.getRepo() + "-" + archive.getName() + CACHE_FILE_GZIP_EXTENSION, |
| | | true)); |
| | | } |
| | | |
| | |
| | | import de.micromata.borgbutler.config.Configuration; |
| | | import de.micromata.borgbutler.config.ConfigurationHandler; |
| | | import de.micromata.borgbutler.data.Archive; |
| | | import de.micromata.borgbutler.data.FileSystemFilter; |
| | | import de.micromata.borgbutler.data.Repository; |
| | | import de.micromata.borgbutler.json.borg.BorgFilesystemItem; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | |
| | | } |
| | | |
| | | public List<BorgFilesystemItem> getArchiveContent(String archiveId) { |
| | | return getArchiveContent(archiveId, true, -1); |
| | | return getArchiveContent(archiveId, true, null); |
| | | } |
| | | |
| | | /** |
| | | * @param archiveId |
| | | * @param forceLoad If false, the file list will only get if not yet loaded. |
| | | * @param maxSize |
| | | * @param filter If not null, the result will be filtered. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> getArchiveContent(String archiveId, boolean forceLoad, int maxSize) { |
| | | public List<BorgFilesystemItem> getArchiveContent(String archiveId, boolean forceLoad, FileSystemFilter filter) { |
| | | Archive archive = null; |
| | | outerLoop: |
| | | for (Repository repository : getAllRepositories()) { |
| | |
| | | return null; |
| | | } |
| | | BorgRepoConfig repoConfig = ConfigurationHandler.getConfiguration().getRepoConfig(archive.getRepoId()); |
| | | return getArchiveContent(repoConfig, archive, forceLoad, maxSize); |
| | | return getArchiveContent(repoConfig, archive, forceLoad, filter); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> getArchiveContent(BorgRepoConfig repoConfig, Archive archive) { |
| | | return getArchiveContent(repoConfig, archive, true, -1); |
| | | return getArchiveContent(repoConfig, archive, true, null); |
| | | } |
| | | |
| | | /** |
| | | * @param repoConfig |
| | | * @param archive |
| | | * @param maxSize Max result size (default is -1 meaning all). |
| | | * @param filter If given, only the items matching this filter are returned.. |
| | | * @return |
| | | */ |
| | | public List<BorgFilesystemItem> getArchiveContent(BorgRepoConfig repoConfig, Archive archive, boolean forceLoad, int maxSize) { |
| | | public List<BorgFilesystemItem> getArchiveContent(BorgRepoConfig repoConfig, Archive archive, boolean forceLoad, |
| | | FileSystemFilter filter) { |
| | | if (archive == null || StringUtils.isBlank(archive.getName())) { |
| | | return null; |
| | | } |
| | | List<BorgFilesystemItem> items = archiveFilelistCache.load(repoConfig, archive, maxSize); |
| | | List<BorgFilesystemItem> items = archiveFilelistCache.load(repoConfig, archive, filter); |
| | | if (items == null && forceLoad) { |
| | | List<BorgFilesystemItem> list = BorgCommands.listArchiveContent(repoConfig, archive.getName()); |
| | | if (CollectionUtils.isNotEmpty(list)) { |
| | | archiveFilelistCache.save(repoConfig, archive, list); |
| | | items = new ArrayList<>(); |
| | | int i = 0; |
| | | int counter = 0; |
| | | boolean search = filter != null && StringUtils.isNotBlank(filter.getSearchString()); |
| | | int maxSize = filter != null ? filter.getMaxResultSize() : -1; |
| | | for (BorgFilesystemItem item : list) { |
| | | if (++i > maxSize) break; |
| | | items.add(item); |
| | | if (filter == null || filter.matches(item)) { |
| | | items.add(item); |
| | | if (maxSize > 0 && counter++ >= maxSize) break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public List<BorgFilesystemItem> getArchiveContent(File file) { |
| | | return archiveFilelistCache.load(file, -1); |
| | | return archiveFilelistCache.load(file, null); |
| | | } |
| | | |
| | | public void shutdown() { |
| New file |
| | |
| | | package de.micromata.borgbutler.data; |
| | | |
| | | import de.micromata.borgbutler.json.borg.BorgFilesystemItem; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | public class FileSystemFilter { |
| | | @Getter |
| | | @Setter |
| | | private String searchString; |
| | | @Getter |
| | | @Setter |
| | | private int maxResultSize; |
| | | |
| | | public boolean matches(BorgFilesystemItem item) { |
| | | if (searchString == null || searchString.length() == 0) { |
| | | return true; |
| | | } |
| | | return StringUtils.containsIgnoreCase(item.getPath(), searchString); |
| | | } |
| | | } |
| | |
| | | |
| | | import de.micromata.borgbutler.cache.ButlerCache; |
| | | import de.micromata.borgbutler.data.Archive; |
| | | import de.micromata.borgbutler.data.FileSystemFilter; |
| | | import de.micromata.borgbutler.data.Repository; |
| | | import de.micromata.borgbutler.json.JsonUtils; |
| | | import de.micromata.borgbutler.json.borg.BorgFilesystemItem; |
| | |
| | | * @see JsonUtils#toJson(Object, boolean) |
| | | */ |
| | | public String getArchiveFileLIst(@QueryParam("archiveId") String archiveId, |
| | | @QueryParam("search") String search, |
| | | @QueryParam("searchString") String searchString, |
| | | @QueryParam("maxResultSize") String maxResultSize, |
| | | @QueryParam("force") boolean force, |
| | | @QueryParam("prettyPrinter") boolean prettyPrinter) { |
| | | int maxSize = NumberUtils.toInt(maxResultSize, 50); |
| | | List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, force, maxSize); |
| | | FileSystemFilter filter = new FileSystemFilter() |
| | | .setSearchString(searchString) |
| | | .setMaxResultSize(maxSize); |
| | | List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, force, |
| | | filter); |
| | | if (items == null) { |
| | | return "[]"; |
| | | return "[{patch: 'notLoaded'}]"; |
| | | } |
| | | return JsonUtils.toJson(items, prettyPrinter); |
| | | } |
| | |
| | | fetch(getRestServiceUrl('archives/filelist', { |
| | | archiveId: this.props.archiveId, |
| | | force: forceReload, |
| | | search: this.state.filter.search, |
| | | searchString: this.state.filter.search, |
| | | maxResultSize: this.state.filter.maxSize |
| | | }), { |
| | | method: 'GET', |