use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class CatWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
final Context geogig = this.getCommandLocator(context);
Preconditions.checkState(geogig.stagingDatabase().exists(object));
final RevObject revObject = geogig.stagingDatabase().get(object);
switch(revObject.getType()) {
case COMMIT:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommit((RevCommit) revObject, "commit", null, null, null);
out.finish();
}
});
break;
case TREE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTree((RevTree) revObject, "tree");
out.finish();
}
});
break;
case FEATURE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeature((RevFeature) revObject, "feature");
out.finish();
}
});
break;
case FEATURETYPE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeatureType((RevFeatureType) revObject, "featuretype");
out.finish();
}
});
break;
case TAG:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTag((RevTag) revObject, "tag");
out.finish();
}
});
break;
}
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WorkingTreeInsertHelper method findOrCreateTree.
private NodeRef findOrCreateTree(final String treePath, final FeatureType type) {
RevTree tree = context.command(FindOrCreateSubtree.class).setChildPath(treePath).setIndex(true).setParent(workHead).setParentPath(NodeRef.ROOT).call();
ObjectId metadataId = ObjectId.NULL;
if (type != null) {
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(type);
if (tree.isEmpty()) {
indexDatabase.put(revFeatureType);
}
metadataId = revFeatureType.getId();
}
Envelope bounds = SpatialOps.boundsOf(tree);
Node node = Node.create(NodeRef.nodeFromPath(treePath), tree.getId(), metadataId, TYPE.TREE, bounds);
String parentPath = NodeRef.parentPath(treePath);
return new NodeRef(node, parentPath, ObjectId.NULL);
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WorkingTree method createTypeTree.
public synchronized NodeRef createTypeTree(final String treePath, final FeatureType featureType) {
final RevTree workHead = getTree();
Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(workHead).setChildPath(treePath).call();
final RevFeatureType revType = RevFeatureTypeImpl.build(featureType);
if (typeTreeRef.isPresent()) {
throw new IllegalArgumentException("Tree already exists at " + treePath);
}
indexDatabase.put(revType);
final ObjectId metadataId = revType.getId();
final RevTree newTree = new RevTreeBuilder(indexDatabase).build();
ObjectId newWorkHeadId = context.command(WriteBack.class).setToIndex(true).setAncestor(workHead.builder(indexDatabase)).setChildPath(treePath).setTree(newTree).setMetadataId(metadataId).call();
updateWorkHead(newWorkHeadId);
return context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(treePath).call().get();
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class RevTreeBuilder2 method build.
/**
* Traverses the nodes in the {@link NodeIndex}, deletes the ones with {@link ObjectId#NULL
* NULL} ObjectIds, and adds the ones with non "NULL" ids.
*
* @return the new tree, not saved to the object database. Any bucket tree though is saved when
* this method returns.
*/
public RevTree build() {
if (nodeIndex == null) {
return original.builder(db).build();
}
Stopwatch sw = Stopwatch.createStarted();
RevTreeBuilder builder;
try {
builder = new RevTreeBuilder(db, original);
Iterator<Node> nodes = nodeIndex.nodes();
while (nodes.hasNext()) {
Node node = nodes.next();
if (node.getObjectId().isNull()) {
builder.remove(node.getName());
} else {
builder.put(node);
}
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} finally {
nodeIndex.close();
}
LOGGER.debug("Index traversed in {}", sw.stop());
sw.reset().start();
RevTree namedTree = builder.build();
saveExtraFeatureTypes();
LOGGER.debug("RevTreeBuilder.build() in {}", sw.stop());
return namedTree;
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeMultiple.
@Test
public void testMergeMultiple() throws Exception {
// Create the following revision graph
// . o
// . |
// . o - Points 1 added
// . |\
// . | o - branch1 - Points 2 added
// . |
// . o - Points 3 added
// ./|
// o | - branch 2 - Lines 1 added
// . |
// . o - master - HEAD - Lines 2 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);
final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
// checkout master, then create branch2 and checkout
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(points3);
final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
insertAndAdd(lines1);
final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(lines2);
final RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
// Merge branch1 and branch2 into master to create the following revision graph
// . o
// . |
// . o - Points 1 added
// . |\
// . | o - branch1 - Points 2 added
// . | |
// . o | - Points 3 added
// ./| |
// o | | - branch 2 - Lines 1 added
// | | |
// | o | - Lines 2 added
// .\|/
// . o - master - HEAD - Merge commit
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).addCommit(Suppliers.ofInstance(branch2.getObjectId())).setMessage("My merge message.").call();
RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
String path = appendChild(pointsName, points1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(pointsName, points2.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(pointsName, points3.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(linesName, lines1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(linesName, lines2.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
// Commit 4
RevCommit logC4 = log.next();
assertEquals("My merge message.", logC4.getMessage());
assertEquals(3, logC4.getParentIds().size());
assertEquals(c5.getId(), logC4.getParentIds().get(0));
assertEquals(c2.getId(), logC4.getParentIds().get(1));
assertEquals(c4.getId(), logC4.getParentIds().get(2));
// Commit 3
RevCommit logC3 = log.next();
assertEquals(c5.getAuthor(), logC3.getAuthor());
assertEquals(c5.getCommitter(), logC3.getCommitter());
assertEquals(c5.getMessage(), logC3.getMessage());
assertEquals(c5.getTreeId(), logC3.getTreeId());
// Commit 2
RevCommit logC2 = log.next();
assertEquals(c3.getAuthor(), logC2.getAuthor());
assertEquals(c3.getCommitter(), logC2.getCommitter());
assertEquals(c3.getMessage(), logC2.getMessage());
assertEquals(c3.getTreeId(), logC2.getTreeId());
// Commit 1
RevCommit logC1 = log.next();
assertEquals(c1.getAuthor(), logC1.getAuthor());
assertEquals(c1.getCommitter(), logC1.getCommitter());
assertEquals(c1.getMessage(), logC1.getMessage());
assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Aggregations