Class AbstractContentMigrationTask

java.lang.Object
org.onehippo.forge.content.exim.core.impl.AbstractContentMigrationTask
All Implemented Interfaces:
ContentMigrationTask
Direct Known Subclasses:
AbstractContentExportTask, AbstractContentImportTask

public abstract class AbstractContentMigrationTask extends Object implements ContentMigrationTask
Abstract ContentMigrationTask implementation class to provide common properties and utility operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs with documentManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    beginRecord(String contentId, String contentPath)
    Begins a new unit of content migration work item which can be identified by either contentId or contentPath.
    Ends the current unit of content migration work item.
    org.apache.commons.vfs2.FileObject[]
    findFilesByNamePattern(org.apache.commons.vfs2.FileObject baseFolder, String nameRegex, int minDepth, int maxDepth)
    Finds files (type of FileObject) under baseFolder based on the file name pattern specified by the regular expression, nameRegex.
    org.apache.commons.vfs2.FileObject
    Returns base folder object of type FileObject, which is used as a base folder when storing a binary value into an external file.
    Returns the collection containing all the content migration work item records.
    org.onehippo.forge.content.pojo.common.ContentValueConverter<Value>
    Returns ContentValueConverter instance.
    Returns the current ContentMigrationRecord instance in the current context thread.
    long
    Returns the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
    Returns DocumentManager instance.
    org.slf4j.Logger
    Returns logger used by this task.
    com.fasterxml.jackson.databind.ObjectMapper
    Returns ObjectMapper instance.
    long
    Returns the started time milliseconds.
    long
    Returns the stopped time milliseconds.
    Return the execution summary.
    void
    Logs the execution summary by using the logger.
    org.onehippo.forge.content.pojo.model.ContentNode
    readContentNodeFromJsonFile(org.apache.commons.vfs2.FileObject sourceFile)
    Reads sourceFile containing a ContentNode data in JSON format and returns a parsed ContentNode object.
    org.onehippo.forge.content.pojo.model.ContentNode
    readContentNodeFromXmlFile(org.apache.commons.vfs2.FileObject sourceFile)
    Reads sourceFile containing a ContentNode data in XML format and returns a parsed ContentNode object.
    void
    setBinaryValueFileFolder(org.apache.commons.vfs2.FileObject binaryValueFileFolder)
    Sets the base folder object of type FileObject, which is used as a base folder when storing a binary value into an external file.
    void
    setContentValueConverter(org.onehippo.forge.content.pojo.common.ContentValueConverter<Value> contentValueConverter)
    Sets ContentValueConverter.
    void
    setDataUrlSizeThreashold(long dataUrlSizeThreashold)
    Sets the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
    void
    setLogger(org.slf4j.Logger logger)
    Sets a logger to be used by this task.
    void
    setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Sets ObjectMapper instance.
    void
    Starts this task.
    void
    Stops this task.
    void
    writeContentNodeToJsonFile(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile)
    Writes contentNode object into targetFile in JSON format.
    void
    writeContentNodeToXmlFile(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile)
    Writes contentNode object into targetFile in XML format.

    Methods inherited from class java.lang.Object

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

    • AbstractContentMigrationTask

      public AbstractContentMigrationTask(DocumentManager documentManager)
      Constructs with documentManager.
      Parameters:
      documentManager - DocumentManager instance
  • Method Details

    • getLogger

      public org.slf4j.Logger getLogger()
      Returns logger used by this task.
      Specified by:
      getLogger in interface ContentMigrationTask
      Returns:
      logger used by this task
    • setLogger

      public void setLogger(org.slf4j.Logger logger)
      Sets a logger to be used by this task.
      Specified by:
      setLogger in interface ContentMigrationTask
      Parameters:
      logger - logger to be used by this task
    • start

      public void start()
      Starts this task. By 'starting', this task is supposed to reset its content migration records and initialize the internal data. e.g, started time milliseconds.
      Specified by:
      start in interface ContentMigrationTask
    • stop

      public void stop()
      Stops this task. By 'stopping', this task is supposed to update the internal data. e.g, stopped time milliseconds. But this task is supposed to keep the content migration records even after stopping for reporting purpose.
      Specified by:
      stop in interface ContentMigrationTask
    • getStartedTimeMillis

      public long getStartedTimeMillis()
      Returns the started time milliseconds.
      Specified by:
      getStartedTimeMillis in interface ContentMigrationTask
      Returns:
      the started time milliseconds
    • getStoppedTimeMillis

      public long getStoppedTimeMillis()
      Returns the stopped time milliseconds.
      Specified by:
      getStoppedTimeMillis in interface ContentMigrationTask
      Returns:
      the stopped time milliseconds
    • beginRecord

      public ContentMigrationRecord beginRecord(String contentId, String contentPath)
      Begins a new unit of content migration work item which can be identified by either contentId or contentPath.
      Specified by:
      beginRecord in interface ContentMigrationTask
      Parameters:
      contentId - content identifier for this unit of content migration work
      contentPath - content path for this unit of content migration work
      Returns:
      a new ContentMigrationRecord instance
    • endRecord

      public ContentMigrationRecord endRecord()
      Ends the current unit of content migration work item.
      Specified by:
      endRecord in interface ContentMigrationTask
      Returns:
      the current ContentMigrationRecord instance
    • getContentMigrationRecords

      public Collection<ContentMigrationRecord> getContentMigrationRecords()
      Returns the collection containing all the content migration work item records.
      Specified by:
      getContentMigrationRecords in interface ContentMigrationTask
      Returns:
      the collection containing all the content migration work item records
    • getCurrentContentMigrationRecord

      public static ContentMigrationRecord getCurrentContentMigrationRecord()
      Returns the current ContentMigrationRecord instance in the current context thread.
      Returns:
      the current ContentMigrationRecord instance in the current context thread
    • getSummary

      public String getSummary()
      Description copied from interface: ContentMigrationTask
      Return the execution summary.
      Specified by:
      getSummary in interface ContentMigrationTask
      Returns:
      the execution summary
    • logSummary

      public void logSummary()
      Logs the execution summary by using the logger.

      The default implementation summarizes the result with details on each execution record in CSV format.

      Specified by:
      logSummary in interface ContentMigrationTask
    • getDocumentManager

      public DocumentManager getDocumentManager()
      Returns DocumentManager instance.
      Returns:
      DocumentManager instance
    • getObjectMapper

      public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Returns ObjectMapper instance. If not set, returns a default ObjectMapper instance.
      Returns:
      ObjectMapper instance
    • setObjectMapper

      public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Sets ObjectMapper instance.
      Parameters:
      objectMapper - ObjectMapper instance
    • getContentValueConverter

      public org.onehippo.forge.content.pojo.common.ContentValueConverter<Value> getContentValueConverter()
      Returns ContentValueConverter instance. If not set, returns a default ContentValueConverter instance.
      Returns:
      ContentValueConverter instance
    • setContentValueConverter

      public void setContentValueConverter(org.onehippo.forge.content.pojo.common.ContentValueConverter<Value> contentValueConverter)
      Sets ContentValueConverter.
      Parameters:
      contentValueConverter - ContentValueConverter instance
    • getBinaryValueFileFolder

      public org.apache.commons.vfs2.FileObject getBinaryValueFileFolder()
      Returns base folder object of type FileObject, which is used as a base folder when storing a binary value into an external file.
      Returns:
      base folder object of type FileObject
    • setBinaryValueFileFolder

      public void setBinaryValueFileFolder(org.apache.commons.vfs2.FileObject binaryValueFileFolder)
      Sets the base folder object of type FileObject, which is used as a base folder when storing a binary value into an external file.
      Parameters:
      binaryValueFileFolder - base folder object of type FileObject
    • getDataUrlSizeThreashold

      public long getDataUrlSizeThreashold()
      Returns the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
      Returns:
      the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
    • setDataUrlSizeThreashold

      public void setDataUrlSizeThreashold(long dataUrlSizeThreashold)
      Sets the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
      Parameters:
      dataUrlSizeThreashold - the threshold binary value data size used to determine if the specific binary value data should be stored in either an embedded data: url inside a ContentNode object or an external file when the data size is bigger than the threshold.
    • findFilesByNamePattern

      public org.apache.commons.vfs2.FileObject[] findFilesByNamePattern(org.apache.commons.vfs2.FileObject baseFolder, String nameRegex, int minDepth, int maxDepth) throws org.apache.commons.vfs2.FileSystemException
      Finds files (type of FileObject) under baseFolder based on the file name pattern specified by the regular expression, nameRegex. It only matches when the depth of a descendant file in the range, [minDepth, maxDepth].
      Parameters:
      baseFolder - base folder to search from
      nameRegex - file name pattern regular expression
      minDepth - minimum depth of a descendant file
      maxDepth - maximum depth of a descendant file
      Returns:
      array of files (type of FileObject) found
      Throws:
      org.apache.commons.vfs2.FileSystemException - if any file system exception occurs
    • readContentNodeFromJsonFile

      public org.onehippo.forge.content.pojo.model.ContentNode readContentNodeFromJsonFile(org.apache.commons.vfs2.FileObject sourceFile) throws ContentMigrationException
      Reads sourceFile containing a ContentNode data in JSON format and returns a parsed ContentNode object.
      Specified by:
      readContentNodeFromJsonFile in interface ContentMigrationTask
      Parameters:
      sourceFile - source file containing a ContentNode data in JSON format
      Returns:
      a parsed ContentNode object
      Throws:
      ContentMigrationException - if reading fails.
    • readContentNodeFromXmlFile

      public org.onehippo.forge.content.pojo.model.ContentNode readContentNodeFromXmlFile(org.apache.commons.vfs2.FileObject sourceFile) throws ContentMigrationException
      Reads sourceFile containing a ContentNode data in XML format and returns a parsed ContentNode object.
      Specified by:
      readContentNodeFromXmlFile in interface ContentMigrationTask
      Parameters:
      sourceFile - source file containing a ContentNode data in XML format
      Returns:
      a parsed ContentNode object
      Throws:
      ContentMigrationException - if reading fails.
    • writeContentNodeToJsonFile

      public void writeContentNodeToJsonFile(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile) throws ContentMigrationException
      Writes contentNode object into targetFile in JSON format.
      Specified by:
      writeContentNodeToJsonFile in interface ContentMigrationTask
      Parameters:
      contentNode - a ContentNode object
      targetFile - target file to write the contentNode
      Throws:
      ContentMigrationException - if writing fails.
    • writeContentNodeToXmlFile

      public void writeContentNodeToXmlFile(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile) throws ContentMigrationException
      Writes contentNode object into targetFile in XML format.
      Specified by:
      writeContentNodeToXmlFile in interface ContentMigrationTask
      Parameters:
      contentNode - a ContentNode object
      targetFile - target file to write the contentNode
      Throws:
      ContentMigrationException - if writing fails.