use of org.opendatakit.briefcase.model.BriefcaseFormDefinition in project briefcase by opendatakit.
the class SwingTestRig method installFormsFrom.
public static void installFormsFrom(Path path) {
uncheckedWalk(path).forEach(sourcePath -> {
BriefcaseFormDefinition briefcaseFormDefinition = readForm(path, sourcePath);
FileSystemUtils.formCache.putFormFileMd5Hash(sourcePath.toString(), getMd5Hash(sourcePath.toFile()));
FileSystemUtils.formCache.putFormFileFormDefinition(sourcePath.toString(), briefcaseFormDefinition);
});
}
use of org.opendatakit.briefcase.model.BriefcaseFormDefinition in project briefcase by opendatakit.
the class FormsTableUnitTest method appends_to_a_forms_status_history_when_export_events_are_sent.
@Test
@Ignore
public void appends_to_a_forms_status_history_when_export_events_are_sent() {
FormStatus theForm = buildFormStatus(1);
ExportForms forms = new ExportForms(Collections.singletonList(theForm), ExportConfiguration.empty(), new HashMap<>(), new HashMap<>(), new HashMap<>());
TestFormsTableViewModel viewModel = new TestFormsTableViewModel(forms);
new FormsTable(forms, new TestFormsTableView(viewModel), viewModel);
// TODO Event publishing happens asynchronously. We have to work this test a little more to stop ignoring it
EventBus.publish(new ExportProgressEvent("some progress", (BriefcaseFormDefinition) theForm.getFormDefinition()));
EventBus.publish(new ExportFailedEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
EventBus.publish(new ExportSucceededEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
EventBus.publish(new ExportSucceededWithErrorsEvent((BriefcaseFormDefinition) theForm.getFormDefinition()));
assertThat(theForm.getStatusHistory(), Matchers.containsString("some progress"));
assertThat(theForm.getStatusHistory(), Matchers.containsString("Failed."));
assertThat(theForm.getStatusHistory(), Matchers.containsString("Succeeded."));
assertThat(theForm.getStatusHistory(), Matchers.containsString("Succeeded, but with errors."));
}
use of org.opendatakit.briefcase.model.BriefcaseFormDefinition in project briefcase by opendatakit.
the class ExportPanel method export.
private void export() {
form.disableUI();
terminationFuture.reset();
forms.getSelectedForms().parallelStream().peek(FormStatus::clearStatusHistory).forEach(form -> {
String formId = form.getFormDefinition().getFormId();
ExportConfiguration configuration = forms.getConfiguration(formId);
if (configuration.resolvePullBefore())
forms.getTransferSettings(formId).ifPresent(sci -> NewTransferAction.transferServerToBriefcase(sci, terminationFuture, Collections.singletonList(form)));
ExportAction.export((BriefcaseFormDefinition) form.getFormDefinition(), configuration, terminationFuture);
});
form.enableUI();
}
use of org.opendatakit.briefcase.model.BriefcaseFormDefinition in project briefcase by opendatakit.
the class FileSystemUtils method getBriefcaseFormList.
public static final List<BriefcaseFormDefinition> getBriefcaseFormList() {
List<BriefcaseFormDefinition> formsList = new ArrayList<>();
File forms = FileSystemUtils.getFormsFolder();
if (forms.exists()) {
File[] formDirs = forms.listFiles();
for (File f : formDirs) {
if (f.isDirectory()) {
try {
File formFile = new File(f, f.getName() + ".xml");
String formFileHash = getMd5Hash(formFile);
String existingFormFileHash = formCache.getFormFileMd5Hash(formFile.getAbsolutePath());
BriefcaseFormDefinition existingDefinition = formCache.getFormFileFormDefinition(formFile.getAbsolutePath());
if (existingFormFileHash == null || existingDefinition == null || !existingFormFileHash.equalsIgnoreCase(formFileHash)) {
// overwrite cache if the form's hash is not the same or there's no entry for the form in the cache.
formCache.putFormFileMd5Hash(formFile.getAbsolutePath(), formFileHash);
existingDefinition = new BriefcaseFormDefinition(f, formFile);
formCache.putFormFileFormDefinition(formFile.getAbsolutePath(), existingDefinition);
}
formsList.add(existingDefinition);
} catch (BadFormDefinition e) {
log.debug("bad form definition", e);
}
} else {
// junk?
f.delete();
}
}
}
return formsList;
}
use of org.opendatakit.briefcase.model.BriefcaseFormDefinition in project briefcase by opendatakit.
the class TransferFromODK method doResolveOdkCollectFormDefinition.
/**
* Given the OdkCollectFormDefinition within the FormStatus argument, try to match it up
* with an existing Briefcase storage form definition, or create a new Briefcase storage
* form definition for it.
*
* @param fs the form transfer status object for an ODK Collect form definition.
* @return the Briefcase storage form definition.
*/
private BriefcaseFormDefinition doResolveOdkCollectFormDefinition(FormStatus fs) {
fs.setStatusString("resolving against briefcase form definitions", true);
EventBus.publish(new FormStatusEvent(fs));
OdkCollectFormDefinition formDef = (OdkCollectFormDefinition) fs.getFormDefinition();
File odkFormDefFile = formDef.getFormDefinitionFile();
BriefcaseFormDefinition briefcaseLfd;
// copy form definition files from ODK to briefcase (scratch area)
try {
briefcaseLfd = BriefcaseFormDefinition.resolveAgainstBriefcaseDefn(odkFormDefFile, true);
if (briefcaseLfd.needsMediaUpdate()) {
File destinationFormMediaDir;
try {
destinationFormMediaDir = FileSystemUtils.getMediaDirectory(briefcaseLfd.getFormDirectory());
} catch (FileSystemException e) {
String msg = "unable to create media folder";
log.error(msg, e);
fs.setStatusString(msg + ": " + e.getMessage(), false);
EventBus.publish(new FormStatusEvent(fs));
return null;
}
// compose the ODK media directory...
final String odkFormName = odkFormDefFile.getName().substring(0, odkFormDefFile.getName().lastIndexOf("."));
String odkMediaName = odkFormName + "-media";
File odkFormMediaDir = new File(odkFormDefFile.getParentFile(), odkMediaName);
if (odkFormMediaDir.exists()) {
FileUtils.copyDirectory(odkFormMediaDir, destinationFormMediaDir);
}
briefcaseLfd.clearMediaUpdate();
}
} catch (Exception e) {
String msg = "unable to copy form definition and/or media folder";
log.error(msg, e);
fs.setStatusString(msg + ": " + e.getMessage(), false);
EventBus.publish(new FormStatusEvent(fs));
return null;
}
return briefcaseLfd;
}
Aggregations