From 3f04f62ddeb1c6b4a4371a5059ea9b5b0eaacbb3 Mon Sep 17 00:00:00 2001 From: valentinogiardino Date: Tue, 19 Nov 2024 11:07:56 -0300 Subject: [PATCH] #30669 add contentImport params --- .../v1/contentImport/ContentImportParams.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportParams.java diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportParams.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportParams.java new file mode 100644 index 000000000000..7f9f9738c62b --- /dev/null +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportParams.java @@ -0,0 +1,76 @@ +package com.dotcms.rest.api.v1.contentImport; + +import com.dotcms.rest.api.Validated; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.dotmarketing.exception.DotDataException; +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataParam; + +import java.io.InputStream; + +/** + * Bean class that encapsulates the multipart form parameters for content import operations. + */ +public class ContentImportParams extends Validated { + + @FormDataParam("file") + private InputStream fileInputStream; + + @FormDataParam("file") + private FormDataContentDisposition contentDisposition; + + @FormDataParam("form") + private com.dotcms.rest.api.v1.contentImport.ContentImportForm form; + + @FormDataParam("form") + private String jsonForm; + + public InputStream getFileInputStream() { + return fileInputStream; + } + + public void setFileInputStream(InputStream fileInputStream) { + this.fileInputStream = fileInputStream; + } + + public FormDataContentDisposition getContentDisposition() { + return contentDisposition; + } + + public void setContentDisposition(FormDataContentDisposition contentDisposition) { + this.contentDisposition = contentDisposition; + } + + public String getJsonForm() { + return jsonForm; + } + + public void setForm(com.dotcms.rest.api.v1.contentImport.ContentImportForm form) { + this.form = form; + } + + /** + * Gets the parsed form object, lazily parsing the JSON if needed + * @return The ContentImportForm object + */ + public com.dotcms.rest.api.v1.contentImport.ContentImportForm getForm() throws DotDataException, JsonProcessingException { + if (null == form && (null != jsonForm && !jsonForm.isEmpty())) { + form = new ObjectMapper().readValue(jsonForm, com.dotcms.rest.api.v1.contentImport.ContentImportForm.class); + } + + if (form == null) { + throw new DotDataException("Import form parameters are required"); + } + return form; + } + + @Override + public String toString() { + return "ContentImportParams{" + + "form=" + form + + ", hasFile=" + (fileInputStream != null) + + ", fileName=" + (contentDisposition != null ? contentDisposition.getFileName() : "null") + + '}'; + } +} \ No newline at end of file