Search in sources :

Example 1 with RequestBuilder

use of org.opendatakit.briefcase.reused.http.RequestBuilder in project briefcase by opendatakit.

the class PullFromAggregate method getFormAttachments.

List<AggregateAttachment> getFormAttachments(FormStatus form, RunnerStatus runnerStatus, PullFromAggregateTracker tracker) {
    if (runnerStatus.isCancelled()) {
        tracker.trackCancellation("Get form attachments");
        return emptyList();
    }
    if (!form.getManifestUrl().filter(RequestBuilder::isUri).isPresent())
        return emptyList();
    tracker.trackStartGettingFormManifest();
    URL manifestUrl = form.getManifestUrl().map(RequestBuilder::url).get();
    Request<List<AggregateAttachment>> request = get(manifestUrl).asXmlElement().withResponseMapper(PullFromAggregate::parseMediaFiles).build();
    Response<List<AggregateAttachment>> response = http.execute(request);
    if (!response.isSuccess()) {
        tracker.trackErrorGettingFormManifest(response);
        return Collections.emptyList();
    }
    List<AggregateAttachment> attachments = response.get();
    List<AggregateAttachment> attachmentsToDownload = attachments.stream().filter(mediaFile -> mediaFile.needsUpdate(form.getFormMediaDir(briefcaseDir))).collect(toList());
    tracker.trackEndGettingFormManifest();
    tracker.trackIgnoredFormAttachments(attachmentsToDownload.size(), attachments.size());
    return attachmentsToDownload;
}
Also used : Job.run(org.opendatakit.briefcase.reused.job.Job.run) TRUNCATE_EXISTING(java.nio.file.StandardOpenOption.TRUNCATE_EXISTING) URL(java.net.URL) Response(org.opendatakit.briefcase.reused.http.response.Response) RequestBuilder(org.opendatakit.briefcase.reused.http.RequestBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FormMetadataPort(org.opendatakit.briefcase.model.form.FormMetadataPort) PullEvent(org.opendatakit.briefcase.pull.PullEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventBus(org.bushe.swing.event.EventBus) AggregateServer(org.opendatakit.briefcase.reused.transfer.AggregateServer) Pair(org.opendatakit.briefcase.reused.Pair) DatabaseUtils.withDb(org.opendatakit.briefcase.util.DatabaseUtils.withDb) Path(java.nio.file.Path) FormKey(org.opendatakit.briefcase.model.form.FormKey) RemoteFormDefinition(org.opendatakit.briefcase.model.RemoteFormDefinition) BinaryOperator.maxBy(java.util.function.BinaryOperator.maxBy) OptionalProduct(org.opendatakit.briefcase.reused.OptionalProduct) FormStatus(org.opendatakit.briefcase.model.FormStatus) FormStatusEvent(org.opendatakit.briefcase.model.FormStatusEvent) Request(org.opendatakit.briefcase.reused.http.Request) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) RunnerStatus(org.opendatakit.briefcase.reused.job.RunnerStatus) FormMetadataCommands.updateAsPulled(org.opendatakit.briefcase.model.form.FormMetadataCommands.updateAsPulled) Http(org.opendatakit.briefcase.reused.http.Http) UncheckedFiles.createDirectories(org.opendatakit.briefcase.reused.UncheckedFiles.createDirectories) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) UncheckedFiles.write(org.opendatakit.briefcase.reused.UncheckedFiles.write) CREATE(java.nio.file.StandardOpenOption.CREATE) Triple(org.opendatakit.briefcase.reused.Triple) Optional(java.util.Optional) Job(org.opendatakit.briefcase.reused.job.Job) Collections(java.util.Collections) RequestBuilder.get(org.opendatakit.briefcase.reused.http.RequestBuilder.get) XmlElement(org.opendatakit.briefcase.export.XmlElement) RequestBuilder(org.opendatakit.briefcase.reused.http.RequestBuilder) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) URL(java.net.URL)

Aggregations

URL (java.net.URL)1 Path (java.nio.file.Path)1 CREATE (java.nio.file.StandardOpenOption.CREATE)1 TRUNCATE_EXISTING (java.nio.file.StandardOpenOption.TRUNCATE_EXISTING)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BinaryOperator.maxBy (java.util.function.BinaryOperator.maxBy)1 Consumer (java.util.function.Consumer)1 Collectors.toList (java.util.stream.Collectors.toList)1 EventBus (org.bushe.swing.event.EventBus)1 XmlElement (org.opendatakit.briefcase.export.XmlElement)1 FormStatus (org.opendatakit.briefcase.model.FormStatus)1 FormStatusEvent (org.opendatakit.briefcase.model.FormStatusEvent)1 RemoteFormDefinition (org.opendatakit.briefcase.model.RemoteFormDefinition)1