Search in sources :

Example 1 with CacheUpdateEvent

use of org.opendatakit.briefcase.reused.CacheUpdateEvent in project briefcase by opendatakit.

the class FormCache method update.

public void update() {
    briefcaseDir.ifPresent(path -> {
        Set<String> scannedFiles = new HashSet<>();
        list(path.resolve("forms")).filter(UncheckedFiles::isFormDir).forEach(formDir -> {
            Path form = getFormFilePath(formDir);
            scannedFiles.add(form.toString());
            String hash = FileSystemUtils.getMd5Hash(form.toFile());
            if (isFormNewOrChanged(form, hash)) {
                try {
                    formDefByPath.put(form.toString(), new BriefcaseFormDefinition(form.getParent().toFile(), form.toFile()));
                    hashByPath.put(form.toString(), hash);
                } catch (BadFormDefinition e) {
                    log.warn("Can't parse form file", e);
                }
            }
        });
        // Warning: Remove map entries by mutating the key set works because the key set is a view on the map
        hashByPath.keySet().removeIf(negate(scannedFiles::contains));
        formDefByPath.keySet().removeIf(negate(scannedFiles::contains));
        EventBus.publish(new CacheUpdateEvent());
        save();
    });
}
Also used : Path(java.nio.file.Path) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) CacheUpdateEvent(org.opendatakit.briefcase.reused.CacheUpdateEvent) HashSet(java.util.HashSet)

Aggregations

Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 BriefcaseFormDefinition (org.opendatakit.briefcase.model.BriefcaseFormDefinition)1 CacheUpdateEvent (org.opendatakit.briefcase.reused.CacheUpdateEvent)1