Class AbstractContentMigrationTask
java.lang.Object
org.onehippo.forge.content.exim.core.impl.AbstractContentMigrationTask
- All Implemented Interfaces:
ContentMigrationTask
- Direct Known Subclasses:
AbstractContentExportTask
,AbstractContentImportTask
Abstract
ContentMigrationTask
implementation class to provide common properties and utility operations.-
Constructor Summary
ConstructorsConstructorDescriptionAbstractContentMigrationTask
(DocumentManager documentManager) Constructs withdocumentManager
. -
Method Summary
Modifier and TypeMethodDescriptionbeginRecord
(String contentId, String contentPath) Begins a new unit of content migration work item which can be identified by eithercontentId
orcontentPath
.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 ofFileObject
) underbaseFolder
based on the file name pattern specified by the regular expression,nameRegex
.org.apache.commons.vfs2.FileObject
Returns base folder object of typeFileObject
, 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>
ReturnsContentValueConverter
instance.static ContentMigrationRecord
Returns the currentContentMigrationRecord
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 aContentNode
object or an external file when the data size is bigger than the threshold.ReturnsDocumentManager
instance.org.slf4j.Logger
Returns logger used by this task.com.fasterxml.jackson.databind.ObjectMapper
ReturnsObjectMapper
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) ReadssourceFile
containing aContentNode
data in JSON format and returns a parsedContentNode
object.org.onehippo.forge.content.pojo.model.ContentNode
readContentNodeFromXmlFile
(org.apache.commons.vfs2.FileObject sourceFile) ReadssourceFile
containing aContentNode
data in XML format and returns a parsedContentNode
object.void
setBinaryValueFileFolder
(org.apache.commons.vfs2.FileObject binaryValueFileFolder) Sets the base folder object of typeFileObject
, 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) SetsContentValueConverter
.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 aContentNode
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) SetsObjectMapper
instance.void
start()
Starts this task.void
stop()
Stops this task.void
writeContentNodeToJsonFile
(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile) WritescontentNode
object intotargetFile
in JSON format.void
writeContentNodeToXmlFile
(org.onehippo.forge.content.pojo.model.ContentNode contentNode, org.apache.commons.vfs2.FileObject targetFile) WritescontentNode
object intotargetFile
in XML format.
-
Constructor Details
-
AbstractContentMigrationTask
Constructs withdocumentManager
.- Parameters:
documentManager
-DocumentManager
instance
-
-
Method Details
-
getLogger
public org.slf4j.Logger getLogger()Returns logger used by this task.- Specified by:
getLogger
in interfaceContentMigrationTask
- 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 interfaceContentMigrationTask
- 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 interfaceContentMigrationTask
-
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 interfaceContentMigrationTask
-
getStartedTimeMillis
public long getStartedTimeMillis()Returns the started time milliseconds.- Specified by:
getStartedTimeMillis
in interfaceContentMigrationTask
- Returns:
- the started time milliseconds
-
getStoppedTimeMillis
public long getStoppedTimeMillis()Returns the stopped time milliseconds.- Specified by:
getStoppedTimeMillis
in interfaceContentMigrationTask
- Returns:
- the stopped time milliseconds
-
beginRecord
Begins a new unit of content migration work item which can be identified by eithercontentId
orcontentPath
.- Specified by:
beginRecord
in interfaceContentMigrationTask
- Parameters:
contentId
- content identifier for this unit of content migration workcontentPath
- content path for this unit of content migration work- Returns:
- a new
ContentMigrationRecord
instance
-
endRecord
Ends the current unit of content migration work item.- Specified by:
endRecord
in interfaceContentMigrationTask
- Returns:
- the current
ContentMigrationRecord
instance
-
getContentMigrationRecords
Returns the collection containing all the content migration work item records.- Specified by:
getContentMigrationRecords
in interfaceContentMigrationTask
- Returns:
- the collection containing all the content migration work item records
-
getCurrentContentMigrationRecord
Returns the currentContentMigrationRecord
instance in the current context thread.- Returns:
- the current
ContentMigrationRecord
instance in the current context thread
-
getSummary
Description copied from interface:ContentMigrationTask
Return the execution summary.- Specified by:
getSummary
in interfaceContentMigrationTask
- 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 interfaceContentMigrationTask
-
getDocumentManager
ReturnsDocumentManager
instance.- Returns:
DocumentManager
instance
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()ReturnsObjectMapper
instance. If not set, returns a defaultObjectMapper
instance.- Returns:
ObjectMapper
instance
-
setObjectMapper
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) SetsObjectMapper
instance.- Parameters:
objectMapper
-ObjectMapper
instance
-
getContentValueConverter
public org.onehippo.forge.content.pojo.common.ContentValueConverter<Value> getContentValueConverter()ReturnsContentValueConverter
instance. If not set, returns a defaultContentValueConverter
instance.- Returns:
ContentValueConverter
instance
-
setContentValueConverter
public void setContentValueConverter(org.onehippo.forge.content.pojo.common.ContentValueConverter<Value> contentValueConverter) SetsContentValueConverter
.- Parameters:
contentValueConverter
-ContentValueConverter
instance
-
getBinaryValueFileFolder
public org.apache.commons.vfs2.FileObject getBinaryValueFileFolder()Returns base folder object of typeFileObject
, 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 typeFileObject
, which is used as a base folder when storing a binary value into an external file.- Parameters:
binaryValueFileFolder
- base folder object of typeFileObject
-
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 aContentNode
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 aContentNode
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 aContentNode
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 ofFileObject
) underbaseFolder
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 fromnameRegex
- file name pattern regular expressionminDepth
- minimum depth of a descendant filemaxDepth
- 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 ReadssourceFile
containing aContentNode
data in JSON format and returns a parsedContentNode
object.- Specified by:
readContentNodeFromJsonFile
in interfaceContentMigrationTask
- Parameters:
sourceFile
- source file containing aContentNode
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 ReadssourceFile
containing aContentNode
data in XML format and returns a parsedContentNode
object.- Specified by:
readContentNodeFromXmlFile
in interfaceContentMigrationTask
- Parameters:
sourceFile
- source file containing aContentNode
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 WritescontentNode
object intotargetFile
in JSON format.- Specified by:
writeContentNodeToJsonFile
in interfaceContentMigrationTask
- Parameters:
contentNode
- aContentNode
objecttargetFile
- target file to write thecontentNode
- 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 WritescontentNode
object intotargetFile
in XML format.- Specified by:
writeContentNodeToXmlFile
in interfaceContentMigrationTask
- Parameters:
contentNode
- aContentNode
objecttargetFile
- target file to write thecontentNode
- Throws:
ContentMigrationException
- if writing fails.
-