use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class RebuildGraphWebOp 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) {
final Context geogig = this.getCommandLocator(context);
final ImmutableList<ObjectId> updatedObjects = geogig.command(RebuildGraphOp.class).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeRebuildGraphResponse(updatedObjects, quiet);
out.finish();
}
});
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class RemoteWebOp method remoteRemove.
private void remoteRemove(CommandContext context, final Context geogig) {
if (remoteName == null || remoteName.trim().isEmpty()) {
throw new CommandSpecException("No remote was specified.");
}
final Remote remote;
try {
remote = geogig.command(RemoteRemoveOp.class).setName(remoteName).call();
} catch (RemoteException e) {
context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
return;
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting Remote Remove"));
return;
}
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("name", remote.getName());
out.finish();
}
});
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class RemoteWebOp method remoteUpdate.
private void remoteUpdate(CommandContext context, final Context geogig) {
if (remoteName == null || remoteName.trim().isEmpty()) {
throw new CommandSpecException("No remote was specified.");
} else if (remoteURL == null || remoteURL.trim().isEmpty()) {
throw new CommandSpecException("No URL was specified.");
}
final Remote newRemote;
try {
if (newName != null && !newName.trim().isEmpty() && !newName.equals(remoteName)) {
newRemote = geogig.command(RemoteAddOp.class).setName(newName).setURL(remoteURL).setUserName(username).setPassword(password).call();
geogig.command(RemoteRemoveOp.class).setName(remoteName).call();
} else {
geogig.command(RemoteRemoveOp.class).setName(remoteName).call();
newRemote = geogig.command(RemoteAddOp.class).setName(remoteName).setURL(remoteURL).setUserName(username).setPassword(password).call();
}
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("name", newRemote.getName());
out.finish();
}
});
} catch (RemoteException e) {
context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting Remote Update"));
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class Log method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*
* @throws IllegalArgumentException
*/
@Override
public void run(final CommandContext context) {
final Context geogig = this.getCommandLocator(context);
LogOp op = geogig.command(LogOp.class).setFirstParentOnly(firstParentOnly);
if (skip != null) {
op.setSkip(skip.intValue());
}
if (limit != null) {
op.setLimit(limit.intValue());
}
if (this.sinceTime != null || this.untilTime != null) {
Date since = new Date(0);
Date until = new Date();
if (this.sinceTime != null) {
since = new Date(geogig.command(ParseTimestamp.class).setString(this.sinceTime).call());
}
if (this.untilTime != null) {
until = new Date(geogig.command(ParseTimestamp.class).setString(this.untilTime).call());
}
op.setTimeRange(new Range<Date>(Date.class, since, until));
}
if (this.since != null) {
Optional<ObjectId> since;
since = geogig.command(RevParse.class).setRefSpec(this.since).call();
Preconditions.checkArgument(since.isPresent(), "Object not found '%s'", this.since);
op.setSince(since.get());
}
if (this.until != null) {
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(this.until).call();
Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
op.setUntil(until.get());
}
if (paths != null && !paths.isEmpty()) {
for (String path : paths) {
op.addPath(path);
}
}
final Iterator<RevCommit> log = op.call();
Iterators.advance(log, page * elementsPerPage);
if (countChanges) {
final String pathFilter;
if (paths != null && !paths.isEmpty()) {
pathFilter = paths.get(0);
} else {
pathFilter = null;
}
Function<RevCommit, CommitWithChangeCounts> changeCountFunctor = new Function<RevCommit, CommitWithChangeCounts>() {
@Override
public CommitWithChangeCounts apply(RevCommit input) {
ObjectId parent = ObjectId.NULL;
if (input.getParentIds().size() > 0) {
parent = input.getParentIds().get(0);
}
int added = 0;
int modified = 0;
int removed = 0;
// If it's a shallow clone, the commit may not exist
if (parent.equals(ObjectId.NULL) || geogig.stagingDatabase().exists(parent)) {
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parent).setNewVersion(input.getId()).setFilter(pathFilter).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
added++;
} else if (entry.changeType() == DiffEntry.ChangeType.MODIFIED) {
modified++;
} else {
removed++;
}
}
}
return new CommitWithChangeCounts(input, added, modified, removed);
}
};
final Iterator<CommitWithChangeCounts> summarizedLog = Iterators.transform(log, changeCountFunctor);
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommitsWithChangeCounts(summarizedLog, elementsPerPage);
out.finish();
}
});
} else if (summary) {
if (paths != null && paths.size() > 0) {
context.setResponseContent(new StreamResponse() {
@Override
public void write(Writer out) throws Exception {
writeCSV(context.getGeoGIG(), out, log);
}
});
} else {
throw new CommandSpecException("You must specify a feature type path when getting a summary.");
}
} else {
final boolean rangeLog = returnRange;
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommits(log, elementsPerPage, rangeLog);
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class Diff 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 (oldRefSpec == null || oldRefSpec.trim().isEmpty()) {
throw new CommandSpecException("No old ref spec");
}
final Context geogig = this.getCommandLocator(context);
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(oldRefSpec).setNewVersion(newRefSpec).setFilter(pathFilter).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
if (showGeometryChanges) {
out.writeGeometryChanges(geogig, diff, page, elementsPerPage);
} else {
out.writeDiffEntries("diff", page * elementsPerPage, elementsPerPage, diff);
}
out.finish();
}
});
}
Aggregations