Package com.orchestranetworks.addon.dex.configuration


package com.orchestranetworks.addon.dex.configuration

Classes and interfaces to define specifications for the import, export and transfer data services.


Overview

The examples shown herein show how to specify configurations for data import, export and transfer. In most instances you'll need to define and generate source tables. For more information on this topic and to see examples, you can refer to the com.orchestranetworks.addon.dex.common.generation package.

Creating a data transfer configuration

The following steps outline the process of creating a data transfer configuration:

  1. Define the list of EBX® source tables:

                    AdaptationTable libraryAdaptationTable = sourceDataset.getTable(Path.parse("/root/Libraries"));
                    EBXField libraryIdField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Id")));
                    EBXField libraryNameField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Name")));
                    List<EBXField> libraryFields = new ArrayList<EBXField>();
                    libraryFields.add(libraryIdField);
                    libraryFields.add(libraryNameField);
                    EBXTable libraryTable = new EBXTable(libraryAdaptationTable, libraryFields);
                    
                    AdaptationTable courseAdaptationTable = sourceDataset.getTable(Path.parse("/root/Courses"));
                    EBXField courseIdField = new EBXField(
                            courseAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Courses/Id")));
                    EBXField courseNameField = new EBXField(
                            courseAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Courses/Name")));
                    List<EBXField> courseFields = new ArrayList<EBXField>();
                    courseFields.add(courseIdField);
                    courseFields.add(courseNameField);
                    EBXTable courseTable = new EBXTable(courseAdaptationTable, courseFields);
                    
                    List<EBXTable> sourceEBXTables = new ArrayList<EBXTable>();
                    sourceEBXTables.add(libraryTable);
                    sourceEBXTables.add(courseTable);
    
  2. Use the list of source tables to create the transfer data configuration specification:

                    TransferConfigurationSpec transferConfig = new TransferConfigurationSpec(
                            sourceDataset,
                            sourceEBXTables,
                            targetDataset,
                            session);
    
  3. When transferring data with table filters, define a TableFilter for each source table as shown below:

                    Map<EBXTable, TableFilter> sourceTableFilters = new HashMap<EBXTable, TableFilter>();
                    EBXTable sourceTable = new EBXTable(sourceDataset.getTable(Path.parse("/root/Libraries")));
                    TableFilter tableFilter = new TableFilter();
                    tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                    sourceTableFilters.put(sourceTable, tableFilter);
                    TransferConfigurationSpec transferConfigWithTableFilter = new TransferConfigurationSpec(
                            sourceDataset,
                            sourceEBXTables,
                            sourceTableFilters,
                            targetDataset,
                            session);
    

Creating an XML import configuration

The following steps demonstrate how to create an XML import configuration:

  1. Define the source XML table as follows:

                    List<XMLField> sourceFields = new ArrayList<XMLField>();
                    XMLField sourceFieldName = new XMLField("/root/Libraries/Name");
                    XMLField sourceFieldStatus = new XMLField("/root/Libraries/Status");
                    sourceFields.add(sourceFieldName);
                    sourceFields.add(sourceFieldStatus);
                    XMLTable srcXMLTable = new XMLTable("/root/Libraries", sourceFields);
    
  2. Use the source table to create the configuration specification:

                    XMLImportConfigurationSpec importSpec = new XMLImportConfigurationSpec(
                            currentTable,
                            srcXMLTable,
                            session);
                    File importedFile = new File(importedFilePath);
                    importSpec.setImportedFile(importedFile);                       
    

Creating an XML export configuration

The following shows how to create an XML export configuration:

                XMLExportConfigurationSpec exportSpec = new XMLExportConfigurationSpec(
                        currentTable,
                        session);

When exporting XML with table filters, use the steps below:

  1. Define the EBX® source table:

                    AdaptationTable libraryAdaptationTable = sourceDataset.getTable(Path.parse("/root/Libraries"));
                    EBXField libraryIdField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Id")));
                    EBXField libraryNameField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Name")));
                    List<EBXField> libraryFields = new ArrayList<EBXField>();
                    libraryFields.add(libraryIdField);
                    libraryFields.add(libraryNameField);
                    EBXTable ebxTable = new EBXTable(libraryAdaptationTable, libraryFields);
    
  2. Create the TableFilter and apply it along with the EBX® source table:

                    TableFilter tableFilter = new TableFilter();
                    tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                    XMLExportConfigurationSpec exportConfig = new XMLExportConfigurationSpec(
                            ebxTable,
                            tableFilter,
                            session);
    

Creating an SQL import configuration

Create the configuration with the data source declared in the application server as follows:

                SQLImportConfigurationSpec sqlConfigSpec = new SQLImportConfigurationSpec(
                        currentTable,
                        sqlDataSourceName,
                        sqlTableOrView,
                        session);

Without having to declare the data source in the application server, you can also create the configuration by defining a JNDI data source as shown below:

                JNDIDataSource jndiDataSource = new JNDIDataSource();
                jndiDataSource.setName(sqlDataSourceName);
                jndiDataSource.setURL(url);
                jndiDataSource.setUser(username);
                jndiDataSource.setPassword(password);
                SQLImportConfigurationSpec sqlConfigSpec = new SQLImportConfigurationSpec(currentTable,jndiDataSource,sqlTableOrView,session);                          

When importing SQL with table filters, define a TableFilter for the source table as shown below:

                TableFilter tableFilter = new TableFilter();
                tableFilter.setPredicate("SQLLibraryID ='ID001'");
                SQLImportConfigurationSpec sqlConfigSpec = new SQLImportConfigurationSpec(
                        currentTable,
                        sqlDataSourceName,
                        sqlTableOrView,
                        tableFilter,
                        session);

Creating a configuration for SQL export

Create the configuration with the data source declared in the application server as follows:

                SQLExportConfigurationSpec sqlConfigSpec = new SQLExportConfigurationSpec(
                        currentTable,
                        sqlDataSourceName,
                        session);

Without having to declare the data source in the application server, you can also create the configuration by defining a JNDI data source as shown below:

                JNDIDataSource jndiDataSource = new JNDIDataSource();
                jndiDataSource.setName(sqlDataSourceName);
                jndiDataSource.setURL(url);
                jndiDataSource.setUser(username);
                jndiDataSource.setPassword(password);
                
                SQLExportConfigurationSpec sqlConfigSpec = new SQLExportConfigurationSpec(
                        currentTable,
                        jndiDataSource,
                        session);

When exporting SQL with table filters, define a TableFilter for the source table as shown below:

                TableFilter tableFilter = new TableFilter();
                tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                SQLExportConfigurationSpec sqlConfigSpec = new SQLExportConfigurationSpec(
                        currentTable,
                        tableFilter,
                        sqlDataSourceName,
                        session);

Creating a configuration for CSV import

                AdaptationTable sourceTable = sourceDataset.getTable(Path.parse("/root/Libraries"));
                List<CSVField> csvFields = new ArrayList<CSVField>();
                CSVField idField = new CSVField(0, "Id", "Id");
                CSVField nameField = new CSVField(1, "Name", "Name");
                csvFields.add(idField);
                csvFields.add(nameField);
                CSVTable csvTable = new CSVTable("Libraries", csvFields);
                
                CSVImportConfigurationSpec importCSVSpec = new CSVImportConfigurationSpec(
                        sourceTable,
                        csvTable,
                        session);
                File importedFile = new File(importedFilePath);
                importCSVSpec.setImportedFile(importedFile);
                importCSVSpec.setSeparator(Separator.SEMICOLON.getSeparatorCharacter());
                importCSVSpec.setFileEncoding("UTF-8");

Creating a configuration for CSV export

                AdaptationTable currentTable = dataset.getTable(Path.parse("/root/Library"));
                TableFilter tableFilter = new TableFilter();
                tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                CSVExportConfigurationSpec exportCSVSpec = new CSVExportConfigurationSpec(
                        currentTable,
                        tableFilter,
                        session);

Creating a configuration for Excel import

The following example shows how to define a configuration using a single table:

                List<SpreadsheetField> libraryFields = new LinkedList<SpreadsheetField>();
                SpreadsheetField libraryIDField = new SpreadsheetField(0, "id", "LibraryID");
                SpreadsheetField libraryNameField = new SpreadsheetField(1, "name", "LibraryName");
                libraryFields.add(libraryIDField);
                libraryFields.add(libraryNameField);
                SpreadsheetTable spreadsheetTable = new SpreadsheetTable(0, "Library", libraryFields);
                SpreadsheetImportConfigurationSpec importSpreadsheetConfig = new SpreadsheetImportConfigurationSpec(
                        currentTable,
                        spreadsheetTable,
                        session);

When using multiple tables:

                List<SpreadsheetTable> spreadsheetTables = new LinkedList<SpreadsheetTable>();
                List<SpreadsheetField> libraryFields = new LinkedList<SpreadsheetField>();
                SpreadsheetField libraryIDField = new SpreadsheetField(0, "id", "LibraryID");
                SpreadsheetField libraryNameField = new SpreadsheetField(1, "name", "LibraryName");
                libraryFields.add(libraryIDField);
                libraryFields.add(libraryNameField);
                SpreadsheetTable libraryTable = new SpreadsheetTable(0, "Library", libraryFields);
                spreadsheetTables.add(libraryTable);

                List<SpreadsheetField> courseFields = new LinkedList<SpreadsheetField>();
                SpreadsheetField courseIDField = new SpreadsheetField(0, "id", "CourseID");
                SpreadsheetField courseCreditsField = new SpreadsheetField(1, "credits", "CourseCredits");
                courseFields.add(courseIDField);
                courseFields.add(courseCreditsField);
                SpreadsheetTable courseTable = new SpreadsheetTable(1, "Course", courseFields);
                spreadsheetTables.add(courseTable);
                
                SpreadsheetImportConfigurationSpec importSpreadsheetConfig = new SpreadsheetImportConfigurationSpec(
                        dataset,
                        spreadsheetTables,
                        session);

Creating a configuration for Excel export

To create an Excel export configuration:

  1. Define the EBX® source tables:

                    AdaptationTable libraryAdaptationTable = dataset.getTable(Path.parse("/root/Libraries"));
                    EBXField libraryIdField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Id")));
                    EBXField libraryNameField = new EBXField(
                            libraryAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Libraries/Name")));
                    List<EBXField> libraryFields = new ArrayList<EBXField>();
                    libraryFields.add(libraryIdField);
                    libraryFields.add(libraryNameField);
                    EBXTable libraryTable = new EBXTable(libraryAdaptationTable, libraryFields);
                    
                    AdaptationTable courseAdaptationTable = dataset.getTable(Path.parse("/root/Courses"));
                    EBXField courseIdField = new EBXField(
                            courseAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Courses/Id")));
                    EBXField courseNameField = new EBXField(
                            courseAdaptationTable.getTableOccurrenceRootNode()
                                    .getNode(Path.parse("/root/Courses/Name")));
                    List<EBXField> courseFields = new ArrayList<EBXField>();
                    courseFields.add(courseIdField);
                    courseFields.add(courseNameField);
                    EBXTable courseTable = new EBXTable(courseAdaptationTable, courseFields);
                    
                    List<EBXTable> sourceTables = new ArrayList<EBXTable>();
                    sourceTables.add(libraryTable);
                    sourceTables.add(courseTable);
    
  2. When exporting a single table:

                    EBXTable sourceTable = sourceTables.get(0);
                    TableFilter tableFilter = new TableFilter();
                    tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                    SpreadsheetExportConfigurationSpec exportSpreadsheetConfigurationSpec = new SpreadsheetExportConfigurationSpec(
                            sourceTable,
                            tableFilter,
                            session);
                    exportSpreadsheetConfigurationSpec.setHeaderExported(true);
                    exportSpreadsheetConfigurationSpec.setFileFormat(SpreadsheetFileFormat.EXCEL2003);
    
  3. When exporting multiple tables:

                    Map<EBXTable, TableFilter> sourceTableFilters = new HashMap<EBXTable, TableFilter>();
                    TableFilter tableFilter = new TableFilter();
                    tableFilter.setPredicate("contains(./LibraryID,'ID001')");
                    sourceTableFilters.put(libraryTable, tableFilter);
                    SpreadsheetExportConfigurationSpec exportSpreadsheetConfigurationSpec = new SpreadsheetExportConfigurationSpec(
                            dataset,
                            sourceTables,
                            sourceTableFilters,
                            session);
                    exportSpreadsheetConfigurationSpec.setHeaderExported(true);
                    exportSpreadsheetConfigurationSpec.setFileFormat(SpreadsheetFileFormat.EXCEL2007);
                    exportSpreadsheetConfigurationSpec.setReferenceSheetIncluded(false);