Class GitContentRepository
java.lang.Object
org.craftercms.studio.impl.v1.repository.git.GitContentRepository
- All Implemented Interfaces:
ContentRepository
,org.springframework.beans.factory.Aware
,org.springframework.web.context.ServletContextAware
public class GitContentRepository
extends Object
implements ContentRepository, org.springframework.web.context.ServletContextAware
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContextManager
protected jakarta.servlet.ServletContext
protected org.craftercms.commons.crypto.TextEncryptor
protected GeneralLockService
protected GitRepositoryHelper
protected ProcessedCommitsDAO
protected RemoteRepositoryDAO
protected RetryingDatabaseOperationFacade
protected RetryingRepositoryOperationFacade
protected SecurityService
protected ServicesConfig
protected SiteDAO
protected StudioConfiguration
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addRemote
(String siteId, String remoteName, String remoteUrl, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) Add remote repository for site content repositoryvoid
bootstrap the global repositoryprotected void
cleanup
(String siteId, GitRepositories repository) void
cleanupRepositories
(String siteId) Performs a cleanup all repositories for the given siteboolean
contentExists
(String site, String path) Determine if content exists in the repository at a given pathcopyContent
(String siteId, String fromPath, String toPath) copy content from PathA to pathBcreateFolder
(String siteId, String path, String name) create a foldercreateVersion
(String site, String path, boolean majorVersion) create a versioncreateVersion
(String site, String path, String comment, boolean majorVersion) create a versiondeleteContent
(String siteId, String path, String approver) delete contentboolean
deleteSite
(String site) Deletes an existing site.getContent
(String site, String path, boolean shallow) Get content from the repositorygetContentChildren
(String site, String path) get immediate children for pathgetContentVersionHistory
(String site, String path) get the version history for an itemgetRepoFirstCommitId
(String site) Get first id from repository for given sitegetRepoLastCommitId
(String site) Get last commit id from repository for given site.void
initialPublish
(String site, String sandboxBranch, String environment, String author, String comment) Initial publish to specified environment.boolean
Check if content at given path is folderlistRemote
(String siteId, String sandboxBranch) List remote repositories for given sitevoid
lockItemForPublishing
(String site, String path) lock an item NOTE: site will be removed from this interfacemoveContent
(String siteId, String fromPath, String toPath, String newName) move content from PathA to pathBboolean
pullFromRemote
(String siteId, String remoteName, String remoteBranch) Pull from remote repositoryboolean
pushToRemote
(String siteId, String remoteName, String remoteBranch) Push content to remote repositoryvoid
Remove all remotes for given sitevoid
resetStagingRepository
(String siteId) Reset staging repository to live for given siterevertContent
(String site, String path, String version, boolean major, String comment) revert a version (create a new version based on an old version)void
setContextManager
(ContextManager contextManager) void
setEncryptor
(org.craftercms.commons.crypto.TextEncryptor encryptor) void
setGeneralLockService
(GeneralLockService generalLockService) void
setHelper
(GitRepositoryHelper helper) void
setProcessedCommitsDao
(ProcessedCommitsDAO processedCommitsDao) void
setRemoteRepositoryDAO
(RemoteRepositoryDAO remoteRepositoryDAO) void
setRetryingDatabaseOperationFacade
(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade) void
setRetryingRepositoryOperationFacade
(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) void
setSecurityService
(SecurityService securityService) void
setServicesConfig
(ServicesConfig servicesConfig) void
setServletContext
(jakarta.servlet.ServletContext ctx) void
setSiteDao
(SiteDAO siteDao) void
setStudioConfiguration
(StudioConfiguration studioConfiguration) boolean
shallowContentExists
(String site, String path) This is a faster, but less accurate, version of contentExists.protected InputStream
shallowGetContent
(String site, String path) void
unLockItem
(String site, String path) unlock an item for publishing NOTE: site will be removed from this interfacevoid
unLockItemForPublishing
(String site, String path) unlock an item for publishing NOTE: site will be removed from this interfacewriteContent
(String siteId, String path, InputStream content) write contentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.craftercms.studio.api.v1.repository.ContentRepository
getContent, moveContent
-
Field Details
-
encryptor
protected org.craftercms.commons.crypto.TextEncryptor encryptor -
ctx
protected jakarta.servlet.ServletContext ctx -
studioConfiguration
-
servicesConfig
-
remoteRepositoryDAO
-
securityService
-
siteDao
-
contextManager
-
generalLockService
-
helper
-
processedCommitsDao
-
retryingRepositoryOperationFacade
-
retryingDatabaseOperationFacade
-
-
Constructor Details
-
GitContentRepository
public GitContentRepository()
-
-
Method Details
-
contentExists
Description copied from interface:ContentRepository
Determine if content exists in the repository at a given path- Specified by:
contentExists
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path to check if content exists- Returns:
- true if site has content object at path
-
shallowContentExists
Description copied from interface:ContentRepository
This is a faster, but less accurate, version of contentExists. This prioritizes performance over checking the actual underlying repository if the content is actually in the store or we simply hold a reference to the object in the actual store.- Specified by:
shallowContentExists
in interfaceContentRepository
- Returns:
- true if site has content object at path
-
shallowGetContent
- Throws:
ContentNotFoundException
-
getContent
public InputStream getContent(String site, String path, boolean shallow) throws ContentNotFoundException Description copied from interface:ContentRepository
Get content from the repository- Specified by:
getContent
in interfaceContentRepository
- Parameters:
site
- the site idpath
- the path of the contentshallow
- if true, it will load the file from disk directly, instead of retrieving it from git repository- Returns:
- InputStream to read the content
- Throws:
ContentNotFoundException
- if the content is not found
-
writeContent
Description copied from interface:ContentRepository
write content- Specified by:
writeContent
in interfaceContentRepository
- Parameters:
siteId
- site id where the operation will be executedpath
- path to contentcontent
- stream of content to write- Returns:
- Commit Id if successful, null otherwise
-
createFolder
Description copied from interface:ContentRepository
create a folder- Specified by:
createFolder
in interfaceContentRepository
- Parameters:
siteId
- site id where the operation will be executedpath
- path to create a folder inname
- a folder name to create- Returns:
- Commit Id if successful, null otherwise
-
deleteContent
Description copied from interface:ContentRepository
delete content- Specified by:
deleteContent
in interfaceContentRepository
- Parameters:
siteId
- site id where the operation will be executedpath
- path to contentapprover
- user that approves delete content- Returns:
- Commit ID if successful, null otherwise
-
moveContent
Description copied from interface:ContentRepository
move content from PathA to pathB- Specified by:
moveContent
in interfaceContentRepository
- Parameters:
siteId
- site id where the operation will be executedfromPath
- source contenttoPath
- target pathnewName
- new file name for rename- Returns:
- Commit ID if successful, empty string otherwise
-
copyContent
Description copied from interface:ContentRepository
copy content from PathA to pathB- Specified by:
copyContent
in interfaceContentRepository
- Parameters:
siteId
- site id where the operation will be executedfromPath
- paths to contenttoPath
- target path- Returns:
- Commit ID if successful, empty string otherwise
-
getContentChildren
Description copied from interface:ContentRepository
get immediate children for path- Specified by:
getContentChildren
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path to content- Returns:
- a list of children
-
getContentVersionHistory
Description copied from interface:ContentRepository
get the version history for an item- Specified by:
getContentVersionHistory
in interfaceContentRepository
- Parameters:
site
- - the project IDpath
- - the path of the item- Returns:
- a list of versions
-
createVersion
Description copied from interface:ContentRepository
create a version- Specified by:
createVersion
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- location of contentmajorVersion
- true if major- Returns:
- the created version ID or null on failure
-
createVersion
Description copied from interface:ContentRepository
create a version- Specified by:
createVersion
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- location of contentcomment
- version history commentmajorVersion
- true if major- Returns:
- the created version ID or null on failure
-
revertContent
public String revertContent(String site, String path, String version, boolean major, String comment) Description copied from interface:ContentRepository
revert a version (create a new version based on an old version)- Specified by:
revertContent
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- - the path of the item to "revert"version
- - old version ID to base to version onmajor
- flag if it is major versioncomment
- add comment when committing content- Returns:
- Commit ID if successful, empty string otherwise
-
lockItemForPublishing
Description copied from interface:ContentRepository
lock an item NOTE: site will be removed from this interface- Specified by:
lockItemForPublishing
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path of the item
-
unLockItem
Description copied from interface:ContentRepository
unlock an item for publishing NOTE: site will be removed from this interface- Specified by:
unLockItem
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path of the item
-
unLockItemForPublishing
Description copied from interface:ContentRepository
unlock an item for publishing NOTE: site will be removed from this interface- Specified by:
unLockItemForPublishing
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path of the item
-
bootstrap
@Order(1) @EventListener(org.springframework.context.event.ContextRefreshedEvent.class) public void bootstrap() throws Exceptionbootstrap the global repository- Throws:
Exception
-
deleteSite
Description copied from interface:ContentRepository
Deletes an existing site.- Specified by:
deleteSite
in interfaceContentRepository
- Parameters:
site
- site to delete- Returns:
- true if successful, false otherwise
-
initialPublish
public void initialPublish(String site, String sandboxBranch, String environment, String author, String comment) throws DeploymentException Description copied from interface:ContentRepository
Initial publish to specified environment.- Specified by:
initialPublish
in interfaceContentRepository
- Parameters:
site
- site identifiersandboxBranch
- sandbox branch nameenvironment
- environment to publishauthor
- authorcomment
- comment- Throws:
DeploymentException
- deployment error
-
getRepoLastCommitId
Description copied from interface:ContentRepository
Get last commit id from repository for given site.- Specified by:
getRepoLastCommitId
in interfaceContentRepository
- Parameters:
site
- site id- Returns:
- last commit id (current HEAD)
-
getRepoFirstCommitId
Description copied from interface:ContentRepository
Get first id from repository for given site- Specified by:
getRepoFirstCommitId
in interfaceContentRepository
- Parameters:
site
- site id- Returns:
- first commit id
-
addRemote
public boolean addRemote(String siteId, String remoteName, String remoteUrl, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) throws InvalidRemoteUrlException, ServiceLayerException Description copied from interface:ContentRepository
Add remote repository for site content repository- Specified by:
addRemote
in interfaceContentRepository
- Parameters:
siteId
- site identifierremoteName
- remote nameremoteUrl
- remote urlauthenticationType
- authentication typeremoteUsername
- remote usernameremotePassword
- remote passwordremoteToken
- remote tokenremotePrivateKey
- remote private key- Returns:
- true if operation was successful
- Throws:
InvalidRemoteUrlException
- invalid url for remote repositoryServiceLayerException
- general service error
-
removeRemoteRepositoriesForSite
Description copied from interface:ContentRepository
Remove all remotes for given site- Specified by:
removeRemoteRepositoriesForSite
in interfaceContentRepository
- Parameters:
siteId
- site identifier
-
listRemote
public List<RemoteRepositoryInfoTO> listRemote(String siteId, String sandboxBranch) throws ServiceLayerException Description copied from interface:ContentRepository
List remote repositories for given site- Specified by:
listRemote
in interfaceContentRepository
- Parameters:
siteId
- site identifiersandboxBranch
- sandbox branch name- Returns:
- list of names of remote repositories
- Throws:
ServiceLayerException
- general service error
-
pushToRemote
public boolean pushToRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException Description copied from interface:ContentRepository
Push content to remote repository- Specified by:
pushToRemote
in interfaceContentRepository
- Parameters:
siteId
- site identifierremoteName
- remote nameremoteBranch
- remote branch- Returns:
- true if operation was successful
- Throws:
ServiceLayerException
- general service errorInvalidRemoteUrlException
- invalid url for remote repository
-
pullFromRemote
public boolean pullFromRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException Description copied from interface:ContentRepository
Pull from remote repository- Specified by:
pullFromRemote
in interfaceContentRepository
- Parameters:
siteId
- site identifierremoteName
- remote nameremoteBranch
- remote branch- Returns:
- true if operation was successful
- Throws:
ServiceLayerException
- general service errorInvalidRemoteUrlException
- invalid url for remote repository
-
isFolder
Description copied from interface:ContentRepository
Check if content at given path is folder- Specified by:
isFolder
in interfaceContentRepository
- Parameters:
siteId
- site identifierpath
- content path- Returns:
- true if path is folder, otherwise false
-
resetStagingRepository
Description copied from interface:ContentRepository
Reset staging repository to live for given site- Specified by:
resetStagingRepository
in interfaceContentRepository
- Parameters:
siteId
- site identifier to use for resetting- Throws:
ServiceLayerException
- general service error
-
cleanup
-
cleanupRepositories
Performs a cleanup all repositories for the given site- Specified by:
cleanupRepositories
in interfaceContentRepository
- Parameters:
siteId
- site identifier
-
setServletContext
public void setServletContext(jakarta.servlet.ServletContext ctx) - Specified by:
setServletContext
in interfaceorg.springframework.web.context.ServletContextAware
-
setStudioConfiguration
-
setServicesConfig
-
setRemoteRepositoryDAO
-
setSecurityService
-
setSiteDao
-
setEncryptor
public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor) -
setContextManager
-
setGeneralLockService
-
setHelper
-
setProcessedCommitsDao
-
setRetryingRepositoryOperationFacade
public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) -
setRetryingDatabaseOperationFacade
public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)
-