Example #1
0
  /**
   * Runs the command and builds the appropriate response
   *
   * @param context - the context to use for this command
   * @throws CommandSpecException
   */
  @Override
  protected void runInternal(CommandContext context) {
    final Context geogig = this.getCommandLocator(context);

    ConfigOp command = geogig.command(ConfigOp.class).setScope(ConfigScope.LOCAL);

    final ConfigAction action;
    if (context.getMethod() == Method.POST) {
      checkArgument(name != null, "You must specify the key when setting a config key.");
      checkArgument(value != null, "You must specify the value when setting a config key.");
      action = ConfigAction.CONFIG_SET;
      command.setName(name);
      command.setValue(value);
    } else {
      if (name == null) {
        action = ConfigAction.CONFIG_LIST;
      } else {
        action = ConfigAction.CONFIG_GET;
        command.setName(name);
      }
    }

    command.setAction(action);

    final Optional<Map<String, String>> results = command.call();
    context.setResponseContent(
        new CommandResponse() {
          @Override
          public void write(ResponseWriter out) throws Exception {
            out.start();
            if (results.isPresent()) {
              if (action == ConfigAction.CONFIG_LIST) {
                Iterator<Map.Entry<String, String>> it = results.get().entrySet().iterator();
                while (it.hasNext()) {
                  Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
                  out.getWriter().writeStartElement("config");
                  out.writeElement("name", pairs.getKey());
                  out.writeElement("value", pairs.getValue());
                  out.getWriter().writeEndElement();
                }
              } else if (action == ConfigAction.CONFIG_GET) {
                out.writeElement("value", results.get().get(name));
              }
            }
            out.finish();
          }
        });
  }
Example #2
0
  /**
   * 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();
          }
        });
  }
Example #3
0
  @Override
  protected void runInternal(CommandContext context) {
    final OutputFormat outputFormat = resolveOutputFormat();

    @Nullable final String rootTreeIsh = this.root;

    @Nullable final ReferencedEnvelope bboxFilter = parseBBOX(this.bbox);

    @Nullable final List<String> sourceTreeNames = parseTreePahts(this.path);

    // setup the Export command
    Supplier<DataStore> targetStore = outputFormat.getDataStore();
    DataStoreExportOp<?> command = outputFormat.createCommand(context);
    command.setTarget(targetStore);
    command.setSourceTreePaths(sourceTreeNames);
    command.setSourceCommitish(rootTreeIsh);
    command.setBBoxFilter(bboxFilter);

    final String commandDescription = outputFormat.getCommandDescription();

    AsyncContext asyncContext = this.asyncContext;
    if (asyncContext == null) {
      asyncContext = AsyncContext.get();
    }
    final AsyncCommand<?> asyncCommand = asyncContext.run(command, commandDescription);

    Function<MediaType, Representation> rep =
        new Function<MediaType, Representation>() {

          private final String baseUrl = context.getBaseURL();

          @Override
          public Representation apply(MediaType mediaType) {
            AsyncCommandRepresentation<?> repr;
            repr = Representations.newRepresentation(asyncCommand, mediaType, baseUrl);
            return repr;
          }
        };

    context.setResponse(rep);
  }