Search in sources :

Example 1 with QueryResultIterable

use of org.codice.ddf.commands.util.QueryResultIterable in project ddf by codice.

the class ExportCommand method doMetacardExport.

private List<ExportItem> doMetacardExport(/*Mutable,IO*/
ZipFile zipFile, Filter filter) {
    Set<String> seenIds = new HashSet<>(1024);
    List<ExportItem> exportedItems = new ArrayList<>();
    for (Result result : new QueryResultIterable(catalogFramework, (i) -> getQuery(filter, i, PAGE_SIZE), PAGE_SIZE)) {
        if (!seenIds.contains(result.getMetacard().getId())) {
            writeToZip(zipFile, result);
            exportedItems.add(new ExportItem(result.getMetacard().getId(), getTag(result), result.getMetacard().getResourceURI(), getDerivedResources(result)));
            seenIds.add(result.getMetacard().getId());
        }
        // Fetch and export all history for each exported item
        for (Result revision : new QueryResultIterable(catalogFramework, (i) -> getQuery(getHistoryFilter(result), i, PAGE_SIZE), PAGE_SIZE)) {
            if (seenIds.contains(revision.getMetacard().getId())) {
                continue;
            }
            writeToZip(zipFile, revision);
            exportedItems.add(new ExportItem(revision.getMetacard().getId(), getTag(revision), revision.getMetacard().getResourceURI(), getDerivedResources(result)));
            seenIds.add(revision.getMetacard().getId());
        }
    }
    return exportedItems;
}
Also used : QueryResultIterable(org.codice.ddf.commands.util.QueryResultIterable) ExportItem(org.codice.ddf.commands.catalog.export.ExportItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Result(ddf.catalog.data.Result)

Aggregations

Result (ddf.catalog.data.Result)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ExportItem (org.codice.ddf.commands.catalog.export.ExportItem)1 QueryResultIterable (org.codice.ddf.commands.util.QueryResultIterable)1