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);
}
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();
}
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
}
}
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());
}
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());
}
Aggregations