use of org.opendatakit.briefcase.pull.aggregate.Cursor in project briefcase by opendatakit.
the class AggregateServerTest method knows_how_to_build_instance_id_batch_urls.
@Test
public void knows_how_to_build_instance_id_batch_urls() throws UnsupportedEncodingException {
assertThat(server.getInstanceIdBatchRequest("some-form", 100, Cursor.empty(), true).getUrl().toString(), is("https://some.server.com/view/submissionList?formId=some-form&cursor=&numEntries=100&includeIncomplete=true"));
Cursor cursor = Cursor.of(LocalDate.parse("2010-01-01"));
assertThat(server.getInstanceIdBatchRequest("some-form", 100, cursor, false).getUrl().toString(), is("https://some.server.com/view/submissionList?formId=some-form&cursor=" + encode(cursor.getValue(), UTF_8.toString()) + "&numEntries=100&includeIncomplete=false"));
}
use of org.opendatakit.briefcase.pull.aggregate.Cursor in project briefcase by opendatakit.
the class FormMetadataQueriesTest method queries_the_last_cursor_of_a_form.
@Test
public void queries_the_last_cursor_of_a_form() {
FormKey key = FormKey.of("Some form", "some-form");
Path storageRoot = Paths.get("/some/path");
Path formDir = storageRoot.resolve("forms/Some form");
FormMetadata formMetadata = new FormMetadata(key, storageRoot, formDir, false, Cursor.empty(), Optional.empty(), Collections.emptySet());
FormMetadataPort formMetadataPort = new InMemoryFormMetadataAdapter();
formMetadataPort.persist(formMetadata);
assertThat(formMetadataPort.query(lastCursorOf(key)), isPresentAndIs(Cursor.empty()));
Cursor cursor = Cursor.from("some cursor");
formMetadataPort.execute(FormMetadataCommands.updateAsPulled(key, cursor, storageRoot, formDir, new HashSet<>()));
assertThat(formMetadataPort.query(lastCursorOf(key)), isPresentAndIs(cursor));
}
use of org.opendatakit.briefcase.pull.aggregate.Cursor in project briefcase by opendatakit.
the class FileSystemFormMetadataAdapterTest method persists_and_fetches_form_metadata.
@Test
public void persists_and_fetches_form_metadata() {
// The filesystem-based adapter we're testing uses an in-memory cache of metadata
// to avoid hitting the filesystem each time we need to fetch one.
// In this tests, we persist and fetch a range of possible metadata objects with
// all combinations of version and lastCursor, and we use different adapter instances
// for persisting and fetching them to work around the in-memory cache.
Arrays.<Pair<Supplier<Path>, Cursor>>asList(Pair.of(() -> installForm(storageRoot, "Form 1", "form-1", Optional.empty()), Cursor.empty()), Pair.of(() -> installForm(storageRoot, "Form 2", "form-2", Optional.of("20190701002")), Cursor.empty()), Pair.of(() -> installForm(storageRoot, "Form 3", "form-3", Optional.of("20190701003")), AggregateCursor.of(OffsetDateTime.now(), "uuid:" + UUID.randomUUID().toString())), Pair.of(() -> installForm(storageRoot, "Form 4", "form-4", Optional.of("20190701004")), OnaCursor.from("1234")), Pair.of(() -> installForm(storageRoot, "Form 5", "form-5", Optional.empty()), AggregateCursor.of(OffsetDateTime.now(), "uuid:" + UUID.randomUUID().toString())), Pair.of(() -> installForm(storageRoot, "Form 6", "form-6", Optional.empty()), OnaCursor.from("1234"))).forEach(pair -> {
// Clean the storage root to isolate side-effects of each iteration
deleteRecursive(storageRoot);
createDirectories(storageRoot.resolve("forms"));
// Get the scenario settings of this test
Supplier<Path> formInstaller = pair.getLeft();
Cursor cursor = pair.getRight();
// Install the form in the storage root, and get a metadata object from it
Path formFile = formInstaller.get();
FormMetadata metadataToBePersisted = buildMetadataFrom(storageRoot, formFile, cursor);
// Persist metadata into the filesystem
FormMetadataPort persistPort = FileSystemFormMetadataAdapter.at(storageRoot);
persistPort.persist(metadataToBePersisted);
// Can't use the same adapter because it would return the object stored
// in its in-memory cache, and we want to force the adapter to go search for
// it in the filesystem.
FormMetadataPort fetchPort = FileSystemFormMetadataAdapter.at(storageRoot);
Optional<FormMetadata> fetchedMetadata = fetchPort.fetch(metadataToBePersisted.getKey());
assertThat(fetchedMetadata, isPresentAnd(is(metadataToBePersisted)));
});
}
use of org.opendatakit.briefcase.pull.aggregate.Cursor in project briefcase by opendatakit.
the class FormMetadataCommandsTest method updates_a_form_as_having_been_pulled_adding_the_last_cursor_used_to_pull_it.
@Test
public void updates_a_form_as_having_been_pulled_adding_the_last_cursor_used_to_pull_it() {
Cursor cursor = Cursor.from("some cursor data");
formMetadataPort.execute(updateAsPulled(key, cursor, storageRoot, formDir, Collections.emptySet()));
FormMetadata formMetadata = formMetadataPort.fetch(key).get();
assertThat(formMetadata.hasBeenPulled(), is(true));
assertThat(formMetadata.getCursor(), is(cursor));
}
use of org.opendatakit.briefcase.pull.aggregate.Cursor in project briefcase by opendatakit.
the class TransferTestHelpers method generatePages.
public static List<Pair<String, Cursor>> generatePages(int totalIds, int idsPerPage) {
AtomicInteger idSeq = new AtomicInteger(0);
OffsetDateTime startingDateTime = OffsetDateTime.parse("2010-01-01T00:00:00.000Z");
Cursor lastCursor = Cursor.empty();
List<Pair<String, Cursor>> pages = new ArrayList<>();
for (int page : IntStream.range(0, (totalIds / idsPerPage) + 1).boxed().collect(Collectors.toList())) {
int from = page * idsPerPage;
int to = min(totalIds, (page + 1) * idsPerPage);
List<String> ids = IntStream.range(from, to).mapToObj(i -> buildSequentialUid(idSeq.getAndIncrement())).collect(Collectors.toList());
Cursor cursor = Cursor.of(startingDateTime.plusDays(to - 1), buildSequentialUid(idSeq.get()));
pages.add(Pair.of("" + "<idChunk xmlns=\"http://opendatakit.org/submissions\">" + "<idList>" + ids.stream().map(id -> "<id>" + id + "</id>").collect(joining("")) + "</idList>" + "<resumptionCursor>" + escape(cursor.getValue()) + "</resumptionCursor>" + "</idChunk>" + "", cursor));
lastCursor = cursor;
}
pages.add(Pair.of("" + "<idChunk xmlns=\"http://opendatakit.org/submissions\">" + "<idList></idList>" + "<resumptionCursor>" + escape(lastCursor.getValue()) + "</resumptionCursor>" + "</idChunk>" + "", lastCursor));
return pages;
}
Aggregations