Search in sources :

Example 56 with Node

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

the class CommitOpTest method testPathFilteringWithUnstaged.

@Test
public void testPathFilteringWithUnstaged() throws Exception {
    insertAndAdd(points1);
    insertAndAdd(points2);
    RevCommit commit = geogig.command(CommitOp.class).call();
    insertAndAdd(lines1);
    insertAndAdd(lines3);
    insert(lines2);
    insert(points3);
    List<String> filters = Arrays.asList(pointsName, linesName);
    commit = geogig.command(CommitOp.class).setPathFilters(filters).call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(1, commit.getParentIds().size());
    assertNotNull(commit.getId());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = points3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertFalse(featureBlobId.isPresent());
    typeTreeId = repo.getTreeChild(root, linesName);
    assertTrue(typeTreeId.isPresent());
    typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    featureId = lines1.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
    featureId = lines2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertFalse(featureBlobId.isPresent());
    featureId = lines3.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
    assertTrue(featureBlobId.isPresent());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 57 with Node

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

the class DiffOpTest method testReportRename.

@Test
public void testReportRename() throws Exception {
    insertAndAdd(lines1);
    final RevCommit commit1 = geogig.command(CommitOp.class).setAll(true).call();
    Feature lines1B = feature(linesType, idL2, "StringProp2_1", new Integer(1000), "LINESTRING (1 1, 2 2)");
    delete(lines1);
    // insert(lines2);
    WorkingTree workTree = repo.workingTree();
    Name name = lines1.getType().getName();
    String parentPath = name.getLocalPart();
    @SuppressWarnings("unused") Node ref = workTree.insert(parentPath, lines1B);
    geogig.command(AddOp.class).call();
    RevCommit commit2 = geogig.command(CommitOp.class).setAll(true).call();
    List<DiffEntry> diffs;
    diffOp.setOldVersion(commit1.getId());
    diffOp.setNewVersion(commit2.getId());
    diffs = toList(diffOp.call());
    // this is reported as an addition and a removal, with both
    assertEquals(2, diffs.size());
    // nodes pointing to same ObjectId
    assertEquals(diffs.get(0).newObjectId(), diffs.get(1).oldObjectId());
    assertEquals(diffs.get(1).newObjectId(), diffs.get(0).oldObjectId());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Node(org.locationtech.geogig.api.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) Name(org.opengis.feature.type.Name) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 58 with Node

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

the class RemoteRepositoryTestCase method insert.

/**
     * Inserts the feature to the index but does not stages it to be committed
     */
protected ObjectId insert(GeoGIG geogig, Feature f) throws Exception {
    final WorkingTree workTree = geogig.getRepository().workingTree();
    Name name = f.getType().getName();
    String parentPath = name.getLocalPart();
    Node ref = workTree.insert(parentPath, f);
    ObjectId objectId = ref.getObjectId();
    return objectId;
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Name(org.opengis.feature.type.Name)

Example 59 with Node

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

the class ApplyPatchOpTest method testAddFeaturePatch.

@Test
public void testAddFeaturePatch() throws Exception {
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    patch.addAddedFeature(path, points1, RevFeatureTypeImpl.build(pointsType));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> typeTreeId = findTreeChild(root, pointsName);
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    Optional<Node> featureBlobId = findTreeChild(root, path);
    assertTrue(featureBlobId.isPresent());
}
Also used : Node(org.locationtech.geogig.api.Node) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 60 with Node

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

the class ApplyPatchOpTest method testModifyFeatureAttributePatch.

@Test
public void testModifyFeatureAttributePatch() throws Exception {
    insert(points1);
    Patch patch = new Patch();
    String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
    Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
    Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
    GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
    map.put(pointsType.getDescriptor("sp"), diff);
    FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
    patch.addModifiedFeature(feaureDiff);
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    Optional<Node> featureBlobId = findTreeChild(root, path);
    assertTrue(featureBlobId.isPresent());
    Iterator<DiffEntry> unstaged = repo.workingTree().getUnstaged(pointsName);
    ArrayList<DiffEntry> diffs = Lists.newArrayList(unstaged);
    assertEquals(2, diffs.size());
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class);
    assertTrue(feature.isPresent());
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals("new", values.get(0).get());
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) GenericAttributeDiffImpl(org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl) Node(org.locationtech.geogig.api.Node) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Aggregations

Node (org.locationtech.geogig.api.Node)117 RevTree (org.locationtech.geogig.api.RevTree)56 Test (org.junit.Test)50 ObjectId (org.locationtech.geogig.api.ObjectId)44 NodeRef (org.locationtech.geogig.api.NodeRef)24 Bucket (org.locationtech.geogig.api.Bucket)20 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)18 Envelope (com.vividsolutions.jts.geom.Envelope)16 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)14 RevCommit (org.locationtech.geogig.api.RevCommit)10 Map (java.util.Map)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)9 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)9 File (java.io.File)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 WorkingTree (org.locationtech.geogig.repository.WorkingTree)7 Feature (org.opengis.feature.Feature)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Stopwatch (com.google.common.base.Stopwatch)6 SortedMap (java.util.SortedMap)5