Class RestUtils

java.lang.Object
overit.geocallapp.utilities.rs.RestUtils

public class RestUtils extends Object
Comprehensive utility class providing static methods for REST service operations and data transformations.
Since:
1.0
  • Field Details

  • Method Details

    • create

      public static <I> org.springframework.http.ResponseEntity<DTOIdentifier<Long>> create(InsertEvent<I> event) throws DAException, DAValidateException
      Creates a new resource using the provided insert event with default validation.
      Type Parameters:
      I - the business object type of the create event
      Parameters:
      event - the InsertEvent to execute for resource creation
      Returns:
      a ResponseEntity with HTTP 201 status and the new resource ID wrapped in DTOIdentifier
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • create

      public static <I> org.springframework.http.ResponseEntity<DTOIdentifier<Long>> create(InsertEvent<I> event, Validator<I> validator) throws DAException, DAValidateException
      Creates a new resource using the provided insert event with custom validation. Validates the input object, executes the insert event, and returns a response with the new resource location.
      Type Parameters:
      I - the business object type of the create event
      Parameters:
      event - the InsertEvent to execute for resource creation
      validator - the Validator to validate the business object before creation
      Returns:
      a ResponseEntity with HTTP 201 status, location header, and the new resource ID wrapped in DTOIdentifier
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • getLocation

      public static URI getLocation(Long itemId)
      Builds a location URI for a newly created resource using a Long identifier. Appends the resource ID to the current request path for use in HTTP 201 Created responses.
      Parameters:
      itemId - the Long identifier of the newly created resource
      Returns:
      a URI pointing to the new resource location
    • getLocation

      public static URI getLocation(String itemUuid)
      Builds a location URI for a newly created resource using a String UUID identifier. Appends the resource UUID to the current request path for use in HTTP 201 Created responses.
      Parameters:
      itemUuid - the String UUID identifier of the newly created resource
      Returns:
      a URI pointing to the new resource location
    • batchCreate

      public static <I> org.springframework.http.ResponseEntity<List<DTOIdentifier<Long>>> batchCreate(BatchInsertEvent<I> event) throws DAException, DAValidateException
      Creates multiple resources using the provided batch insert event with default validation.
      Type Parameters:
      I - the business object type of the batch create event
      Parameters:
      event - the BatchInsertEvent to execute for multiple resource creation
      Returns:
      a ResponseEntity with HTTP 201 status and a list of new resource IDs wrapped in DTOIdentifier
      Throws:
      DAException - if the database operation fails
      DAValidateException - if validation fails for any object
    • batchCreate

      public static <I> org.springframework.http.ResponseEntity<List<DTOIdentifier<Long>>> batchCreate(BatchInsertEvent<I> event, Validator<I> validator) throws DAException, DAValidateException
      Creates multiple resources using the provided batch insert event with custom validation. Validates all input objects, executes the batch insert event, and returns a response with the new resource IDs.
      Type Parameters:
      I - the business object type of the batch create event
      Parameters:
      event - the BatchInsertEvent to execute for multiple resource creation
      validator - the Validator to validate each business object before creation
      Returns:
      a ResponseEntity with HTTP 201 status and a list of new resource IDs wrapped in DTOIdentifier
      Throws:
      DAException - if the database operation fails
      DAValidateException - if validation fails for any object
    • update

      public static <I> org.springframework.http.ResponseEntity<Void> update(UpdateEvent<I> event) throws DAValidateException, DAException
      Updates a single resource using the provided update event with default validation.
      Type Parameters:
      I - the business object type of the update event
      Parameters:
      event - the UpdateEvent to execute for resource modification
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • update

      public static <I> org.springframework.http.ResponseEntity<Void> update(UpdateEvent<I> event, Validator<I> validator) throws DAValidateException, DAException
      Updates a single resource using the provided update event with custom validation. Validates the input object, executes the update event, and returns a no-content response.
      Type Parameters:
      I - the business object type of the update event
      Parameters:
      event - the UpdateEvent to execute for resource modification
      validator - the Validator to validate the business object before update
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • batchUpdate

      public static <I> org.springframework.http.ResponseEntity<Void> batchUpdate(BatchUpdateEvent<I> event) throws DAValidateException, DAException
      Updates multiple resources using the provided batch update event with default validation.
      Type Parameters:
      I - the business object type of the update event
      Parameters:
      event - the BatchUpdateEvent to execute for multiple resource modifications
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails for any object
      DAException - if the database operation fails
    • batchUpdate

      public static <I> org.springframework.http.ResponseEntity<Void> batchUpdate(BatchUpdateEvent<I> event, Validator<I> validator) throws DAValidateException, DAException
      Updates multiple resources using the provided batch update event with custom validation. Validates all input objects, executes the batch update event, and returns a no-content response.
      Type Parameters:
      I - the business object type of the update event
      Parameters:
      event - the BatchUpdateEvent to execute for multiple resource modifications
      validator - the Validator to validate each business object before update
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails for any object
      DAException - if the database operation fails
    • load

      public static <I, O, T extends DynO> org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I,O> event, Class<T> outClass) throws DAValidateException, DAException
      Retrieves a single resource using the provided load event with user language filtering.
      Type Parameters:
      I - the input parameter type of the load event
      O - the loaded business object type
      T - the target DTO type extending DynO
      Parameters:
      event - the GenericLoadEvent to execute for resource retrieval
      outClass - the target class for object mapping
      Returns:
      a ResponseEntity with HTTP 200 status and the mapped resource
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • load

      public static <I, O, T extends DynO> org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I,O> event, Class<T> outClass, String language) throws DAValidateException, DAException
      Retrieves a single resource using the provided load event with custom language filtering. Filters multilanguage fields according to the specified language setting.
      Type Parameters:
      I - the input parameter type of the load event
      O - the loaded business object type
      T - the target DTO type extending DynO
      Parameters:
      event - the GenericLoadEvent to execute for resource retrieval
      outClass - the target class for object mapping
      language - the language name for filtering multilanguage fields
      Returns:
      a ResponseEntity with HTTP 200 status and the mapped resource
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • load

      public static <I, O, T extends DynO> org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I,O> event, Class<T> outClass, Collection<String> fields) throws DAValidateException, DAException
      Retrieves a single resource with field filtering and user language settings.
      Type Parameters:
      I - the input parameter type of the load event
      O - the loaded business object type
      T - the target DTO type extending DynO
      Parameters:
      event - the GenericLoadEvent to execute for resource retrieval
      outClass - the target class for object mapping
      fields - the collection of field names to include in the output object
      Returns:
      a ResponseEntity with HTTP 200 status and the mapped resource with specified fields
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • load

      public static <I, O, T extends DynO> org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I,O> event, Class<T> outClass, String language, Collection<String> fields) throws DAValidateException, DAException
      Retrieves a single resource with custom language filtering and field selection. Provides full control over language filtering and field inclusion in the response.
      Type Parameters:
      I - the input parameter type of the load event
      O - the loaded business object type
      T - the target DTO type extending DynO
      Parameters:
      event - the GenericLoadEvent to execute for resource retrieval
      outClass - the target class for object mapping
      language - the language name for filtering multilanguage fields
      fields - the collection of field names to include in the output object
      Returns:
      a ResponseEntity with HTTP 200 status and the mapped resource with specified fields and language
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • load

      public static <I, O, T extends DynO> org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I,O> event, Class<T> outClass, String language, Collection<String> fields, Validator<O> validator) throws DAValidateException, DAException
      Retrieves a single resource with full customization options including validation. Provides complete control over validation, language filtering, and field selection.
      Type Parameters:
      I - the input parameter type of the load event
      O - the loaded business object type
      T - the target DTO type extending DynO
      Parameters:
      event - the GenericLoadEvent to execute for resource retrieval
      outClass - the target class for object mapping
      language - the language name for filtering multilanguage fields
      fields - the collection of field names to include in the output object
      validator - the Validator to validate the loaded business object
      Returns:
      a ResponseEntity with HTTP 200 status and the fully customized mapped resource
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • delete

      public static <I> org.springframework.http.ResponseEntity<Void> delete(DeleteEvent<I> event) throws DAValidateException, DAException
      Deletes a single resource using the provided delete event. Executes the delete operation and returns a no-content response.
      Type Parameters:
      I - the business object type of the delete event
      Parameters:
      event - the DeleteEvent to execute for resource deletion
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • batchDelete

      public static <I> org.springframework.http.ResponseEntity<Void> batchDelete(BatchDeleteEvent<I> event) throws DAValidateException, DAException
      Deletes multiple resources using the provided batch delete event. Executes the batch delete operation and returns a no-content response.
      Type Parameters:
      I - the business object type of the delete event
      Parameters:
      event - the BatchDeleteEvent to execute for multiple resource deletion
      Returns:
      a ResponseEntity with HTTP 204 No Content status
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • search

      public static <F, T, D extends DynO> org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F,T> event, Class<D> outClass) throws DAValidateException, DAException
      Searches for resources using the provided search event with default settings.
      Type Parameters:
      F - the filter type for search criteria
      T - the business object type returned by the search
      D - the target DTO type extending DynO
      Parameters:
      event - the SearchEvent to execute for resource search
      outClass - the target class for object mapping
      Returns:
      a ResponseEntity with HTTP 200 status and a PageResponse containing the search results
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • search

      public static <F, T, D extends DynO> org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F,T> event, String ordering, Class<D> outClass) throws DAValidateException, DAException
      Searches for resources using the provided search event with custom ordering.
      Type Parameters:
      F - the filter type for search criteria
      T - the business object type returned by the search
      D - the target DTO type extending DynO
      Parameters:
      event - the SearchEvent to execute for resource search
      ordering - the ordering string for result sorting
      outClass - the target class for object mapping
      Returns:
      a ResponseEntity with HTTP 200 status and a PageResponse containing the ordered search results
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • search

      public static <F, T, D extends DynO> org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F,T> event, String ordering, String language, Class<D> outClass) throws DAValidateException, DAException
      Searches for resources using the provided search event with custom ordering and language filtering.
      Type Parameters:
      F - the filter type for search criteria
      T - the business object type returned by the search
      D - the target DTO type extending DynO
      Parameters:
      event - the SearchEvent to execute for resource search
      ordering - the ordering string for result sorting
      language - the language name for filtering multilanguage fields
      outClass - the target class for object mapping
      Returns:
      a ResponseEntity with HTTP 200 status and a PageResponse containing the search results with language filtering
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • search

      public static <F, T, D extends DynO> org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F,T> event, String ordering, String language, Collection<String> fields, Class<D> outClass) throws DAValidateException, DAException
      Searches for resources using the provided search event with ordering, language filtering, and field selection.
      Type Parameters:
      F - the filter type for search criteria
      T - the business object type returned by the search
      D - the target DTO type extending DynO
      Parameters:
      event - the SearchEvent to execute for resource search
      ordering - the ordering string for result sorting
      language - the language name for filtering multilanguage fields
      fields - the collection of field names to include in the output objects
      outClass - the target class for object mapping
      Returns:
      a ResponseEntity with HTTP 200 status and a PageResponse containing the customized search results
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • search

      public static <F, T, D extends DynO> org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F,T> event, String ordering, String language, Collection<String> fields, Class<D> outClass, Validator<T> validator) throws DAValidateException, DAException
      Searches for resources with full customization options including validation. Provides complete control over ordering, language filtering, field selection, and validation.
      Type Parameters:
      F - the filter type for search criteria
      T - the business object type returned by the search
      D - the target DTO type extending DynO
      Parameters:
      event - the SearchEvent to execute for resource search
      ordering - the ordering string for result sorting
      language - the language name for filtering multilanguage fields
      fields - the collection of field names to include in the output objects
      outClass - the target class for object mapping
      validator - the Validator to validate each loaded business object
      Returns:
      a ResponseEntity with HTTP 200 status and a PageResponse containing the fully customized search results
      Throws:
      DAValidateException - if validation fails
      DAException - if the database operation fails
    • filterLocalizedStrings

      protected static <T extends DynO> void filterLocalizedStrings(Class<T> outClass, Collection<T> dtos, String language)
      Filters LocalizedString fields in the provided DTOs by the specified language. Uses reflection to find all LocalizedString fields in the class and applies language filtering to each DTO.
      Type Parameters:
      T - the type of the DTO entities extending DynO
      Parameters:
      outClass - the class definition used for field reflection
      dtos - the collection of DTO objects to process
      language - the language name for filtering multilanguage fields
    • getOrder

      public static <D extends DynO> Order getOrder(String ordering, Class<D> outClass)
      Converts an ordering string into an Order object for database queries. Supports both prefix-based ordering (+field, -field) and separator-based ordering (field-ASC-field2-DESC).
      Type Parameters:
      D - the target DTO type extending DynO
      Parameters:
      ordering - the ordering string to parse
      outClass - the class definition used for field name resolution
      Returns:
      the Order object generated from the input ordering string, or null if ordering is null/empty
    • defaultMapper

      public static M2Mapper defaultMapper()
      Creates a default M2Mapper configured for business object to DTO conversions. Uses default timezone and no field filtering.
      Returns:
      a configured M2Mapper instance with standard converters
    • defaultMapper

      public static M2Mapper defaultMapper(TimeZone timeZone)
      Creates a default M2Mapper with custom timezone configuration.
      Parameters:
      timeZone - the TimeZone to use for date/time conversions
      Returns:
      a configured M2Mapper instance with the specified timezone
    • defaultMapper

      public static M2Mapper defaultMapper(Collection<String> fields)
      Creates a default M2Mapper with field filtering configuration.
      Parameters:
      fields - the collection of field names to include in mappings
      Returns:
      a configured M2Mapper instance with field filtering
    • defaultMapper

      public static M2Mapper defaultMapper(TimeZone timeZone, Collection<String> fields)
      Creates a fully customized M2Mapper with timezone and field filtering. Configures all standard converters for date/time transformations and sets up field conditions.
      Parameters:
      timeZone - the TimeZone to use for date/time conversions, or null for system default
      fields - the collection of field names to include in mappings, or null for all fields
      Returns:
      a fully configured M2Mapper instance
    • defaultMapperMatchingStrategiesStrict

      public static M2Mapper defaultMapperMatchingStrategiesStrict()
      Creates a default M2Mapper with strict matching strategy. Uses strict field matching to ensure precise property mapping between objects.
      Returns:
      a configured M2Mapper instance with strict matching strategy
    • getIdCollection

      public static Collection<Long> getIdCollection(String input)
      Parses a delimited string into a collection of Long identifiers. Uses the default separator character for parsing.
      Parameters:
      input - the delimited string containing Long identifiers
      Returns:
      a collection of Long values, or null if input is null/empty
    • getIdCollection

      public static Collection<Long> getIdCollection(String input, String separator)
      Parses a delimited string into a collection of Long identifiers using a custom separator. Trims whitespace from each identifier before parsing.
      Parameters:
      input - the delimited string containing Long identifiers
      separator - the separator character used to split the input string
      Returns:
      a collection of Long values, or null if input is null/empty
    • getDefaultEmptyResponse

      public static org.springframework.http.ResponseEntity<Void> getDefaultEmptyResponse()
      Creates a standard empty success response with HTTP 200 OK status.
      Returns:
      a ResponseEntity with HTTP 200 status and no body content
    • getDefaultEmptyResponse

      public static org.springframework.http.ResponseEntity<Void> getDefaultEmptyResponse(org.springframework.http.HttpStatusCode statusCode)
      Creates an empty response with a custom HTTP status code.
      Parameters:
      statusCode - the HttpStatusCode to use for the response
      Returns:
      a ResponseEntity with the specified status and no body content
    • getDefaultNoContentResponse

      public static org.springframework.http.ResponseEntity<Void> getDefaultNoContentResponse()
      Creates a standard no-content response with HTTP 204 No Content status. Commonly used for successful update and delete operations.
      Returns:
      a ResponseEntity with HTTP 204 status and no body content