Class HistoryUtil


  • public class HistoryUtil
    extends Object
    Reads and writes history entries.
    Author:
    Roland Gruber
    • Constructor Detail

      • HistoryUtil

        public HistoryUtil()
    • Method Detail

      • createHistoryEntry

        public de.valtech.aecu.api.service.HistoryEntry createHistoryEntry​(org.apache.sling.api.resource.ResourceResolver resolver)
                                                                    throws de.valtech.aecu.api.service.AecuException
        Starts a new history entry.
        Parameters:
        resolver - resource resolver
        Returns:
        history entry
        Throws:
        de.valtech.aecu.api.service.AecuException - error setting up entry
      • storeExecutionInHistory

        public void storeExecutionInHistory​(de.valtech.aecu.api.service.HistoryEntry history,
                                            de.valtech.aecu.api.service.ExecutionResult result,
                                            org.apache.sling.api.resource.ResourceResolver resolver)
                                     throws de.valtech.aecu.api.service.AecuException
        Stores an execution run in existing history.
        Parameters:
        history - history entry
        result - script execution result
        resolver - resource resolver
        Throws:
        de.valtech.aecu.api.service.AecuException - error inserting history entry
      • finishHistoryEntry

        public void finishHistoryEntry​(de.valtech.aecu.api.service.HistoryEntry history,
                                       org.apache.sling.api.resource.ResourceResolver resolver)
        Finishes the history entry.
        Parameters:
        history - open history entry
        resolver - resource resolver
      • getHistory

        public List<de.valtech.aecu.api.service.HistoryEntry> getHistory​(int startIndex,
                                                                         int count,
                                                                         org.apache.sling.api.resource.ResourceResolver resolver)
        Returns the last history entries. The search starts at the newest entry.
        Parameters:
        startIndex - start reading at this index (first is 0)
        count - number of entries to read
        resolver - resource resolver
        Returns:
        history entries (newest first)
      • getHistoryEntryResource

        public org.apache.sling.api.resource.Resource getHistoryEntryResource​(org.apache.sling.api.resource.Resource child)
        Returns the base resource for a (fallback) script resource.
        Parameters:
        child - child of base resource
        Returns:
        base run resource
      • readHistoryEntry

        public de.valtech.aecu.api.service.HistoryEntry readHistoryEntry​(org.apache.sling.api.resource.Resource resource)
        Reads a history entry from JCR.
        Parameters:
        resource - history resource
        Returns:
        history entry
      • readHistorySingleResult

        public de.valtech.aecu.api.service.ExecutionResult readHistorySingleResult​(org.apache.sling.api.resource.Resource resource)
        Reads a single script run from history.
        Parameters:
        resource - resource
        Returns:
        result
      • createPath

        protected void createPath​(String path,
                                  org.apache.sling.api.resource.ResourceResolver resolver,
                                  String primaryType)
                           throws de.valtech.aecu.api.service.AecuException
        Creates the folder at the given path if not yet existing.
        Parameters:
        path - path
        resolver - resource resolver
        primaryType - primary type
        Throws:
        de.valtech.aecu.api.service.AecuException - error creating folder
      • purgeHistory

        public void purgeHistory​(org.apache.sling.api.resource.ResourceResolver resolver,
                                 int daysToKeep)
                          throws org.apache.sling.api.resource.PersistenceException
        Purges the history by keeping only entries within the set number of days.
        Parameters:
        resolver - resource resolver
        daysToKeep - number of days to keep
        Throws:
        org.apache.sling.api.resource.PersistenceException - error deleting node
      • selfCheck

        public void selfCheck​(org.apache.sling.api.resource.ResourceResolver resolver)
                       throws de.valtech.aecu.api.service.AecuException
        Self test of history. Checks if the history node exists.
        Parameters:
        resolver - resource resolver
        Throws:
        de.valtech.aecu.api.service.AecuException - check failed