Package com.jalios.jcms.restv2
Class RestV2Util
java.lang.Object
com.jalios.jcms.restv2.RestV2Util
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Data>
javax.ws.rs.core.Responsecreate(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 newDataentity.static <T extends Data>
javax.ws.rs.core.Responsedelete(String id, ThrowingFunction<String, T> getData, ThrowingSupplier<String> getCurrentUserLang, org.apache.log4j.Logger logger, Member member) Deletes an entity by its ID.static <T> javax.ws.rs.core.Responseget(String id, ThrowingFunction<String, T> getData, com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.log4j.Logger logger) Retrieves a single entity by its ID.static javax.ws.rs.core.ResponsegetAll(ThrowingSupplier<? extends PagerData> getPagerData, ThrowingSupplier<?> datas, com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.log4j.Logger logger) Retrieves a collection ofDataentities.static <T extends Data>
javax.ws.rs.core.Responseupdate(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.static <T extends FileDocument>
javax.ws.rs.core.ResponseupsertFileDocument(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 aFileDocumentusing multipart upload.
-
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 newDataentity.- Type Parameters:
T- type of entity- Parameters:
mapper- JSON mapper used to serialize the responseupdating- the entity to createclazz- the entity classlogger- logger instancegetCurrentUserLang- supplier providing the current user languagegetId- function to extract the entity IDmember- the current useruriInfo- 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 ofDataentities.- Parameters:
getPagerData- supplier for pager metadatadatas- supplier returning the data collectionmapper- JSON mapperlogger- 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 entitygetData- function used to retrieve the entitymapper- JSON mapperlogger- 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 entityupdating- JSON payloadclazz- expected classgetData- function to retrieve the existing entitymapper- JSON mappergetCurrentUserLang- supplier for user languagelogger- logger instancemember- current useruriInfo- 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 entitygetData- function to retrieve the entitygetCurrentUserLang- supplier for user languagelogger- logger instancemember- 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 aFileDocumentusing multipart upload.Supports:
- File upload
- JSON metadata update
- Combined file + JSON operations
- Type Parameters:
T- type extendingFileDocument- Parameters:
id- optional ID (null for creation)getData- function to retrieve existing entitygetId- function to extract IDmapper- JSON mapperinput- multipart request inputlogger- logger instancegetRequest- supplier for HTTP requestclazz- entity classparams- upload request parametersuriInfo- URI contextgetCurrentUserLang- supplier for languagemember- current user- Returns:
- HTTP response with created/updated document
-