Package org.openmetadata.csv
Class EntityCsv<T extends EntityInterface>
- java.lang.Object
-
- org.openmetadata.csv.EntityCsv<T>
-
- Direct Known Subclasses:
GlossaryRepository.GlossaryCsv,TeamRepository.TeamCsv,UserRepository.UserCsv
public abstract class EntityCsv<T extends EntityInterface> extends Object
EntityCsv provides export and import capabilities for an entity. Each entity must implement the abstract methods to provide entity specific processing functionality to export an entity to a CSV record, and import an entity from a CSV record.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,T>dryRunCreatedEntitiesstatic StringENTITY_CREATEDstatic StringENTITY_UPDATEDstatic StringFIELD_ERROR_MSGstatic StringIMPORT_STATUS_DETAILSstatic StringIMPORT_STATUS_FAILEDstatic StringIMPORT_STATUS_HEADERstatic StringIMPORT_STATUS_SUCCESSprotected booleanprocessRecord
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static StringentityNotFound(int field, String fqn)StringexportCsv(List<T> entities)Stringfailed(String exception, CsvErrorType errorType)static StringfieldRequired(int field)protected BooleangetBoolean(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber)static CsvDocumentationgetCsvDocumentation(String entityType)protected EntityInterfacegetEntityByName(String entityType, String fqn)protected EntityReferencegetEntityReference(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType)protected EntityReferencegetEntityReference(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType, String fqn)protected List<EntityReference>getEntityReferences(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType)EntityReferencegetOwner(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber)Owner field is in entityType;entityName formatEntityReferencegetOwnerAsUser(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber)Owner field is in entityName formatstatic String[]getResultHeaders(List<CsvHeader> csvHeaders)protected List<TagLabel>getTagLabels(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber)protected List<EntityReference>getUserOrTeamEntityReferences(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType)CsvImportResultimportCsv(String csv, boolean dryRun)Import entities from a CSV fileprotected voidimportFailure(org.apache.commons.csv.CSVPrinter printer, String failedReason, org.apache.commons.csv.CSVRecord inputRecord)static StringinvalidBoolean(int field, String fieldValue)static StringinvalidField(int field, String error)static StringinvalidFieldCount(int expectedFieldCount, int actualFieldCount)static StringinvalidHeader(String expected, String actual)static StringinvalidOwner(int field)protected abstract TtoEntity(org.apache.commons.csv.CSVPrinter resultsPrinter, org.apache.commons.csv.CSVRecord csvRecord)Implement this method to a CSV record and turn it into an entityprotected abstract List<String>toRecord(T entity)Implement this method to export an entity into a list of fields to create a CSV record
-
-
-
Field Detail
-
FIELD_ERROR_MSG
public static final String FIELD_ERROR_MSG
- See Also:
- Constant Field Values
-
IMPORT_STATUS_HEADER
public static final String IMPORT_STATUS_HEADER
- See Also:
- Constant Field Values
-
IMPORT_STATUS_DETAILS
public static final String IMPORT_STATUS_DETAILS
- See Also:
- Constant Field Values
-
IMPORT_STATUS_SUCCESS
public static final String IMPORT_STATUS_SUCCESS
- See Also:
- Constant Field Values
-
IMPORT_STATUS_FAILED
public static final String IMPORT_STATUS_FAILED
- See Also:
- Constant Field Values
-
ENTITY_CREATED
public static final String ENTITY_CREATED
- See Also:
- Constant Field Values
-
ENTITY_UPDATED
public static final String ENTITY_UPDATED
- See Also:
- Constant Field Values
-
processRecord
protected boolean processRecord
-
dryRunCreatedEntities
protected final Map<String,T extends EntityInterface> dryRunCreatedEntities
-
-
Method Detail
-
importCsv
public final CsvImportResult importCsv(String csv, boolean dryRun) throws IOException
Import entities from a CSV file- Throws:
IOException
-
toEntity
protected abstract T toEntity(org.apache.commons.csv.CSVPrinter resultsPrinter, org.apache.commons.csv.CSVRecord csvRecord) throws IOException
Implement this method to a CSV record and turn it into an entity- Throws:
IOException
-
exportCsv
public final String exportCsv(List<T> entities) throws IOException
- Throws:
IOException
-
getCsvDocumentation
public static CsvDocumentation getCsvDocumentation(String entityType)
-
toRecord
protected abstract List<String> toRecord(T entity)
Implement this method to export an entity into a list of fields to create a CSV record
-
getOwner
public EntityReference getOwner(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber) throws IOException
Owner field is in entityType;entityName format- Throws:
IOException
-
getOwnerAsUser
public EntityReference getOwnerAsUser(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber) throws IOException
Owner field is in entityName format- Throws:
IOException
-
getBoolean
protected final Boolean getBoolean(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber) throws IOException
- Throws:
IOException
-
getEntityReference
protected final EntityReference getEntityReference(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType) throws IOException
- Throws:
IOException
-
getEntityByName
protected EntityInterface getEntityByName(String entityType, String fqn)
-
getEntityReference
protected final EntityReference getEntityReference(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType, String fqn) throws IOException
- Throws:
IOException
-
getEntityReferences
protected final List<EntityReference> getEntityReferences(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType) throws IOException
- Throws:
IOException
-
getUserOrTeamEntityReferences
protected final List<EntityReference> getUserOrTeamEntityReferences(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber, String entityType) throws IOException
- Throws:
IOException
-
getTagLabels
protected final List<TagLabel> getTagLabels(org.apache.commons.csv.CSVPrinter printer, org.apache.commons.csv.CSVRecord csvRecord, int fieldNumber) throws IOException
- Throws:
IOException
-
failed
public String failed(String exception, CsvErrorType errorType)
-
invalidFieldCount
public static String invalidFieldCount(int expectedFieldCount, int actualFieldCount)
-
fieldRequired
public static String fieldRequired(int field)
-
invalidOwner
public static String invalidOwner(int field)
-
importFailure
protected void importFailure(org.apache.commons.csv.CSVPrinter printer, String failedReason, org.apache.commons.csv.CSVRecord inputRecord) throws IOException- Throws:
IOException
-
-