use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class FindCommonAncestorTest method testFindCommonAncestorCase3.
@Test
public void testFindCommonAncestorCase3() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - Points 2 added
// | |
// | o - Points 3 added
// | |\
// | | o - Lines 1 added - branch2
// | |
// o | - Lines 2 added
// | |
// | o - Lines 3 added - branch1
// |/
// o - master - HEAD - Merge Commit
insertAndAdd(points1);
geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
insertAndAdd(points3);
final RevCommit ancestor = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
insertAndAdd(lines1);
final RevCommit branch2 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
geogig.command(CheckoutOp.class).setSource("branch1").call();
insertAndAdd(lines3);
final RevCommit left = geogig.command(CommitOp.class).setMessage("commit for " + idL3).call();
// checkout master
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(lines2);
geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(left.getId())).call();
Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class).setLeft(mergeReport.getMergeCommit()).setRight(branch2).call();
assertTrue(commonAncestor.isPresent());
assertEquals(commonAncestor.get(), ancestor.getId());
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class FindCommonAncestorTest method testFindCommonAncestorCase2.
@Test
public void testFindCommonAncestorCase2() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - Points 2 added
// | |
// | o - Points 3 added
// | |
// | o - Lines 2 added - branch1
// |
// o - master - HEAD - Lines 1 added
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
insertAndAdd(points3);
geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
insertAndAdd(lines2);
final RevCommit left = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
// checkout master
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(lines1);
final RevCommit right = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class).setLeft(left).setRight(right).call();
assertTrue(commonAncestor.isPresent());
assertEquals(commonAncestor.get(), c1.getId());
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class OSMMapOp method getFeatures.
private Iterator<Feature> getFeatures(String ref) {
Optional<ObjectId> id = command(RevParse.class).setRefSpec(ref).call();
if (!id.isPresent()) {
return Iterators.emptyIterator();
}
LsTreeOp op = command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
Iterator<NodeRef> iterator = op.call();
Function<NodeRef, Feature> nodeRefToFeature = new Function<NodeRef, Feature>() {
private final //
Map<String, FeatureBuilder> builders = //
ImmutableMap.<//
String, //
FeatureBuilder>of(//
OSMUtils.NODE_TYPE_NAME, //
new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.nodeType())), //
OSMUtils.WAY_TYPE_NAME, new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.wayType())));
private final RevObjectParse parseCommand = command(RevObjectParse.class);
@Override
@Nullable
public Feature apply(@Nullable NodeRef ref) {
RevFeature revFeature = parseCommand.setObjectId(ref.objectId()).call(RevFeature.class).get();
final String parentPath = ref.getParentPath();
FeatureBuilder featureBuilder = builders.get(parentPath);
String fid = ref.name();
Feature feature = featureBuilder.build(fid, revFeature);
return feature;
}
};
return Iterators.transform(iterator, nodeRefToFeature);
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class OSMUnmapOp method _call.
@Override
protected RevTree _call() {
Optional<OSMMappingLogEntry> entry = command(ReadOSMMappingLogEntry.class).setPath(path).call();
if (entry.isPresent()) {
Optional<Mapping> opt = command(ReadOSMMapping.class).setEntry(entry.get()).call();
if (opt.isPresent()) {
mapping = opt.get();
}
}
Iterator<NodeRef> iter = command(LsTreeOp.class).setReference(path).setStrategy(Strategy.FEATURES_ONLY).call();
FeatureMapFlusher flusher = new FeatureMapFlusher(workingTree());
while (iter.hasNext()) {
NodeRef node = iter.next();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class).get();
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
String id = null;
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
if (descriptor.getName().getLocalPart().equals("id")) {
id = values.get(i).get().toString();
}
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
Preconditions.checkNotNull(id, "No 'id' attribute found");
SimpleFeature feature = featureBuilder.buildFeature(id);
unmapFeature(feature, flusher);
}
flusher.flushAll();
if (entry.isPresent()) {
Iterator<DiffEntry> diffs = command(DiffTree.class).setPathFilter(path).setNewTree(workingTree().getTree().getId()).setOldTree(entry.get().getPostMappingId()).call();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (diff.changeType().equals(DiffEntry.ChangeType.REMOVED)) {
ObjectId featureId = diff.getOldObject().getNode().getObjectId();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(featureId).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(diff.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
String id = null;
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
if (descriptor.getName().getLocalPart().equals("id")) {
id = values.get(i).get().toString();
}
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
Preconditions.checkNotNull(id, "No 'id' attribute found");
SimpleFeature feature = featureBuilder.buildFeature(id);
Class<?> clazz = feature.getDefaultGeometryProperty().getType().getBinding();
String deletePath = clazz.equals(Point.class) ? OSMUtils.NODE_TYPE_NAME : OSMUtils.WAY_TYPE_NAME;
workingTree().delete(deletePath, id);
}
}
}
return workingTree().getTree();
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class OSMImportOp method _call.
@Override
protected Optional<OSMReport> _call() {
checkNotNull(urlOrFilepath);
ObjectId oldTreeId = workingTree().getTree().getId();
File osmDataFile = null;
final InputStream osmDataStream;
if (urlOrFilepath.startsWith("http")) {
osmDataStream = downloadFile();
} else {
osmDataFile = new File(urlOrFilepath);
Preconditions.checkArgument(osmDataFile.exists(), "File does not exist: " + urlOrFilepath);
try {
osmDataStream = new BufferedInputStream(new FileInputStream(osmDataFile), 1024 * 1024);
} catch (FileNotFoundException e) {
throw Throwables.propagate(e);
}
}
ProgressListener progressListener = getProgressListener();
progressListener.setDescription("Importing into GeoGig repo...");
EntityConverter converter = new EntityConverter();
OSMReport report;
try {
report = parseDataFileAndInsert(osmDataFile, osmDataStream, converter);
} finally {
Closeables.closeQuietly(osmDataStream);
}
if (!progressListener.isCanceled() && report != null) {
ObjectId newTreeId = workingTree().getTree().getId();
if (!noRaw) {
if (mapping != null || filter != null) {
progressListener.setDescription("Staging features...");
command(AddOp.class).setProgressListener(progressListener).call();
progressListener.setDescription("Committing features...");
command(CommitOp.class).setMessage(message).setProgressListener(progressListener).call();
OSMLogEntry entry = new OSMLogEntry(newTreeId, report.getLatestChangeset(), report.getLatestTimestamp());
command(AddOSMLogEntry.class).setEntry(entry).call();
if (filter != null) {
command(WriteOSMFilterFile.class).setEntry(entry).setFilterCode(filter).call();
}
if (mapping != null) {
command(WriteOSMMappingEntries.class).setMapping(mapping).setMappingLogEntry(new OSMMappingLogEntry(oldTreeId, newTreeId)).call();
}
}
}
}
return Optional.fromNullable(report);
}
Aggregations