Class Inventory


  • public class Inventory
    extends java.lang.Object

    An API for the PDMDB inventory stored as a .fods OpenDocument flat XML spreadsheet.

    • Constructor Summary

      Constructors 
      Constructor Description
      Inventory​(java.lang.String fileName, java.lang.String tableName)
      Loads the inventory (.fods) document and locates the named table.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void doIndex​(java.lang.String indexField, java.lang.String attributeName)
      Indexes the table.
      void forEach​(java.util.function.Consumer<? super org.w3c.dom.NodeList> action)  
      java.lang.String getFieldValue​(java.lang.String name)
      Get the value for the named field for the current row.
      java.lang.String getFieldValue​(org.w3c.dom.NodeList nl, java.lang.String name)
      Get the value for the named field in the NodeList.
      org.w3c.dom.Element identify​(java.lang.String id)
      Locates an existing element matching the (unique) id.
      java.lang.String identify​(java.lang.String id, java.lang.String match, java.lang.String reference, java.lang.String idAttributeName)
      Locates the element matching the id and updates currentElement.
      boolean isCurrentElementNull()  
      static void main​(java.lang.String[] args)  
      void updateField​(java.lang.String name, java.lang.String value)
      Update the value for the named field.
      void updateField​(java.lang.String id, java.lang.String name, java.lang.String value)
      Update the value for the named field.
      void write​(java.nio.file.Path path)
      Writes the modfied inventory of PDMDBs.
      void writeBackup​(java.nio.file.Path path)
      Writes the current inventory document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • inventoryDocument

        org.w3c.dom.Document inventoryDocument
      • inventoryElement

        org.w3c.dom.Element inventoryElement
      • currentElement

        org.w3c.dom.Element currentElement
      • headerList

        java.util.ArrayList<java.lang.String> headerList
      • pdmdbInventory

        static Inventory pdmdbInventory
      • moduleInventory

        static Inventory moduleInventory
      • dtmUpdate

        public static java.util.function.Consumer<org.w3c.dom.NodeList> dtmUpdate
      • tcmUpdate

        public static java.util.function.Consumer<org.w3c.dom.NodeList> tcmUpdate
    • Constructor Detail

      • Inventory

        public Inventory​(java.lang.String fileName,
                         java.lang.String tableName)

        Loads the inventory (.fods) document and locates the named table.

        Parameters:
        fileName - Directory path of .fods (OpenDocument spreadsheet, flat XML) file.
        tableName - Name of the table (sheet) containing the inventory data.
    • Method Detail

      • doIndex

        public void doIndex​(java.lang.String indexField,
                            java.lang.String attributeName)

        Indexes the table.

        An indexing attribute is added to each table row to allow simple searching using the getElementById method.

        LibreOffice won't recognise and will silently ignore this attribute therefore it will probably not be persistent.

        Parameters:
        indexField - The name of the field (column) in the table that will be used to create the index values.
        attributeName - The name of the attribute that will be created.
      • identify

        public org.w3c.dom.Element identify​(java.lang.String id)

        Locates an existing element matching the (unique) id.

        Does not update currentElement to avoid changing the context for other methods.

        Parameters:
        id - The identifier.
        Returns:
        The element or null if not found.
      • identify

        public java.lang.String identify​(java.lang.String id,
                                         java.lang.String match,
                                         java.lang.String reference,
                                         java.lang.String idAttributeName)

        Locates the element matching the id and updates currentElement.

        A new element is created if the id is not found. The new element id must match the provided pattern. It is cloned from reference and idAttributeName is set as the ID attribute.

        Parameters:
        id - The identifier.
        match - The identifier must match this regular expression.
        reference - Identifier of existing element to clone.
        idAttributeName - The name of the id attribute.
        Returns:
        The id.
      • write

        public void write​(java.nio.file.Path path)

        Writes the modfied inventory of PDMDBs.

        Parameters:
        path - Path of database XML file.
      • writeBackup

        public void writeBackup​(java.nio.file.Path path)

        Writes the current inventory document.

        A timestamp is appended to the created file name after the provided prefix.

        Note that the created files has .xml extension but it is also a valid .fods file that can be opened in LibreOffice.

        Parameters:
        path - The path name.
      • updateField

        public void updateField​(java.lang.String id,
                                java.lang.String name,
                                java.lang.String value)

        Update the value for the named field.

        Parameters:
        id - The value of the ID attribute of the record to be updated.
        name - Name of the field to update.
        value - The new value.
      • updateField

        public void updateField​(java.lang.String name,
                                java.lang.String value)

        Update the value for the named field.

        Parameters:
        name - Name of the field to update.
        value - The new value.
      • getFieldValue

        public java.lang.String getFieldValue​(java.lang.String name)

        Get the value for the named field for the current row.

        Parameters:
        name - Name of the field.
        Returns:
        The value.
      • getFieldValue

        public java.lang.String getFieldValue​(org.w3c.dom.NodeList nl,
                                              java.lang.String name)

        Get the value for the named field in the NodeList.

        Parameters:
        nl - A NodeList containing the fields.
        name - Name of the field.
        Returns:
        The value.
      • isCurrentElementNull

        public boolean isCurrentElementNull()
      • forEach

        public void forEach​(java.util.function.Consumer<? super org.w3c.dom.NodeList> action)
      • main

        public static void main​(java.lang.String[] args)