Search in sources :

Example 81 with Node

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

the class DepthSearch method getDirectChild.

/**
     * @param parent
     * @param directChildName
     * @return
     */
public Optional<Node> getDirectChild(RevTree parent, String directChildName, final int subtreesDepth) {
    if (parent.isEmpty()) {
        return Optional.absent();
    }
    if (parent.trees().isPresent() || parent.features().isPresent()) {
        if (parent.trees().isPresent()) {
            ImmutableList<Node> refs = parent.trees().get();
            for (int i = 0; i < refs.size(); i++) {
                if (directChildName.equals(refs.get(i).getName())) {
                    return Optional.of(refs.get(i));
                }
            }
        }
        if (parent.features().isPresent()) {
            ImmutableList<Node> refs = parent.features().get();
            for (int i = 0; i < refs.size(); i++) {
                if (directChildName.equals(refs.get(i).getName())) {
                    return Optional.of(refs.get(i));
                }
            }
        }
        return Optional.absent();
    }
    Integer bucket = refOrder.bucket(directChildName, subtreesDepth);
    ImmutableSortedMap<Integer, Bucket> buckets = parent.buckets().get();
    Bucket subtreeBucket = buckets.get(bucket);
    if (subtreeBucket == null) {
        return Optional.absent();
    }
    RevTree subtree = objectDb.get(subtreeBucket.id(), RevTree.class);
    return getDirectChild(subtree, directChildName, subtreesDepth + 1);
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 82 with Node

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

the class Index method stage.

/**
     * Stages the changes indicated by the {@link DiffEntry} iterator.
     * 
     * @param progress the progress listener for the process
     * @param unstaged an iterator for the unstaged changes
     * @param numChanges number of unstaged changes
     */
@Override
public void stage(final ProgressListener progress, final Iterator<DiffEntry> unstaged, final long numChanges) {
    int i = 0;
    progress.started();
    final RevTree currentIndexHead = getTree();
    Map<String, RevTreeBuilder> parentTress = Maps.newHashMap();
    Map<String, ObjectId> parentMetadataIds = Maps.newHashMap();
    Set<String> removedTrees = Sets.newHashSet();
    StagingDatabase database = getDatabase();
    while (unstaged.hasNext()) {
        final DiffEntry diff = unstaged.next();
        final String fullPath = diff.oldPath() == null ? diff.newPath() : diff.oldPath();
        final String parentPath = NodeRef.parentPath(fullPath);
        /*
             * TODO: revisit, ideally the list of diff entries would come with one single entry for
             * the whole removed tree instead of that one and every single children of it.
             */
        if (removedTrees.contains(parentPath)) {
            continue;
        }
        if (null == parentPath) {
            // it is the root tree that's been changed, update head and ignore anything else
            ObjectId newRoot = diff.newObjectId();
            updateStageHead(newRoot);
            progress.setProgress(100f);
            progress.complete();
            return;
        }
        RevTreeBuilder parentTree = getParentTree(currentIndexHead, parentPath, parentTress, parentMetadataIds);
        i++;
        progress.setProgress((float) (i * 100) / numChanges);
        NodeRef oldObject = diff.getOldObject();
        NodeRef newObject = diff.getNewObject();
        if (newObject == null) {
            // Delete
            parentTree.remove(oldObject.name());
            if (TYPE.TREE.equals(oldObject.getType())) {
                removedTrees.add(oldObject.path());
            }
        } else if (oldObject == null) {
            // Add
            Node node = newObject.getNode();
            parentTree.put(node);
            parentMetadataIds.put(newObject.path(), newObject.getMetadataId());
        } else {
            // Modify
            Node node = newObject.getNode();
            parentTree.put(node);
        }
        database.removeConflict(null, fullPath);
    }
    ObjectId newRootTree = currentIndexHead.getId();
    for (Map.Entry<String, RevTreeBuilder> entry : parentTress.entrySet()) {
        String changedTreePath = entry.getKey();
        RevTreeBuilder changedTreeBuilder = entry.getValue();
        RevTree changedTree = changedTreeBuilder.build();
        ObjectId parentMetadataId = parentMetadataIds.get(changedTreePath);
        if (NodeRef.ROOT.equals(changedTreePath)) {
            // root
            database.put(changedTree);
            newRootTree = changedTree.getId();
        } else {
            // parentMetadataId = parentMetadataId == null ?
            Supplier<RevTreeBuilder> rootTreeSupplier = getTreeSupplier();
            newRootTree = context.command(WriteBack.class).setAncestor(rootTreeSupplier).setChildPath(changedTreePath).setMetadataId(parentMetadataId).setToIndex(true).setTree(changedTree).call();
        }
        updateStageHead(newRootTree);
    }
    progress.complete();
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) WriteBack(org.locationtech.geogig.api.plumbing.WriteBack) NodeRef(org.locationtech.geogig.api.NodeRef) Map(java.util.Map) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 83 with Node

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

the class OSMDownloadOpTest method testUpdate.

@Ignore
@Test
public void testUpdate() throws Exception {
    String filename = OSMImportOp.class.getResource("fire_station_filter.txt").getFile();
    File filterFile = new File(filename);
    OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
    download.setFilterFile(filterFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
    Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
    assertTrue(tree.isPresent());
    tree = geogig.getRepository().getRootTreeChild("way");
    assertTrue(tree.isPresent());
    List<OSMLogEntry> entries = geogig.command(ReadOSMLogEntries.class).call();
    assertFalse(entries.isEmpty());
    OSMUpdateOp update = geogig.command(OSMUpdateOp.class);
    try {
        update.setAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
    } catch (NothingToCommitException e) {
    // No new data
    }
}
Also used : ReadOSMLogEntries(org.locationtech.geogig.osm.internal.log.ReadOSMLogEntries) Node(org.locationtech.geogig.api.Node) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) File(java.io.File) OSMLogEntry(org.locationtech.geogig.osm.internal.log.OSMLogEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 84 with Node

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

the class OSMDownloadOpTest method testDownloadWithBBoxAndMapping.

// @Ignore
@Test
public void testDownloadWithBBoxAndMapping() throws Exception {
    String mappingFilename = OSMMapOp.class.getResource("mapping.json").getFile();
    File mappingFile = new File(mappingFilename);
    OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
    download.setMappingFile(mappingFile).setBbox(Arrays.asList("50.79", "7.19", "50.8", "7.20")).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
    Optional<Node> tree = geogig.getRepository().getRootTreeChild("way");
    assertTrue(tree.isPresent());
    tree = geogig.getRepository().getRootTreeChild("onewaystreets");
    assertTrue(tree.isPresent());
    // check it has created mapping log files
    File osmMapFolder = geogig.command(ResolveOSMMappingLogFolder.class).call();
    File file = new File(osmMapFolder, "onewaystreets");
    assertTrue(file.exists());
    file = new File(osmMapFolder, geogig.getRepository().workingTree().getTree().getId().toString());
    assertTrue(file.exists());
}
Also used : ResolveOSMMappingLogFolder(org.locationtech.geogig.osm.internal.log.ResolveOSMMappingLogFolder) Node(org.locationtech.geogig.api.Node) File(java.io.File) Test(org.junit.Test)

Example 85 with Node

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

the class OSMDownloadOpTest method testDownaloadWays.

@Ignore
@Test
public void testDownaloadWays() throws Exception {
    String filename = OSMImportOp.class.getResource("ways_overpass_filter.txt").getFile();
    File filterFile = new File(filename);
    OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
    download.setFilterFile(filterFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
    Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
    assertTrue(tree.isPresent());
    tree = geogig.getRepository().getRootTreeChild("way");
    assertTrue(tree.isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    assertTrue(log.hasNext());
}
Also used : Node(org.locationtech.geogig.api.Node) LogOp(org.locationtech.geogig.api.porcelain.LogOp) File(java.io.File) RevCommit(org.locationtech.geogig.api.RevCommit) Ignore(org.junit.Ignore) 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