Interface DataTemplateService

All Superinterfaces:
Service

public interface DataTemplateService
extends Service
API for loading data from a template file similar to LoadData.xml.
  • Method Summary

    Modifier and Type Method Description
    java.io.File getRegisteredTemplateByName​(java.lang.String name)
    Returns the registered DataTemplate file by the name defined in DataTemplate.xml.
    java.util.List<java.io.File> getRegisteredTemplates()
    Returns the list of all DataTemplates registered via registerTemplate(File)
    java.util.Map<java.lang.String,​java.lang.Object> loadDataTemplate​(java.io.File dataTemplateFile, java.util.Map<java.lang.String,​java.lang.String> bindings, PlatformUserContext context)
    Loads data using a DataTemplate file.
    java.util.Map<java.lang.String,​java.lang.Object> loadEptDataTemplate​(java.lang.String fileName, java.util.Map<java.lang.String,​java.lang.String> bindings, PlatformUserContext context)
    Loads data using a DataTemplate file defined in EPT under "/data" folder.
    void registerTemplate​(java.io.File dataTemplateFile)
    Registers a DataTemplate file, typically defined in a module under the "/data" folder.
  • Method Details

    • loadDataTemplate

      java.util.Map<java.lang.String,​java.lang.Object> loadDataTemplate​(java.io.File dataTemplateFile, java.util.Map<java.lang.String,​java.lang.String> bindings, PlatformUserContext context)
      Loads data using a DataTemplate file. This XML file contains a combination of:

      • XML data template files
      • CSV template files
      • Scripts written in Groovy

      For example:

       
       <DataTemplate xmlns="http://www.onenetwork.com/Platform">
          <ModelFile>Enterprises.xml</ModelFile>
          <InboundInterfaceFile inboundInterface="PLT.Organization_IB" inboundInterfaceVersion="1.0">csv/PLT.Organization_IB.csv</InboundInterfaceFile> 
          <Script>
            com.onenetwork.platform.env.servicelocator.Services.get(com.onenetwork.platform.data.sql.SqlService.class).executeQuery("update enterprise set description = 'Test Update Through Script' where ent_name = 'TestEnterprise' and vc_id = " + context.getValueChainId());
          </Script>
       </DataTemplate> 
       
       

      All paths will be resolved relative to the DataTemplate.xml file. In the data files, you can provide variables like ${ENT_NAME} and this will be replaced at runtime based on the bindings you provide. These are interpreted literally ... if you give "${ENT_NAME}" as "FOO", it will replace "My ent is ${ENT_NAME}" with "My ent is FOO". If you give "ENT_NAME" as "FOO", it would replace "My ent is ${ENT_NAME}" with "My ent is ${FOO}". Please note that these are also replaced literally in the content of your groovy script, just as if it was a text file (they are not bound as groovy variables).

      Additionaly, the PlatformUserContext you pass in will be bound automatically as "context" for any groovy Script.

      Parameters:
      dataTemplateFile - template file containing a combination of XML, CSV template files to load
      bindings - map which will be used at runtime to replace the variables during loading of data template.
      context - caller's context
      Returns:
      map of file name to errors. If there are no errors, the map will be empty. For each XML file, the error value will be a List containing only the error Models. For each CSV file, the error value will be the String content of the CSV error file. For any XML or CSV file which had no errors, there will be no key in the map for that file.
    • loadEptDataTemplate

      java.util.Map<java.lang.String,​java.lang.Object> loadEptDataTemplate​(java.lang.String fileName, java.util.Map<java.lang.String,​java.lang.String> bindings, PlatformUserContext context)
      Loads data using a DataTemplate file defined in EPT under "/data" folder. Same as loadDataTemplate(File, Map, PlatformUserContext), this XML file contains a combination of XML, CSV and Scripts written in Groovy. XML and CSV should exist relative to DataTemplate file in EPT.
      Parameters:
      fileName - template file containing a combination of XML, CSV template files to load. For EPT, DataTemplate file should exist in the "/data" folder
      bindings - map which will be used at runtime to replace the variables during loading of data template.
      context - enterprise level caller's context which has access to the EPT
      Returns:
      map of file name to errors. If there are no errors, the map will be empty. For each XML file, the error value will be a List containing only the error Models. For each CSV file, the error value will be the String content of the CSV error file. For any XML or CSV file which had no errors, there will be no key in the map for that file.
    • registerTemplate

      void registerTemplate​(java.io.File dataTemplateFile)
      Registers a DataTemplate file, typically defined in a module under the "/data" folder. Registering it makes it available to be executed by a VC Admin through the Data Templates UI.

      The XML file contains Name, Params and combination of:

      • XML data template files
      • CSV template files
      • Scripts written in Groovy

      Name is a required field when registering. Parameters are optional; when provided, users will be prompted for values before evaluating the template.

      For example:

       
       <DataTemplate xmlns="http://www.onenetwork.com/Platform">
         <Name>TMS.SampleDataTemplate</Name>
         <Params>
            <Param name="ENTERPRISE_NAME"/>
            <Param name="ORG_NAME"/>
          </Params>
          <ModelFile>Enterprises.xml</ModelFile>
          <InboundInterfaceFile inboundInterface="PLT.Organization_IB" inboundInterfaceVersion="1.0">csv/PLT.Organization_IB.csv</InboundInterfaceFile> 
          <Script>
            com.onenetwork.platform.env.servicelocator.Services.get(com.onenetwork.platform.data.sql.SqlService.class).executeQuery("update enterprise set description = 'Test Update Through Script' where ent_name = 'TestEnterprise' and vc_id = " + context.getValueChainId());
          </Script>
       </DataTemplate> 
       
       
      Parameters:
      dataTemplateFile - template file containing a combination of XML, CSV template files to load
    • getRegisteredTemplates

      java.util.List<java.io.File> getRegisteredTemplates()
      Returns the list of all DataTemplates registered via registerTemplate(File)
    • getRegisteredTemplateByName

      java.io.File getRegisteredTemplateByName​(java.lang.String name)
      Returns the registered DataTemplate file by the name defined in DataTemplate.xml. Similar to registerTemplate(File), this XML file contains a combination of XML, CSV and Scripts written in Groovy.
      Parameters:
      template - name
      Returns:
      DataTemplate file currently registered by module with given name.