Class GitContentRepository
java.lang.Object
org.craftercms.studio.impl.v2.repository.GitContentRepository
- All Implemented Interfaces:
ContentRepository
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbranchExists(org.eclipse.jgit.lib.Repository repo, String branch) voidcancelPublishAll(String siteId, String publishingTarget) Performs the cleanup after a failed publish all operation for the given site & targetvoidcheckContentExists(String site, String path) Checks if a content exists at a given path and throw an exception if it does not.protected voidcheckoutBranch(org.eclipse.jgit.api.Git git, String name) protected voidcheckoutBranch(org.eclipse.jgit.api.Git git, String name, boolean create) booleancommitIdExists(String site, String commitId) Check if given commit id existsbooleancommitIdExists(String site, GitRepositories repoType, String commitId) Check if given commit id (or revision string) existsvoidcompletePublishAll(String siteId, String publishingTarget, RepositoryChanges changes, String comment) Performs the actual publish of all changes for the given site & targetbooleancontentExists(String site, String path) Determine if content exists in the repository at a given pathintcountUnprocessedCommits(String siteId, long marker) Count unprocessed commits from databasebooleancreateSiteCloneRemote(String siteId, String sandboxBranch, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey, Map<String, String> params, boolean createAsOrphan, String creator) Create new site as a clone from remote repositorybooleancreateSiteFromBlueprint(String blueprintLocation, String site, String sandboxBranch, Map<String, String> params, String creator) Create a new site based on a blueprintprotected voiddeleteBranches(org.eclipse.jgit.api.Git git, String... names) voidduplicateSite(String sourceSiteId, String siteId, String sourceSandboxBranch, String sandboxBranch) Create copies of the source site's repositories.getChangeSetPathsFromDelta(String site, String commitIdFrom, String commitIdTo) Get a list of paths that changed since the commit ID provided to commit ID providedOptional<org.springframework.core.io.Resource> getContentByCommitId(String site, String path, String commitId) return a specific version of the contentgetContentItemHistory(String site, String path) Get the history of a content item.longgetContentSize(String site, String path) get file sizeGet git log object from databaseorg.craftercms.core.service.ItemgetItemEnvironmentProperties(String siteId, GitRepositories repoType, String environment, String path) Get environment properties for itemgetLastEditCommitId(String siteId, String path) getOperations(String site, String commitIdFrom, String commitIdTo) Get a list of operations since the commit ID provided (compare that commit to HEAD)getOperationsFromDelta(String site, String commitIdFrom, String commitIdTo) Get a list of operations since the commit ID provided (compare that commit to HEAD)getPreviousCommitId(String siteId, String commitId) Get the previous commit id from repository for given a site id and a commit idgetPublishingHistory(String siteId, String environment, String pathRegex, String publisher, ZonedDateTime fromDate, ZonedDateTime toDate, int limit) Get publishing historygetRepoFirstCommitId(String site) Get first id from repository for given sitegetRepoLastCommitId(String site) Get last commit id from repository for given site.getSubtreeItems(String site, String path, GitRepositories repoType, String branch) List subtree items for give site and pathgetUnauditedCommits(String siteId, int batchSize) Get unaudited commits from databasegetUnprocessedCommits(String siteId, long marker) Get unprocessed commits from databasevoidinitialPublish(String siteId) Execute initial publish for given sitevoidinsertGitLog(String siteId, String commitId, int processed) Insert Git LogvoidinsertGitLog(String siteId, String commitId, int processed, int audited) Insert Git LogvoiditemUnlock(String site, String path) unlock an itemvoidlock an item NOTE: site will be removed from this interfacevoidmarkGitLogAudited(String siteId, String commitId) Mark Git log as auditedvoidmarkGitLogProcessedBeforeMarker(String siteId, long marker, int processed) Mark all git logs as processed if they are inserted before markervoidmarkGitLogVerifiedProcessed(String siteId, String commitId) Mark Git log as verifiedvoidmarkGitLogVerifiedProcessedBulk(String siteId, List<String> commitIds) Mark Git logs as verifiedvoidpopulateGitLog(String siteId) Populates the full git log of the sandbox repository into the databasepreparePublishAll(String siteId, String publishingTarget) Prepares the repository to publish all changes for the given site & targetvoidpublish(String site, String sandboxBranch, List<DeploymentItemTO> deploymentItems, String environment, String author, String comment) Publish content to specified environment.publishAll(String siteId, String publishingTarget, String comment) Publishes all changes for the given site & targetbooleanpublishedRepositoryExists(String siteId) Check if published repository exists for given site.booleanremoveRemote(String siteId, String remoteName) Remove remote with given name for sitebooleanrepositoryExists(String siteId) Check if repository exists for given siteprotected voidresetIfNeeded(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.api.Git git) voidsetContentStoreService(org.craftercms.core.service.ContentStoreService contentStoreService) voidsetContextManager(ContextManager contextManager) voidsetEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor) voidsetGeneralLockService(GeneralLockService generalLockService) voidsetGitLogDao(GitLogDAO gitLogDao) voidsetHelper(GitRepositoryHelper helper) voidsetItemServiceInternal(ItemServiceInternal itemServiceInternal) voidsetPublishingProgressServiceInternal(PublishingProgressServiceInternal publishingProgressServiceInternal) voidsetPublishRequestDao(PublishRequestDAO publishRequestDao) voidsetRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO) voidsetRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade) voidsetRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) voidsetScriptRunnerFactory(StudioDBScriptRunnerFactory scriptRunnerFactory) voidsetServicesConfig(ServicesConfig servicesConfig) voidsetSiteFeedMapper(SiteFeedMapper siteFeedMapper) voidsetSiteService(SiteService siteService) voidsetStudioConfiguration(StudioConfiguration studioConfiguration) voidsetStudioUtils(StudioUtils studioUtils) voidsetUserServiceInternal(UserServiceInternal userServiceInternal) booleanshallowContentExists(String site, String path) This is a faster, but less accurate, version of contentExists.voidupdateGitlog(String siteId, String lastProcessedCommitId, int batchSize) Update gitlog table with commit ids from repositoryvoidupsertGitLogList(String siteId, List<String> commitIds, boolean processed, boolean audited) Upsert git logs as processed and auditedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.craftercms.studio.api.v2.repository.ContentRepository
getItemPaths, getSubtreeItems
-
Field Details
-
scriptRunnerFactory
-
-
Constructor Details
-
GitContentRepository
public GitContentRepository()
-
-
Method Details
-
getSubtreeItems
public List<String> getSubtreeItems(String site, String path, GitRepositories repoType, String branch) Description copied from interface:ContentRepositoryList subtree items for give site and path- Specified by:
getSubtreeItemsin interfaceContentRepository- Parameters:
site- site identifierpath- path for subtree rootrepoType- repository typebranch- A git object references expression (e.g.: HEAD, branch name, commit id)- Returns:
- list of item paths contained in the subtree
-
getOperations
Description copied from interface:ContentRepositoryGet a list of operations since the commit ID provided (compare that commit to HEAD)- Specified by:
getOperationsin interfaceContentRepository- Parameters:
site- site to usecommitIdFrom- commit ID to start atcommitIdTo- commit ID to end at- Returns:
- commit ID of current HEAD, updated operationsSinceCommit
-
getOperationsFromDelta
public List<RepoOperation> getOperationsFromDelta(String site, String commitIdFrom, String commitIdTo) Description copied from interface:ContentRepositoryGet a list of operations since the commit ID provided (compare that commit to HEAD)- Specified by:
getOperationsFromDeltain interfaceContentRepository- Parameters:
site- site to usecommitIdFrom- commit ID to start atcommitIdTo- commit ID to end at- Returns:
- commit ID of current HEAD, updated operationsSinceCommit
-
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
-
getGitLog
Description copied from interface:ContentRepositoryGet git log object from database- Specified by:
getGitLogin interfaceContentRepository- Parameters:
siteId- site idcommitId- commit ID- Returns:
- git log object
-
markGitLogVerifiedProcessed
Description copied from interface:ContentRepositoryMark Git log as verified- Specified by:
markGitLogVerifiedProcessedin interfaceContentRepository- Parameters:
siteId- site identifiercommitId- commit id
-
markGitLogVerifiedProcessedBulk
Description copied from interface:ContentRepositoryMark Git logs as verified- Specified by:
markGitLogVerifiedProcessedBulkin interfaceContentRepository- Parameters:
siteId- site identifiercommitIds- list of commit ids
-
insertGitLog
Description copied from interface:ContentRepositoryInsert Git Log- Specified by:
insertGitLogin interfaceContentRepository- Parameters:
siteId- sitecommitId- commit IDprocessed- processed
-
insertGitLog
Description copied from interface:ContentRepositoryInsert Git Log- Specified by:
insertGitLogin interfaceContentRepository- Parameters:
siteId- sitecommitId- commit IDprocessed- processedaudited- audited
-
getPublishingHistory
public List<PublishingHistoryItem> getPublishingHistory(String siteId, String environment, String pathRegex, String publisher, ZonedDateTime fromDate, ZonedDateTime toDate, int limit) Description copied from interface:ContentRepositoryGet publishing history- Specified by:
getPublishingHistoryin interfaceContentRepository- Parameters:
siteId- site identifierenvironment- environmentpathRegex- path regular expression to use as filterpublisher- user to filter byfromDate- lower boundary for published datetoDate- upper boundary for published datelimit- number of records to return- Returns:
- publishing history
-
createSiteFromBlueprint
public boolean createSiteFromBlueprint(String blueprintLocation, String site, String sandboxBranch, Map<String, String> params, String creator) Description copied from interface:ContentRepositoryCreate a new site based on a blueprint- Specified by:
createSiteFromBlueprintin interfaceContentRepository- Parameters:
blueprintLocation- blueprint locationsite- site identifiersandboxBranch- sandbox branch nameparams- site parameterscreator- site creator- Returns:
- true if successful, false otherwise
-
publish
public void publish(String site, String sandboxBranch, List<DeploymentItemTO> deploymentItems, String environment, String author, String comment) throws DeploymentException Description copied from interface:ContentRepositoryPublish content to specified environment.- Specified by:
publishin interfaceContentRepository- Parameters:
site- site identifiersandboxBranch- sandbox branch namedeploymentItems- items to be publishedenvironment- environment to publish toauthor- authorcomment- submission comment- Throws:
DeploymentException- deployment error
-
resetIfNeeded
protected void resetIfNeeded(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.api.Git git) throws IOException, org.eclipse.jgit.api.errors.GitAPIException - Throws:
IOExceptionorg.eclipse.jgit.api.errors.GitAPIException
-
checkoutBranch
protected void checkoutBranch(org.eclipse.jgit.api.Git git, String name, boolean create) throws org.eclipse.jgit.api.errors.GitAPIException - Throws:
org.eclipse.jgit.api.errors.GitAPIException
-
checkoutBranch
protected void checkoutBranch(org.eclipse.jgit.api.Git git, String name) throws org.eclipse.jgit.api.errors.GitAPIException - Throws:
org.eclipse.jgit.api.errors.GitAPIException
-
deleteBranches
protected void deleteBranches(org.eclipse.jgit.api.Git git, String... names) throws org.eclipse.jgit.api.errors.GitAPIException - Throws:
org.eclipse.jgit.api.errors.GitAPIException
-
branchExists
protected boolean branchExists(org.eclipse.jgit.lib.Repository repo, String branch) throws IOException - Throws:
IOException
-
repositoryExists
Description copied from interface:ContentRepositoryCheck if repository exists for given site- Specified by:
repositoryExistsin interfaceContentRepository- Parameters:
siteId- site id- Returns:
- true if repository exists, otherwise false
-
commitIdExists
Description copied from interface:ContentRepositoryCheck if given commit id exists- Specified by:
commitIdExistsin interfaceContentRepository- Parameters:
site- site idcommitId- commit id to check- Returns:
- true if it exists in site repository, otherwise false
-
commitIdExists
Description copied from interface:ContentRepositoryCheck if given commit id (or revision string) exists- Specified by:
commitIdExistsin interfaceContentRepository- Parameters:
site- site idrepoType- repository typecommitId- commit id or revision to check- Returns:
- true if it exists in site repository, otherwise false
-
createSiteCloneRemote
public boolean createSiteCloneRemote(String siteId, String sandboxBranch, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey, Map<String, String> params, boolean createAsOrphan, String creator) throws InvalidRemoteRepositoryException, InvalidRemoteRepositoryCredentialsException, RemoteRepositoryNotFoundException, ServiceLayerExceptionDescription copied from interface:ContentRepositoryCreate new site as a clone from remote repository- Specified by:
createSiteCloneRemotein interfaceContentRepository- Parameters:
siteId- site identifiersandboxBranch- sandbox branch nameremoteName- remote nameremoteUrl- remote repository urlremoteBranch- remote branch namesingleBranch- flag to signal if clone single branch or full repositoryauthenticationType- type of authentication to use to connect remote repositoryremoteUsername- remote usernameremotePassword- remote passwordremoteToken- remote tokenremotePrivateKey- remote private keyparams- site parameterscreateAsOrphan- create as orphancreator- site creator- Returns:
- true if success
- Throws:
InvalidRemoteRepositoryException- invalid remote repositoryInvalidRemoteRepositoryCredentialsException- invalid credentials for remote repositoryRemoteRepositoryNotFoundException- remote repository not foundServiceLayerException- general service error
-
removeRemote
Description copied from interface:ContentRepositoryRemove remote with given name for site- Specified by:
removeRemotein interfaceContentRepository- Parameters:
siteId- site identifierremoteName- remote name- Returns:
- true if operation was successful
-
checkContentExists
Description copied from interface:ContentRepositoryChecks if a content exists at a given path and throw an exception if it does not.- Specified by:
checkContentExistsin interfaceContentRepository- Parameters:
site- id of the sitepath- the content path- Throws:
ServiceLayerException- if no content is found at the given 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
-
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-- Returns:
- true if site has content object at path
-
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)
-
getItem
- Specified by:
getItemin interfaceContentRepository
-
getContentSize
Description copied from interface:ContentRepositoryget file size- Specified by:
getContentSizein interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path to content- Returns:
- Size in bytes
-
getLastEditCommitId
- Specified by:
getLastEditCommitIdin interfaceContentRepository
-
getChangeSetPathsFromDelta
public Map<String,String> getChangeSetPathsFromDelta(String site, String commitIdFrom, String commitIdTo) Description copied from interface:ContentRepositoryGet a list of paths that changed since the commit ID provided to commit ID provided- Specified by:
getChangeSetPathsFromDeltain interfaceContentRepository- Parameters:
site- site to usecommitIdFrom- commit ID to start atcommitIdTo- commit ID to end at- Returns:
- list of paths of files that changed between two commits
-
markGitLogAudited
Description copied from interface:ContentRepositoryMark Git log as audited- Specified by:
markGitLogAuditedin interfaceContentRepository- Parameters:
siteId- site identifiercommitId- commit id
-
updateGitlog
Description copied from interface:ContentRepositoryUpdate gitlog table with commit ids from repository- Specified by:
updateGitlogin interfaceContentRepository- Parameters:
siteId- site identifierlastProcessedCommitId- last processed commit idbatchSize- size of a batch to update
-
getUnauditedCommits
Description copied from interface:ContentRepositoryGet unaudited commits from database- Specified by:
getUnauditedCommitsin interfaceContentRepository- Parameters:
siteId- site identifierbatchSize- size of a batch to retrieve- Returns:
- list of gitlog records
-
getUnprocessedCommits
Description copied from interface:ContentRepositoryGet unprocessed commits from database- Specified by:
getUnprocessedCommitsin interfaceContentRepository- Parameters:
siteId- site identifiermarker- id of last verified commit Id- Returns:
- list of gitlog records
-
getItemEnvironmentProperties
public DetailedItem.Environment getItemEnvironmentProperties(String siteId, GitRepositories repoType, String environment, String path) Description copied from interface:ContentRepositoryGet environment properties for item- Specified by:
getItemEnvironmentPropertiesin interfaceContentRepository- Parameters:
siteId- site identifierrepoType- repository typeenvironment- branchpath- path of the item- Returns:
- environment properties
-
countUnprocessedCommits
Description copied from interface:ContentRepositoryCount unprocessed commits from database- Specified by:
countUnprocessedCommitsin interfaceContentRepository- Parameters:
siteId- site identifiermarker- id of last verified commit Id- Returns:
- number of unprocessed gitlog records
-
markGitLogProcessedBeforeMarker
Description copied from interface:ContentRepositoryMark all git logs as processed if they are inserted before marker- Specified by:
markGitLogProcessedBeforeMarkerin interfaceContentRepository- Parameters:
siteId- site identifiermarker- marker git commitprocessed- value for processed
-
getPreviousCommitId
Description copied from interface:ContentRepositoryGet the previous commit id from repository for given a site id and a commit id- Specified by:
getPreviousCommitIdin interfaceContentRepository- Parameters:
siteId- site identifiercommitId- commit Id- Returns:
-
lockItem
Description copied from interface:ContentRepositorylock an item NOTE: site will be removed from this interface- Specified by:
lockItemin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path of the item
-
itemUnlock
Description copied from interface:ContentRepositoryunlock an item- Specified by:
itemUnlockin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path of the item
-
upsertGitLogList
public void upsertGitLogList(String siteId, List<String> commitIds, boolean processed, boolean audited) Description copied from interface:ContentRepositoryUpsert git logs as processed and audited- Specified by:
upsertGitLogListin interfaceContentRepository- Parameters:
siteId- site identifiercommitIds- commit idsprocessed- true if already processedaudited- true if already audited
-
getContentByCommitId
public Optional<org.springframework.core.io.Resource> getContentByCommitId(String site, String path, String commitId) Description copied from interface:ContentRepositoryreturn a specific version of the content- Specified by:
getContentByCommitIdin interfaceContentRepository- Parameters:
site- site id where the operation will be executedpath- path of the contentcommitId- version to return- Returns:
- the resource if available
-
publishedRepositoryExists
Description copied from interface:ContentRepositoryCheck if published repository exists for given site.- Specified by:
publishedRepositoryExistsin interfaceContentRepository- Parameters:
siteId- site identifier- Returns:
- true if PUBLISHED repository exists, otherwise false
-
initialPublish
Description copied from interface:ContentRepositoryExecute initial publish for given site- Specified by:
initialPublishin interfaceContentRepository- Parameters:
siteId- site identifier- Throws:
SiteNotFoundException
-
publishAll
Description copied from interface:ContentRepositoryPublishes all changes for the given site & target- Specified by:
publishAllin interfaceContentRepository- Parameters:
siteId- the id of the sitepublishingTarget- the publishing targetcomment- submission comment
-
preparePublishAll
public RepositoryChanges preparePublishAll(String siteId, String publishingTarget) throws ServiceLayerException Description copied from interface:ContentRepositoryPrepares the repository to publish all changes for the given site & target- Specified by:
preparePublishAllin interfaceContentRepository- Parameters:
siteId- the id of the sitepublishingTarget- the publishing target- Returns:
- the set of changed files
- Throws:
ServiceLayerException- if there is any error during the preparation
-
completePublishAll
public void completePublishAll(String siteId, String publishingTarget, RepositoryChanges changes, String comment) throws ServiceLayerException Description copied from interface:ContentRepositoryPerforms the actual publish of all changes for the given site & target- Specified by:
completePublishAllin interfaceContentRepository- Parameters:
siteId- the id of the sitepublishingTarget- the publishing targetchanges- the set of changed filescomment- submission comment- Throws:
ServiceLayerException- if there is any error during publishing
-
cancelPublishAll
Description copied from interface:ContentRepositoryPerforms the cleanup after a failed publish all operation for the given site & target- Specified by:
cancelPublishAllin interfaceContentRepository- Parameters:
siteId- the id of the sitepublishingTarget- the publishing target- Throws:
ServiceLayerException- if there is any error during cleanup
-
populateGitLog
public void populateGitLog(String siteId) throws org.eclipse.jgit.api.errors.GitAPIException, IOException Description copied from interface:ContentRepositoryPopulates the full git log of the sandbox repository into the database- Specified by:
populateGitLogin interfaceContentRepository- Parameters:
siteId- the id of the site- Throws:
org.eclipse.jgit.api.errors.GitAPIException- if there is any error reading the git logIOException- if there is any error executing the db script
-
getContentItemHistory
public List<ItemVersion> getContentItemHistory(String site, String path) throws IOException, org.eclipse.jgit.api.errors.GitAPIException Description copied from interface:ContentRepositoryGet the history of a content item.
Note: the results of this method are not guaranteed when the path does not currently exist in the repository.- Specified by:
getContentItemHistoryin interfaceContentRepository- Parameters:
site- site idpath- path of the content item- Returns:
- list of item versions
- Throws:
IOException- if there is any error reading the git log or getting diffs between commitsorg.eclipse.jgit.api.errors.GitAPIException- if there is any error while executing git commands
-
duplicateSite
public void duplicateSite(String sourceSiteId, String siteId, String sourceSandboxBranch, String sandboxBranch) throws IOException, ServiceLayerException Description copied from interface:ContentRepositoryCreate copies of the source site's repositories. This method will copy sandbox and published (if exists) repositories under a new directory with the new site id. For sandbox repository, a new branch will be created (from the currently checked-out branch) with the given sandbox branch name if it does not exist.- Specified by:
duplicateSitein interfaceContentRepository- Parameters:
sourceSiteId- source site idsiteId- new site idsandboxBranch- sandbox branch name- Throws:
IOException- if there is any error while copying the directoriesServiceLayerException
-
setHelper
-
setStudioConfiguration
-
setGitLogDao
-
setUserServiceInternal
-
setRemoteRepositoryDAO
-
setEncryptor
public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor) -
setContextManager
-
setContentStoreService
public void setContentStoreService(org.craftercms.core.service.ContentStoreService contentStoreService) -
setGeneralLockService
-
setSiteService
-
setPublishRequestDao
-
setItemServiceInternal
-
setStudioUtils
-
setRetryingRepositoryOperationFacade
public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) -
setRetryingDatabaseOperationFacade
public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade) -
setPublishingProgressServiceInternal
public void setPublishingProgressServiceInternal(PublishingProgressServiceInternal publishingProgressServiceInternal) -
setSiteFeedMapper
-
setServicesConfig
-
setScriptRunnerFactory
-