Interface SzConfig


public interface SzConfig

Defines the Java interface that encapsulates and represents a Senzing configuration and provides functions to operate on that configuration.

An SzConfig instance is typically obtained from an SzConfigManager instance via one of the following methods:

Create from template configuration:

// How to create an SzConfig instance representing the template configuration
try {
  // obtain the SzEnvironment (varies by application)
  SzEnvironment env = getEnvironment();

  // get the SzConfigManager instance
  SzConfigManager configMgr = env.getConfigManager();

  // create the config from the template
  SzConfig config = configMgr.createConfig();

  // do something with the SzConfig
  if (config == null) {
    throw new Exception();
  }

} catch (SzException e) {
  // handle or rethrow the exception
  logError("Failed to create new SzConfig from the template.", e);
}

Create from configuration definition:

// How to create an SzConfig instance representing a specified config definition
try {
  // obtain the SzEnvironment (varies by application)
  SzEnvironment env = getEnvironment();

  // get the SzConfigManager instance
  SzConfigManager configMgr = env.getConfigManager();

  // obtain a JSON config definition (varies by application)
  String configDefinition = readConfigFile();

  // create the config using the config definition
  SzConfig config = configMgr.createConfig(configDefinition);

  // do something with the SzConfig
  if (config == null) {
    throw new Exception();
  }

} catch (SzException e) {
  // handle or rethrow the exception
  logError("Failed to create a new SzConfig from a definition.", e);
}

Create from registered configuration ID:

// How to get a config definition by its configuration ID
try {
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = getEnvironment();

    // get the config manager
    SzConfigManager configMgr = env.getConfigManager();

    // get a valid configuration ID (will vary by application)
    long configId = configMgr.getDefaultConfigId();

    // get the config definition for the config ID
    SzConfig config = configMgr.createConfig(configId);

    // do something with the SzConfig
    ...

} catch (SzException e) {
    // handle or rethrow the exception
    logError("Failed to create SzConfig from config ID.", e);
}
  • Method Summary

    Modifier and Type
    Method
    Description
    addDataSource(String dataSourceCode)
    Adds a new data source that is identified by the specified data source code to this configuration.
    void
    deleteDataSource(String dataSourceCode)
    Deletes the data source identified by the specified data source code from this configuration.
    Obtains the configuration definition (typically formatted as JSON) for this configuration.
    Extracts the data sources from this configuration and returns the JSON text describing the data sources from the configuration.
  • Method Details

    • export

      String export() throws SzException
      Obtains the configuration definition (typically formatted as JSON) for this configuration.

      Note: Typically, an implementation's Object.toString() function will be implemented to return the result from this function.

      Usage:

      // How to export config JSON from a config handle
      try {
        // obtain the SzEnvironment (varies by application)
        SzEnvironment env = getEnvironment();
      
        // get the SzConfigManager instance
        SzConfigManager configMgr = env.getConfigManager();
      
        // get an SzConfig object (varies by application)
        SzConfig config = configMgr.createConfig();
      
        // export the config
        String configDefinition = config.export();
      
        if (configDefinition == null) {
          throw new Exception();
        }
      
      } catch (SzException e) {
        // handle or rethrow the exception
        logError("Failed to export configuration.", e);
      }
      

      Returns:
      The configuration definition (typically formatted as JSON).
      Throws:
      SzException - If a failure occurs.
      See Also:
    • getDataSources

      String getDataSources() throws SzException
      Extracts the data sources from this configuration and returns the JSON text describing the data sources from the configuration.

      The format of the JSON response is as follows:

       {
         "DATA_SOURCES": [
           {
             "DSRC_ID": 1,
             "DSRC_CODE": "TEST"
           },
           {
             "DSRC_ID": 2,
             "DSRC_CODE": "SEARCH"
           }
         ]
       }
       

      Usage:

      // How to get the data sources from an in-memory config
      try {
        // obtain the SzEnvironment (varies by application)
        SzEnvironment env = getEnvironment();
      
        // get the SzConfigManager instance
        SzConfigManager configMgr = env.getConfigManager();
      
        // get an SzConfig object (varies by application)
        SzConfig config = configMgr.createConfig();
      
        // get the data sources
        String sourcesJson = config.getDataSources();
      
        // do something with the returned JSON (e.g.: parse it and extract values)
        JsonObject jsonObj = Json.createReader(
            new StringReader(sourcesJson)).readObject();
      
        JsonArray jsonArr = jsonObj.getJsonArray("DATA_SOURCES");
      
        // iterate over the data sources
        for (JsonObject sourceObj : jsonArr.getValuesAs(JsonObject.class)) {
          String dataSourceCode = sourceObj.getString("DSRC_CODE");
      
          if (dataSourceCode == null) {
            throw new Exception();
          }
        }
      
      } catch (SzException e) {
        // handle or rethrow the exception
        logError("Failed to get data sources.", e);
      }
      

      Returns:
      The JSON String describing the data sources found in the configuration.
      Throws:
      SzException - If a failure occurs.
    • addDataSource

      String addDataSource(String dataSourceCode) throws SzException
      Adds a new data source that is identified by the specified data source code to this configuration. An exception is thrown if the data source already exists in the configuration.

      The response JSON provides the data source ID of the created data source and has the following format:

         {
           "DSRC_ID": 410
         }
       

      Usage:

      // How to add data sources to an in-memory config
      try {
        // obtain the SzEnvironment (varies by application)
        SzEnvironment env = getEnvironment();
      
        // get the SzConfigManager instance
        SzConfigManager configMgr = env.getConfigManager();
      
        // get an SzConfig object (varies by application)
        SzConfig config = configMgr.createConfig();
      
        // add data sources to the config
        config.addDataSource("CUSTOMERS");
      
        config.addDataSource("EMPLOYEES");
      
        config.addDataSource("WATCHLIST");
      
        if (config == configMgr) {
          throw new Exception();
        }
      
      } catch (SzException e) {
        // handle or rethrow the exception
        logError("Failed to add data sources.", e);
      }
      

      Parameters:
      dataSourceCode - The data source code for the new data source.
      Returns:
      The JSON String describing the data source was added to the configuration.
      Throws:
      SzException - If a failure occurs.
      See Also:
    • deleteDataSource

      void deleteDataSource(String dataSourceCode) throws SzException
      Deletes the data source identified by the specified data source code from this configuration.

      Usage:

      // How to delete a data source from an in-memory config
      try {
        // obtain the SzEnvironment (varies by application)
        SzEnvironment env = getEnvironment();
      
        // get the SzConfigManager instance
        SzConfigManager configMgr = env.getConfigManager();
      
        // get an SzConfig object (varies by application)
        SzConfig config = configMgr.createConfig();
      
        // delete the data source from the config
        config.deleteDataSource("CUSTOMERS");
      
        if (config == configMgr) {
          throw new Exception();
        }
      
      } catch (SzException e) {
        // handle or rethrow the exception
        logError("Failed to delete data source.", e);
      }
      

      Parameters:
      dataSourceCode - The data source code that identifies the data source to delete from the configuration.
      Throws:
      SzException - If a failure occurs.