Class ImportConfigurationBuilder

java.lang.Object
io.jmix.dataimport.configuration.ImportConfigurationBuilder

public class ImportConfigurationBuilder extends Object
Builds an instance of ImportConfiguration using the following parameters:
  1. Entity class (required): class of entity that will be imported using created import configuration
  2. Input data format (required): xlsx, csv, json or xml.
  3. Property mappings: list of PropertyMapping
  4. Transaction strategy: ImportTransactionStrategy. By default, each entity is imported in the separate transaction.
  5. Import batch size: number of entities that will imported in one batch if ImportTransactionStrategy.TRANSACTION_PER_BATCH is used. By default, 100.
  6. Date format
  7. Custom formats of boolean true and false values
  8. 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.
  9. Entity initializer: a consumer that is executed after pre-import check and allows to make additional changes with extracted entity before import.
  10. Input data charset: this parameter is required if CSV is input data format. Default value: UTF-8
  11. Unique entity configurations: list of UniqueEntityConfiguration.
  • Constructor Details

    • ImportConfigurationBuilder

      protected ImportConfigurationBuilder(Class entityClass, String inputDataFormat)
  • Method Details

    • withInputDataCharset

      public ImportConfigurationBuilder withInputDataCharset(String inputDataCharset)
      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 name
      dataFieldName - 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 name
      customValueFunction - function to get value for the
      Returns:
      current instance of builder
    • addUniqueEntityConfiguration

      public ImportConfigurationBuilder addUniqueEntityConfiguration(DuplicateEntityPolicy policy, String... entityPropertyNames)
      Creates and adds a UniqueEntityConfiguration.
      Parameters:
      policy - policy which be applied for found duplicates
      entityPropertyNames - 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 a UniqueEntityConfiguration.
      Parameters:
      policy - policy which be applied for found duplicates
      entityPropertyNames - 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

      public ImportConfigurationBuilder withImportBatchSize(int importBatchSize)
      Sets a number of entities that will be imported in one batch.
      Note: it is actual if ImportTransactionStrategy.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 name
      dataFieldName - name of the field from input data that contains a raw value of lookup property
      lookupPropertyName - property name from the reference entity
      policy - reference import policy
      Returns:
      current instance of builder
      See Also:
    • addPropertyMapping

      public ImportConfigurationBuilder addPropertyMapping(PropertyMapping propertyMapping)
      Parameters:
      propertyMapping - property mapping
      Returns:
      current instance of builder
      See Also:
    • withDateFormat

      public ImportConfigurationBuilder withDateFormat(String dateFormat)
      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 value
      booleanFalseValue - 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

      public ImportConfigurationBuilder withEntityInitializer(Consumer<Object> entityInitializer)
      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

      public ImportConfiguration build()
      Creates an instance of ImportConfiguration based on the specified parameters.
      Returns:
      created instance of ImportConfiguration