Class RestV2Util

java.lang.Object
com.jalios.jcms.restv2.RestV2Util

public class RestV2Util extends Object
Utility class providing helper methods for REST V2 endpoints.

This class centralizes common CRUD operations (create, read, update, delete) as well as file upload handling for Data and FileDocument objects. It standardizes:

  • HTTP response construction
  • Error handling and logging
  • JSON serialization/deserialization
  • Multipart file upload processing
  • Constructor Details

    • RestV2Util

      public RestV2Util()
  • Method Details

    • create

      public static <T extends Data> javax.ws.rs.core.Response create(com.fasterxml.jackson.databind.ObjectMapper mapper, T updating, Class<T> clazz, org.apache.log4j.Logger logger, ThrowingSupplier<String> getCurrentUserLang, ThrowingFunction<T,String> getId, Member member, javax.ws.rs.core.UriInfo uriInfo)
      Creates a new Data entity.
      Type Parameters:
      T - type of entity
      Parameters:
      mapper - JSON mapper used to serialize the response
      updating - the entity to create
      clazz - the entity class
      logger - logger instance
      getCurrentUserLang - supplier providing the current user language
      getId - function to extract the entity ID
      member - the current user
      uriInfo - URI context for building the Location header
      Returns:
      HTTP response with created entity or error
    • getAll

      public static javax.ws.rs.core.Response getAll(ThrowingSupplier<? extends PagerData> getPagerData, ThrowingSupplier<?> datas, com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.log4j.Logger logger)
      Retrieves a collection of Data entities.
      Parameters:
      getPagerData - supplier for pager metadata
      datas - supplier returning the data collection
      mapper - JSON mapper
      logger - logger instance
      Returns:
      HTTP response containing serialized collection
    • get

      public static <T> javax.ws.rs.core.Response get(String id, ThrowingFunction<String,T> getData, com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.log4j.Logger logger)
      Retrieves a single entity by its ID.
      Type Parameters:
      T - entity type
      Parameters:
      id - identifier of the entity
      getData - function used to retrieve the entity
      mapper - JSON mapper
      logger - logger instance
      Returns:
      HTTP response with the entity or error
    • update

      public static <T extends Data> javax.ws.rs.core.Response update(String id, String updating, Class<T> clazz, ThrowingFunction<String,T> getData, com.fasterxml.jackson.databind.ObjectMapper mapper, ThrowingSupplier<String> getCurrentUserLang, org.apache.log4j.Logger logger, Member member, javax.ws.rs.core.UriInfo uriInfo)
      Updates an existing entity using a JSON payload.
      Type Parameters:
      T - entity type
      Parameters:
      id - identifier of the entity
      updating - JSON payload
      clazz - expected class
      getData - function to retrieve the existing entity
      mapper - JSON mapper
      getCurrentUserLang - supplier for user language
      logger - logger instance
      member - current user
      uriInfo - URI context
      Returns:
      HTTP response with updated entity or error
    • delete

      public static <T extends Data> javax.ws.rs.core.Response delete(String id, ThrowingFunction<String,T> getData, ThrowingSupplier<String> getCurrentUserLang, org.apache.log4j.Logger logger, Member member)
      Deletes an entity by its ID.
      Type Parameters:
      T - entity type
      Parameters:
      id - identifier of the entity
      getData - function to retrieve the entity
      getCurrentUserLang - supplier for user language
      logger - logger instance
      member - current user
      Returns:
      HTTP response indicating result
    • upsertFileDocument

      public static <T extends FileDocument> javax.ws.rs.core.Response upsertFileDocument(String id, ThrowingFunction<String,T> getData, ThrowingFunction<T,String> getId, com.fasterxml.jackson.databind.ObjectMapper mapper, org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput input, org.apache.log4j.Logger logger, ThrowingSupplier<javax.servlet.http.HttpServletRequest> getRequest, Class<T> clazz, DocUploadRequestParams params, javax.ws.rs.core.UriInfo uriInfo, ThrowingSupplier<String> getCurrentUserLang, Member member)
      Creates or updates a FileDocument using multipart upload.

      Supports:

      • File upload
      • JSON metadata update
      • Combined file + JSON operations
      Type Parameters:
      T - type extending FileDocument
      Parameters:
      id - optional ID (null for creation)
      getData - function to retrieve existing entity
      getId - function to extract ID
      mapper - JSON mapper
      input - multipart request input
      logger - logger instance
      getRequest - supplier for HTTP request
      clazz - entity class
      params - upload request parameters
      uriInfo - URI context
      getCurrentUserLang - supplier for language
      member - current user
      Returns:
      HTTP response with created/updated document