Class ResourceUriBuilder

java.lang.Object
com.emc.documentum.rest.context.ResourceUriBuilder

public class ResourceUriBuilder extends Object
Builder to build the URI based on a given resource or a custom URI template. The methods onResource(Class) and onResource(String) are used to build URIs from a given resource; and the method onTemplate(String) is used to build URIs from a give YAML URI template. These methods can not be called simultaneously on a single builder instance.
  • Field Details

  • Method Details

    • onResource

      public static ResourceUriBuilder onResource(String resource)
      Create the resource URI builder from a resource. If the resource name is not found in classpath, the built URI will be INACTIVE_URL. Creating ResourceUriBuilder upon the resource name has advantages over the resource controller class because at runtime the resource could be overridden. In such a case, the overridden controller class may not be loaded, but the resource name remains effective.
      Parameters:
      resource - the resource name from the resource controller definition.
      Returns:
      the ResourceUriBuilder itself
      See Also:
    • onResource

      public static ResourceUriBuilder onResource(Class<?> controller)
      Create the resource URI builder from a resource controller.
      Parameters:
      controller - the resource controller class
      Returns:
      the ResourceUriBuilder itself
      See Also:
    • onTemplate

      public static ResourceUriBuilder onTemplate(String templateName)
      Create the resource URI builder from a custom URI template in YAML.
      Parameters:
      templateName - the URI template name
      Returns:
      the ResourceUriBuilder itself
    • uriInfo

      public ResourceUriBuilder uriInfo(UriInfo uriInfo)
      Specify the base URI information, including base URI and format extenstion.
      Parameters:
      uriInfo - the URI info from last request.
      Returns:
      the ResourceUriBuilder itself
    • baseUri

      public ResourceUriBuilder baseUri(String baseUri)
      Specify the base URI for the builder when required. This will overwrite the default base URI.
      Parameters:
      baseUri - the base URI of the REST server, e.g. http://localhost:8080/dctm-rest
      Returns:
      the ResourceUriBuilder itself
    • extension

      public ResourceUriBuilder extension(String extension)
      Specify the extension for the builder when required. This will overwrite the default base URI.
      Parameters:
      extension - the format extension, e.g. .xml or .json
      Returns:
      the ResourceUriBuilder itself
    • pathVariables

      public ResourceUriBuilder pathVariables(String... pathVariables)
      Specify the path variable values for the given resource URI template. If the URI template starts with the relative repository path segment "/repositories/{repositoryName}", it is optional to specify the repository name in the path variables. The builder will resolve the repository name implicitly from current HTTP request. This method can be called multiple times to accumulate the path variables in order.
      Parameters:
      pathVariables - the raw variable values in the path; the values cannot contain null or empty string, otherwise the built link is invalid.
      Returns:
      the ResourceUriBuilder itself
      See Also:
    • pathVariable

      public ResourceUriBuilder pathVariable(boolean safeEncoding, String pathVariable)
      Specify the path variable for the given resource URI template. If the URI template starts with the relative repository path segment "/repositories/{repositoryName}", it is optional to specify the repository name in the path variables. The builder will resolve the repository name implicitly from current HTTP request. This method can be called multiple times to accumulate the path variables in order.
      Parameters:
      safeEncoding - indicate whether to safe encoding the path variable values; it is required to safe encode the path value for the value that contains URI reservered characters, e.g. '/', '.', etc.
      pathVariable - the raw variable value in the path; the value cannot be null or empty, otherwise the built link is invalid.
      Returns:
      the ResourceUriBuilder itself
      See Also:
    • pathVariable

      public ResourceUriBuilder pathVariable(String pathVariable)
      Specify the path variable for the given resource URI template. If the URI template starts with the relative repository path segment "/repositories/{repositoryName}", it is optional to specify the repository name in the path variables. The builder will resolve the repository name implicitly from current HTTP request. This method can be called multiple times to accumulate the path variables in order.
      Parameters:
      pathVariable - the raw variable value in the path; the value cannot be null or empty, otherwise the built link is invalid.
      Returns:
      the ResourceUriBuilder itself
      See Also:
    • queryParams

      public ResourceUriBuilder queryParams(Map<String,String> parameters)
      Specify the query queryParams for the resource URI. This method can be called multiple times to accumulate the path variables in order. The existing parameter values will be overwritten. The query queryParams in the built URI is in the order of alpha-beta of the query parameter names.
      Parameters:
      parameters - the query queryParams
      Returns:
      the ResourceUriBuilder itself
    • queryParam

      public ResourceUriBuilder queryParam(String key, Object value)
      Specify the single query parameter for the resource URI. The existing parameter values will be overwritten. This method can be called multiple times for multiple queryParams.
      Parameters:
      key - the query parameter key
      value - the query parameter value
      Returns:
      the ResourceUriBuilder itself
    • repository

      public ResourceUriBuilder repository(String repository)
      Specify the repository name for the builder when required. It is optional to specify the repository name as the builder will resolve it implicitly from current HTTP request. However, it is necessary to set the repository name if the builder is building a repository level URI from non repository level HTTP requests. This setting override the implicit repository name. This will overwrite the default repository name.
      Parameters:
      repository - the repository name
      Returns:
      the ResourceUriBuilder itself
    • validate

      public ResourceUriBuilder validate(boolean validate)
      Whether validate the resource when building the URI. If true, the link will be built only when the corresponding resource controller is active. Default is true. The default can be changed to false by setting the REST runtime property 'rest.link.relation.validate=false'.
      Parameters:
      validate - whether validate when build
      Returns:
      the ResourceUriBuilder itself
    • relative

      public ResourceUriBuilder relative()
      Whether force to make relative URI.
      Returns:
      the ResourceUriBuilder itself
    • asTemplate

      public ResourceUriBuilder asTemplate(String... templateParams)
      Force this resource URI to be normalized as an URI template.
      Parameters:
      templateParams - the additional template query queryParams. The input template queryParams will be merged with the template queryParams defined on the resource URI.
      Returns:
      the ResourceUriBuilder itself
    • noHrefTemplate

      public ResourceUriBuilder noHrefTemplate()
      Resource URI is bound with controller. Once the controller has annotation @TemplateParams, the URI built with ResourceUriBuilder is always href template. This method overrides the behavior of building href template so that URI based on controllers like SearchController can be built with no template parameters.
      Returns:
      the ResourceUriBuilder itself
    • build

      public String build()
      Build the URI for the resource. If the target resource's URI is a href template, or the build is explicitly set with asTemplate(String...), the built URI is a URI template.
      Returns:
      the URI of the resource
    • getRepositoryName

      protected String getRepositoryName()
    • getBaseUri

      protected String getBaseUri()
    • getExtension

      protected String getExtension()