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();
});
}
Aggregations