/**
  * Gets all the class variables to properly generate the variables and their getter functions.
  * This consists of all constructor arguments and optional arguments being converted into
  * variables.
  */
 @Override
 public ImmutableList<Variable> toClassVariableArguments(final Ds3Request ds3Request) {
   final ImmutableList.Builder<Variable> builder = ImmutableList.builder();
   for (final Arguments arg : toConstructorArgumentsList(ds3Request)) {
     builder.add(new Variable(arg.getName(), arg.getType(), true));
   }
   for (final Arguments arg : toOptionalArgumentsList(ds3Request.getOptionalQueryParams())) {
     builder.add(new Variable(arg.getName(), arg.getType(), false));
   }
   return builder.build();
 }
 /**
  * Updates the Ds3Request's parameter: BucketId is changed from type UUID to String if said
  * parameter exists within the request
  */
 protected static Ds3Request updateDs3RequestParamTypes(final Ds3Request ds3Request) {
   return new Ds3Request(
       ds3Request.getName(),
       ds3Request.getHttpVerb(),
       ds3Request.getClassification(),
       ds3Request.getBucketRequirement(),
       ds3Request.getObjectRequirement(),
       ds3Request.getAction(),
       ds3Request.getResource(),
       ds3Request.getResourceType(),
       ds3Request.getOperation(),
       ds3Request.getIncludeInPath(),
       ds3Request.getDs3ResponseCodes(),
       updateDs3ParamListTypes(ds3Request.getOptionalQueryParams()),
       updateDs3ParamListTypes(ds3Request.getRequiredQueryParams()));
 }
  /**
   * Gets all the required imports that the Request will need in order to properly generate the Java
   * request code
   *
   * @param ds3Request A Ds3Request
   * @return The list of all imports that the Request requires for generating the Java request code
   */
  @Override
  public ImmutableList<String> getAllImports(
      final Ds3Request ds3Request, final String packageName) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    builder.add(getParentImport(ds3Request));
    builder.addAll(getImportsFromParamList(ds3Request.getRequiredQueryParams()));
    builder.addAll(getImportsFromParamList(ds3Request.getOptionalQueryParams()));

    if (isResourceAnArg(ds3Request.getResource(), ds3Request.getIncludeInPath())) {
      if (RequestConverterUtil.isResourceId(ds3Request.getResource())) {
        builder.add("java.util.UUID");
      }
      builder.add("com.google.common.net.UrlEscapers");
    }

    return builder.build().asList();
  }
  @Test
  public void SingleRequestHandler() throws IOException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec =
        parser.getSpec(
            Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/singleRequestHandler.xml"));
    assertThat(spec, is(notNullValue()));
    assertThat(spec.getRequests().size(), is(1));

    final Ds3Request ds3Request = spec.getRequests().get(0);
    assertThat(
        ds3Request.getName(),
        is("com.spectralogic.s3.server.handler.reqhandler.amazons3.GetObjectRequest"));
    assertThat(ds3Request.getHttpVerb(), is(HttpVerb.GET));
    assertThat(ds3Request.getClassification(), is(Classification.amazons3));
    assertThat(ds3Request.getBucketRequirement(), is(Requirement.REQUIRED));
    assertThat(ds3Request.getObjectRequirement(), is(Requirement.REQUIRED));
    assertThat(ds3Request.getAction(), is(nullValue()));
    assertThat(ds3Request.getResource(), is(nullValue()));
    assertThat(ds3Request.getResourceType(), is(nullValue()));
    assertThat(ds3Request.getOperation(), is(nullValue()));

    assertThat(ds3Request.getDs3ResponseCodes().size(), is(1));
    assertThat(ds3Request.getDs3ResponseCodes().get(0).getCode(), is(200));
    assertThat(ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().size(), is(1));
    assertThat(
        ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().get(0).getType(),
        is("java.lang.String"));
    assertThat(
        ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().get(0).getComponentType(),
        is(nullValue()));

    assertThat(ds3Request.getOptionalQueryParams().size(), is(0));
    assertThat(ds3Request.getRequiredQueryParams().size(), is(1));
    assertThat(ds3Request.getRequiredQueryParams().get(0).getName(), is("Id"));
    assertThat(ds3Request.getRequiredQueryParams().get(0).getType(), is("java.util.UUID"));
  }
  @Override
  public Request generate(
      final Ds3Request ds3Request, final String packageName, final Ds3DocSpec docSpec) {
    final Ds3Request updatedRequest = updateDs3RequestParamTypes(ds3Request);
    final String requestName = removePath(updatedRequest.getName());
    final String requestPath = getRequestPath(updatedRequest);
    final String parentClass = getParentClass(ds3Request);

    final ImmutableList<Arguments> optionalArguments =
        splitAllUuidOptionalArguments(
            toOptionalArgumentsList(updatedRequest.getOptionalQueryParams()));

    final ImmutableList<RequestConstructor> constructors =
        splitAllUuidConstructors(toConstructorList(updatedRequest, requestName, docSpec));

    final ImmutableList<Variable> classVariableArguments =
        convertAllUuidClassVariables(toClassVariableArguments(updatedRequest));

    final ImmutableList<String> imports = getAllImports(updatedRequest, packageName);

    final ImmutableList<String> withConstructors =
        toWithConstructorList(optionalArguments, requestName, docSpec);

    return new Request(
        packageName,
        requestName,
        parentClass,
        updatedRequest.getHttpVerb(),
        requestPath,
        updatedRequest.getOperation(),
        updatedRequest.getAction(),
        optionalArguments,
        constructors,
        classVariableArguments,
        imports,
        withConstructors);
  }