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 ContextManagerprotected jakarta.servlet.ServletContextprotected org.craftercms.commons.crypto.TextEncryptorprotected GeneralLockServiceprotected GitRepositoryHelperprotected ProcessedCommitsDAOprotected RemoteRepositoryDAOprotected RetryingDatabaseOperationFacadeprotected RetryingRepositoryOperationFacadeprotected SecurityServiceprotected ServicesConfigprotected SiteDAOprotected StudioConfiguration -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddRemote(String siteId, String remoteName, String remoteUrl, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) Add remote repository for site content repositoryvoidbootstrap the global repositoryprotected voidcleanup(String siteId, GitRepositories repository) voidcleanupRepositories(String siteId) Performs a cleanup all repositories for the given sitebooleancontentExists(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 contentbooleandeleteSite(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.voidinitialPublish(String site, String sandboxBranch, String environment, String author, String comment) Initial publish to specified environment.booleanCheck if content at given path is folderlistRemote(String siteId, String sandboxBranch) List remote repositories for given sitevoidlockItemForPublishing(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 pathBbooleanpullFromRemote(String siteId, String remoteName, String remoteBranch) Pull from remote repositorybooleanpushToRemote(String siteId, String remoteName, String remoteBranch) Push content to remote repositoryvoidRemove all remotes for given sitevoidresetStagingRepository(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)voidsetContextManager(ContextManager contextManager) voidsetEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor) voidsetGeneralLockService(GeneralLockService generalLockService) voidsetHelper(GitRepositoryHelper helper) voidsetProcessedCommitsDao(ProcessedCommitsDAO processedCommitsDao) voidsetRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO) voidsetRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade) voidsetRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) voidsetSecurityService(SecurityService securityService) voidsetServicesConfig(ServicesConfig servicesConfig) voidsetServletContext(jakarta.servlet.ServletContext ctx) voidsetSiteDao(SiteDAO siteDao) voidsetStudioConfiguration(StudioConfiguration studioConfiguration) booleanshallowContentExists(String site, String path) This is a faster, but less accurate, version of contentExists.protected InputStreamshallowGetContent(String site, String path) voidunLockItem(String site, String path) unlock an item for publishing NOTE: site will be removed from this interfacevoidunLockItemForPublishing(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, waitMethods 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:ContentRepositoryDetermine if content exists in the repository at a given path- Specified by:
contentExistsin 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:ContentRepositoryThis 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:
shallowContentExistsin 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:ContentRepositoryGet content from the repository- Specified by:
getContentin 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:ContentRepositorywrite content- Specified by:
writeContentin 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:ContentRepositorycreate a folder- Specified by:
createFolderin 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:ContentRepositorydelete content- Specified by:
deleteContentin 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:ContentRepositorymove content from PathA to pathB- Specified by:
moveContentin 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:ContentRepositorycopy content from PathA to pathB- Specified by:
copyContentin 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:ContentRepositoryget immediate children for path- Specified by:
getContentChildrenin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path to content- Returns:
- a list of children
-
getContentVersionHistory
Description copied from interface:ContentRepositoryget the version history for an item- Specified by:
getContentVersionHistoryin interfaceContentRepository- Parameters:
site- - the project IDpath- - the path of the item- Returns:
- a list of versions
-
createVersion
Description copied from interface:ContentRepositorycreate a version- Specified by:
createVersionin 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:ContentRepositorycreate a version- Specified by:
createVersionin 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:ContentRepositoryrevert a version (create a new version based on an old version)- Specified by:
revertContentin 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:ContentRepositorylock an item NOTE: site will be removed from this interface- Specified by:
lockItemForPublishingin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path of the item
-
unLockItem
Description copied from interface:ContentRepositoryunlock an item for publishing NOTE: site will be removed from this interface- Specified by:
unLockItemin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path of the item
-
unLockItemForPublishing
Description copied from interface:ContentRepositoryunlock an item for publishing NOTE: site will be removed from this interface- Specified by:
unLockItemForPublishingin 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:ContentRepositoryDeletes an existing site.- Specified by:
deleteSitein 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:ContentRepositoryInitial publish to specified environment.- Specified by:
initialPublishin interfaceContentRepository- Parameters:
site- site identifiersandboxBranch- sandbox branch nameenvironment- environment to publishauthor- authorcomment- comment- Throws:
DeploymentException- deployment error
-
getRepoLastCommitId
Description copied from interface:ContentRepositoryGet last commit id from repository for given site.- Specified by:
getRepoLastCommitIdin interfaceContentRepository- Parameters:
site- site id- Returns:
- last commit id (current HEAD)
-
getRepoFirstCommitId
Description copied from interface:ContentRepositoryGet first id from repository for given site- Specified by:
getRepoFirstCommitIdin 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:ContentRepositoryAdd remote repository for site content repository- Specified by:
addRemotein 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:ContentRepositoryRemove all remotes for given site- Specified by:
removeRemoteRepositoriesForSitein interfaceContentRepository- Parameters:
siteId- site identifier
-
listRemote
public List<RemoteRepositoryInfoTO> listRemote(String siteId, String sandboxBranch) throws ServiceLayerException Description copied from interface:ContentRepositoryList remote repositories for given site- Specified by:
listRemotein 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:ContentRepositoryPush content to remote repository- Specified by:
pushToRemotein 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:ContentRepositoryPull from remote repository- Specified by:
pullFromRemotein 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:ContentRepositoryCheck if content at given path is folder- Specified by:
isFolderin interfaceContentRepository- Parameters:
siteId- site identifierpath- content path- Returns:
- true if path is folder, otherwise false
-
resetStagingRepository
Description copied from interface:ContentRepositoryReset staging repository to live for given site- Specified by:
resetStagingRepositoryin 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:
cleanupRepositoriesin interfaceContentRepository- Parameters:
siteId- site identifier
-
setServletContext
public void setServletContext(jakarta.servlet.ServletContext ctx) - Specified by:
setServletContextin 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)
-