Class DefaultExcelImportService

  • All Implemented Interfaces:
    ExcelImportService

    public class DefaultExcelImportService
    extends java.lang.Object
    implements ExcelImportService
    Service responsible for generating Impex based on excel file represented by Workbook object. In order to generating impex script, we can pass the cellValidation of {#importData} to ImpexConverter.convert(Impex).
    • Constructor Detail

      • DefaultExcelImportService

        public DefaultExcelImportService()
    • Method Detail

      • convertToImpex

        public Impex convertToImpex​(org.apache.poi.ss.usermodel.Workbook workbook)
        Transforms excel workbook into Impex object. It takes into account all sheets included in excel file.
        Specified by:
        convertToImpex in interface ExcelImportService
        Parameters:
        workbook - Workbook object which represents excel file
        Returns:
        generated Impex object which represents data from the workbook
      • validate

        public java.util.List<ExcelValidationResult> validate​(org.apache.poi.ss.usermodel.Workbook workbook,
                                                              java.util.Set<java.lang.String> mediaContentEntries)
        Description copied from interface: ExcelImportService
        Validates a workbook.
        Specified by:
        validate in interface ExcelImportService
        Parameters:
        workbook - workbook to validate.
        mediaContentEntries - set of entries names inside media content attached to the excel file. Null if media is not attached.
        Returns:
        list of validation results.
      • validate

        public java.util.List<ExcelValidationResult> validate​(org.apache.poi.ss.usermodel.Workbook workbook,
                                                              java.util.Set<java.lang.String> mediaContentEntries,
                                                              java.util.Map<java.lang.String,​java.lang.Object> context)
        Description copied from interface: ExcelImportService
        Validates a workbook.
        Specified by:
        validate in interface ExcelImportService
        Parameters:
        workbook - workbook to validate.
        mediaContentEntries - set of entries names inside media content attached to the excel file. Null if media is not attached.
        context - context with additional parameters
        Returns:
        list of validation results.
      • validate

        public java.util.List<ExcelValidationResult> validate​(org.apache.poi.ss.usermodel.Workbook workbook)
        Description copied from interface: ExcelImportService
        Validates a workbook.
        Specified by:
        validate in interface ExcelImportService
        Parameters:
        workbook - workbook to validate.
        Returns:
        list of validation results.
      • validateExcelFileOrigin

        protected java.util.Optional<ExcelValidationResult> validateExcelFileOrigin​(org.apache.poi.ss.usermodel.Workbook workbook)
      • validateWorkbook

        protected java.util.List<ExcelValidationResult> validateWorkbook​(org.apache.poi.ss.usermodel.Workbook workbook)
      • populate

        protected ExcelWorkbook populate​(org.apache.poi.ss.usermodel.Workbook workbook)
      • populate

        protected ExcelWorksheet populate​(org.apache.poi.ss.usermodel.Sheet typeSystemSheet,
                                          org.apache.poi.ss.usermodel.Sheet typeSheet)
      • populateRows

        protected void populateRows​(org.apache.poi.ss.usermodel.Sheet typeSheet,
                                    ExcelWorksheet excelWorksheet,
                                    java.util.List<java.lang.String> entriesRef,
                                    SelectedAttribute selectedAttribute,
                                    int columnIndex)
      • hasRowCorrectData

        protected boolean hasRowCorrectData​(org.apache.poi.ss.usermodel.Row row)
      • findFirstNotBlankCell

        protected boolean findFirstNotBlankCell​(org.apache.poi.ss.usermodel.Row row)
      • mergeWithRowValidation

        protected void mergeWithRowValidation​(java.util.Map<java.lang.Integer,​ExcelValidationResult> rowsValidation,
                                              java.lang.Integer rowIndex,
                                              ExcelValidationResult cellValidation)
      • getAttributeDisplayName

        protected java.lang.String getAttributeDisplayName​(SelectedAttribute attribute)
      • generateImpexForSheet

        protected Impex generateImpexForSheet​(org.apache.poi.ss.usermodel.Sheet typeSystemSheet,
                                              org.apache.poi.ss.usermodel.Sheet typeSheet)
        Generates impex for given sheet
        Parameters:
        typeSystemSheet - - sheet contains metainformation about type codes
        typeSheet - - sheet contains data for given type code
        Returns:
        Impex generated impex object
      • insertDocumentReferences

        protected void insertDocumentReferences​(Impex mainImpex,
                                                java.lang.String typeCode,
                                                java.util.List<java.lang.String> entriesRef)
        In order to simplify cross-reference imports, impex allows to use document reference. This method inserts references for each row.
        Parameters:
        mainImpex - Impex - represents impex for currently processing workbook
        typeCode - - type code of currently processing sheet
        entriesRef - - list of generated document references
      • generateDocumentRefs

        protected java.util.List<java.lang.String> generateDocumentRefs​(java.lang.Integer rowsCount)
        In order to simplify cross-reference imports, impex allows to use document reference. The method generates list of random UUIDs for each row of imported excel.
        Parameters:
        rowsCount - - indicates how many document references should be generated.
        Returns:
        list of UUIDs
      • findImportParameters

        protected ImportParameters findImportParameters​(SelectedAttribute selectedAttribute,
                                                        java.lang.String cellValue,
                                                        java.lang.String typeCode,
                                                        java.lang.String entryRef)
        Parses cell's value taking into account reference pattern and default values (which are located in the second and third row). Merges default values if needed.
        Parameters:
        selectedAttribute - SelectedAttribute - Information about selected attribute: its isoCode (for localized values), referencePattern for references and attributeDescriptor
        cellValue - - Original cell's value represented as String
        typeCode - - Type code of current sheet
        Returns:
        ImportParameters Converted import parameters, merged with default values
      • getExcelTemplateService

        @Deprecated(since="1808",
                    forRemoval=true)
        public ExcelTemplateService getExcelTemplateService()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 1808
      • setExcelTemplateService

        @Deprecated(since="1808",
                    forRemoval=true)
        public void setExcelTemplateService​(ExcelTemplateService excelTemplateService)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 1808
      • setExcelTranslatorRegistry

        public void setExcelTranslatorRegistry​(ExcelTranslatorRegistry excelTranslatorRegistry)
      • getWorkbookValidators

        public java.util.List<WorkbookValidator> getWorkbookValidators()
      • setWorkbookValidators

        public void setWorkbookValidators​(java.util.List<WorkbookValidator> workbookValidators)
      • setParserRegistry

        public void setParserRegistry​(ParserRegistry parserRegistry)
      • setExcelWorkbookService

        public void setExcelWorkbookService​(ExcelWorkbookService excelWorkbookService)
      • setExcelSheetService

        public void setExcelSheetService​(ExcelSheetService excelSheetService)
      • setExcelCellService

        public void setExcelCellService​(ExcelCellService excelCellService)
      • setExcelHeaderService

        public void setExcelHeaderService​(ExcelHeaderService excelHeaderService)