Search in sources :

Example 51 with RevTree

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

the class WriteTree2 method handleNewTrees.

private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) {
    SortedSet<NodeRef> newTrees = treeDifference.findNewTrees();
    for (NodeRef ref : newTrees) {
        final String path = ref.path();
        if (ignoreList.contains(path)) {
            continue;
        }
        ignoreList.add(path);
        if (!filterMatchesOrIsParent(path)) {
            MutableTree rightTree = treeDifference.getRightTree();
            if (filterApplies(path, rightTree)) {
                // can't optimize
                RevTree newTree = applyChanges(null, ref);
                Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
                MutableTree leftTree = treeDifference.getLeftTree();
                leftTree.forceChild(ref.getParentPath(), newNode);
            }
        } else {
            LOGGER.trace("Creating new tree {}", path);
            deepMove(ref.getNode());
            MutableTree leftTree = treeDifference.getLeftTree();
            String parentPath = ref.getParentPath();
            Node node = ref.getNode();
            leftTree.setChild(parentPath, node);
        }
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 52 with RevTree

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

the class FindOrCreateSubtree method _call.

/**
     * Executes the command.
     * 
     * @return the subtree if it was found, or a new one if it wasn't
     */
@Override
protected RevTree _call() {
    checkNotNull(parentSupplier, "parent");
    checkNotNull(childPath, "childPath");
    ObjectId subtreeId;
    if (parentSupplier.get().isPresent()) {
        RevTree parent = parentSupplier.get().get();
        Optional<NodeRef> treeChildRef = command(FindTreeChild.class).setIndex(indexDb).setParentPath(parentPath).setChildPath(childPath).setParent(Suppliers.ofInstance(parent)).call();
        if (treeChildRef.isPresent()) {
            NodeRef treeRef = treeChildRef.get();
            if (!TYPE.TREE.equals(treeRef.getType())) {
                throw new IllegalArgumentException("Object exists as child of tree " + parent.getId() + " but is not a tree: " + treeChildRef);
            }
            subtreeId = treeRef.objectId();
        } else {
            subtreeId = RevTree.EMPTY_TREE_ID;
        }
    } else {
        subtreeId = RevTree.EMPTY_TREE_ID;
    }
    if (RevTree.EMPTY_TREE_ID.equals(subtreeId)) {
        return RevTree.EMPTY;
    }
    ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
    RevTree tree = target.getTree(subtreeId);
    return tree;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTree(org.locationtech.geogig.api.RevTree)

Example 53 with RevTree

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

the class CheckoutOpTest method testCheckoutPathFilter.

@Test
public void testCheckoutPathFilter() throws Exception {
    ObjectId points1Id = insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insert(points1_modified);
    CheckoutResult result = geogig.command(CheckoutOp.class).addPath("Points/Points.1").call();
    Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
    Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
    assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 54 with RevTree

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

the class RevTreeTextSerialiationTest method testMalformedSerializedObject.

@Test
public void testMalformedSerializedObject() throws Exception {
    // TODO: add more cases here
    // a wrong type
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
    writer.write(TYPE.FEATURE.name() + "\n");
    writer.flush();
    ObjectReader<RevTree> reader = factory.createRevTreeReader();
    try {
        reader.read(ObjectId.forString("ID_STRING"), new ByteArrayInputStream(out.toByteArray()));
        fail();
    } catch (Exception e) {
        assertTrue(e.getMessage().equals("Wrong type: FEATURE"));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevTree(org.locationtech.geogig.api.RevTree) RevTreeSerializationTest(org.locationtech.geogig.storage.RevTreeSerializationTest) Test(org.junit.Test)

Example 55 with RevTree

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

the class ApplyPatchOpTest method testModifiedFeatureType.

@Test
public void testModifiedFeatureType() throws Exception {
    insert(points2, points3, points1B);
    Patch patch = new Patch();
    RevFeatureType oldFeatureType = RevFeatureTypeImpl.build(pointsType);
    RevFeatureType featureType = RevFeatureTypeImpl.build(modifiedPointsType);
    patch.addFeatureType(featureType);
    patch.addAlteredTree(new FeatureTypeDiff(pointsName, oldFeatureType.getId(), featureType.getId()));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> typeTree = findTreeChild(root, pointsName);
    assertTrue(typeTree.isPresent());
    assertEquals(featureType.getId(), typeTree.get().getMetadataId().get());
    Optional<Node> featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP2));
    assertTrue(featureNode.isPresent());
    assertEquals(oldFeatureType.getId(), featureNode.get().getMetadataId().get());
    featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP1));
    assertTrue(featureNode.isPresent());
    assertFalse(featureNode.get().getMetadataId().isPresent());
}
Also used : FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) Node(org.locationtech.geogig.api.Node) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

RevTree (org.locationtech.geogig.api.RevTree)214 Test (org.junit.Test)120 ObjectId (org.locationtech.geogig.api.ObjectId)91 NodeRef (org.locationtech.geogig.api.NodeRef)73 Node (org.locationtech.geogig.api.Node)56 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)47 RevCommit (org.locationtech.geogig.api.RevCommit)36 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)29 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)27 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)24 RevObject (org.locationtech.geogig.api.RevObject)21 RevFeature (org.locationtech.geogig.api.RevFeature)18 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)18 Bucket (org.locationtech.geogig.api.Bucket)17 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)17 File (java.io.File)16 Ref (org.locationtech.geogig.api.Ref)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)15 GeoGIG (org.locationtech.geogig.api.GeoGIG)14 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)14