Class ImportConfiguration

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

public class ImportConfiguration extends Object
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:
  1. Entity class (required): class of the entity that should be imported.
  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: date format used in the input data.
  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.

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 Details

  • Constructor Details

    • ImportConfiguration

      public ImportConfiguration(Class entityClass, String inputDataFormat)
  • Method Details

    • getPropertyMappings

      public List<PropertyMapping> getPropertyMappings()
      Gets mappings for entity properties.
      Returns:
      property mappings
    • setPropertyMappings

      public ImportConfiguration setPropertyMappings(List<PropertyMapping> propertyMappings)
      Sets mappings for entity properties.
      Parameters:
      propertyMappings - property mappings
      Returns:
      current instance of import configuration
    • addPropertyMapping

      public ImportConfiguration addPropertyMapping(PropertyMapping propertyMapping)
      Adds a property mapping.
      Parameters:
      propertyMapping - property mapping
      Returns:
      current instance of import configuration
    • getTransactionStrategy

      public ImportTransactionStrategy getTransactionStrategy()
      Gets an import transaction strategy.
      Returns:
      transaction strategy
    • setTransactionStrategy

      public ImportConfiguration setTransactionStrategy(ImportTransactionStrategy transactionStrategy)
      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

      public ImportConfiguration setImportBatchSize(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 import configuration
    • getEntityClass

      public Class getEntityClass()
      Gets a class of entity to import.
      Returns:
      class of entity to import
    • getInputDataFormat

      public String getInputDataFormat()
      Gets an input data format.
      Returns:
      input data format
    • getInputDataCharset

      public String getInputDataCharset()
      Gets a charset of input data.
      Returns:
      charset of input data
    • setInputDataCharset

      public ImportConfiguration setInputDataCharset(String inputDataCharset)
      Sets a charset of input data.
      Parameters:
      inputDataCharset - charset of input data
      Returns:
      current instance of import configuration
    • getUniqueEntityConfigurations

      public List<UniqueEntityConfiguration> 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

      public String getDateFormat()
      Gets a date format.
      Returns:
      date format
    • setDateFormat

      public ImportConfiguration setDateFormat(String dateFormat)
      Sets a date format to parse date strings.
      Parameters:
      dateFormat - date format used in input data
      Returns:
      current instance of import configuration
    • getBooleanTrueValue

      public String getBooleanTrueValue()
      Gets a format of boolean true value.
      Returns:
      format of boolean true value
    • setBooleanTrueValue

      public ImportConfiguration setBooleanTrueValue(String booleanTrueValue)
      Sets a format of boolean true value.
      Parameters:
      booleanTrueValue - format of boolean true value
      Returns:
      current instance of import configuration
    • getBooleanFalseValue

      public String getBooleanFalseValue()
      Gets a format of boolean false value.
      Returns:
      format of boolean false value
    • setBooleanFalseValue

      public ImportConfiguration setBooleanFalseValue(String booleanFalseValue)
      Sets a format of boolean false value.
      Parameters:
      booleanFalseValue - format of boolean false value
      Returns:
      current instance of import configuration
    • getPreImportPredicate

      public Predicate<EntityExtractionResult> 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

      public Consumer<Object> getEntityInitializer()
      Gets a consumer that makes additional changes with entity before import.
      Returns:
      consumer that makes additional changes with entity before import
    • setEntityInitializer

      public ImportConfiguration setEntityInitializer(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 import configuration
    • builder

      public static ImportConfigurationBuilder builder(Class entityClass, String inputDataFormat)
      Creates an instance of ImportConfigurationBuilder for the specified entity class and import configuration code.
      Parameters:
      entityClass - entity class
      inputDataFormat - input data format
      Returns:
      new instance of ImportConfigurationBuilder