Search in sources :

Example 1 with BriefcaseFormDefinition

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);
    });
}
Also used : BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition)

Example 2 with 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."));
}
Also used : ExportForms(org.opendatakit.briefcase.export.ExportForms) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusBuilder.buildFormStatus(org.opendatakit.briefcase.model.FormStatusBuilder.buildFormStatus) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) ExportSucceededWithErrorsEvent(org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent) ExportProgressEvent(org.opendatakit.briefcase.model.ExportProgressEvent) ExportFailedEvent(org.opendatakit.briefcase.model.ExportFailedEvent) ExportSucceededEvent(org.opendatakit.briefcase.model.ExportSucceededEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with BriefcaseFormDefinition

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();
}
Also used : ConfigurationPanel(org.opendatakit.briefcase.ui.export.components.ConfigurationPanel) TransferSucceededEvent(org.opendatakit.briefcase.model.TransferSucceededEvent) ExportProgressEvent(org.opendatakit.briefcase.model.ExportProgressEvent) LocalDateTime(java.time.LocalDateTime) BriefcasePreferences(org.opendatakit.briefcase.model.BriefcasePreferences) EXPORT(org.opendatakit.briefcase.model.FormStatus.TransferType.EXPORT) ExportFailedEvent(org.opendatakit.briefcase.model.ExportFailedEvent) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) AnnotationProcessor(org.bushe.swing.event.annotation.AnnotationProcessor) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration) ISO_DATE_TIME(java.time.format.DateTimeFormatter.ISO_DATE_TIME) SavePasswordsConsentRevoked(org.opendatakit.briefcase.model.SavePasswordsConsentRevoked) ExportForms(org.opendatakit.briefcase.export.ExportForms) ExportSucceededWithErrorsEvent(org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent) FileSystemUtils(org.opendatakit.briefcase.util.FileSystemUtils) ExportSucceededEvent(org.opendatakit.briefcase.model.ExportSucceededEvent) ExportForms.buildCustomConfPrefix(org.opendatakit.briefcase.export.ExportForms.buildCustomConfPrefix) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) Executor(java.util.concurrent.Executor) ExportAction(org.opendatakit.briefcase.export.ExportAction) SavePasswordsConsentGiven(org.opendatakit.briefcase.model.SavePasswordsConsentGiven) Collectors.joining(java.util.stream.Collectors.joining) NewTransferAction(org.opendatakit.briefcase.transfer.NewTransferAction) TerminationFuture(org.opendatakit.briefcase.model.TerminationFuture) Collectors.toList(java.util.stream.Collectors.toList) ODKOptionPane.showErrorDialog(org.opendatakit.briefcase.ui.ODKOptionPane.showErrorDialog) List(java.util.List) Stream(java.util.stream.Stream) EventSubscriber(org.bushe.swing.event.annotation.EventSubscriber) Analytics(org.opendatakit.briefcase.ui.reused.Analytics) Collections(java.util.Collections) ExportConfiguration(org.opendatakit.briefcase.export.ExportConfiguration)

Example 4 with BriefcaseFormDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) File(java.io.File)

Example 5 with BriefcaseFormDefinition

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;
}
Also used : FileSystemException(org.opendatakit.briefcase.model.FileSystemException) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) BriefcaseFormDefinition(org.opendatakit.briefcase.model.BriefcaseFormDefinition) OdkCollectFormDefinition(org.opendatakit.briefcase.model.OdkCollectFormDefinition) File(java.io.File) FileSystemException(org.opendatakit.briefcase.model.FileSystemException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ParsingException(org.opendatakit.briefcase.model.ParsingException)

Aggregations

BriefcaseFormDefinition (org.opendatakit.briefcase.model.BriefcaseFormDefinition)10 FormStatus (org.opendatakit.briefcase.model.FormStatus)6 File (java.io.File)5 FormStatusEvent (org.opendatakit.briefcase.model.FormStatusEvent)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 FileSystemException (org.opendatakit.briefcase.model.FileSystemException)4 ExportProgressEvent (org.opendatakit.briefcase.model.ExportProgressEvent)3 LocalDateTime (java.time.LocalDateTime)2 ISO_DATE_TIME (java.time.format.DateTimeFormatter.ISO_DATE_TIME)2 ArrayList (java.util.ArrayList)2 ExportForms (org.opendatakit.briefcase.export.ExportForms)2 BriefcasePreferences (org.opendatakit.briefcase.model.BriefcasePreferences)2 ExportFailedEvent (org.opendatakit.briefcase.model.ExportFailedEvent)2 ExportSucceededEvent (org.opendatakit.briefcase.model.ExportSucceededEvent)2 ExportSucceededWithErrorsEvent (org.opendatakit.briefcase.model.ExportSucceededWithErrorsEvent)2 OdkCollectFormDefinition (org.opendatakit.briefcase.model.OdkCollectFormDefinition)2 ParsingException (org.opendatakit.briefcase.model.ParsingException)2 FileSystemUtils (org.opendatakit.briefcase.util.FileSystemUtils)2 BufferedReader (java.io.BufferedReader)1