From e454da3ca122bd981131ada6da3d7c4454a8dab8 Mon Sep 17 00:00:00 2001
From: valentinogiardino
Date: Tue, 3 Dec 2024 18:01:04 -0300
Subject: [PATCH 1/4] #30669 fix key fields to be passed as id
---
.../business/processor/impl/ImportContentletsProcessor.java | 2 +-
.../api/v1/content/dotimport/ContentImportParamsSchema.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java b/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
index bf42bf0fc249..3f07cc6e3bf9 100644
--- a/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
+++ b/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
@@ -229,7 +229,7 @@ && getWorkflowActionId(parameters).isEmpty()) {
private void validateFields(final Map parameters, final ContentType contentTypeFound) {
var fields = contentTypeFound.fields();
for (String field : getFields(parameters)) {
- if (fields.stream().noneMatch(f -> Objects.equals(f.variable(), field))) {
+ if (fields.stream().noneMatch(f -> Objects.equals(f.id(), field))) {
final var errorMessage = String.format(
"Field [%s] not found in Content Type [%s].", field, contentTypeFound.variable()
);
diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportParamsSchema.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportParamsSchema.java
index 9e59db2ac3ae..4daddf0a3ac0 100644
--- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportParamsSchema.java
+++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportParamsSchema.java
@@ -28,7 +28,7 @@ public class ContentImportParamsSchema {
" \"contentType\": \"activity\",\n" +
" \"language\": \"en-US\",\n" +
" \"workflowActionId\": \"1234\",\n" +
- " \"fields\": [\"title\"]\n" +
+ " \"fields\": [\"e1f99107-fd0e-49d4-a099-1cc10aa284d8\"]\n" +
"}"
)
private String form;
From b7b8c60bc0d9544c5c467a6ff92bfe122fc95502 Mon Sep 17 00:00:00 2001
From: valentinogiardino
Date: Tue, 3 Dec 2024 18:02:09 -0300
Subject: [PATCH 2/4] #30669 Update ContentImportResource IT
---
.../ContentImportResourceIntegrationTest.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportResourceIntegrationTest.java b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportResourceIntegrationTest.java
index bd50dd777cc7..398d918fa8cb 100644
--- a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportResourceIntegrationTest.java
+++ b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportResourceIntegrationTest.java
@@ -57,6 +57,7 @@ public class ContentImportResourceIntegrationTest extends Junit5WeldBaseTest {
private static File csvFile;
private static ContentType contentType;
+ private static String fieldId;
@Inject
ContentImportHelper contentImportHelper;
@@ -73,6 +74,8 @@ static void setUp() throws Exception {
defaultLanguage = APILocator.getLanguageAPI().getDefaultLanguage();
contentType = TestDataUtils.getRichTextLikeContentType();
+ fieldId = contentType.fields().get(0).id();
+ assert fieldId != null;
csvFile = createTestCsvFile();
}
@@ -101,11 +104,11 @@ static void cleanup() {
*/
@Test
public void test_import_content_with_valid_params() throws IOException, DotDataException {
- ContentImportForm form = createContentImportForm(contentType.name(), String.valueOf(defaultLanguage.getId()), WORKFLOW_PUBLISH_ACTION_ID, List.of("title"));
+ ContentImportForm form = createContentImportForm(contentType.name(), String.valueOf(defaultLanguage.getId()), WORKFLOW_PUBLISH_ACTION_ID, List.of(fieldId));
ContentImportParams params = createContentImportParams(csvFile, form);
Response importContentResponse = importResource.importContent(request, response, params);
- validateSuccessfulResponse(importContentResponse, contentType.name(), String.valueOf(defaultLanguage.getId()), List.of("title"), WORKFLOW_PUBLISH_ACTION_ID, CMD_PUBLISH);
+ validateSuccessfulResponse(importContentResponse, contentType.name(), String.valueOf(defaultLanguage.getId()), List.of(fieldId), WORKFLOW_PUBLISH_ACTION_ID, CMD_PUBLISH);
}
@@ -119,11 +122,11 @@ public void test_import_content_with_valid_params() throws IOException, DotDataE
*/
@Test
public void test_import_content_validate_with_valid_params() throws IOException, DotDataException {
- ContentImportForm form = createContentImportForm(contentType.name(), String.valueOf(defaultLanguage.getId()), WORKFLOW_PUBLISH_ACTION_ID, List.of("title"));
+ ContentImportForm form = createContentImportForm(contentType.name(), String.valueOf(defaultLanguage.getId()), WORKFLOW_PUBLISH_ACTION_ID, List.of(fieldId));
ContentImportParams params = createContentImportParams(csvFile, form);
Response importContentResponse = importResource.validateContentImport(request, response, params);
- validateSuccessfulResponse(importContentResponse, contentType.name(), String.valueOf(defaultLanguage.getId()), List.of("title"), WORKFLOW_PUBLISH_ACTION_ID, CMD_PREVIEW);
+ validateSuccessfulResponse(importContentResponse, contentType.name(), String.valueOf(defaultLanguage.getId()), List.of(fieldId), WORKFLOW_PUBLISH_ACTION_ID, CMD_PREVIEW);
}
/**
@@ -136,11 +139,11 @@ public void test_import_content_validate_with_valid_params() throws IOException,
*/
@Test
public void test_import_content_with_language_iso_code() throws IOException, DotDataException {
- ContentImportForm form = createContentImportForm(contentType.name(), defaultLanguage.getIsoCode(), WORKFLOW_PUBLISH_ACTION_ID, List.of("title"));
+ ContentImportForm form = createContentImportForm(contentType.name(), defaultLanguage.getIsoCode(), WORKFLOW_PUBLISH_ACTION_ID, List.of(fieldId));
ContentImportParams params = createContentImportParams(csvFile, form);
Response importContentResponse = importResource.importContent(request, response, params);
- validateSuccessfulResponse(importContentResponse, contentType.name(), defaultLanguage.getIsoCode(), List.of("title"), WORKFLOW_PUBLISH_ACTION_ID, CMD_PUBLISH);
+ validateSuccessfulResponse(importContentResponse, contentType.name(), defaultLanguage.getIsoCode(), List.of(fieldId), WORKFLOW_PUBLISH_ACTION_ID, CMD_PUBLISH);
}
@@ -154,11 +157,11 @@ public void test_import_content_with_language_iso_code() throws IOException, Dot
*/
@Test
public void test_import_content__validate_with_language_iso_code() throws IOException, DotDataException {
- ContentImportForm form = createContentImportForm(contentType.name(), defaultLanguage.getIsoCode(), WORKFLOW_PUBLISH_ACTION_ID, List.of("title"));
+ ContentImportForm form = createContentImportForm(contentType.name(), defaultLanguage.getIsoCode(), WORKFLOW_PUBLISH_ACTION_ID, List.of(fieldId));
ContentImportParams params = createContentImportParams(csvFile, form);
Response importContentResponse = importResource.validateContentImport(request, response, params);
- validateSuccessfulResponse(importContentResponse, contentType.name(), defaultLanguage.getIsoCode(), List.of("title"), WORKFLOW_PUBLISH_ACTION_ID, CMD_PREVIEW);
+ validateSuccessfulResponse(importContentResponse, contentType.name(), defaultLanguage.getIsoCode(), List.of(fieldId), WORKFLOW_PUBLISH_ACTION_ID, CMD_PREVIEW);
}
/**
From d0bc5680674b8a44eb42de5c4df3f1ceff41ea78 Mon Sep 17 00:00:00 2001
From: valentinogiardino
Date: Tue, 3 Dec 2024 18:13:28 -0300
Subject: [PATCH 3/4] #30669 Update ContentImportResource postman tests
---
...tentImportResource.postman_collection.json | 27 +++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/dotcms-postman/src/main/resources/postman/ContentImportResource.postman_collection.json b/dotcms-postman/src/main/resources/postman/ContentImportResource.postman_collection.json
index 25cebbf18a26..45d5294c190c 100644
--- a/dotcms-postman/src/main/resources/postman/ContentImportResource.postman_collection.json
+++ b/dotcms-postman/src/main/resources/postman/ContentImportResource.postman_collection.json
@@ -11,7 +11,30 @@
"name": "pre-execution-scripts",
"item": [
{
- "name": "Create ContentType Copy",
+ "name": "Create ContentType",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "exec": [
+ "var jsonData = pm.response.json();",
+ "",
+ "pm.test(\"Status code should be ok 200\", function () {",
+ " pm.response.to.have.status(200);",
+ "});",
+ "",
+ "pm.test(\"fields check\", function () {",
+ " pm.expect(jsonData.entity[0].fields.length).to.eql(8);",
+ " pm.expect(jsonData.entity[0].fields[3].variable).to.eql('title');",
+ " pm.collectionVariables.set(\"fields\", JSON.stringify([jsonData.entity[0].fields[3].id]))",
+ "});",
+ ""
+ ],
+ "type": "text/javascript",
+ "packages": {}
+ }
+ }
+ ],
"request": {
"method": "POST",
"header": [],
@@ -1913,7 +1936,7 @@
},
{
"key": "fields",
- "value": "[\"title\"]",
+ "value": "",
"type": "string"
}
]
From e4e55bae97025f4c1e8d83e041c413d1d74c3d84 Mon Sep 17 00:00:00 2001
From: valentinogiardino
Date: Tue, 3 Dec 2024 18:24:39 -0300
Subject: [PATCH 4/4] #30669 update variable names
---
.../processor/impl/ImportContentletsProcessor.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java b/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
index 3f07cc6e3bf9..12d1a8b70fde 100644
--- a/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
+++ b/dotCMS/src/main/java/com/dotcms/jobs/business/processor/impl/ImportContentletsProcessor.java
@@ -223,15 +223,15 @@ && getWorkflowActionId(parameters).isEmpty()) {
* {@link JobValidationException} is thrown.
*
* @param parameters The job parameters containing the fields to validate
- * @param contentTypeFound The content type to validate the fields against
+ * @param contentType The content type to validate the fields against
* @throws JobValidationException if any field specified in the parameters is not found in the content type
*/
- private void validateFields(final Map parameters, final ContentType contentTypeFound) {
- var fields = contentTypeFound.fields();
- for (String field : getFields(parameters)) {
- if (fields.stream().noneMatch(f -> Objects.equals(f.id(), field))) {
+ private void validateFields(final Map parameters, final ContentType contentType) {
+ var contentTypeFields = contentType.fields();
+ for (String providedField : getFields(parameters)) {
+ if (contentTypeFields.stream().noneMatch(field -> Objects.equals(field.id(), providedField))) {
final var errorMessage = String.format(
- "Field [%s] not found in Content Type [%s].", field, contentTypeFound.variable()
+ "Field [%s] not found in Content Type [%s].", providedField, contentType.variable()
);
Logger.error(this, errorMessage);
throw new JobValidationException(errorMessage);