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..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.variable(), 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); 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; 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); } /** 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" } ]