Package com.orchestranetworks.addon.dataexchange.validator
package com.orchestranetworks.addon.dataexchange.validator
Classes and interfaces to call EBX Data Exchange Add-on import Excel, CSV, XML and transfer data service using validators.
Example of creating validator in the import Excel, CSV, XML and data transfer
Create the definition to add a validator.
For example:
public final class SalaryValidatorDefinition implements ValidatorDefinition { public UserMessage getLabel() { return UserMessage.createInfo("Validator for 'Salary' field of 'Employee' table"); } public UserMessage getDescription() { return UserMessage.createInfo("Allow import record with unempty 'Salary' field value"); } public Validator getValidator(Operation operation) { switch (operation) { case IMPORT_EXCEL_FOR_SINGLE_TABLE: case IMPORT_EXCEL_FOR_MULTIPLE_TABLES: return new SalaryValidatorForExcelFile(); case IMPORT_CSV: return new SalaryValidatorForCSVFile(); case IMPORT_XML: return new SalaryValidatorForXMLFile(); case TRANSFER_DATA: return new SalaryValidatorForTransferData(); default: return null; } } }
Next, create the definition of the implementation.
Example of import Excel
public final class SalaryValidatorForExcelFile implements Validator<ExcelValidatorContext> { public ValidatorStatus preTransform(ExcelValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } String sheetName = validatorContext.getSheetName(); if (sheetName.equals("Employee")) { ColumnHeaderSpec headerSpec = new ColumnHeaderSpec("Salary", 3);// 'Salary' index is 3 Object salary = validatorContext.getSourceRow().get(headerSpec); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } } return ValidatorStatus.CONTINUE; } public ValidatorStatus postTransform(ExcelValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } String sheetName = validatorContext.getSheetName(); if (sheetName.equals("Employee")) { ColumnHeaderSpec headerSpec = new ColumnHeaderSpec("Salary", 3);// 'Salary' index is 3 Object salary = validatorContext.getSourceRow().get(headerSpec); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } } return ValidatorStatus.CONTINUE; } }
Example of import CSV
public final class SalaryValidatorForCSVFile implements Validator<CSVValidatorContext> { public ValidatorStatus preTransform(CSVValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } // 'Salary' index is 3 ColumnHeaderSpec headerSpec = new ColumnHeaderSpec("Salary", 3); Object salary = validatorContext.getSourceValues().get(headerSpec); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } public ValidatorStatus postTransform(CSVValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } // 'Salary' index is 3 ColumnHeaderSpec headerSpec = new ColumnHeaderSpec("Salary", 3); Object salary = validatorContext.getSourceValues().get(headerSpec); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } }
Example of import XML
public final class SalaryValidatorForXMLFile implements Validator<XMLValidatorContext> { // Validator is located on "Employee" table mapping of EBX Data Exchange Add-on configuration public ValidatorStatus preTransform(XMLValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } Object salary = validatorContext.getSourceXML().get("/root/Employee/salary"); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } public ValidatorStatus postTransform(XMLValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } Object salary = validatorContext.getSourceXML().get("/root/Employee/salary"); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } }
Example of transfer data
public final class SalaryValidatorForTransferData implements Validator<EBXValidatorContext> { // Validator is located on "Employee" table mapping of EBX Data Exchange Add-on configuration public ValidatorStatus preTransform(EBXValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } Object salary = validatorContext.getSourceRecord().get(Path.parse("/root/Employee/salary")); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } public ValidatorStatus postTransform(EBXValidatorContext validatorContext) { if (validatorContext == null) { return ValidatorStatus.FAIL; } Object salary = validatorContext.getSourceRecord().get(Path.parse("/root/Employee/salary")); if (AddonStringUtils.isEmpty(String.valueOf(salary))) { return ValidatorStatus.IGNORE; } return ValidatorStatus.CONTINUE; } }
Finally, the validator definition must be registered in the add-on in order to be available in the configuration:
ValidatorCatalog.add(new SalaryValidatorDefinition());
In another way, with the import Excel and CSV, the validator can be declared on Extension table.
-
ClassDescriptionDeprecated.Deprecated.Since 2.3.0, replaced by
ValidatorContext
.Deprecated.Since 2.3.0, replaced byValidatorContext
.Deprecated.Since 2.3.0, replaced byValidatorContext
.Validator<T extends ValidatorContext>Deprecated.Since 2.3.0, replaced byValidator
.Deprecated.Since 2.3.0, replaced byValidatorCatalog
.Deprecated.Since 2.3.0, replaced byValidatorContext
.Deprecated.Since 2.3.0, replaced byValidatorDefinition
.Deprecated.Since 2.3.0, replaced byValidatorStatus
.Deprecated.Since 2.3.0, replaced byValidatorContext
.
SpreadsheetField
,CSVField
.