Package overit.geocallapp.utilities.rs
Class RestUtils
java.lang.Object
overit.geocallapp.utilities.rs.RestUtils
Comprehensive utility class providing static methods for REST service operations and data transformations.
- Since:
- 1.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <I> org.springframework.http.ResponseEntity<List<DTOIdentifier<Long>>> batchCreate(BatchInsertEvent<I> event) Creates multiple resources using the provided batch insert event with default validation.static <I> org.springframework.http.ResponseEntity<List<DTOIdentifier<Long>>> batchCreate(BatchInsertEvent<I> event, Validator<I> validator) Creates multiple resources using the provided batch insert event with custom validation.static <I> org.springframework.http.ResponseEntity<Void> batchDelete(BatchDeleteEvent<I> event) Deletes multiple resources using the provided batch delete event.static <I> org.springframework.http.ResponseEntity<Void> batchUpdate(BatchUpdateEvent<I> event) Updates multiple resources using the provided batch update event with default validation.static <I> org.springframework.http.ResponseEntity<Void> batchUpdate(BatchUpdateEvent<I> event, Validator<I> validator) Updates multiple resources using the provided batch update event with custom validation.static <I> org.springframework.http.ResponseEntity<DTOIdentifier<Long>> create(InsertEvent<I> event) Creates a new resource using the provided insert event with default validation.static <I> org.springframework.http.ResponseEntity<DTOIdentifier<Long>> create(InsertEvent<I> event, Validator<I> validator) Creates a new resource using the provided insert event with custom validation.static M2MapperCreates a defaultM2Mapperconfigured for business object to DTO conversions.static M2MapperdefaultMapper(Collection<String> fields) Creates a defaultM2Mapperwith field filtering configuration.static M2MapperdefaultMapper(TimeZone timeZone) Creates a defaultM2Mapperwith custom timezone configuration.static M2MapperdefaultMapper(TimeZone timeZone, Collection<String> fields) Creates a fully customizedM2Mapperwith timezone and field filtering.static M2MapperCreates a defaultM2Mapperwith strict matching strategy.static <I> org.springframework.http.ResponseEntity<Void> delete(DeleteEvent<I> event) Deletes a single resource using the provided delete event.protected static <T extends DynO>
voidfilterLocalizedStrings(Class<T> outClass, Collection<T> dtos, String language) FiltersLocalizedStringfields in the provided DTOs by the specified language.static org.springframework.http.ResponseEntity<Void> Creates a standard empty success response with HTTP 200 OK status.static org.springframework.http.ResponseEntity<Void> getDefaultEmptyResponse(org.springframework.http.HttpStatusCode statusCode) Creates an empty response with a custom HTTP status code.static org.springframework.http.ResponseEntity<Void> Creates a standard no-content response with HTTP 204 No Content status.static Collection<Long> getIdCollection(String input) Parses a delimited string into a collection of Long identifiers.static Collection<Long> getIdCollection(String input, String separator) Parses a delimited string into a collection of Long identifiers using a custom separator.static URIgetLocation(Long itemId) Builds a location URI for a newly created resource using a Long identifier.static URIgetLocation(String itemUuid) Builds a location URI for a newly created resource using a String UUID identifier.Converts an ordering string into anOrderobject for database queries.static <I,O, T extends DynO>
org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I, O> event, Class<T> outClass) Retrieves a single resource using the provided load event with user language filtering.static <I,O, T extends DynO>
org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I, O> event, Class<T> outClass, String language) Retrieves a single resource using the provided load event with custom language filtering.static <I,O, T extends DynO>
org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I, O> event, Class<T> outClass, String language, Collection<String> fields) Retrieves a single resource with custom language filtering and field selection.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) Retrieves a single resource with full customization options including validation.static <I,O, T extends DynO>
org.springframework.http.ResponseEntity<T> load(GenericLoadEvent<I, O> event, Class<T> outClass, Collection<String> fields) Retrieves a single resource with field filtering and user language settings.static <F,T, D extends DynO>
org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F, T> event, Class<D> outClass) Searches for resources using the provided search event with default settings.static <F,T, D extends DynO>
org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F, T> event, String ordering, Class<D> outClass) Searches for resources using the provided search event with custom ordering.static <F,T, D extends DynO>
org.springframework.http.ResponseEntity<PageResponse<D>> search(SearchEvent<F, T> event, String ordering, String language, Class<D> outClass) Searches for resources using the provided search event with custom ordering and language filtering.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) Searches for resources using the provided search event with ordering, language filtering, and field selection.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) Searches for resources with full customization options including validation.static <I> org.springframework.http.ResponseEntity<Void> update(UpdateEvent<I> event) Updates a single resource using the provided update event with default validation.static <I> org.springframework.http.ResponseEntity<Void> update(UpdateEvent<I> event, Validator<I> validator) Updates a single resource using the provided update event with custom validation.
-
Field Details
-
DEFAULT_VALUES_SEPARATOR
- See Also:
-
ITEM_ID
- See Also:
-
-
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- theInsertEventto execute for resource creation- Returns:
- a
ResponseEntitywith HTTP 201 status and the new resource ID wrapped inDTOIdentifier - Throws:
DAValidateException- if validation failsDAException- 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- theInsertEventto execute for resource creationvalidator- theValidatorto validate the business object before creation- Returns:
- a
ResponseEntitywith HTTP 201 status, location header, and the new resource ID wrapped inDTOIdentifier - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
getLocation
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
URIpointing to the new resource location
-
getLocation
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
URIpointing 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- theBatchInsertEventto execute for multiple resource creation- Returns:
- a
ResponseEntitywith HTTP 201 status and a list of new resource IDs wrapped inDTOIdentifier - Throws:
DAException- if the database operation failsDAValidateException- 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- theBatchInsertEventto execute for multiple resource creationvalidator- theValidatorto validate each business object before creation- Returns:
- a
ResponseEntitywith HTTP 201 status and a list of new resource IDs wrapped inDTOIdentifier - Throws:
DAException- if the database operation failsDAValidateException- 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- theUpdateEventto execute for resource modification- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation failsDAException- 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- theUpdateEventto execute for resource modificationvalidator- theValidatorto validate the business object before update- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation failsDAException- 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- theBatchUpdateEventto execute for multiple resource modifications- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation fails for any objectDAException- 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- theBatchUpdateEventto execute for multiple resource modificationsvalidator- theValidatorto validate each business object before update- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation fails for any objectDAException- if the database operation fails
-
load
public static <I,O, org.springframework.http.ResponseEntity<T> loadT extends DynO> (GenericLoadEvent<I, O> event, Class<T> outClass) throws DAValidateException, DAExceptionRetrieves a single resource using the provided load event with user language filtering.- Type Parameters:
I- the input parameter type of the load eventO- the loaded business object typeT- the target DTO type extendingDynO- Parameters:
event- theGenericLoadEventto execute for resource retrievaloutClass- the target class for object mapping- Returns:
- a
ResponseEntitywith HTTP 200 status and the mapped resource - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
load
public static <I,O, org.springframework.http.ResponseEntity<T> loadT extends DynO> (GenericLoadEvent<I, O> event, Class<T> outClass, String language) throws DAValidateException, DAExceptionRetrieves 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 eventO- the loaded business object typeT- the target DTO type extendingDynO- Parameters:
event- theGenericLoadEventto execute for resource retrievaloutClass- the target class for object mappinglanguage- the language name for filtering multilanguage fields- Returns:
- a
ResponseEntitywith HTTP 200 status and the mapped resource - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
load
public static <I,O, org.springframework.http.ResponseEntity<T> loadT extends DynO> (GenericLoadEvent<I, O> event, Class<T> outClass, Collection<String> fields) throws DAValidateException, DAExceptionRetrieves a single resource with field filtering and user language settings.- Type Parameters:
I- the input parameter type of the load eventO- the loaded business object typeT- the target DTO type extendingDynO- Parameters:
event- theGenericLoadEventto execute for resource retrievaloutClass- the target class for object mappingfields- the collection of field names to include in the output object- Returns:
- a
ResponseEntitywith HTTP 200 status and the mapped resource with specified fields - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
load
public static <I,O, org.springframework.http.ResponseEntity<T> loadT extends DynO> (GenericLoadEvent<I, O> event, Class<T> outClass, String language, Collection<String> fields) throws DAValidateException, DAExceptionRetrieves 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 eventO- the loaded business object typeT- the target DTO type extendingDynO- Parameters:
event- theGenericLoadEventto execute for resource retrievaloutClass- the target class for object mappinglanguage- the language name for filtering multilanguage fieldsfields- the collection of field names to include in the output object- Returns:
- a
ResponseEntitywith HTTP 200 status and the mapped resource with specified fields and language - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
load
public static <I,O, org.springframework.http.ResponseEntity<T> loadT extends DynO> (GenericLoadEvent<I, O> event, Class<T> outClass, String language, Collection<String> fields, Validator<O> validator) throws DAValidateException, DAExceptionRetrieves 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 eventO- the loaded business object typeT- the target DTO type extendingDynO- Parameters:
event- theGenericLoadEventto execute for resource retrievaloutClass- the target class for object mappinglanguage- the language name for filtering multilanguage fieldsfields- the collection of field names to include in the output objectvalidator- theValidatorto validate the loaded business object- Returns:
- a
ResponseEntitywith HTTP 200 status and the fully customized mapped resource - Throws:
DAValidateException- if validation failsDAException- 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- theDeleteEventto execute for resource deletion- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation failsDAException- 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- theBatchDeleteEventto execute for multiple resource deletion- Returns:
- a
ResponseEntitywith HTTP 204 No Content status - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
search
public static <F,T, org.springframework.http.ResponseEntity<PageResponse<D>> searchD extends DynO> (SearchEvent<F, T> event, Class<D> outClass) throws DAValidateException, DAExceptionSearches for resources using the provided search event with default settings.- Type Parameters:
F- the filter type for search criteriaT- the business object type returned by the searchD- the target DTO type extendingDynO- Parameters:
event- theSearchEventto execute for resource searchoutClass- the target class for object mapping- Returns:
- a
ResponseEntitywith HTTP 200 status and aPageResponsecontaining the search results - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
search
public static <F,T, org.springframework.http.ResponseEntity<PageResponse<D>> searchD extends DynO> (SearchEvent<F, T> event, String ordering, Class<D> outClass) throws DAValidateException, DAExceptionSearches for resources using the provided search event with custom ordering.- Type Parameters:
F- the filter type for search criteriaT- the business object type returned by the searchD- the target DTO type extendingDynO- Parameters:
event- theSearchEventto execute for resource searchordering- the ordering string for result sortingoutClass- the target class for object mapping- Returns:
- a
ResponseEntitywith HTTP 200 status and aPageResponsecontaining the ordered search results - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
search
public static <F,T, org.springframework.http.ResponseEntity<PageResponse<D>> searchD extends DynO> (SearchEvent<F, T> event, String ordering, String language, Class<D> outClass) throws DAValidateException, DAExceptionSearches for resources using the provided search event with custom ordering and language filtering.- Type Parameters:
F- the filter type for search criteriaT- the business object type returned by the searchD- the target DTO type extendingDynO- Parameters:
event- theSearchEventto execute for resource searchordering- the ordering string for result sortinglanguage- the language name for filtering multilanguage fieldsoutClass- the target class for object mapping- Returns:
- a
ResponseEntitywith HTTP 200 status and aPageResponsecontaining the search results with language filtering - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
search
public static <F,T, org.springframework.http.ResponseEntity<PageResponse<D>> searchD extends DynO> (SearchEvent<F, T> event, String ordering, String language, Collection<String> fields, Class<D> outClass) throws DAValidateException, DAExceptionSearches for resources using the provided search event with ordering, language filtering, and field selection.- Type Parameters:
F- the filter type for search criteriaT- the business object type returned by the searchD- the target DTO type extendingDynO- Parameters:
event- theSearchEventto execute for resource searchordering- the ordering string for result sortinglanguage- the language name for filtering multilanguage fieldsfields- the collection of field names to include in the output objectsoutClass- the target class for object mapping- Returns:
- a
ResponseEntitywith HTTP 200 status and aPageResponsecontaining the customized search results - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
search
public static <F,T, org.springframework.http.ResponseEntity<PageResponse<D>> searchD extends DynO> (SearchEvent<F, T> event, String ordering, String language, Collection<String> fields, Class<D> outClass, Validator<T> validator) throws DAValidateException, DAExceptionSearches 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 criteriaT- the business object type returned by the searchD- the target DTO type extendingDynO- Parameters:
event- theSearchEventto execute for resource searchordering- the ordering string for result sortinglanguage- the language name for filtering multilanguage fieldsfields- the collection of field names to include in the output objectsoutClass- the target class for object mappingvalidator- theValidatorto validate each loaded business object- Returns:
- a
ResponseEntitywith HTTP 200 status and aPageResponsecontaining the fully customized search results - Throws:
DAValidateException- if validation failsDAException- if the database operation fails
-
filterLocalizedStrings
protected static <T extends DynO> void filterLocalizedStrings(Class<T> outClass, Collection<T> dtos, String language) FiltersLocalizedStringfields in the provided DTOs by the specified language. Uses reflection to find allLocalizedStringfields in the class and applies language filtering to each DTO.- Type Parameters:
T- the type of the DTO entities extendingDynO- Parameters:
outClass- the class definition used for field reflectiondtos- the collection of DTO objects to processlanguage- the language name for filtering multilanguage fields
-
getOrder
Converts an ordering string into anOrderobject for database queries. Supports both prefix-based ordering (+field, -field) and separator-based ordering (field-ASC-field2-DESC). -
defaultMapper
Creates a defaultM2Mapperconfigured for business object to DTO conversions. Uses default timezone and no field filtering.- Returns:
- a configured
M2Mapperinstance with standard converters
-
defaultMapper
Creates a defaultM2Mapperwith custom timezone configuration. -
defaultMapper
Creates a defaultM2Mapperwith field filtering configuration.- Parameters:
fields- the collection of field names to include in mappings- Returns:
- a configured
M2Mapperinstance with field filtering
-
defaultMapper
Creates a fully customizedM2Mapperwith timezone and field filtering. Configures all standard converters for date/time transformations and sets up field conditions. -
defaultMapperMatchingStrategiesStrict
Creates a defaultM2Mapperwith strict matching strategy. Uses strict field matching to ensure precise property mapping between objects.- Returns:
- a configured
M2Mapperinstance with strict matching strategy
-
getIdCollection
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
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 identifiersseparator- the separator character used to split the input string- Returns:
- a collection of Long values, or null if input is null/empty
-
getDefaultEmptyResponse
Creates a standard empty success response with HTTP 200 OK status.- Returns:
- a
ResponseEntitywith 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- theHttpStatusCodeto use for the response- Returns:
- a
ResponseEntitywith the specified status and no body content
-
getDefaultNoContentResponse
Creates a standard no-content response with HTTP 204 No Content status. Commonly used for successful update and delete operations.- Returns:
- a
ResponseEntitywith HTTP 204 status and no body content
-