Class FileManagementConnector

  • All Implemented Interfaces:
    ConnectorInterface, VersionInfoInterface

    public class FileManagementConnector
    extends Connector
    implements ConnectorInterface
    Connector which can read or modify files structure and metadata. It can create, find and delete files and directories. It works on Iterator, Lookup, Delete, AddOnly or Update modes.
    Since:
    7.2
    • Constructor Detail

      • FileManagementConnector

        public FileManagementConnector()
        Constructor. Initializes the connector to work in AddOnly, Iterator, Lookup, Update and Delete mode.
    • Method Detail

      • initialize

        public void initialize​(java.lang.Object o)
                        throws java.lang.Exception
        Initialize the connector. The connector may be passed a parameter of any kind by the user. It is up to the connector to determine whether this object can be used or not. The parameter is typically provided by a user script. When an AssemblyLine initializes it's Connectors, they are passed a ConnectorMode object.
        Specified by:
        initialize in interface ConnectorInterface
        Overrides:
        initialize in class Connector
        Parameters:
        o - User provided parameter
        Throws:
        java.lang.Exception - if the initialization of this connector fails.
      • selectEntries

        public void selectEntries()
                           throws java.lang.Exception
        Prepare the Connector for sequential read. Setup start directory. When the Connector is used as an Iterator in an AssemblyLine, this method will be called.
        Specified by:
        selectEntries in interface ConnectorInterface
        Overrides:
        selectEntries in class Connector
        Throws:
        java.lang.Exception - if startDirectory parameter is not name of existing directory or maxDirDepth is negative.
      • getNextEntry

        public Entry getNextEntry()
                           throws java.lang.Exception
        Returns the next Entry from the connector. The entry is populated with attributes and values from the next entry in the input set.

        Example:

         var ctor = input.getConnector();
         var entry = ctor.getNextEntry();
         
         for (; entry != null; entry = ctor.getNextEntry()) {
                main.logmsg("Read entry...");
                main.dumpEntry(entry);
         }
         
        Specified by:
        getNextEntry in interface ConnectorInterface
        Overrides:
        getNextEntry in class Connector
        Returns:
        - the next Entry, or null if no more data
        Throws:
        java.lang.Exception - if an error occurs.
        See Also:
        ConnectorInterface.selectEntries()
      • findEntry

        public Entry findEntry​(SearchCriteria searchCrit)
                        throws java.lang.Exception
        Finds an existing entry. The search criteria specifies which entry to locate

        Here is an example of how to find all people with names starting with 'J' which are from IBM organization in US.

        Example:

         var ctor = input.getConnector();
         var crit = new com.ibm.di.SearchCriteria("$dn",
                        com.ibm.di.SearchCriteria.SUBSTRING, "c=US,o=IBM");
         crit.addCriteria("name", com.ibm.di.SearchCriteria.INITIAL_STRING, "J");
         crit.addCriteria("objectclass", com.ibm.di.SearchCriteria.SUBSTRING, "person");
         
         var res = ctor.findEntry(crit);
         if (res != null) {
                main.logmsg("Found entry:");
                main.dumpEntry(res);
         } else {
          if( getFindEntryCount()> 1 ){
           main.logmsg("Found these entries:");
           while ( (entry = ctor.getNextFindEntry()) != null ) {
             main.dumpEntry(entry);
           }
          }
          else {
                 main.logmsg("Entry not found!");
          }
         }
         
        Specified by:
        findEntry in interface ConnectorInterface
        Overrides:
        findEntry in class Connector
        Parameters:
        searchCrit - The search criteria used to locate the entry to be modified
        Returns:
        The entry found, or null if no or multiple entries found
        Throws:
        java.lang.Exception - if an error occurs.
      • deleteEntry

        public void deleteEntry​(Entry entry,
                                SearchCriteria searchCrit)
                         throws java.lang.Exception
        Deletes an existing entry. The search criteria specifies which entry to modify. Some connectors may silently ignore the search criteria. For example, the LDAP connector will use the distinguished name ($dn) from the entry parameter (if it exists) rather than expanding the search criteria and search for the entry. Each connector's inner semantics governs whether the search parameter is used or not.
        Specified by:
        deleteEntry in interface ConnectorInterface
        Overrides:
        deleteEntry in class Connector
        Parameters:
        entry - The entry data
        searchCrit - The search criteria used to locate the entry to be deleted
        Throws:
        java.lang.Exception - if an error occurs.
      • forceDelete

        public void forceDelete​(java.lang.String filePathToDelete)
                         throws java.lang.Exception
        Delete the file or directory which path is provided. Both read-only files and non-empty directories will be deleted.
        Parameters:
        filePathToDelete - to be deleted.
        Throws:
        java.lang.Exception - if the file or directory cannot be deleted.
      • forceDelete

        public void forceDelete​(java.io.File fileToDelete)
                         throws java.lang.Exception
        Delete the given file or directory. Both read-only files and non-empty directories will be deleted.
        Parameters:
        fileToDelete - to be deleted.
        Throws:
        java.lang.Exception - if the file or directory cannot be deleted.
      • putEntry

        public void putEntry​(Entry newEntry)
                      throws java.lang.Exception
        Adds a new entry to the data source

        Example:

         var ctor = write.getConnector();
         
         for (i = 0; i < 10; i++) {
                var entry = system.newEntry();
                entry.setAttribute("linenumber", i);
                entry.setAttribute("line", i + " line of text...");
         
                main.logmsg("Writes entry to output...");
                main.dumpEntry(entry);
                ctor.putEntry(entry);
         }
         
        Specified by:
        putEntry in interface ConnectorInterface
        Overrides:
        putEntry in class Connector
        Parameters:
        newEntry - The entry data to add
        Throws:
        java.lang.Exception - if an error occurs.
      • modEntry

        public void modEntry​(Entry newEntry,
                             SearchCriteria searchCrit)
                      throws java.lang.Exception
        Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify.
        Specified by:
        modEntry in interface ConnectorInterface
        Overrides:
        modEntry in class Connector
        Parameters:
        newEntry - The entry data
        searchCrit - The search criteria used to locate the entry to be modified
        Throws:
        java.lang.Exception - if an error occurs.
      • modEntry

        public void modEntry​(Entry newEntry,
                             SearchCriteria searchCrit,
                             Entry oldEntry)
                      throws java.lang.Exception
        Modifies an existing entry. The new entry data is given by the entry parameter and the search criteria specifies which entry to modify.
        Specified by:
        modEntry in interface ConnectorInterface
        Overrides:
        modEntry in class Connector
        Parameters:
        newEntry - The entry data
        searchCrit - The search criteria used to locate the entry to be modified
        oldEntry - The old entry found by the search criteria
        Throws:
        java.lang.Exception - if an error occurs.
      • getVersion

        public java.lang.String getVersion()
        Version information.
        Specified by:
        getVersion in interface VersionInfoInterface
        Returns:
        version information