Package io.jmix.dataimport.configuration
Class ImportConfigurationBuilder
java.lang.Object
io.jmix.dataimport.configuration.ImportConfigurationBuilder
Builds an instance of
ImportConfiguration
using the following parameters:
- Entity class (required): class of entity that will be imported using created import configuration
- 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
- 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
.
-
Constructor Summary
ModifierConstructorDescriptionprotected
ImportConfigurationBuilder
(Class entityClass, String inputDataFormat) -
Method Summary
Modifier and TypeMethodDescriptionaddCustomPropertyMapping
(String entityPropertyName, Function<CustomMappingContext, Object> customValueFunction) Adds a custom mapping for property.addPropertyMapping
(PropertyMapping propertyMapping) Adds specified property mapping.addReferencePropertyMapping
(String entityPropertyName, String dataFieldName, String lookupPropertyName, ReferenceImportPolicy policy) Creates and adds a property mapping for the reference property mapped by one data field.addSimplePropertyMapping
(String entityPropertyName, String dataFieldName) Adds a mapping for specified simple property.addUniqueEntityConfiguration
(DuplicateEntityPolicy policy, String... entityPropertyNames) Creates and adds aUniqueEntityConfiguration
.addUniqueEntityConfiguration
(DuplicateEntityPolicy policy, List<String> entityPropertyNames) Creates and adds aUniqueEntityConfiguration
.build()
Creates an instance ofImportConfiguration
based on the specified parameters.withBooleanFormats
(String booleanTrueValue, String booleanFalseValue) Sets the strings for boolean true and false values.withDateFormat
(String dateFormat) Sets a date format.withEntityInitializer
(Consumer<Object> entityInitializer) Sets a consumer that makes additional changes with entity before import.withImportBatchSize
(int importBatchSize) Sets a number of entities that will be imported in one batch.withInputDataCharset
(String inputDataCharset) Sets a charset of input data.withPreImportPredicate
(Predicate<EntityExtractionResult> preImportPredicate) Sets a predicate that is executed for each created entity before import.withTransactionStrategy
(ImportTransactionStrategy transactionStrategy) Sets a transaction strategy.
-
Constructor Details
-
ImportConfigurationBuilder
-
-
Method Details
-
withInputDataCharset
Sets a charset of input data.- Parameters:
inputDataCharset
- charset of input data.- Returns:
- current instance of builder
-
addSimplePropertyMapping
public ImportConfigurationBuilder addSimplePropertyMapping(String entityPropertyName, String dataFieldName) Adds a mapping for specified simple property.- Parameters:
entityPropertyName
- entity property namedataFieldName
- name of the field from input data that contains a raw value of property- Returns:
- current instance of builder
-
addCustomPropertyMapping
public ImportConfigurationBuilder addCustomPropertyMapping(String entityPropertyName, Function<CustomMappingContext, Object> customValueFunction) Adds a custom mapping for property.- Parameters:
entityPropertyName
- entity property namecustomValueFunction
- function to get value for the- Returns:
- current instance of builder
-
addUniqueEntityConfiguration
public ImportConfigurationBuilder addUniqueEntityConfiguration(DuplicateEntityPolicy policy, String... entityPropertyNames) Creates and adds aUniqueEntityConfiguration
.- Parameters:
policy
- policy which be applied for found duplicatesentityPropertyNames
- names of the entity properties by which values the duplicates will be searched- Returns:
- current instance of builder
-
addUniqueEntityConfiguration
public ImportConfigurationBuilder addUniqueEntityConfiguration(DuplicateEntityPolicy policy, List<String> entityPropertyNames) Creates and adds aUniqueEntityConfiguration
.- Parameters:
policy
- policy which be applied for found duplicatesentityPropertyNames
- names of the entity properties by which values the duplicates will be searched- Returns:
- current instance of builder
-
withTransactionStrategy
public ImportConfigurationBuilder withTransactionStrategy(ImportTransactionStrategy transactionStrategy) Sets a transaction strategy.- Parameters:
transactionStrategy
- transaction strategy- Returns:
- current instance of builder
-
withImportBatchSize
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 builder
-
addReferencePropertyMapping
public ImportConfigurationBuilder addReferencePropertyMapping(String entityPropertyName, String dataFieldName, String lookupPropertyName, ReferenceImportPolicy policy) Creates and adds a property mapping for the reference property mapped by one data field.- Parameters:
entityPropertyName
- reference property namedataFieldName
- name of the field from input data that contains a raw value of lookup propertylookupPropertyName
- property name from the reference entitypolicy
- reference import policy- Returns:
- current instance of builder
- See Also:
-
addPropertyMapping
Adds specified property mapping. Property mapping can be:- Parameters:
propertyMapping
- property mapping- Returns:
- current instance of builder
- See Also:
-
withDateFormat
Sets a date format.- Parameters:
dateFormat
- date format used in the input data- Returns:
- current instance of builder
-
withBooleanFormats
public ImportConfigurationBuilder withBooleanFormats(String booleanTrueValue, String booleanFalseValue) Sets the strings for boolean true and false values.- Parameters:
booleanTrueValue
- string that represents boolean true valuebooleanFalseValue
- string that represents boolean false value- Returns:
- current instance of builder
-
withPreImportPredicate
public ImportConfigurationBuilder withPreImportPredicate(Predicate<EntityExtractionResult> preImportPredicate) Sets a predicate that is executed for each created entity before import. If the predicate returns false, the entity is not imported.- Parameters:
preImportPredicate
- pre-import predicate- Returns:
- current instance of builder
-
withEntityInitializer
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 builder
-
build
Creates an instance ofImportConfiguration
based on the specified parameters.- Returns:
- created instance of
ImportConfiguration
-