Class PersistentQueryConfigurationMarshaller

java.lang.Object
com.illumon.iris.controller.PersistentQueryConfigurationMarshaller

public class PersistentQueryConfigurationMarshaller extends Object
  • Constructor Details

    • PersistentQueryConfigurationMarshaller

      public PersistentQueryConfigurationMarshaller()
  • Method Details

    • isValidXmlText

      public static boolean isValidXmlText(String value)
    • createFromXmlByteArray

      public static List<PersistentQueryConfiguration> createFromXmlByteArray(byte[] xmlBytes) throws IOException, org.jdom2.JDOMException
      Create a list of PersistentQueryConfiguration instances from a byte array containing XML. The XML should have been created by the corresponding createXmlDocumentFromConfigurations(Collection,BiConsumer) method. There are no guarantees on the type, mutability, serializability, or thread-safety of the returned List.
      Parameters:
      xmlBytes - the byte array containing the XML
      Returns:
      a List of PersistentQueryConfiguration instances
      Throws:
      IOException
      org.jdom2.JDOMException
    • createFromXmlFile

      public static List<PersistentQueryConfiguration> createFromXmlFile(String fileName)
      Create a list of PersistentQueryConfiguration instances from a file containing XML. The XML should have been created by the corresponding createXmlDocumentFromConfigurations(Collection,BiConsumer) method. There are no guarantees on the type, mutability, serializability, or thread-safety of the returned List.
      Parameters:
      fileName - the name of the file to read
      Returns:
      a List of PersistentQueryConfiguration instances
    • createFromXmlFile

      public static List<PersistentQueryConfiguration> createFromXmlFile(String persistentQueryFileName, String overrideFileName)
      Create a list of PersistentQueryConfiguration instances from a file containing persistent query XML configurations and, if provided, a file containing override XML configurations.

      The overrides may be a subset of the full query configs. The override configuration document must have a root <PersistentQueryOverrideRoot> element, and <PersistentQueryOverride> child elements that will hold partial query configuration values. A <Serial> element is required under both the the <PersistentQuery> and the <PersistentQueryOverride> element, and their values must match in order for a set of overrides to get applied to a query. If a persistent query configuration element exists in the override it will completely replace what is in the persistent query config. If that element is a complex structure such as <Schedule> then the entire <Schedule> element will be replaced. Overrides of specific parts of complex elements is not supported. If the overrideFileName is null or an empty string, no attempt will be made to apply any overrides.

      The XML should have been created by the corresponding createXmlDocumentFromConfigurations(Collection,BiConsumer) method. There are no guarantees on the type, mutability, serializability, or thread-safety of the returned List.

      Parameters:
      persistentQueryFileName - the name of the persistent query file to read
      overrideFileName - the name of the override file to read
      Returns:
      a List of PersistentQueryConfiguration instances
    • applyPersistentQueryOverrides

      public static void applyPersistentQueryOverrides(org.jdom2.Document persistentQueryDocument, org.jdom2.Document overrideDocument)
      Applies values in the overrideDocument to the persistentQueryDocument. Overrides will be applied to the persistent query if the override has a <Serial> element whose value matches the <Serial> element in the persistent query. Consider the example below.

      Persistent Query XML fragment:

      <PersistentQueryRoot>
         <PersistentQuery>
           <Serial>90125</Serial>
           <HeapSizeInGB>1.0</HeapSizeInGB>
           ...
         </PersistentQuery>
       </PersistentQueryRoot>
      Persistent Query Override fragment:
      <PersistentQueryOverrideRoot>
          <PersistentQueryOverride>
           <Serial>90125</Serial>
           <HeapSizeInGB>2.0</HeapSizeInGB>
           ...
         </PersistentQueryOverride>
       </PersistentQueryOverrideRoot>
       
      The override has a serial value of 90125, which matches that of the query, and so the resulting document will have a HeapSizeInGB value of 2.0.
      Parameters:
      persistentQueryDocument - the document generated from a persistent query xml file
      overrideDocument - the document generated from a persistent query override xml file
    • streamToDocument

      public static org.jdom2.Document streamToDocument(InputStream inputStream)
      Parses xml file read from the input stream. Throws only unchecked exceptions.
      Parameters:
      inputStream - stream of data used to build JDOM Document.
    • asXmlString

      public static String asXmlString(PersistentQueryConfiguration config)
      Convert this persistent query into an XML String.
      Returns:
      this persistent query represented as an XML string.
    • asXmlString

      public static String asXmlString(@NotNull Collection<PersistentQueryConfiguration> configurations)
      Convert the provided persistent queries into an XML string
      Parameters:
      configurations - Persistent queries to convert
      Returns:
      Persistent queries represented as an XML string
    • writeXmlFromConfigurations

      public static void writeXmlFromConfigurations(@NotNull Collection<PersistentQueryConfiguration> configurations, Writer outputWriter, BiConsumer<Boolean,PersistentQueryConfiguration> contextCallback)
      Write XML text resenting a collection of persistent query configurations to the specified Writer.
      Parameters:
      configurations - the PersistentQueryConfiguration instances to be written
      outputWriter - the Writer to use for the output
    • createXmlDocumentFromConfigurations

      public static org.jdom2.Document createXmlDocumentFromConfigurations(@NotNull Collection<PersistentQueryConfiguration> configurations, BiConsumer<Boolean,PersistentQueryConfiguration> contextCallback)
      Create a complete XML Document containing details on a collection of PersistentQueryConfiguration instances.
      Parameters:
      configurations - the configurations to be added to the document
      Returns:
      the XML document
    • encodeTypeSpecificFieldsJson

      public static String encodeTypeSpecificFieldsJson(@NotNull Map<String,Object> typeSpecificFields)
      Encode a config's TypeSpecificFields as JSON. This method assumes they exist, that is DefaultPersistentQueryConfiguration.getTypeSpecificFields() is not null. Only Primitive types, Strings, and Arrays of them are allowed. The map will be encoded with type information

      For example, a single floating point field would be encoded like this

         "floatField": {
           "type": "float",
           "value": 2.3
         }
       
      While an array field would look like this
         "stringAField": {
           "type": "string[]",
           "value": [
             "Cantaloupe",
             "Apple",
             "Bagel"
           ]
         }
       
      Parameters:
      typeSpecificFields - the map of objects to encode
      Returns:
      a JSON string encoding the objects
    • decodeTypeSpecificFieldsJson

      public static Map<String,Object> decodeTypeSpecificFieldsJson(String typeSpecificFieldsJson)