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
Fields Modifier and Type Field Description protected ContextManager
contextManager
protected javax.servlet.ServletContext
ctx
protected org.craftercms.commons.crypto.TextEncryptor
encryptor
protected GeneralLockService
generalLockService
protected GitLogDAO
gitLogDao
protected GitRepositoryHelper
helper
protected RemoteRepositoryDAO
remoteRepositoryDAO
protected RetryingDatabaseOperationFacade
retryingDatabaseOperationFacade
protected RetryingRepositoryOperationFacade
retryingRepositoryOperationFacade
protected SecurityService
securityService
protected ServicesConfig
servicesConfig
protected SiteFeedMapper
siteFeedMapper
protected StudioConfiguration
studioConfiguration
-
Constructor Summary
Constructors Constructor Description GitContentRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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()
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 pathString
copyContent(String site, String fromPath, String toPath)
copy content from PathA to pathBString
createFolder(String site, String path, String name)
create a folderString
createVersion(String site, String path, boolean majorVersion)
create a versionString
createVersion(String site, String path, String comment, boolean majorVersion)
create a versionString
deleteContent(String site, String path, String approver)
delete contentvoid
deleteGitLogForSite(String siteId)
Delete Git log for siteboolean
deleteSite(String site)
Deletes an existing site.InputStream
getContent(String site, String path)
get document from wcm contentRepositoryItem[]
getContentChildren(String site, String path)
get immediate children for pathVersionTO[]
getContentVersionHistory(String site, String path)
get the version history for an itemList<String>
getEditCommitIds(String site, String path, String commitIdFrom, String commitIdTo)
Get a list of commits for updates on a contentGeneralLockService
getGeneralLockService()
GitLogDAO
getGitLogDao()
GitRepositoryHelper
getHelper()
RemoteRepositoryDAO
getRemoteRepositoryDAO()
String
getRepoFirstCommitId(String site)
Get first id from repository for given siteString
getRepoLastCommitId(String site)
Get last commit id from repository for given site.RetryingDatabaseOperationFacade
getRetryingDatabaseOperationFacade()
RetryingRepositoryOperationFacade
getRetryingRepositoryOperationFacade()
SecurityService
getSecurityService()
ServicesConfig
getServicesConfig()
SiteFeedMapper
getSiteFeedMapper()
void
initialPublish(String site, String sandboxBranch, String environment, String author, String comment)
Initial publish to specified environment.void
insertFullGitLog(String siteId, int processed)
Insert Full Git Logboolean
isFolder(String siteId, String path)
Check if content at given path is folderList<RemoteRepositoryInfoTO>
listRemote(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 interfaceMap<String,String>
moveContent(String site, 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
reloadRepository(String siteId)
Reload repository for given sitevoid
removeRemoteRepositoriesForSite(String siteId)
Remove all remotes for given sitevoid
resetStagingRepository(String siteId)
Reset staging repository to live for given siteString
revertContent(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
setGitLogDao(GitLogDAO gitLogDao)
void
setHelper(GitRepositoryHelper helper)
void
setRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO)
void
setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)
void
setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade)
void
setSecurityService(SecurityService securityService)
void
setServicesConfig(ServicesConfig servicesConfig)
void
setServletContext(javax.servlet.ServletContext ctx)
void
setSiteFeedMapper(SiteFeedMapper siteFeedMapper)
void
setStudioConfiguration(StudioConfiguration studioConfiguration)
boolean
shallowContentExists(String site, String path)
This is a faster, but less accurate, version of contentExists.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 interfaceString
writeContent(String site, String path, InputStream content)
write content-
Methods 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
moveContent
-
-
-
-
Field Detail
-
encryptor
protected org.craftercms.commons.crypto.TextEncryptor encryptor
-
ctx
protected javax.servlet.ServletContext ctx
-
studioConfiguration
protected StudioConfiguration studioConfiguration
-
servicesConfig
protected ServicesConfig servicesConfig
-
gitLogDao
protected GitLogDAO gitLogDao
-
remoteRepositoryDAO
protected RemoteRepositoryDAO remoteRepositoryDAO
-
securityService
protected SecurityService securityService
-
siteFeedMapper
protected SiteFeedMapper siteFeedMapper
-
contextManager
protected ContextManager contextManager
-
generalLockService
protected GeneralLockService generalLockService
-
helper
protected GitRepositoryHelper helper
-
retryingRepositoryOperationFacade
protected RetryingRepositoryOperationFacade retryingRepositoryOperationFacade
-
retryingDatabaseOperationFacade
protected RetryingDatabaseOperationFacade retryingDatabaseOperationFacade
-
-
Method Detail
-
contentExists
public boolean contentExists(String site, String path)
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
public boolean shallowContentExists(String site, String path)
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
-
getContent
public InputStream getContent(String site, String path) throws ContentNotFoundException
Description copied from interface:ContentRepository
get document from wcm content- Specified by:
getContent
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path of the content- Returns:
- document
- Throws:
ContentNotFoundException
- content not found at given path
-
writeContent
public String writeContent(String site, String path, InputStream content)
Description copied from interface:ContentRepository
write content- Specified by:
writeContent
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path to contentcontent
- stream of content to write- Returns:
- Commit Id if successful, null otherwise
-
createFolder
public String createFolder(String site, String path, String name)
Description copied from interface:ContentRepository
create a folder- Specified by:
createFolder
in interfaceContentRepository
- Parameters:
site
- 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
public String deleteContent(String site, String path, String approver)
Description copied from interface:ContentRepository
delete content- Specified by:
deleteContent
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedpath
- path to contentapprover
- user that approves delete content- Returns:
- Commit ID if successful, null otherwise
-
moveContent
public Map<String,String> moveContent(String site, String fromPath, String toPath, String newName)
Description copied from interface:ContentRepository
move content from PathA to pathB- Specified by:
moveContent
in interfaceContentRepository
- Parameters:
site
- 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
public String copyContent(String site, String fromPath, String toPath)
Description copied from interface:ContentRepository
copy content from PathA to pathB- Specified by:
copyContent
in interfaceContentRepository
- Parameters:
site
- site id where the operation will be executedfromPath
- paths to contenttoPath
- target path- Returns:
- Commit ID if successful, empty string otherwise
-
getContentChildren
public RepositoryItem[] getContentChildren(String site, String path)
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
public VersionTO[] getContentVersionHistory(String site, String path)
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
public String createVersion(String site, String path, boolean majorVersion)
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
public String createVersion(String site, String path, String comment, boolean majorVersion)
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
public void lockItemForPublishing(String site, String path)
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
public void unLockItem(String site, String path)
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
public void unLockItemForPublishing(String site, String path)
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 Exception
bootstrap the global repository- Throws:
Exception
-
deleteSite
public boolean deleteSite(String site)
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
public String getRepoLastCommitId(String site)
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
public String getRepoFirstCommitId(String site)
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
-
getEditCommitIds
public List<String> getEditCommitIds(String site, String path, String commitIdFrom, String commitIdTo)
Description copied from interface:ContentRepository
Get a list of commits for updates on a content- Specified by:
getEditCommitIds
in interfaceContentRepository
- Parameters:
site
- site idpath
- pathcommitIdFrom
- range from commit id (inclusive)commitIdTo
- range to commit id (inclusive)- Returns:
- list of edit commit ids
-
insertFullGitLog
public void insertFullGitLog(String siteId, int processed)
Description copied from interface:ContentRepository
Insert Full Git Log- Specified by:
insertFullGitLog
in interfaceContentRepository
- Parameters:
siteId
- siteprocessed
- processed
-
deleteGitLogForSite
public void deleteGitLogForSite(String siteId)
Description copied from interface:ContentRepository
Delete Git log for site- Specified by:
deleteGitLogForSite
in interfaceContentRepository
- Parameters:
siteId
- site identifier
-
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
public void removeRemoteRepositoriesForSite(String siteId)
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
public boolean isFolder(String siteId, String path)
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
public void resetStagingRepository(String siteId) throws ServiceLayerException
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
-
reloadRepository
public void reloadRepository(String siteId)
Description copied from interface:ContentRepository
Reload repository for given site- Specified by:
reloadRepository
in interfaceContentRepository
- Parameters:
siteId
- site identifier
-
cleanup
protected void cleanup(String siteId, GitRepositories repository)
-
cleanupRepositories
public void cleanupRepositories(String siteId)
Performs a cleanup all repositories for the given site- Specified by:
cleanupRepositories
in interfaceContentRepository
- Parameters:
siteId
- site identifier
-
setServletContext
public void setServletContext(javax.servlet.ServletContext ctx)
- Specified by:
setServletContext
in interfaceorg.springframework.web.context.ServletContextAware
-
setStudioConfiguration
public void setStudioConfiguration(StudioConfiguration studioConfiguration)
-
getServicesConfig
public ServicesConfig getServicesConfig()
-
setServicesConfig
public void setServicesConfig(ServicesConfig servicesConfig)
-
getGitLogDao
public GitLogDAO getGitLogDao()
-
setGitLogDao
public void setGitLogDao(GitLogDAO gitLogDao)
-
getRemoteRepositoryDAO
public RemoteRepositoryDAO getRemoteRepositoryDAO()
-
setRemoteRepositoryDAO
public void setRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO)
-
getSecurityService
public SecurityService getSecurityService()
-
setSecurityService
public void setSecurityService(SecurityService securityService)
-
getSiteFeedMapper
public SiteFeedMapper getSiteFeedMapper()
-
setSiteFeedMapper
public void setSiteFeedMapper(SiteFeedMapper siteFeedMapper)
-
setEncryptor
public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor)
-
setContextManager
public void setContextManager(ContextManager contextManager)
-
getGeneralLockService
public GeneralLockService getGeneralLockService()
-
setGeneralLockService
public void setGeneralLockService(GeneralLockService generalLockService)
-
getHelper
public GitRepositoryHelper getHelper()
-
setHelper
public void setHelper(GitRepositoryHelper helper)
-
getRetryingRepositoryOperationFacade
public RetryingRepositoryOperationFacade getRetryingRepositoryOperationFacade()
-
setRetryingRepositoryOperationFacade
public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade)
-
getRetryingDatabaseOperationFacade
public RetryingDatabaseOperationFacade getRetryingDatabaseOperationFacade()
-
setRetryingDatabaseOperationFacade
public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)
-
-