Package com.orchestranetworks.addon.dex.validator


package com.orchestranetworks.addon.dex.validator

Classes and interfaces to call {addon.label} import Excel, CSV, XML and transfer data services using validator.


Creating a validator in the import Excel, CSV, XML and transfer data services

To create a validator:

  1. Create the definition to add a validator.

    public final class TestValidatorDefinition 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(ServiceType serviceType)
            {
                    switch (serviceType)
                    {
                    case SPREADSHEET_IMPORT:
                            return new TestValidatorForSpreadsheetImport();
                    case CSV_IMPORT:
                            return new TestValidatorForCSVImport();
                    case XML_IMPORT:
                            return new TestValidatorForXMLImport();
                    case TRANSFER:
                            return new TestValidatorForTransfer();
                    default:
                            return null;
                    }
            }
    }
    
  2. Create the implementation definition.

    • Example of Excel import:

      public final class TestValidatorForSpreadsheetImport implements Validator
      {
              public ValidatorStatus preTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      Record<SpreadsheetField> spreadsheetRecord = validatorContext.getSourceRecord();
                      SpreadsheetTable spreadsheetTable = (SpreadsheetTable) spreadsheetRecord.getTable();
                      String sheetName = spreadsheetTable.getSheetName();
                      if (sheetName.equals("Libraries"))
                      {
                              Iterator<SpreadsheetField> iterator = spreadsheetTable.getFields().iterator();
                              while (iterator.hasNext())
                              {
                                      SpreadsheetField spreadsheetField = iterator.next();
                                      if (spreadsheetRecord.getValue(spreadsheetField) == null)
                                      {
                                              return ValidatorStatus.IGNORE;
                                      }
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
              
              public ValidatorStatus postTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      EBXTable targetTable = validatorContext.getTargetTable();
                      for (EBXField targetField : targetTable.getFields())
                      {
                              if (validatorContext.getValue(targetField) == null)
                              {
                                      return ValidatorStatus.IGNORE;
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
      }
      
    • Example of CSV import:

      public final class TestValidatorForCSVImport implements Validator
      {
              public ValidatorStatus preTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      Record<CSVField> csvRecord = validatorContext.getSourceRecord();
                      CSVTable csvTable = (CSVTable) csvRecord.getTable();
                      String csvTableName = csvTable.getName();
                      if (csvTableName.equals("Libraries"))
                      {
                              Iterator<CSVField> iterator = csvTable.getFields().iterator();
                              while (iterator.hasNext())
                              {
                                      CSVField csvField = iterator.next();
                                      if (csvRecord.getValue(csvField) == null)
                                      {
                                              return ValidatorStatus.IGNORE;
                                      }
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
              
              public ValidatorStatus postTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      EBXTable targetTable = validatorContext.getTargetTable();
                      for (EBXField targetField : targetTable.getFields())
                      {
                              if (validatorContext.getValue(targetField) == null)
                              {
                                      return ValidatorStatus.IGNORE;
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
      }
      
    • Example of XML import:

      public final class TestValidatorForXMLImport implements Validator
      {
              public ValidatorStatus preTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      Record<XMLField> xmlRecord = validatorContext.getSourceRecord();
                      XMLTable xmlTable = (XMLTable) xmlRecord.getTable();
                      String xmlTablePath = xmlTable.getXMLPath();
                      if (xmlTablePath.equals("/root/Libraries"))
                      {
                              Iterator<XMLField> iterator = xmlTable.getFields().iterator();
                              while (iterator.hasNext())
                              {
                                      XMLField xmlField = iterator.next();
                                      if (xmlRecord.getValue(xmlField) == null)
                                      {
                                              return ValidatorStatus.IGNORE;
                                      }
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
              
              public ValidatorStatus postTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      EBXTable targetTable = validatorContext.getTargetTable();
                      for (EBXField targetField : targetTable.getFields())
                      {
                              if (validatorContext.getValue(targetField) == null)
                              {
                                      return ValidatorStatus.IGNORE;
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
      }
      
    • Example of data transfer:

      public final class TestValidatorForTransfer implements Validator
      {
              public ValidatorStatus preTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      Record<EBXField> ebxSourceRecords = validatorContext.getSourceRecord();
                      EBXTable ebxSourceTable = (EBXTable) ebxSourceRecords.getTable();
                      String ebxSourceTablePath = ebxSourceTable.getTableNode().getPathInSchema().format();
                      if (ebxSourceTablePath.equals("/root/Libraries"))
                      {
                              Iterator<EBXField> iterator = ebxSourceTable.getFields().iterator();
                              while (iterator.hasNext())
                              {
                                      EBXField ebxField = iterator.next();
                                      if (ebxSourceRecords.getValue(ebxField) == null)
                                      {
                                              return ValidatorStatus.IGNORE;
                                      }
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
              
              public ValidatorStatus postTransform(ValidatorContext validatorContext)
              {
                      if (validatorContext == null)
                      {
                              return ValidatorStatus.FAIL;
                      }
                      EBXTable targetTable = validatorContext.getTargetTable();
                      for (EBXField targetField : targetTable.getFields())
                      {
                              if (validatorContext.getValue(targetField) == null)
                              {
                                      return ValidatorStatus.IGNORE;
                              }
                      }
                      return ValidatorStatus.CONTINUE;
              }
      }
      
  3. Register the validator with the add-on via the catalog so that it can be used in the configuration:

            ValidatorCatalog.add(new TestValidatorDefinition());