Search in sources :

Example 41 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class CreatePatchOp method _call.

@Override
protected Patch _call() {
    Patch patch = new Patch();
    Map<ObjectId, RevFeatureType> featureTypes = Maps.newHashMap();
    while (diffs.hasNext()) {
        DiffEntry diffEntry = diffs.next();
        final NodeRef newObject = diffEntry.getNewObject();
        final NodeRef oldObject = diffEntry.getOldObject();
        if (diffEntry.changeType() == ChangeType.MODIFIED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                FeatureDiff diff = command(DiffFeature.class).setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject())).setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();
                patch.addModifiedFeature(diff);
            } else if (revObject instanceof RevTree) {
                RevFeatureType oldFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
                RevFeatureType newFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
                patch.addFeatureType(oldFeatureType);
                patch.addFeatureType(newFeatureType);
                patch.addAlteredTree(diffEntry);
            }
        } else if (diffEntry.changeType() == ChangeType.ADDED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                RevFeatureType featureType;
                if (featureTypes.containsKey(newObject.getMetadataId())) {
                    featureType = featureTypes.get(newObject.getMetadataId());
                } else {
                    featureType = command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call(RevFeatureType.class).get();
                    featureTypes.put(newObject.getMetadataId(), featureType);
                }
                FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                Feature feature = featureBuilder.build(diffEntry.newObjectId().toString(), (RevFeature) revObject);
                String name = diffEntry.newPath();
                patch.addAddedFeature(name, feature, featureType);
            } else if (revObject instanceof RevTree) {
                ObjectId metadataId = diffEntry.getNewObject().getMetadataId();
                if (!metadataId.isNull()) {
                    RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
                    patch.addAlteredTree(diffEntry);
                    patch.addFeatureType(featureType);
                }
            }
        } else if (diffEntry.changeType() == ChangeType.REMOVED) {
            RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.oldObjectId()).call().get();
            if (revObject instanceof RevFeature) {
                RevFeatureType featureType;
                if (featureTypes.containsKey(oldObject.getMetadataId())) {
                    featureType = featureTypes.get(oldObject.getMetadataId());
                } else {
                    featureType = command(RevObjectParse.class).setObjectId(oldObject.getMetadataId()).call(RevFeatureType.class).get();
                    featureTypes.put(oldObject.getMetadataId(), featureType);
                }
                FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
                Feature feature = featureBuilder.build(diffEntry.oldObjectId().toString(), (RevFeature) revObject);
                String name = diffEntry.oldPath();
                patch.addRemovedFeature(name, feature, featureType);
            } else if (revObject instanceof RevTree) {
                ObjectId metadataId = diffEntry.getOldObject().getMetadataId();
                if (!metadataId.isNull()) {
                    RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
                    patch.addAlteredTree(diffEntry);
                    patch.addFeatureType(featureType);
                }
            }
        }
    }
    return patch;
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) NodeRef(org.locationtech.geogig.api.NodeRef) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 42 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testPushCommitsFromSparseClone.

@Test
public void testPushCommitsFromSparseClone() throws Exception {
    setupSparseClone();
    // Add some commits to the local (sparse) repository
    List<Feature> features = Arrays.asList(city1, city1_modified, road3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(localGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = localGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    PushOp push = push();
    push.setAll(true).call();
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Roads.3", logged.get(0).getMessage());
    assertFalse(expected.get(0).getId().equals(logged.get(0).getId()));
    assertEquals("Cities.1", logged.get(1).getMessage());
    assertFalse(expected.get(1).getId().equals(logged.get(1).getId()));
    assertEquals("Cities.1", logged.get(2).getMessage());
    assertFalse(expected.get(2).getId().equals(logged.get(2).getId()));
    assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3));
}
Also used : HashMap(java.util.HashMap) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) PushOp(org.locationtech.geogig.api.porcelain.PushOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 43 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testPushSparseMergeScenario2.

@Test
public void testPushSparseMergeScenario2() throws Exception {
    setupSparseClone();
    // create a branch off an early commit
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    RevCommit initialCommit = logs.next();
    while (logs.hasNext()) {
        initialCommit = logs.next();
    }
    localGeogig.geogig.command(BranchCreateOp.class).setName("Branch1").setAutoCheckout(true).setSource(initialCommit.getId().toString()).call();
    // Add some commits to the local (sparse) repository
    List<Feature> features = Arrays.asList(city1, city1_modified, road3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(localGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = localGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Checkout master
    localGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
    // Merge Branch1 into master
    MergeOp merge = localGeogig.geogig.command(MergeOp.class);
    MergeReport report = merge.addCommit(Suppliers.ofInstance(expected.get(0).getId())).setMessage("Merge").call();
    PushOp push = push();
    push.addRefSpec("refs/heads/master").call();
    logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Merge", logged.get(0).getMessage());
    assertFalse(report.getMergeCommit().getId().equals(logged.get(0).getId()));
    // Because we merged Branch1 into the "sparse" master, we don't need to swap the parents, so
    // the history should look the same.
    ObjectId parent1Id = logged.get(0).getParentIds().get(0);
    ObjectId parent2Id = logged.get(0).getParentIds().get(1);
    RevCommit parent1 = remoteGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.2", parent1.getMessage());
    RevCommit parent2 = remoteGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.3", parent2.getMessage());
    // Verify they weren't swapped in the original
    parent1Id = report.getMergeCommit().getParentIds().get(0);
    parent2Id = report.getMergeCommit().getParentIds().get(1);
    parent1 = localGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.2", parent1.getMessage());
    parent2 = localGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.3", parent2.getMessage());
    assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3));
}
Also used : HashMap(java.util.HashMap) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) PushOp(org.locationtech.geogig.api.porcelain.PushOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 44 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method setupSparseClone.

private void setupSparseClone() throws Exception {
    Map<String, String> filter = new HashMap<String, String>();
    filter.put("default", "BBOX(pp,30, -125, 40, -110,'EPSG:4326')");
    filter.put("Cities", "BBOX(pp,33, -125, 40, -110,'EPSG:4326')");
    createFilterFile(filter);
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(city3, road1, city2, road2);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("master").call();
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Roads.2", logged.get(0).getMessage());
    assertFalse(expected.get(0).getId().equals(logged.get(0).getId()));
    assertEquals(expected.get(2).getId(), logged.get(1).getId());
    assertEquals(expected.get(3).getId(), logged.get(2).getId());
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) HashMap(java.util.HashMap) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 45 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testPullCommitThatDoesNotPassFilter.

@Test
public void testPullCommitThatDoesNotPassFilter() throws Exception {
    setupSparseClone();
    // Add a commit that passes our filter to the remote.
    ObjectId oId = insertAndAdd(remoteGeogig.geogig, city1);
    final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(city1.getIdentifier().toString()).call();
    Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
    assertTrue(childObject.isPresent());
    PullOp pull = pull();
    pull.call();
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(AbstractMappedRemoteRepo.PLACEHOLDER_COMMIT_MESSAGE, logged.get(0).getMessage());
    assertFalse(commit.getId().equals(logged.get(0).getId()));
    assertNotExists(localGeogig, oId);
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8