use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class Config method runInternal.
/**
* Executes the config command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
GeoGIG geogig = cli.getGeogig();
boolean closeIt = geogig == null;
if (closeIt) {
// we're not in a repository, need a geogig anyways to run the global commands
geogig = cli.newGeoGIG(Hints.readOnly());
}
try {
String name = null;
String value = null;
if (nameValuePair != null && !nameValuePair.isEmpty()) {
name = nameValuePair.get(0);
value = buildValueString();
}
ConfigAction action = resolveConfigAction();
if (action == ConfigAction.CONFIG_NO_ACTION) {
printUsage(cli);
throw new CommandFailedException();
}
if (global && local) {
printUsage(cli);
throw new CommandFailedException();
}
ConfigScope scope = ConfigScope.DEFAULT;
if (global) {
scope = ConfigScope.GLOBAL;
} else if (local) {
scope = ConfigScope.LOCAL;
}
final Optional<Map<String, String>> commandResult = geogig.command(ConfigOp.class).setScope(scope).setAction(action).setName(name).setValue(value).call();
if (commandResult.isPresent()) {
switch(action) {
case CONFIG_GET:
{
cli.getConsole().println(commandResult.get().get(name));
break;
}
case CONFIG_LIST:
{
Iterator<Map.Entry<String, String>> it = commandResult.get().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
cli.getConsole().println(pairs.getKey() + "=" + pairs.getValue());
}
break;
}
default:
break;
}
}
} catch (ConfigException e) {
// since we don't have regex support yet.
switch(e.statusCode) {
case INVALID_LOCATION:
// TODO: This could probably be more descriptive.
throw new CommandFailedException("The config location is invalid", e);
case CANNOT_WRITE:
throw new CommandFailedException("Cannot write to the config", e);
case SECTION_OR_NAME_NOT_PROVIDED:
throw new InvalidParameterException("No section or name was provided", e);
case SECTION_OR_KEY_INVALID:
throw new InvalidParameterException("The section or key is invalid", e);
case OPTION_DOES_NOT_EXIST:
throw new InvalidParameterException("Tried to unset an option that does not exist", e);
case MULTIPLE_OPTIONS_MATCH:
throw new InvalidParameterException("Tried to unset/set an option for which multiple lines match", e);
case INVALID_REGEXP:
throw new InvalidParameterException("Tried to use an invalid regexp", e);
case USERHOME_NOT_SET:
throw new InvalidParameterException("Used --global option without $HOME being properly set", e);
case TOO_MANY_ACTIONS:
throw new InvalidParameterException("Tried to use more than one action at a time", e);
case MISSING_SECTION:
throw new InvalidParameterException("Could not find a section with the name provided", e);
case TOO_MANY_ARGS:
throw new InvalidParameterException("Too many arguments provided.", e);
}
} finally {
if (closeIt) {
geogig.close();
}
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class ShpExportTest method testExportWithFeatureNameInsteadOfType.
@Test
public void testExportWithFeatureNameInsteadOfType() throws Exception {
ShpExport exportCommand = new ShpExport();
String shapeFileName = new File(geogig.getPlatform().pwd(), "TestPoints.shp").getAbsolutePath();
exportCommand.args = Arrays.asList("Points/Points.1", shapeFileName);
exportCommand.dataStoreFactory = TestHelper.createTestFactory();
try {
exportCommand.run(cli);
fail();
} catch (InvalidParameterException e) {
} finally {
deleteShapeFile(shapeFileName);
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class Serve method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws InvalidParameterException, CommandFailedException, IOException {
String loc = repo != null && repo.size() > 0 ? repo.get(0) : ".";
GeoGIG geogig = loadGeoGIG(loc, cli);
Application application = new Main(geogig);
Component comp = new Component();
comp.getDefaultHost().attach(application);
comp.getServers().add(Protocol.HTTP, port);
cli.getConsole().println(String.format("Starting server on port %d, use CTRL+C to exit.", port));
try {
comp.start();
cli.setExitOnFinish(false);
} catch (BindException e) {
String msg = String.format("Port %d already in use, use the --port parameter to specify a different port", port);
throw new CommandFailedException(msg, e);
} catch (Exception e) {
throw new CommandFailedException("Unable to start server", e);
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class Log method runInternal.
/**
* Executes the log command using the provided options.
*
* @param cli
* @throws IOException
* @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(!(args.summary && args.oneline), "--summary and --oneline cannot be used together");
checkParameter(!(args.stats && args.oneline), "--stats and --oneline cannot be used together");
checkParameter(!(args.stats && args.oneline), "--name-only and --oneline cannot be used together");
geogig = cli.getGeogig();
LogOp op = geogig.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent);
refs = Maps.newHashMap();
if (args.decoration) {
Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
refs.put(head.get().getObjectId(), Ref.HEAD);
ImmutableSet<Ref> set = geogig.command(ForEachRef.class).setPrefixFilter(Ref.REFS_PREFIX).call();
for (Ref ref : set) {
ObjectId id = ref.getObjectId();
if (refs.containsKey(id)) {
refs.put(id, refs.get(id) + ", " + ref.getName());
} else {
refs.put(id, ref.getName());
}
}
}
if (args.all) {
ImmutableSet<Ref> refs = geogig.command(ForEachRef.class).setPrefixFilter(Ref.REFS_PREFIX).call();
List<ObjectId> list = Lists.newArrayList();
for (Ref ref : refs) {
list.add(ref.getObjectId());
}
Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
if (head.isPresent()) {
Ref ref = head.get();
if (ref instanceof SymRef) {
ObjectId id = ref.getObjectId();
list.remove(id);
// put the HEAD ref in the last position, to give it preference
list.add(id);
}
}
for (ObjectId id : list) {
op.addCommit(id);
}
} else if (args.branch != null) {
Optional<Ref> obj = geogig.command(RefParse.class).setName(args.branch).call();
checkParameter(obj.isPresent(), "Wrong branch name: " + args.branch);
op.addCommit(obj.get().getObjectId());
}
if (args.author != null && !args.author.isEmpty()) {
op.setAuthor(args.author);
}
if (args.committer != null && !args.committer.isEmpty()) {
op.setCommiter(args.committer);
}
if (args.skip != null) {
op.setSkip(args.skip.intValue());
}
if (args.limit != null) {
op.setLimit(args.limit.intValue());
}
if (args.since != null || args.until != null) {
Date since = new Date(0);
Date until = new Date();
if (args.since != null) {
since = new Date(geogig.command(ParseTimestamp.class).setString(args.since).call());
}
if (args.until != null) {
until = new Date(geogig.command(ParseTimestamp.class).setString(args.until).call());
if (args.all) {
throw new InvalidParameterException("Cannot specify 'until' commit when listing all branches");
}
}
op.setTimeRange(new Range<Date>(Date.class, since, until));
}
if (!args.sinceUntilPaths.isEmpty()) {
List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..").split(args.sinceUntilPaths.get(0))));
checkParameter(sinceUntil.size() == 1 || sinceUntil.size() == 2, "Invalid refSpec format, expected [<until>]|[<since>..<until>]: %s", args.sinceUntilPaths.get(0));
String sinceRefSpec;
String untilRefSpec;
if (sinceUntil.size() == 1) {
// just until was given
sinceRefSpec = null;
untilRefSpec = sinceUntil.get(0);
} else {
sinceRefSpec = sinceUntil.get(0);
untilRefSpec = sinceUntil.get(1);
}
if (sinceRefSpec != null) {
Optional<ObjectId> since;
since = geogig.command(RevParse.class).setRefSpec(sinceRefSpec).call();
checkParameter(since.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setSince(since.get());
}
if (untilRefSpec != null) {
if (args.all) {
throw new InvalidParameterException("Cannot specify 'until' commit when listing all branches");
}
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(untilRefSpec).call();
checkParameter(until.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setUntil(until.get());
}
}
if (!args.pathNames.isEmpty()) {
for (String s : args.pathNames) {
op.addPath(s);
}
}
Iterator<RevCommit> log = op.call();
this.console = cli.getConsole();
if (!log.hasNext()) {
console.println("No commits to show");
console.flush();
return;
}
LogEntryPrinter printer;
if (args.oneline) {
printer = new OneLineConverter();
} else {
LOG_DETAIL detail;
if (args.summary) {
detail = LOG_DETAIL.SUMMARY;
} else if (args.names) {
detail = LOG_DETAIL.NAMES_ONLY;
} else if (args.stats) {
detail = LOG_DETAIL.STATS;
} else {
detail = LOG_DETAIL.NOTHING;
}
printer = new StandardConverter(detail, geogig.getPlatform());
}
while (log.hasNext()) {
printer.print(log.next());
console.flush();
}
}
use of org.locationtech.geogig.cli.InvalidParameterException in project GeoGig by boundlessgeo.
the class SLExport method getFeatureType.
private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
checkParameter(path != null, "No path specified.");
String refspec;
if (path.contains(":")) {
refspec = path;
} else {
refspec = "WORK_HEAD:" + path;
}
checkParameter(!refspec.endsWith(":"), "No path specified.");
final GeoGIG geogig = cli.getGeogig();
Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
if (revFeatureType.type() instanceof SimpleFeatureType) {
return (SimpleFeatureType) revFeatureType.type();
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
}
Aggregations