use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class GetCommitGraph 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) {
if (commitId.equals(ObjectId.NULL.toString())) {
throw new CommandSpecException("No commitId was given.");
}
final GeoGIG geogig = context.getGeoGIG();
RevCommit commit = geogig.getRepository().getCommit(ObjectId.valueOf(commitId));
final List<RevCommit> history = Lists.newLinkedList();
List<CommitNode> nodes = Lists.newLinkedList();
CommitNode node = new CommitNode(commit, 1);
nodes.add(node);
while (!nodes.isEmpty()) {
node = nodes.remove(0);
if (!history.contains(node.commit)) {
history.add(node.commit);
}
if (this.depth == 0 || node.depth < this.depth) {
for (ObjectId id : node.commit.getParentIds()) {
nodes.add(new CommitNode(geogig.getRepository().getCommit(id), node.depth + 1));
}
}
}
final Iterator<RevCommit> historyIterator = history.iterator();
Iterators.advance(historyIterator, page * elementsPerPage);
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommits(history.iterator(), elementsPerPage, false);
out.finish();
}
});
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class ResolveConflict 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) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, add requires a transaction to preserve the stability of the repository.");
}
final Context geogig = this.getCommandLocator(context);
RevTree revTree = geogig.workingTree().getTree();
Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(revTree).setChildPath(NodeRef.parentPath(path)).setIndex(true).call();
Preconditions.checkArgument(nodeRef.isPresent(), "Invalid reference: %s", NodeRef.parentPath(path));
RevFeatureType revFeatureType = geogig.command(RevObjectParse.class).setObjectId(nodeRef.get().getMetadataId()).call(RevFeatureType.class).get();
RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(objectId).call(RevFeature.class).get();
CoordinateReferenceSystem crs = revFeatureType.type().getCoordinateReferenceSystem();
Envelope bounds = ReferencedEnvelope.create(crs);
Optional<Object> o;
for (int i = 0; i < revFeature.getValues().size(); i++) {
o = revFeature.getValues().get(i);
if (o.isPresent() && o.get() instanceof Geometry) {
Geometry g = (Geometry) o.get();
if (bounds.isNull()) {
bounds.init(JTS.bounds(g, crs));
} else {
bounds.expandToInclude(JTS.bounds(g, crs));
}
}
}
NodeRef node = new NodeRef(Node.create(NodeRef.nodeFromPath(path), objectId, ObjectId.NULL, TYPE.FEATURE, bounds), NodeRef.parentPath(path), ObjectId.NULL);
Optional<NodeRef> parentNode = geogig.command(FindTreeChild.class).setParent(geogig.workingTree().getTree()).setChildPath(node.getParentPath()).setIndex(true).call();
RevTreeBuilder treeBuilder = null;
ObjectId metadataId = ObjectId.NULL;
if (parentNode.isPresent()) {
metadataId = parentNode.get().getMetadataId();
Optional<RevTree> parsed = geogig.command(RevObjectParse.class).setObjectId(parentNode.get().getNode().getObjectId()).call(RevTree.class);
checkState(parsed.isPresent(), "Parent tree couldn't be found in the repository.");
treeBuilder = new RevTreeBuilder(geogig.objectDatabase(), parsed.get());
treeBuilder.remove(node.getNode().getName());
} else {
treeBuilder = new RevTreeBuilder(geogig.stagingDatabase());
}
treeBuilder.put(node.getNode());
ObjectId newTreeId = geogig.command(WriteBack.class).setAncestor(geogig.workingTree().getTree().builder(geogig.stagingDatabase())).setChildPath(node.getParentPath()).setToIndex(true).setTree(treeBuilder.build()).setMetadataId(metadataId).call();
geogig.workingTree().updateWorkHead(newTreeId);
AddOp command = geogig.command(AddOp.class);
command.addPattern(path);
command.call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("Add", "Success");
out.finish();
}
});
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class TagWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
if (list) {
final Context geogig = this.getCommandLocator(context);
final List<RevTag> tags = geogig.command(TagListOp.class).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTagListResponse(tags);
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class UpdateRefWeb 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) {
if (name == null) {
throw new CommandSpecException("No name was given.");
} else if (!(delete) && newValue == null) {
throw new CommandSpecException("Nothing specified to update with, must specify either deletion or new value to update to.");
}
final Context geogig = this.getCommandLocator(context);
Optional<Ref> ref;
try {
ref = geogig.command(RefParse.class).setName(name).call();
if (!ref.isPresent()) {
throw new CommandSpecException("Invalid name: " + name);
}
if (ref.get() instanceof SymRef) {
Optional<Ref> target = geogig.command(RefParse.class).setName(newValue).call();
if (target.isPresent() && !(target.get() instanceof SymRef)) {
ref = geogig.command(UpdateSymRef.class).setDelete(delete).setName(name).setNewValue(target.get().getName()).call();
} else {
throw new CommandSpecException("Invalid new target: " + newValue);
}
} else {
Optional<ObjectId> target = geogig.command(RevParse.class).setRefSpec(newValue).call();
if (target.isPresent()) {
ref = geogig.command(UpdateRef.class).setDelete(delete).setName(ref.get().getName()).setNewValue(target.get()).call();
} else {
throw new CommandSpecException("Invalid new value: " + newValue);
}
}
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting UpdateRef: " + e.getMessage()));
return;
}
if (ref.isPresent()) {
final Ref newRef = ref.get();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeUpdateRefResponse(newRef);
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class BeginTransaction 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) {
if (this.getTransactionId() != null) {
throw new CommandSpecException("Tried to start a transaction within a transaction.");
}
final GeoGIG geogig = context.getGeoGIG();
final GeogigTransaction transaction = geogig.command(TransactionBegin.class).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTransactionId(transaction.getTransactionId());
out.finish();
}
});
}
Aggregations