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 pathbooleancreateSiteCloneRemote(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) booleandeleteSite(String siteId) Deletes the underlying git repositories for a sitevoidduplicateSite(String sourceSiteId, String siteId, String sourceSandboxBranch, String sandboxBranch) Create copies of the source site's repositories.voidforAllSitePaths(String site, org.springframework.util.function.ThrowingConsumer<String> directoryProcessor, org.springframework.util.function.ThrowingConsumer<String> fileProcessor) Execute consumers for all site paths for the given sitegetCommitIdsBetween(String site, String commitFrom, String commitTo) Get the commits between two commit ids.Optional<org.springframework.core.io.Resource> getContentByCommitId(String site, String path, String commitId) return a specific version of the contentgetContentItemHistory(String site, String path) longgetContentSize(String site, String path) get file sizegetIntroducedCommits(String site, String baseCommit, String commitId) Get the new commits introduced bycommitIdintobaseCommit.
This method assumes that baseCommit is an ancestor of commitId's first parent.org.craftercms.core.service.ItemgetItemEnvironmentProperties(String siteId, GitRepositories repoType, String environment, String path) Get environment properties for itemgetLastEditCommitId(String siteId, String path) 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 pathvoidinitialPublish(String siteId) Execute initial publish for given sitevoiditemUnlock(String site, String path) unlock an itemvoidlock an item NOTE: site will be removed from this interfacepreparePublishAll(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) 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) voidsetSiteService(SiteService siteService) voidsetStudioConfiguration(StudioConfiguration studioConfiguration) voidsetUserServiceInternal(UserServiceInternal userServiceInternal) booleanshallowContentExists(String site, String path) This is a faster, but less accurate, version of contentExists.Methods 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
getGlobalRepoLastCommitId, 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
-
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
-
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
-
deleteSite
Description copied from interface:ContentRepositoryDeletes the underlying git repositories for a site- Specified by:
deleteSitein interfaceContentRepository- Parameters:
siteId- the id of the site- Returns:
- true if successful, false otherwise
-
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, or null for global repository- 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
-
forAllSitePaths
public void forAllSitePaths(String site, org.springframework.util.function.ThrowingConsumer<String> directoryProcessor, org.springframework.util.function.ThrowingConsumer<String> fileProcessor) throws Exception Description copied from interface:ContentRepositoryExecute consumers for all site paths for the given site- Specified by:
forAllSitePathsin interfaceContentRepository- Parameters:
site- the site iddirectoryProcessor- the consumer to process the directory pathsfileProcessor- the consumer to process the file paths- Throws:
Exception
-
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
-
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
-
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
-
getContentItemHistory
public List<ItemVersion> getContentItemHistory(String site, String path) throws IOException, org.eclipse.jgit.api.errors.GitAPIException - Specified by:
getContentItemHistoryin interfaceContentRepository- Throws:
IOExceptionorg.eclipse.jgit.api.errors.GitAPIException
-
getCommitIdsBetween
public List<String> getCommitIdsBetween(String site, String commitFrom, String commitTo) throws IOException Description copied from interface:ContentRepositoryGet the commits between two commit ids. This method must start in the commitTo and go back until it finds commitFrom. The actual result must be equivalent togit log --first-parent --reverse commitFrom..commitTo- Specified by:
getCommitIdsBetweenin interfaceContentRepository- Parameters:
site- site idcommitFrom- the older commit idcommitTo- the newer commit id- Returns:
- list of commit ids between commitFrom (not included) and commitTo (inclusive)
- Throws:
IOException- if there is any error reading the git log
-
getIntroducedCommits
public List<String> getIntroducedCommits(String site, String baseCommit, String commitId) throws IOException, org.eclipse.jgit.api.errors.GitAPIException Description copied from interface:ContentRepositoryGet the new commits introduced bycommitIdintobaseCommit.
This method assumes that baseCommit is an ancestor of commitId's first parent. Result will be equivalent togit log baseCommit..commitId- Specified by:
getIntroducedCommitsin interfaceContentRepository- Parameters:
site- site idbaseCommit- the commit id to compare againstcommitId- the commit id to compare- Throws:
IOExceptionorg.eclipse.jgit.api.errors.GitAPIException
-
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
-
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
-
setRetryingRepositoryOperationFacade
public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) -
setRetryingDatabaseOperationFacade
public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade) -
setPublishingProgressServiceInternal
public void setPublishingProgressServiceInternal(PublishingProgressServiceInternal publishingProgressServiceInternal) -
setServicesConfig
-
setScriptRunnerFactory
-