Class EmbeddedFilesResolver

java.lang.Object
org.sentrysoftware.metricshub.engine.connector.parser.EmbeddedFilesResolver

public class EmbeddedFilesResolver extends Object
Resolves and internalizes embedded files within a JsonNode.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    A custom exception class for errors that occur during the processing of embedded files.
  • Constructor Summary

    Constructors
    Constructor
    Description
    EmbeddedFilesResolver(com.fasterxml.jackson.databind.JsonNode connector, Path connectorDirectory, Set<URI> parents)
    Constructs an EmbeddedFilesResolver with the given parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    Collects all processed embedded files into a map where each file is indexed by its unique identifier.
    void
    Look for all references of embedded files that look like: ${file::}, find the referenced file, load its content as byte array to create a new EmbeddedFile instance, store the created embedded file in the processedEmbeddedFiles lookup and replace the reference to the external file by a reference to the internalized embedded file in the JsonNode representing the connector.
    processFile(String fileName, Path connectorDirectory)
    Reads the file content and generate an EmbeddedFile instance.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EmbeddedFilesResolver

      public EmbeddedFilesResolver(com.fasterxml.jackson.databind.JsonNode connector, Path connectorDirectory, Set<URI> parents)
      Constructs an EmbeddedFilesResolver with the given parameters.
      Parameters:
      connector - The JsonNode representing the connector.
      connectorDirectory - The directory of the connector.
      parents - Set of parent directories URIs.
  • Method Details

    • process

      public void process() throws IOException
      Look for all references of embedded files that look like: ${file::}, find the referenced file, load its content as byte array to create a new EmbeddedFile instance, store the created embedded file in the processedEmbeddedFiles lookup and replace the reference to the external file by a reference to the internalized embedded file in the JsonNode representing the connector.
      Throws:
      IOException - If there is an issue finding the embedded file or processing the JSON structure.
    • processFile

      public EmbeddedFile processFile(String fileName, Path connectorDirectory) throws IOException
      Reads the file content and generate an EmbeddedFile instance.
      Parameters:
      fileName - The name or relative path of the file
      connectorDirectory - The name of the connector directory where to look for the file
      Returns:
      The absolute path of the file if found, null otherwise.
      Throws:
      IOException
      IllegalStateException - when the file can't be found
    • collectEmbeddedFiles

      public Map<Integer,EmbeddedFile> collectEmbeddedFiles()
      Collects all processed embedded files into a map where each file is indexed by its unique identifier.
      Returns:
      A Map with integer keys representing the unique ID of each embedded file and values as the corresponding EmbeddedFile instances.