Class GitContentRepository

java.lang.Object
org.craftercms.studio.impl.v2.repository.GitContentRepository
All Implemented Interfaces:
ContentRepository

public class GitContentRepository extends Object implements ContentRepository
  • Field Details

  • Constructor Details

    • GitContentRepository

      public GitContentRepository()
  • Method Details

    • getSubtreeItems

      public List<String> getSubtreeItems(String site, String path, GitRepositories repoType, String branch)
      Description copied from interface: ContentRepository
      List subtree items for give site and path
      Specified by:
      getSubtreeItems in interface ContentRepository
      Parameters:
      site - site identifier
      path - path for subtree root
      repoType - repository type
      branch - 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: ContentRepository
      Get a list of operations since the commit ID provided (compare that commit to HEAD)
      Specified by:
      getOperationsFromDelta in interface ContentRepository
      Parameters:
      site - site to use
      commitIdFrom - commit ID to start at
      commitIdTo - commit ID to end at
      Returns:
      commit ID of current HEAD, updated operationsSinceCommit
    • getRepoFirstCommitId

      public String getRepoFirstCommitId(String site)
      Description copied from interface: ContentRepository
      Get first id from repository for given site
      Specified by:
      getRepoFirstCommitId in interface ContentRepository
      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: ContentRepository
      Get publishing history
      Specified by:
      getPublishingHistory in interface ContentRepository
      Parameters:
      siteId - site identifier
      environment - environment
      pathRegex - path regular expression to use as filter
      publisher - user to filter by
      fromDate - lower boundary for published date
      toDate - upper boundary for published date
      limit - 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: ContentRepository
      Create a new site based on a blueprint
      Specified by:
      createSiteFromBlueprint in interface ContentRepository
      Parameters:
      blueprintLocation - blueprint location
      site - site identifier
      sandboxBranch - sandbox branch name
      params - site parameters
      creator - 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: ContentRepository
      Publish content to specified environment.
      Specified by:
      publish in interface ContentRepository
      Parameters:
      site - site identifier
      sandboxBranch - sandbox branch name
      deploymentItems - items to be published
      environment - environment to publish to
      author - author
      comment - 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:
      IOException
      org.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

      public boolean repositoryExists(String siteId)
      Description copied from interface: ContentRepository
      Check if repository exists for given site
      Specified by:
      repositoryExists in interface ContentRepository
      Parameters:
      siteId - site id
      Returns:
      true if repository exists, otherwise false
    • commitIdExists

      public boolean commitIdExists(String site, String commitId)
      Description copied from interface: ContentRepository
      Check if given commit id exists
      Specified by:
      commitIdExists in interface ContentRepository
      Parameters:
      site - site id
      commitId - commit id to check
      Returns:
      true if it exists in site repository, otherwise false
    • commitIdExists

      public boolean commitIdExists(String site, GitRepositories repoType, String commitId)
      Description copied from interface: ContentRepository
      Check if given commit id (or revision string) exists
      Specified by:
      commitIdExists in interface ContentRepository
      Parameters:
      site - site id
      repoType - repository type
      commitId - 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, ServiceLayerException
      Description copied from interface: ContentRepository
      Create new site as a clone from remote repository
      Specified by:
      createSiteCloneRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      sandboxBranch - sandbox branch name
      remoteName - remote name
      remoteUrl - remote repository url
      remoteBranch - remote branch name
      singleBranch - flag to signal if clone single branch or full repository
      authenticationType - type of authentication to use to connect remote repository
      remoteUsername - remote username
      remotePassword - remote password
      remoteToken - remote token
      remotePrivateKey - remote private key
      params - site parameters
      createAsOrphan - create as orphan
      creator - site creator
      Returns:
      true if success
      Throws:
      InvalidRemoteRepositoryException - invalid remote repository
      InvalidRemoteRepositoryCredentialsException - invalid credentials for remote repository
      RemoteRepositoryNotFoundException - remote repository not found
      ServiceLayerException - general service error
    • removeRemote

      public boolean removeRemote(String siteId, String remoteName)
      Description copied from interface: ContentRepository
      Remove remote with given name for site
      Specified by:
      removeRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      remoteName - remote name
      Returns:
      true if operation was successful
    • checkContentExists

      public void checkContentExists(String site, String path) throws ServiceLayerException
      Description copied from interface: ContentRepository
      Checks if a content exists at a given path and throw an exception if it does not.
      Specified by:
      checkContentExists in interface ContentRepository
      Parameters:
      site - id of the site
      path - the content path
      Throws:
      ServiceLayerException - if no content is found at the given path
    • deleteSite

      public boolean deleteSite(String siteId)
      Description copied from interface: ContentRepository
      Deletes the underlying git repositories for a site
      Specified by:
      deleteSite in interface ContentRepository
      Parameters:
      siteId - the id of the site
      Returns:
      true if successful, false otherwise
    • 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 interface ContentRepository
      Returns:
      true if site has content object at path
    • 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 interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path -
      Returns:
      true if site has content object at path
    • getRepoLastCommitId

      public String getRepoLastCommitId(String site)
      Description copied from interface: ContentRepository
      Get last commit id from repository for given site.
      Specified by:
      getRepoLastCommitId in interface ContentRepository
      Parameters:
      site - site id, or null for global repository
      Returns:
      last commit id (current HEAD)
    • getItem

      public org.craftercms.core.service.Item getItem(String siteId, String path, boolean flatten)
      Specified by:
      getItem in interface ContentRepository
    • getContentSize

      public long getContentSize(String site, String path)
      Description copied from interface: ContentRepository
      get file size
      Specified by:
      getContentSize in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - path to content
      Returns:
      Size in bytes
    • getLastEditCommitId

      public String getLastEditCommitId(String siteId, String path)
      Specified by:
      getLastEditCommitId in interface ContentRepository
    • 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: ContentRepository
      Execute consumers for all site paths for the given site
      Specified by:
      forAllSitePaths in interface ContentRepository
      Parameters:
      site - the site id
      directoryProcessor - the consumer to process the directory paths
      fileProcessor - 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: ContentRepository
      Get environment properties for item
      Specified by:
      getItemEnvironmentProperties in interface ContentRepository
      Parameters:
      siteId - site identifier
      repoType - repository type
      environment - branch
      path - path of the item
      Returns:
      environment properties
    • getPreviousCommitId

      public String getPreviousCommitId(String siteId, String commitId)
      Description copied from interface: ContentRepository
      Get the previous commit id from repository for given a site id and a commit id
      Specified by:
      getPreviousCommitId in interface ContentRepository
      Parameters:
      siteId - site identifier
      commitId - commit Id
      Returns:
    • lockItem

      public void lockItem(String site, String path)
      Description copied from interface: ContentRepository
      lock an item NOTE: site will be removed from this interface
      Specified by:
      lockItem in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - path of the item
    • itemUnlock

      public void itemUnlock(String site, String path)
      Description copied from interface: ContentRepository
      unlock an item
      Specified by:
      itemUnlock in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - path of the item
    • getContentByCommitId

      public Optional<org.springframework.core.io.Resource> getContentByCommitId(String site, String path, String commitId)
      Description copied from interface: ContentRepository
      return a specific version of the content
      Specified by:
      getContentByCommitId in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - path of the content
      commitId - version to return
      Returns:
      the resource if available
    • publishedRepositoryExists

      public boolean publishedRepositoryExists(String siteId)
      Description copied from interface: ContentRepository
      Check if published repository exists for given site.
      Specified by:
      publishedRepositoryExists in interface ContentRepository
      Parameters:
      siteId - site identifier
      Returns:
      true if PUBLISHED repository exists, otherwise false
    • initialPublish

      public void initialPublish(String siteId) throws SiteNotFoundException
      Description copied from interface: ContentRepository
      Execute initial publish for given site
      Specified by:
      initialPublish in interface ContentRepository
      Parameters:
      siteId - site identifier
      Throws:
      SiteNotFoundException
    • publishAll

      public RepositoryChanges publishAll(String siteId, String publishingTarget, String comment)
      Description copied from interface: ContentRepository
      Publishes all changes for the given site & target
      Specified by:
      publishAll in interface ContentRepository
      Parameters:
      siteId - the id of the site
      publishingTarget - the publishing target
      comment - submission comment
    • preparePublishAll

      public RepositoryChanges preparePublishAll(String siteId, String publishingTarget) throws ServiceLayerException
      Description copied from interface: ContentRepository
      Prepares the repository to publish all changes for the given site & target
      Specified by:
      preparePublishAll in interface ContentRepository
      Parameters:
      siteId - the id of the site
      publishingTarget - 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: ContentRepository
      Performs the actual publish of all changes for the given site & target
      Specified by:
      completePublishAll in interface ContentRepository
      Parameters:
      siteId - the id of the site
      publishingTarget - the publishing target
      changes - the set of changed files
      comment - submission comment
      Throws:
      ServiceLayerException - if there is any error during publishing
    • cancelPublishAll

      public void cancelPublishAll(String siteId, String publishingTarget) throws ServiceLayerException
      Description copied from interface: ContentRepository
      Performs the cleanup after a failed publish all operation for the given site & target
      Specified by:
      cancelPublishAll in interface ContentRepository
      Parameters:
      siteId - the id of the site
      publishingTarget - 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:
      getContentItemHistory in interface ContentRepository
      Throws:
      IOException
      org.eclipse.jgit.api.errors.GitAPIException
    • getCommitIdsBetween

      public List<String> getCommitIdsBetween(String site, String commitFrom, String commitTo) throws IOException
      Description copied from interface: ContentRepository
      Get 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 to git log --first-parent --reverse commitFrom..commitTo
      Specified by:
      getCommitIdsBetween in interface ContentRepository
      Parameters:
      site - site id
      commitFrom - the older commit id
      commitTo - 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: ContentRepository
      Get the new commits introduced by commitId into baseCommit.
      This method assumes that baseCommit is an ancestor of commitId's first parent. Result will be equivalent to git log baseCommit..commitId
      Specified by:
      getIntroducedCommits in interface ContentRepository
      Parameters:
      site - site id
      baseCommit - the commit id to compare against
      commitId - the commit id to compare
      Throws:
      IOException
      org.eclipse.jgit.api.errors.GitAPIException
    • duplicateSite

      public void duplicateSite(String sourceSiteId, String siteId, String sourceSandboxBranch, String sandboxBranch) throws IOException, ServiceLayerException
      Description copied from interface: ContentRepository
      Create 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:
      duplicateSite in interface ContentRepository
      Parameters:
      sourceSiteId - source site id
      siteId - new site id
      sandboxBranch - sandbox branch name
      Throws:
      IOException - if there is any error while copying the directories
      ServiceLayerException
    • setHelper

      public void setHelper(GitRepositoryHelper helper)
    • setStudioConfiguration

      public void setStudioConfiguration(StudioConfiguration studioConfiguration)
    • setUserServiceInternal

      public void setUserServiceInternal(UserServiceInternal userServiceInternal)
    • setRemoteRepositoryDAO

      public void setRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO)
    • setEncryptor

      public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor)
    • setContextManager

      public void setContextManager(ContextManager contextManager)
    • setContentStoreService

      public void setContentStoreService(org.craftercms.core.service.ContentStoreService contentStoreService)
    • setGeneralLockService

      public void setGeneralLockService(GeneralLockService generalLockService)
    • setSiteService

      public void setSiteService(SiteService siteService)
    • setPublishRequestDao

      public void setPublishRequestDao(PublishRequestDAO publishRequestDao)
    • setItemServiceInternal

      public void setItemServiceInternal(ItemServiceInternal itemServiceInternal)
    • setRetryingRepositoryOperationFacade

      public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade)
    • setRetryingDatabaseOperationFacade

      public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)
    • setPublishingProgressServiceInternal

      public void setPublishingProgressServiceInternal(PublishingProgressServiceInternal publishingProgressServiceInternal)
    • setServicesConfig

      public void setServicesConfig(ServicesConfig servicesConfig)
    • setScriptRunnerFactory

      public void setScriptRunnerFactory(StudioDBScriptRunnerFactory scriptRunnerFactory)