Search in sources :

Example 1 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class GeoGigAPI method getUnstagedFeatures.

public Feature[] getUnstagedFeatures(String path, boolean noDeletions) {
    Iterator<DiffEntry> diffs = repository.workingTree().getUnstaged(path);
    List<Feature> list = Lists.newArrayList();
    while (diffs.hasNext()) {
        DiffEntry diff = diffs.next();
        if (!diff.changeType().equals(ChangeType.REMOVED) || !noDeletions) {
            RevFeature revFeature = repository.command(RevObjectParse.class).setObjectId(diff.newObjectId()).call(RevFeature.class).get();
            RevFeatureType revFeatureType = repository.command(RevObjectParse.class).setObjectId(diff.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
            FeatureBuilder builder = new FeatureBuilder(revFeatureType);
            list.add(builder.build(diff.getNewObject().name(), revFeature));
        }
    }
    return list.toArray(new Feature[0]);
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 2 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class DiffTreeTest method testBoundsFilteringReprojecting.

@Test
public void testBoundsFilteringReprojecting() throws Exception {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem nativeCrs = revtype.type().getCoordinateReferenceSystem();
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:4326", true);
    ReferencedEnvelope nativeFilter = new ReferencedEnvelope(49.9, 51.1, 49.9, 51.1, nativeCrs);
    ReferencedEnvelope queryFilter = nativeFilter.transform(queryCrs, true);
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    diffTree.setBoundsFilter(queryFilter);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(2, diffs.size());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 3 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class DiffTreeTest method testBoundsFiltering.

@Test
public void testBoundsFiltering() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
    ReferencedEnvelope filter;
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    filter = new ReferencedEnvelope(50, 51, 50, 51, crs);
    diffTree.setBoundsFilter(filter);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(2, diffs.size());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 4 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class HttpMappedRemoteRepo method pushSparseCommit.

/**
     * Pushes a sparse commit to a remote repository and updates all mappings.
     * 
     * @param commitId the commit to push
     */
@Override
protected void pushSparseCommit(ObjectId commitId) {
    Repository from = localRepository;
    Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId).call();
    if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
        RevCommit commit = (RevCommit) object.get();
        ObjectId parent = ObjectId.NULL;
        List<ObjectId> newParents = new LinkedList<ObjectId>();
        for (int i = 0; i < commit.getParentIds().size(); i++) {
            ObjectId parentId = commit.getParentIds().get(i);
            if (i != 0) {
                Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class).setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
                if (commonAncestor.isPresent()) {
                    if (from.command(CheckSparsePath.class).setStart(parentId).setEnd(commonAncestor.get()).call()) {
                        // This should be the base commit to preserve changes that were filtered
                        // out.
                        newParents.add(0, from.graphDatabase().getMapping(parentId));
                        continue;
                    }
                }
            }
            newParents.add(from.graphDatabase().getMapping(parentId));
        }
        if (newParents.size() > 0) {
            parent = from.graphDatabase().getMapping(newParents.get(0));
        }
        Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId).setOldVersion(parent).setReportTrees(true).call();
        // connect and send packed changes
        final URL resourceURL;
        try {
            resourceURL = new URL(repositoryURL.toString() + "/repo/applychanges");
        } catch (MalformedURLException e) {
            throw Throwables.propagate(e);
        }
        final HttpURLConnection connection;
        final OutputStream out;
        try {
            connection = (HttpURLConnection) resourceURL.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            out = connection.getOutputStream();
            // pack the commit object
            final ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
            final ObjectWriter<RevCommit> commitWriter = factory.createObjectWriter(TYPE.COMMIT);
            commitWriter.write(commit, out);
            // write the new parents
            out.write(newParents.size());
            for (ObjectId parentId : newParents) {
                out.write(parentId.getRawValue());
            }
            // pack the changes
            BinaryPackedChanges changes = new BinaryPackedChanges(from);
            changes.write(out, diffIter);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        final InputStream in;
        try {
            in = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in));
            String line = rd.readLine();
            if (line != null) {
                ObjectId remoteCommitId = ObjectId.valueOf(line);
                from.graphDatabase().map(commit.getId(), remoteCommitId);
                from.graphDatabase().map(remoteCommitId, commit.getId());
            }
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
}
Also used : ObjectSerializingFactory(org.locationtech.geogig.storage.ObjectSerializingFactory) MalformedURLException(java.net.MalformedURLException) OutputStream(java.io.OutputStream) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) CheckSparsePath(org.locationtech.geogig.api.plumbing.CheckSparsePath) InputStreamReader(java.io.InputStreamReader) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) InputStream(java.io.InputStream) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Repository(org.locationtech.geogig.repository.Repository) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) BufferedReader(java.io.BufferedReader)

Example 5 with DiffEntry

use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.

the class RemoveOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected WorkingTree _call() {
    // Check that all paths are valid and exist
    for (String pathToRemove : pathsToRemove) {
        NodeRef.checkValidPath(pathToRemove);
        Optional<NodeRef> node;
        node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        List<Conflict> conflicts = index().getConflicted(pathToRemove);
        if (conflicts.size() > 0) {
            for (Conflict conflict : conflicts) {
                stagingDatabase().removeConflict(null, conflict.getPath());
            }
        } else {
            Preconditions.checkArgument(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
        }
    }
    // separate trees from features an delete accordingly
    for (String pathToRemove : pathsToRemove) {
        Optional<NodeRef> node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        if (!node.isPresent()) {
            continue;
        }
        switch(node.get().getType()) {
            case TREE:
                workingTree().delete(pathToRemove);
                break;
            case FEATURE:
                String parentPath = NodeRef.parentPath(pathToRemove);
                String name = node.get().name();
                workingTree().delete(parentPath, name);
                break;
            default:
                break;
        }
        final long numChanges = workingTree().countUnstaged(pathToRemove).count();
        Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathToRemove);
        index().stage(getProgressListener(), unstaged, numChanges);
    }
    return workingTree();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)83 ObjectId (org.locationtech.geogig.api.ObjectId)38 Test (org.junit.Test)31 RevCommit (org.locationtech.geogig.api.RevCommit)31 NodeRef (org.locationtech.geogig.api.NodeRef)24 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)17 RevFeature (org.locationtech.geogig.api.RevFeature)15 RevTree (org.locationtech.geogig.api.RevTree)15 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)14 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)14 RevObject (org.locationtech.geogig.api.RevObject)11 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)11 Feature (org.opengis.feature.Feature)10 Optional (com.google.common.base.Optional)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)8 Repository (org.locationtech.geogig.repository.Repository)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)8 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 IOException (java.io.IOException)5