mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-14 19:41:50 +00:00
* Fix #10164: Check any name voilations during the import dryrun * Fix test * fix test * Fix checkstyle
This commit is contained in:
parent
8e52c9bd24
commit
a60af7c019
@ -341,15 +341,15 @@ public abstract class EntityCsv<T extends EntityInterface> {
|
|||||||
entity.setUpdatedAt(System.currentTimeMillis());
|
entity.setUpdatedAt(System.currentTimeMillis());
|
||||||
EntityRepository<T> repository = (EntityRepository<T>) Entity.getEntityRepository(entityType);
|
EntityRepository<T> repository = (EntityRepository<T>) Entity.getEntityRepository(entityType);
|
||||||
Response.Status responseStatus;
|
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())) {
|
if (Boolean.FALSE.equals(importResult.getDryRun())) {
|
||||||
try {
|
try {
|
||||||
repository.prepareInternal(entity);
|
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<T> response = repository.createOrUpdate(null, entity);
|
PutResponse<T> response = repository.createOrUpdate(null, entity);
|
||||||
responseStatus = response.getStatus();
|
responseStatus = response.getStatus();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -2,7 +2,6 @@ package org.openmetadata.csv;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
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.common.utils.CommonUtil.nullOrEmpty;
|
||||||
import static org.openmetadata.csv.CsvUtil.LINE_SEPARATOR;
|
import static org.openmetadata.csv.CsvUtil.LINE_SEPARATOR;
|
||||||
import static org.openmetadata.csv.CsvUtil.recordToString;
|
import static org.openmetadata.csv.CsvUtil.recordToString;
|
||||||
@ -62,27 +61,6 @@ public class EntityCsvTest {
|
|||||||
assertEquals(TestCsv.invalidHeader("h1*,h2,h3", ",h2,h3"), importResult.getAbortReason());
|
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<String> 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(
|
public static void assertSummary(
|
||||||
CsvImportResult importResult,
|
CsvImportResult importResult,
|
||||||
Status expectedStatus,
|
Status expectedStatus,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user