Class JellyfinImportMetadata

java.lang.Object
com.lariflix.jemm.csv.JellyfinImportMetadata

public class JellyfinImportMetadata extends Object
The JellyfinImportMetadata class is responsible for importing metadata from a CSV file into a Jellyfin instance. It performs various checks to ensure the integrity of the data and updates the Jellyfin instance accordingly.
Since:
1.2.0
Version:
1.0
Author:
CesarBianchi
See Also:
  • Constructor Details

    • JellyfinImportMetadata

      public JellyfinImportMetadata()
      Default constructor for the JellyfinImportMetadata class.
      Since:
      1.2.0
    • JellyfinImportMetadata

      public JellyfinImportMetadata(String cPath, JellyfinInstanceDetails instData)
      Constructor for the JellyfinImportMetadata class with parameters.
      Parameters:
      cPath - The origin path of the CSV file.
      instData - The instance data for the Jellyfin instance.
      Since:
      1.2.0
  • Method Details

    • getFileLines

      public ArrayList<String> getFileLines()
      Gets the file lines from the CSV file.
      Returns:
      The file lines.
      Since:
      1.2.0
    • setFileLines

      public void setFileLines(ArrayList<String> fileLines)
      Sets the file lines from the CSV file.
      Parameters:
      fileLines - The file lines to set.
      Since:
      1.2.0
    • getLogDiferencesFile

      public String getLogDiferencesFile()
      Gets the log differences file path.
      Returns:
      The log differences file path.
      Since:
      1.2.0
    • setLogDiferencesFile

      public void setLogDiferencesFile()
      Sets the log differences file path.
      Since:
      1.2.0
    • setOriginPath

      public void setOriginPath(String cPath)
      Sets the origin path of the CSV file.
      Parameters:
      cPath - The origin path of the CSV file.
      Since:
      1.2.0
    • getInstanceData

      public JellyfinInstanceDetails getInstanceData()
      Gets the Jellyfin instance data.
      Returns:
      The Jellyfin instance data.
      Since:
      1.2.0
    • setInstanceData

      public void setInstanceData(JellyfinInstanceDetails instanceData)
      Sets the Jellyfin instance data.
      Parameters:
      instanceData - The Jellyfin instance data to set.
      Since:
      1.2.0
    • getcOriginPath

      public String getcOriginPath()
      Gets the origin path of the CSV file.
      Returns:
      The origin path of the CSV file.
      Since:
      1.2.0
    • getTotalLineToProcess

      public int getTotalLineToProcess()
      Gets the total number of lines to be processed.
      Returns:
      The total number of lines to be processed.
      Since:
      1.2.0
    • startPreCheck

      public JellyfinResponseStandard startPreCheck()
      Starts the pre-check process for importing metadata from a CSV file into a Jellyfin instance. This method performs the following steps: 1. Checks if the file header has the same structure as expected. 2. Checks if any line of the file has more or fewer fields than expected. 3. Checks if the file has one or more lines from a different server ID (Instance) or was generated from an older JEMM version. 4. Creates a "From/To" differences log.
      Returns:
      A JellyfinResponseStandard object containing the result of the process. If the process is successful, the response code and message indicate success. If the process fails, the response code and message indicate the error.
      Since:
      1.2.0
    • checkHeader

      public JellyfinResponseStandard checkHeader()
      Checks if the header of the CSV file matches the expected standard header. This method performs the following steps: 1. Gets the standard header expected. 2. Gets the header present in the file. 3. Checks if the fields between the file header and the standard header are the same.
      Returns:
      A JellyfinResponseStandard object containing the result of the check. If the headers match, the response code and message indicate success. If the headers do not match, the response code and message indicate the error.
      Since:
      1.2.0
    • getHeaderFromFile

      public ArrayList<String> getHeaderFromFile() throws FileNotFoundException, IOException
      Throws:
      FileNotFoundException
      IOException
    • preCheckLines

      Checks if each line of the CSV file has the same number of fields as expected. This method performs the following steps: 1. Sets the default return values. 2. Gets the total number of fields in the standard header. 3. Checks if each line of the CSV file has the same number of fields as the standard header.
      Returns:
      A JellyfinResponseStandard object containing the result of the check. If the lines are valid, the response code and message indicate success. If any line has an incorrect number of fields, the response code and message indicate the error.
      Throws:
      FileNotFoundException - If the CSV file is not found.
      IOException - If an I/O error occurs.
      Since:
      1.2.0
    • myTokenizer

      public ArrayList<String> myTokenizer(String cContent, String delimiter)
      Tokenizes a string into an ArrayList of strings based on a specified delimiter.
      Parameters:
      cContent - The string content to be tokenized.
      delimiter - The delimiter to be used for tokenizing the string. If null or empty, the default delimiter ";" is used.
      Returns:
      An ArrayList of strings resulting from the tokenization.
      Since:
      1.2.0
    • grantOrigin

      public JellyfinResponseStandard grantOrigin()
      Checks the origin of the CSV file to ensure it matches the current Jellyfin instance. This method performs the following steps: 1. Sets the default response. 2. Checks all lines of the file for unrecognized server ID or JEMM version. 3. Verifies if the JEMM version and server ID in the file match the current instance.
      Returns:
      A JellyfinResponseStandard object containing the result of the check. If the origin is valid, the response code and message indicate success. If the origin is invalid, the response code and message indicate the error.
      Since:
      1.2.0
    • startImport

      public JellyfinResponseStandard startImport()
      Starts the import process for importing metadata from a CSV file into a Jellyfin instance. This method performs the following steps: 1. Transforms each line in the `linesChanged` array into an array of fields. 2. Gets the ID and ParentID, then identifies if the line refers to a Folder or an Item. 3. If the line refers to a Folder, updates the folder in the main object with values changed from the file. 4. If the line refers to an Item, gets the most recent data and updates the main instance object with values changed from the file.
      Returns:
      A JellyfinResponseStandard object containing the result of the import process. If the process is successful, the response code and message indicate success. If any changes were not applied, the response code and message indicate the error.
      Since:
      1.2.0
    • compareValues

      public boolean compareValues(String oldValue, String newValue, String property, String lineNumber, boolean lChangedBefore)
      Compares the old and new values of a property and registers the difference if they are not equal.
      Parameters:
      oldValue - The original value of the property.
      newValue - The new value of the property.
      property - The name of the property being compared.
      lineNumber - The line number where the difference was found.
      lChangedBefore - Indicates if a change was detected before this comparison.
      Returns:
      true if the values are different, false otherwise.
      Since:
      1.2.0
    • getProcessFinalResult

      public JellyfinResponseStandard getProcessFinalResult()
    • setProcessFinalResult

      public void setProcessFinalResult(JellyfinResponseStandard processFinalResult)