/**
   * Creates the Java request path code for a SpectraS3 request
   *
   * @param ds3Request A request
   * @return The Java request path code for an SpectraS3 request
   */
  protected static String getSpectraDs3RequestPath(final Ds3Request ds3Request) {
    final StringBuilder builder = new StringBuilder();
    if (ds3Request.getClassification() != Classification.spectrads3
        && ds3Request.getClassification() != Classification.spectrainternal) {
      return builder.toString();
    }
    if (ds3Request.getResource() == null) {
      return builder.append("\"/_rest_/\"").toString();
    }

    builder.append("\"/_rest_/").append(ds3Request.getResource().toString().toLowerCase());
    if (isNotificationRequest(ds3Request)
        && ds3Request.getIncludeInPath()
        && (getNotificationType(ds3Request) == NotificationType.DELETE
            || getNotificationType(ds3Request) == NotificationType.GET)) {
      builder.append("/\"").append(" + this.getNotificationId().toString()");
    } else if (hasBucketNameInPath(ds3Request)) {
      builder.append("/\"").append(" + this.bucketName");
    } else if (isResourceAnArg(ds3Request.getResource(), ds3Request.getIncludeInPath())) {
      final Arguments resourceArg = getArgFromResource(ds3Request.getResource());
      builder.append("/\"").append(" + ").append(resourceArgToString(resourceArg));
    } else {
      builder.append("\"");
    }
    return builder.toString();
  }
Ejemplo n.º 2
0
 /**
  * Retrieves a list of arguments from the Ds3Request, including converting the required parameters
  * to arguments, and retrieving the arguments from the request header info
  */
 public static ImmutableList<Arguments> getRequiredArgs(final Ds3Request ds3Request) {
   final ImmutableList.Builder<Arguments> requiredArgs = ImmutableList.builder();
   requiredArgs.addAll(RequestConverterUtil.getRequiredArgsFromRequestHeader(ds3Request));
   requiredArgs.addAll(getArgsFromParamList(ds3Request.getRequiredQueryParams()));
   if (ds3Request.getIncludeInPath() && isResourceNotification(ds3Request.getResource())) {
     requiredArgs.add(new Arguments("Guid", "NotificationId"));
   }
   return requiredArgs.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();
  }