Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.ProgressListener


            } catch (FileNotFoundException e) {
                throw Throwables.propagate(e);
            }
        }

        ProgressListener progressListener = getProgressListener();
        progressListener.setDescription("Importing into GeoGig repo...");

        EntityConverter converter = new EntityConverter();

        OSMReport report;
        try {
            report = parseDataFileAndInsert(osmDataFile, osmDataStream, converter);
        } finally {
            Closeables.closeQuietly(osmDataStream);
        }

        if (!progressListener.isCanceled() && report != null) {
            ObjectId newTreeId = workingTree().getTree().getId();
            if (!noRaw) {
                if (mapping != null || filter != null) {
                    progressListener.setDescription("Staging features...");
                    command(AddOp.class).setProgressListener(progressListener).call();
                    progressListener.setDescription("Committing features...");
                    command(CommitOp.class).setMessage(message)
                            .setProgressListener(progressListener).call();
                    OSMLogEntry entry = new OSMLogEntry(newTreeId, report.getLatestChangeset(),
                            report.getLatestTimestamp());
                    command(AddOSMLogEntry.class).setEntry(entry).call();
View Full Code Here


    }

    private InputStream downloadFile() {

        ProgressListener listener = getProgressListener();
        checkNotNull(filter);
        OSMDownloader downloader = new OSMDownloader(urlOrFilepath, listener);
        listener.setDescription("Connecting to " + urlOrFilepath + "...");
        File destination = null;
        if (keepFile) {
            destination = this.downloadFile;
            if (destination == null) {
                try {
                    destination = File.createTempFile("osm-geogig", ".xml");
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
            } else {
                destination = destination.getAbsoluteFile();
            }
        }
        try {
            InputStream dataStream = downloader.download(filter, destination);
            if (keepFile) {
                listener.setDescription("Downloaded data will be kept in "
                        + destination.getAbsolutePath());
            }
            return dataStream;
        } catch (Exception e) {
            throw Throwables.propagate(Throwables.getRootCause(e));
View Full Code Here

        // producer/consumer approach so that the osm parse thread produces featrures into the
        // iterator's queue, and WorkingTree.insert consumes them on this thread
        QueueIterator<Feature> iterator = new QueueIterator<Feature>(queueCapacity, timeout,
                timeoutUnit);

        ProgressListener progressListener = getProgressListener();
        ConvertAndImportSink sink = new ConvertAndImportSink(converter, iterator, platform(),
                mapping, noRaw, new SubProgressListener(progressListener, 100));
        reader.setSink(sink);

        Thread readerThread = new Thread(reader, "osm-import-reader-thread");
View Full Code Here

    @Override
    protected Optional<OSMReport> _call() {
        checkNotNull(file);
        Preconditions.checkArgument(file.exists(), "File does not exist: " + file);

        ProgressListener progressListener = getProgressListener();
        progressListener.setDescription("Applying OSM diff file to GeoGig repo...");

        OSMReport report = parseDiffFileAndInsert();

        return Optional.fromNullable(report);
View Full Code Here

        QueueIterator<Feature> target = new QueueIterator<Feature>(queueCapacity, timeout,
                timeoutUnit);

        XmlChangeReader reader = new XmlChangeReader(file, true, resolveCompressionMethod(file));

        ProgressListener progressListener = getProgressListener();
        ConvertAndImportSink sink = new ConvertAndImportSink(target, context, workingTree(),
                platform(), new SubProgressListener(progressListener, 100));
        reader.setChangeSink(sink);

        Thread readerThread = new Thread(reader, "osm-diff-reader-thread");
View Full Code Here

        } else if (remotes.size() == 0) {
            // If no remotes are specified, default to the origin remote
            addRemote("origin");
        }

        final ProgressListener progressListener = getProgressListener();
        progressListener.started();

        Optional<Integer> repoDepth = repository().getDepth();
        if (repoDepth.isPresent()) {
            if (fullDepth) {
                depth = Optional.of(Integer.MAX_VALUE);
            }
            if (depth.isPresent()) {
                if (depth.get() > repoDepth.get()) {
                    command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET)
                            .setScope(ConfigScope.LOCAL).setName(Repository.DEPTH_CONFIG_KEY)
                            .setValue(depth.get().toString()).call();
                    repoDepth = depth;
                }
            }
        } else if (depth.isPresent() || fullDepth) {
            // Ignore depth, this is a full repository
            depth = Optional.absent();
            fullDepth = false;
        }

        TransferSummary result = new TransferSummary();

        for (Remote remote : remotes) {
            final ImmutableSet<Ref> remoteRemoteRefs = command(LsRemote.class)
                    .setRemote(Suppliers.ofInstance(Optional.of(remote)))
                    .retrieveTags(!remote.getMapped() && (!repoDepth.isPresent() || fullDepth))
                    .call();
            final ImmutableSet<Ref> localRemoteRefs = command(LsRemote.class)
                    .retrieveLocalRefs(true).setRemote(Suppliers.ofInstance(Optional.of(remote)))
                    .call();

            // If we have specified a depth to pull, we may have more history to pull from existing
            // refs.
            List<ChangedRef> needUpdate = findOutdatedRefs(remote, remoteRemoteRefs,
                    localRemoteRefs, depth);

            if (prune) {
                // Delete local refs that aren't in the remote
                List<Ref> locals = new ArrayList<Ref>();
                // only branches, not tags, appear in the remoteRemoteRefs list so we will not catch
                // any tags in this check. However, we do not track which remote originally
                // provided a tag so it makes sense not to prune them anyway.
                for (Ref remoteRef : remoteRemoteRefs) {
                    Optional<Ref> localRef = findLocal(remoteRef, localRemoteRefs);
                    if (localRef.isPresent()) {
                        locals.add(localRef.get());
                    }
                }
                for (Ref localRef : localRemoteRefs) {
                    if (!locals.contains(localRef)) {
                        // Delete the ref
                        ChangedRef changedRef = new ChangedRef(localRef, null,
                                ChangeTypes.REMOVED_REF);
                        needUpdate.add(changedRef);
                        command(UpdateRef.class).setDelete(true).setName(localRef.getName()).call();
                    }
                }
            }

            Optional<IRemoteRepo> remoteRepo = getRemoteRepo(remote, repository()
                    .deduplicationService());

            Preconditions.checkState(remoteRepo.isPresent(), "Failed to connect to the remote.");
            IRemoteRepo remoteRepoInstance = remoteRepo.get();
            try {
                remoteRepoInstance.open();
            } catch (IOException e) {
                Throwables.propagate(e);
            }
            try {
                int refCount = 0;
                for (ChangedRef ref : needUpdate) {
                    if (ref.getType() != ChangeTypes.REMOVED_REF) {
                        refCount++;

                        Optional<Integer> newFetchLimit = depth;
                        // If we haven't specified a depth, but this is a shallow repository, set
                        // the
                        // fetch limit to the current repository depth.
                        if (!newFetchLimit.isPresent() && repoDepth.isPresent()
                                && ref.getType() == ChangeTypes.ADDED_REF) {
                            newFetchLimit = repoDepth;
                        }
                        // Fetch updated data from this ref
                        Ref newRef = ref.getNewRef();
                        remoteRepoInstance.fetchNewData(newRef, newFetchLimit, progressListener);

                        if (repoDepth.isPresent() && !fullDepth) {
                            // Update the repository depth if it is deeper than before.
                            int newDepth;
                            try {
                                newDepth = repository().graphDatabase().getDepth(
                                        newRef.getObjectId());
                            } catch (IllegalStateException e) {
                                throw new RuntimeException(ref.toString(), e);
                            }

                            if (newDepth > repoDepth.get()) {
                                command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET)
                                        .setScope(ConfigScope.LOCAL)
                                        .setName(Repository.DEPTH_CONFIG_KEY)
                                        .setValue(Integer.toString(newDepth)).call();
                                repoDepth = Optional.of(newDepth);
                            }
                        }

                        // Update the ref
                        Ref updatedRef = updateLocalRef(newRef, remote, localRemoteRefs);
                        ref.setNewRef(updatedRef);
                    }
                }

                if (needUpdate.size() > 0) {
                    result.addAll(remote.getFetchURL(), needUpdate);
                }

                // Update HEAD ref
                if (!remote.getMapped()) {
                    Ref remoteHead = remoteRepoInstance.headRef();
                    if (remoteHead != null) {
                        updateLocalRef(remoteHead, remote, localRemoteRefs);
                    }
                }
            } finally {
                try {
                    remoteRepoInstance.close();
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
            }
        }

        if (fullDepth) {
            // The full history was fetched, this is no longer a shallow clone
            command(ConfigOp.class).setAction(ConfigAction.CONFIG_UNSET)
                    .setScope(ConfigScope.LOCAL).setName(Repository.DEPTH_CONFIG_KEY).call();
        }

        progressListener.complete();

        return result;
    }
View Full Code Here

            } catch (UnsupportedEncodingException e) {
                // shouldn't reach here.
            }
        }

        ProgressListener progressListener = getProgressListener();
        progressListener.started();

        // use a local variable not to alter the command's state
        boolean overwrite = this.overwrite;
        if (alter) {
            overwrite = false;
        }

        final WorkingTree workTree = workingTree();

        RevFeatureType destPathFeatureType = null;
        final boolean destPathProvided = destPath != null;
        if (destPathProvided) {
            destPathFeatureType = this.command(ResolveFeatureType.class).setRefSpec(destPath)
                    .call().orNull();
            // we delete the previous tree to honor the overwrite setting, but then turn it
            // to false. Otherwise, each table imported will overwrite the previous ones and
            // only the last one will be imported.
            if (overwrite) {
                try {
                    workTree.delete(destPath);
                } catch (Exception e) {
                    throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
                }
                overwrite = false;
            }
        }

        int tableCount = 0;

        for (String typeName : typeNames) {
            {
                tableCount++;
                String tableName = String.format("%-16s", typeName);
                if (typeName.length() > 16) {
                    tableName = tableName.substring(0, 13) + "...";
                }
                progressListener.setDescription("Importing " + tableName + " (" + tableCount + "/"
                        + typeNames.length + ")... ");
            }

            FeatureSource featureSource = getFeatureSource(typeName);
            SimpleFeatureType featureType = (SimpleFeatureType) featureSource.getSchema();

            final String fidPrefix = featureType.getTypeName() + ".";

            String path;
            if (destPath == null) {
                path = featureType.getTypeName();
            } else {
                NodeRef.checkValidPath(destPath);
                path = destPath;
                featureType = forceFeatureTypeName(featureType, path);
            }

            featureType = overrideGeometryName(featureType);

            featureSource = new ForceTypeAndFidFeatureSource<FeatureType, Feature>(featureSource,
                    featureType, fidPrefix);
            boolean hasPrimaryKey = hasPrimaryKey(typeName);
            boolean forbidSorting = !usePaging || !hasPrimaryKey;
            ((ForceTypeAndFidFeatureSource) featureSource).setForbidSorting(forbidSorting);

            if (destPathFeatureType != null && adaptToDefaultFeatureType && !alter) {
                featureSource = new FeatureTypeAdapterFeatureSource<FeatureType, Feature>(
                        featureSource, destPathFeatureType.type());
            }

            ProgressListener taskProgress = subProgress(100.f / typeNames.length);
            if (overwrite) {
                try {
                    workTree.delete(path);
                    workTree.createTypeTree(path, featureType);
                } catch (Exception e) {
View Full Code Here

    private void flush(String path) {
        Set<SimpleFeature> features = map.get(path);
        if (!features.isEmpty()) {
            Iterator<? extends Feature> iterator = features.iterator();
            ProgressListener listener = new DefaultProgressListener();
            List<org.locationtech.geogig.api.Node> insertedTarget = null;
            Integer collectionSize = Integer.valueOf(features.size());
            workTree.insert(path, iterator, listener, insertedTarget, collectionSize);
        }
    }
View Full Code Here

        Preconditions.checkState(getDataStore().isAllowTransactions(),
                "Transactions not supported; head is not a local branch");
        final WorkingTree workingTree = delegate.getWorkingTree();
        final String path = delegate.getTypeTreePath();

        ProgressListener listener = new DefaultProgressListener();

        final List<FeatureId> insertedFids = Lists.newArrayList();
        List<Node> deferringTarget = new AbstractList<Node>() {

            @Override
View Full Code Here

        final SimpleFeatureType nativeSchema = delegate.getNativeType();

        features = Iterators.transform(features, new SchemaInforcer(nativeSchema));

        try {
            ProgressListener listener = new DefaultProgressListener();
            Integer count = (Integer) null;
            List<Node> target = (List<Node>) null;
            workingTree.insert(path, features, listener, target, count);
        } catch (Exception e) {
            throw new IOException(e);
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.ProgressListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.