Class AbstractContentUpgradeOperation
- java.lang.Object
-
- org.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
-
- org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
-
- org.craftercms.studio.impl.v2.upgrade.operations.site.AbstractContentUpgradeOperation
-
- All Implemented Interfaces:
org.craftercms.commons.upgrade.UpgradeOperation<String>
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.web.context.ServletContextAware
- Direct Known Subclasses:
AbstractContentTypeUpgradeOperation
,ConfigEncryptionUpgradeOperation
,FindAndReplaceUpgradeOperation
public abstract class AbstractContentUpgradeOperation extends AbstractUpgradeOperation
Base implementation ofUpgradeOperation
for all site content upgradesSupported YAML properties:
- includedPaths: (required) list of patterns to check for files in the repository
- Author:
- joseross
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractContentUpgradeOperation.ListFileVisitor
Implementation ofFileVisitor
that collects files matching any of the given patterns
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_KEY_INCLUDED_PATHS
protected List<String>
includedPaths
List of patterns to check for files in the repository-
Fields inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
changedFiles, commitDetails, CONFIG_KEY_COMMIT_DETAILS, deletedFiles, servletContext, studioConfiguration
-
-
Constructor Summary
Constructors Constructor Description AbstractContentUpgradeOperation(StudioConfiguration studioConfiguration)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
doExecute(StudioUpgradeContext context)
protected void
doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
protected List<Path>
filterPaths(StudioUpgradeContext context, List<Path> matchedPaths)
Filters the given list checking if the files match the update conditionsprotected List<Path>
findIncludedPaths(StudioUpgradeContext context)
Finds all files in the given site that match any of the given patternsprotected String
readFile(Path path)
Performs a read operation from the file systemprotected abstract boolean
shouldBeUpdated(StudioUpgradeContext context, Path file)
Indicates if the given file should be updated by this classprotected abstract void
updateFile(StudioUpgradeContext context, Path path)
Performs any needed updates on the content of the given fileprotected void
writeFile(Path path, String content)
Performs a write operation in the file system without committing any changes in the repository-
Methods inherited from class org.craftercms.studio.impl.v2.upgrade.operations.AbstractUpgradeOperation
commitAllChanges, doExecute, getCommitMessage, init, loadResource, setServletContext, trackChangedFiles, trackDeletedFiles
-
-
-
-
Field Detail
-
CONFIG_KEY_INCLUDED_PATHS
public static final String CONFIG_KEY_INCLUDED_PATHS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractContentUpgradeOperation
public AbstractContentUpgradeOperation(StudioConfiguration studioConfiguration)
-
-
Method Detail
-
doInit
protected void doInit(org.apache.commons.configuration2.HierarchicalConfiguration config)
- Overrides:
doInit
in classorg.craftercms.commons.upgrade.impl.operations.AbstractUpgradeOperation<String>
-
doExecute
public void doExecute(StudioUpgradeContext context) throws org.craftercms.commons.upgrade.exception.UpgradeException
- Specified by:
doExecute
in classAbstractUpgradeOperation
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
-
findIncludedPaths
protected List<Path> findIncludedPaths(StudioUpgradeContext context) throws IOException
Finds all files in the given site that match any of the given patterns- Parameters:
context
- the current upgrade context- Returns:
- the list of matching files
- Throws:
IOException
- if there is any error finding the files
-
filterPaths
protected List<Path> filterPaths(StudioUpgradeContext context, List<Path> matchedPaths) throws org.craftercms.commons.upgrade.exception.UpgradeException
Filters the given list checking if the files match the update conditions- Parameters:
context
- the current upgrade contextmatchedPaths
- the list of files to filter- Returns:
- the filtered list of files
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error filtering the files
-
shouldBeUpdated
protected abstract boolean shouldBeUpdated(StudioUpgradeContext context, Path file) throws org.craftercms.commons.upgrade.exception.UpgradeException
Indicates if the given file should be updated by this class- Parameters:
context
- the current upgrade contextfile
- the file to check- Returns:
- true if the file should be updated
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error checking the file
-
updateFile
protected abstract void updateFile(StudioUpgradeContext context, Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException
Performs any needed updates on the content of the given file- Parameters:
context
- the current upgrade contextpath
- the file to update- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error updating the file
-
readFile
protected String readFile(Path path) throws org.craftercms.commons.upgrade.exception.UpgradeException
Performs a read operation from the file system- Parameters:
path
- the file to read- Returns:
- the content of the file
- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- if there is any error reading the file
-
writeFile
protected void writeFile(Path path, String content) throws org.craftercms.commons.upgrade.exception.UpgradeException
Performs a write operation in the file system without committing any changes in the repository- Parameters:
path
- the file to writecontent
- the content to write- Throws:
org.craftercms.commons.upgrade.exception.UpgradeException
- is there is any error writing the content
-
-