Package io.jmix.dataimport.configuration
Class ImportConfiguration
java.lang.Object
io.jmix.dataimport.configuration.ImportConfiguration
An object that allows configuring import process of entities from JSON, XML, CSV, XLSX.
For that, there are the following options in the import configuration:
Import configuration can be created by constructor or by
Creation examples:
- Entity class (required): class of the entity that should be imported.
- Input data format (required): xlsx, csv, json or xml.
- Property mappings: list of
PropertyMapping
. - Transaction strategy:
ImportTransactionStrategy
. By default, each entity is imported in the separate transaction. - Import batch size: number of entities that will imported in one batch if
ImportTransactionStrategy.TRANSACTION_PER_BATCH
is used. By default, 100. - Date format: date format used in the input data.
- Custom formats of boolean true and false values.
- Pre-import predicate: a predicate that is executed for each extracted entity before import. If the predicate returns false, the entity won't be imported.
- Entity initializer: a consumer that is executed after pre-import check and allows to make additional changes with extracted entity before import.
- Input data charset: this parameter is required if CSV is input data format. Default value: UTF-8.
- Unique entity configurations: list of
UniqueEntityConfiguration
.
Import configuration can be created by constructor or by
ImportConfigurationBuilder
.
Creation examples:
ImportConfiguration importConfiguration = ImportConfiguration.builder(Order.class, InputDataFormat.CSV) .addSimplePropertyMapping("orderNumber", "Order Num") .addSimplePropertyMapping("date", "Order Date") .addSimplePropertyMapping("amount", "Order Amount") .addPropertyMapping(ReferenceMultiFieldPropertyMapping.builder("customer", ReferenceImportPolicy.CREATE_IF_MISSING) .addSimplePropertyMapping("name", "Customer Name") .addSimplePropertyMapping("email", "Customer Email") .lookupByAllSimpleProperties() .build()) .withDateFormat("dd/MM/yyyy HH:mm") .withTransactionStrategy(ImportTransactionStrategy.SINGLE_TRANSACTION) .build(); ImportConfiguration importConfiguration = ImportConfiguration.builder(Customer.class, InputDataFormat.JSON) .addSimplePropertyMapping("name", "name") .addSimplePropertyMapping("email", "email") .addReferencePropertyMapping("bonusCard", "bonusCardNumber", "cardNumber", ReferenceImportPolicy.IGNORE_IF_MISSING) .addUniqueEntityConfiguration(DuplicateEntityPolicy.ABORT, "name", "email") .build(); ImportConfiguration importConfiguration = ImportConfiguration.builder(Customer.class, InputDataFormat.XML) .addSimplePropertyMapping("name", "name") .addSimplePropertyMapping("email", "email") .withTransactionStrategy(ImportTransactionStrategy.TRANSACTION_PER_BATCH) .withImportBatchSize(50) .build();
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected String
protected String
protected Class
protected int
protected String
protected String
protected Predicate<EntityExtractionResult>
protected List<PropertyMapping>
protected ImportTransactionStrategy
protected List<UniqueEntityConfiguration>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddPropertyMapping
(PropertyMapping propertyMapping) Adds a property mapping.addUniqueEntityConfiguration
(UniqueEntityConfiguration uniqueEntityConfiguration) Adds a unique entity configuration.static ImportConfigurationBuilder
Creates an instance ofImportConfigurationBuilder
for the specified entity class and import configuration code.Gets a format of boolean false value.Gets a format of boolean true value.Gets a date format.Gets a class of entity to import.Gets a consumer that makes additional changes with entity before import.int
Gets a number of entities that will be imported in one batch.Gets a charset of input data.Gets an input data format.Gets a predicate executed before entity import.Gets mappings for entity properties.Gets an import transaction strategy.Gets a list of unique entity configurations.setBooleanFalseValue
(String booleanFalseValue) Sets a format of boolean false value.setBooleanTrueValue
(String booleanTrueValue) Sets a format of boolean true value.setDateFormat
(String dateFormat) Sets a date format to parse date strings.setEntityInitializer
(Consumer<Object> entityInitializer) Sets a consumer that makes additional changes with entity before import.setImportBatchSize
(int importBatchSize) Sets a number of entities that will be imported in one batch.setInputDataCharset
(String inputDataCharset) Sets a charset of input data.setPreImportPredicate
(Predicate<EntityExtractionResult> preImportPredicate) Sets a predicate executed before entity import.setPropertyMappings
(List<PropertyMapping> propertyMappings) Sets mappings for entity properties.setTransactionStrategy
(ImportTransactionStrategy transactionStrategy) Sets an import transaction strategy.setUniqueEntityConfigurations
(List<UniqueEntityConfiguration> uniqueEntityConfigurations) Sets a list of unique entity configurations.
-
Field Details
-
entityClass
-
propertyMappings
-
transactionStrategy
-
importBatchSize
protected int importBatchSize -
inputDataFormat
-
dateFormat
-
booleanTrueValue
-
booleanFalseValue
-
inputDataCharset
-
uniqueEntityConfigurations
-
preImportPredicate
-
entityInitializer
-
-
Constructor Details
-
ImportConfiguration
-
-
Method Details
-
getPropertyMappings
Gets mappings for entity properties.- Returns:
- property mappings
-
setPropertyMappings
Sets mappings for entity properties.- Parameters:
propertyMappings
- property mappings- Returns:
- current instance of import configuration
-
addPropertyMapping
Adds a property mapping.- Parameters:
propertyMapping
- property mapping- Returns:
- current instance of import configuration
-
getTransactionStrategy
Gets an import transaction strategy.- Returns:
- transaction strategy
-
setTransactionStrategy
Sets an import transaction strategy.- Parameters:
transactionStrategy
- transaction strategy- Returns:
- current instance of import configuration
-
getImportBatchSize
public int getImportBatchSize()Gets a number of entities that will be imported in one batch.- Returns:
- number of entities that will be imported in one batch
-
setImportBatchSize
Sets a number of entities that will be imported in one batch.
Note: it is actual ifImportTransactionStrategy.TRANSACTION_PER_BATCH
is used.- Parameters:
importBatchSize
- number of entities that will be imported in one batch.- Returns:
- current instance of import configuration
-
getEntityClass
Gets a class of entity to import.- Returns:
- class of entity to import
-
getInputDataFormat
Gets an input data format.- Returns:
- input data format
-
getInputDataCharset
Gets a charset of input data.- Returns:
- charset of input data
-
setInputDataCharset
Sets a charset of input data.- Parameters:
inputDataCharset
- charset of input data- Returns:
- current instance of import configuration
-
getUniqueEntityConfigurations
Gets a list of unique entity configurations.- Returns:
- list of
UniqueEntityConfiguration
-
setUniqueEntityConfigurations
public ImportConfiguration setUniqueEntityConfigurations(List<UniqueEntityConfiguration> uniqueEntityConfigurations) Sets a list of unique entity configurations.- Parameters:
uniqueEntityConfigurations
- list of configurations for unique entity.- Returns:
- current instance of import configuration
-
addUniqueEntityConfiguration
public ImportConfiguration addUniqueEntityConfiguration(UniqueEntityConfiguration uniqueEntityConfiguration) Adds a unique entity configuration.- Parameters:
uniqueEntityConfiguration
- unique entity configuration- Returns:
- current instance of import configuration
-
getDateFormat
Gets a date format.- Returns:
- date format
-
setDateFormat
Sets a date format to parse date strings.- Parameters:
dateFormat
- date format used in input data- Returns:
- current instance of import configuration
-
getBooleanTrueValue
Gets a format of boolean true value.- Returns:
- format of boolean true value
-
setBooleanTrueValue
Sets a format of boolean true value.- Parameters:
booleanTrueValue
- format of boolean true value- Returns:
- current instance of import configuration
-
getBooleanFalseValue
Gets a format of boolean false value.- Returns:
- format of boolean false value
-
setBooleanFalseValue
Sets a format of boolean false value.- Parameters:
booleanFalseValue
- format of boolean false value- Returns:
- current instance of import configuration
-
getPreImportPredicate
Gets a predicate executed before entity import.- Returns:
- predicate executed before entity import
-
setPreImportPredicate
public ImportConfiguration setPreImportPredicate(Predicate<EntityExtractionResult> preImportPredicate) Sets a predicate executed before entity import.- Parameters:
preImportPredicate
- predicate executed before entity import- Returns:
- current instance of import configuration
-
getEntityInitializer
Gets a consumer that makes additional changes with entity before import.- Returns:
- consumer that makes additional changes with entity before import
-
setEntityInitializer
Sets a consumer that makes additional changes with entity before import.- Parameters:
entityInitializer
- consumer that makes additional changes with entity before import- Returns:
- current instance of import configuration
-
builder
Creates an instance ofImportConfigurationBuilder
for the specified entity class and import configuration code.- Parameters:
entityClass
- entity classinputDataFormat
- input data format- Returns:
- new instance of
ImportConfigurationBuilder
-