## Class QueryRunValidator

- java.lang.Object
- - QueryRunValidator

-     public class QueryRunValidator
      extends java.lang.Object

  Get and Validate a Query Source based on a RunQuery configuration. This provides methods to get and validate a source of query records for a particular compound record builder. The source is defined by a RunQuery configuration script. Both the source and the destination Mappings in the configuration can be applied to a query builder object.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `QueryRunValidator​(java.io.File run_config_file, com.tibco.patterns.qbp.AQBPLogger logger)` | Create a query run validator from a RunQuery configuration.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `java.lang.Double` | `getCutoffScore()` | Get the configured cutoff score.
    `java.lang.Integer` | `getQueryLimit()` | Get the configured query limit.
    `com.netrics.likeit.NetricsCompoundRecSrc` | `getQuerySource​(com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder, com.tibco.patterns.qbp.AQBPLogger logger)` | Create a query source for a query builder.
    `static com.netrics.likeit.NetricsServerInterface` | `getServer​(java.lang.String host_desc, java.lang.String host_ip, int host_port, com.tibco.patterns.qbp.AQBPLogger logger)` | Get the server for a QueryHost entry.
    `com.netrics.likeit.NetricsServerInterface` | `getSourceServer​(com.tibco.patterns.qbp.AQBPLogger logger)` | Get a server interface for the query source.
    `static int` | `validateAndSetInputFields​(java.lang.String table_name, java.lang.String[] actual_fields, com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder, com.tibco.patterns.qbp.AQBPLogger logger)` | Validate the fields from a CSV record source.
    `static int` | `validateDestTable​(java.lang.String table_name, java.lang.String[] fields, com.netrics.likeit.NetricsServerInterface nsi, com.tibco.patterns.qbp.AQBPLogger logger)` | Validate field structure for a target server table.
    `static int` | `validateInputTable​(java.lang.String orig_table_name, java.lang.String source_table_name, com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder, com.netrics.likeit.NetricsServerInterface nsi, com.tibco.patterns.qbp.AQBPLogger logger)` | Validate and set input field mapping from a Server Table.
    `int` | `validateTarget​(com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder, com.netrics.likeit.NetricsServerInterface target_server, boolean update_builder, com.tibco.patterns.qbp.AQBPLogger logger)` | Validate query target.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### QueryRunValidator

          public QueryRunValidator​(java.io.File run_config_file,
                                   com.tibco.patterns.qbp.AQBPLogger logger)
                            throws java.lang.IllegalArgumentException,
                                   com.tibco.patterns.qbp.AQBPLogger.QBPException

      Create a query run validator from a RunQuery configuration. This creates a query run validator from a RunQuery configuration. The validator can then be used to validate a query source and a query target for a particular query builder. It also updates the query builder to match the query source and target. All errors in the configuration are logged to the given logger as errors, not configuration errors (as this is not a query builder configuration). If any configuration errors are found a AQBPLogger.QBPException is thrown.
      Parameters:
        `run_config_file` - the configuration for the query run.
        `logger` - logger for reporting errors.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - for all other errors.

  - ### Method Detail

    - #### getServer

          public static com.netrics.likeit.NetricsServerInterface getServer​(java.lang.String host_desc,
                                                                            java.lang.String host_ip,
                                                                            int host_port,
                                                                            com.tibco.patterns.qbp.AQBPLogger logger)
                                                                     throws java.lang.IllegalArgumentException,
                                                                            com.tibco.patterns.qbp.AQBPLogger.QBPException

      Get the server for a QueryHost entry. This applies the default IP (localhost) and port (5051) address if host_info doesn't contain these values.
      Parameters:
        `host_desc` - description of host for error messages.
        `host_ip` - the host IP or URL address.
        `host_port` - the host port number.
        `logger` - logger for error messages.
      Returns:
        an interface object for connecting to the specified host.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - for other errors.

    - #### validateAndSetInputFields

          public static int validateAndSetInputFields​(java.lang.String table_name,
                                                      java.lang.String[] actual_fields,
                                                      com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder,
                                                      com.tibco.patterns.qbp.AQBPLogger logger)
                                               throws com.tibco.patterns.qbp.AQBPLogger.QBPException

      Validate the fields from a CSV record source. This checks the expected field list against the actual field list found in the record source. It attempts to set the input field ordering based on the actual fields in the source.
      Parameters:
        `table_name` - the name of the table being checked.
        `actual_fields` - the list of field names from the record source.
        `our_builder` - the query builder we validate against. The input map of this builder is updated.
        `logger` - the logger used to report errors.
      Returns:
        a count of the number of errors found.
      Throws:
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - if logger is in exception mode and an error is encountered.

    - #### validateInputTable

          public static int validateInputTable​(java.lang.String orig_table_name,
                                               java.lang.String source_table_name,
                                               com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder,
                                               com.netrics.likeit.NetricsServerInterface nsi,
                                               com.tibco.patterns.qbp.AQBPLogger logger)
                                        throws java.lang.IllegalArgumentException,
                                               com.tibco.patterns.qbp.AQBPLogger.QBPException

      Validate and set input field mapping from a Server Table. This checks that a table has the expected field structure needed to act as an input field data source. It attempts to set the input field ordering based on the field structure of the table.
      Parameters:
        `orig_table_name` - the name of the table from query definition.
        `source_table_name` - the name of the table on the source server.
        `our_builder` - the query builder we validate against. The input map of this builder is updated.
        `nsi` - the interface to the server being checked.
        `logger` - the logger for logging errors found.
      Returns:
        a count of the number of errors found.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - if logger exception mode is on.

    - #### validateDestTable

          public static int validateDestTable​(java.lang.String table_name,
                                              java.lang.String[] fields,
                                              com.netrics.likeit.NetricsServerInterface nsi,
                                              com.tibco.patterns.qbp.AQBPLogger logger)
                                       throws java.lang.IllegalArgumentException,
                                              com.tibco.patterns.qbp.AQBPLogger.QBPException

      Validate field structure for a target server table. This checks that a table has the necessary field structure to act as a target for queries. It must have all of the required fields.
      Parameters:
        `table_name` - the name of the table on the target server.
        `fields` - the list of required field names.
        `nsi` - the interface to the server being checked.
        `logger` - the logger for logging errors found.
      Returns:
        a count of the number of errors found.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - if logger exception mode is on and an error occurs.

    - #### getCutoffScore

          public java.lang.Double getCutoffScore()

      Get the configured cutoff score.
      Returns:
        the cutoff score from the configuration, null if none set.

    - #### getQueryLimit

          public java.lang.Integer getQueryLimit()

      Get the configured query limit.
      Returns:
        the query limit from the configuration, null if none set.

    - #### getSourceServer

          public com.netrics.likeit.NetricsServerInterface getSourceServer​(com.tibco.patterns.qbp.AQBPLogger logger)
                                                                    throws java.lang.IllegalArgumentException,
                                                                           com.tibco.patterns.qbp.AQBPLogger.QBPException

      Get a server interface for the query source.
      Parameters:
        `logger` - to report errors getting server.
      Returns:
        server interface object that connects to the query source server, null if source is not a TIBCO Patterns - Search server.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - if the server can't be contacted.

    - #### getQuerySource

          public com.netrics.likeit.NetricsCompoundRecSrc getQuerySource​(com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder,
                                                                         com.tibco.patterns.qbp.AQBPLogger logger)
                                                                  throws java.lang.IllegalArgumentException,
                                                                         com.tibco.patterns.qbp.AQBPLogger.QBPException

      Create a query source for a query builder. The builder is updated to match the query source.
      Parameters:
        `our_builder` - the builder we are creating the source for.
        `logger` - the AQBPLogger used to log all errors.
      Returns:
        the query source, null on error.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - on other errors.

    - #### validateTarget

          public int validateTarget​(com.netrics.likeit.ANetricsCompoundQueryBuilder our_builder,
                                    com.netrics.likeit.NetricsServerInterface target_server,
                                    boolean update_builder,
                                    com.tibco.patterns.qbp.AQBPLogger logger)
                             throws java.lang.IllegalArgumentException,
                                    com.tibco.patterns.qbp.AQBPLogger.QBPException

      Validate query target. This validates a TIBCO Patterns - Search server as a valid target for the given query builder. It adjusts the mappings in the query builder if requested.
      Parameters:
        `our_builder` - the builder of the query.
        `target_server` - the connection to the target server to validate.
        `update_builder` - if true the output field and item names in the server are updated based on the destination mappings in the query run configuration. Otherwise no updates are made.
        `logger` - all errors are logged here.
      Returns:
        0 on success, the number of errors found otherwise.
      Throws:
        `java.lang.IllegalArgumentException` - if logger is null.
        `com.tibco.patterns.qbp.AQBPLogger.QBPException` - for all other fatal errors.