Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content-import-job) fix key fields #30843

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ && getWorkflowActionId(parameters).isEmpty()) {
* {@link JobValidationException} is thrown.</p>
*
* @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<String, Object> 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<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ContentImportResourceIntegrationTest extends Junit5WeldBaseTest {

private static File csvFile;
private static ContentType contentType;
private static String fieldId;

@Inject
ContentImportHelper contentImportHelper;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}


Expand All @@ -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);
}

/**
Expand All @@ -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);
}


Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -1913,7 +1936,7 @@
},
{
"key": "fields",
"value": "[\"title\"]",
"value": "",
"type": "string"
}
]
Expand Down
Loading