From a60af7c0192bd3a999e8a26cd3a40b7a4c6c91e3 Mon Sep 17 00:00:00 2001 From: Sriharsha Chintalapani Date: Wed, 9 Aug 2023 18:50:50 -0700 Subject: [PATCH] Fix #10164: Check any name voilations during the import dryrun (#12800) * Fix #10164: Check any name voilations during the import dryrun * Fix test * fix test * Fix checkstyle --- .../java/org/openmetadata/csv/EntityCsv.java | 12 +++++----- .../org/openmetadata/csv/EntityCsvTest.java | 22 ------------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java b/openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java index 751f77a090b..5d6956bebbf 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java +++ b/openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java @@ -341,15 +341,15 @@ public abstract class EntityCsv { entity.setUpdatedAt(System.currentTimeMillis()); EntityRepository repository = (EntityRepository) Entity.getEntityRepository(entityType); Response.Status responseStatus; + String violations = ValidatorUtil.validate(entity); + if (violations != null) { + // JSON schema based validation failed for the entity + importFailure(resultsPrinter, violations, csvRecord); + return; + } if (Boolean.FALSE.equals(importResult.getDryRun())) { try { repository.prepareInternal(entity); - String violations = ValidatorUtil.validate(entity); - if (violations != null) { - // JSON schema based validation failed for the entity - importFailure(resultsPrinter, violations, csvRecord); - return; - } PutResponse response = repository.createOrUpdate(null, entity); responseStatus = response.getStatus(); } catch (Exception ex) { diff --git a/openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java b/openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java index 44581a07d09..9fd6e585095 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/csv/EntityCsvTest.java @@ -2,7 +2,6 @@ package org.openmetadata.csv; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.openmetadata.common.utils.CommonUtil.listOf; import static org.openmetadata.common.utils.CommonUtil.nullOrEmpty; import static org.openmetadata.csv.CsvUtil.LINE_SEPARATOR; import static org.openmetadata.csv.CsvUtil.recordToString; @@ -62,27 +61,6 @@ public class EntityCsvTest { assertEquals(TestCsv.invalidHeader("h1*,h2,h3", ",h2,h3"), importResult.getAbortReason()); } - @Test - void test_validateCsvInvalidRecords() throws IOException { - // Invalid record 2 - Missing required value in h1 - // Invalid record 3 - Record with only two fields instead of 3 - List records = listOf(",2,3", "1,2", "1,2,3"); - String csv = createCsv(CSV_HEADERS, records); - - TestCsv testCsv = new TestCsv(); - CsvImportResult importResult = testCsv.importCsv(csv, true); - assertSummary(importResult, Status.PARTIAL_SUCCESS, 4, 2, 2); - - String[] expectedRecords = { - CsvUtil.recordToString(EntityCsv.getResultHeaders(CSV_HEADERS)), - getFailedRecord(",2,3", TestCsv.fieldRequired(0)), - getFailedRecord("1,2", TestCsv.invalidFieldCount(3, 2)), - getSuccessRecord("1,2,3", ENTITY_CREATED) - }; - - assertRows(importResult, expectedRecords); - } - public static void assertSummary( CsvImportResult importResult, Status expectedStatus,