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
    • getOperations

      public List<RepoOperation> getOperations(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:
      getOperations 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
    • 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
    • getGitLog

      public GitLog getGitLog(String siteId, String commitId)
      Description copied from interface: ContentRepository
      Get git log object from database
      Specified by:
      getGitLog in interface ContentRepository
      Parameters:
      siteId - site id
      commitId - commit ID
      Returns:
      git log object
    • markGitLogVerifiedProcessed

      public void markGitLogVerifiedProcessed(String siteId, String commitId)
      Description copied from interface: ContentRepository
      Mark Git log as verified
      Specified by:
      markGitLogVerifiedProcessed in interface ContentRepository
      Parameters:
      siteId - site identifier
      commitId - commit id
    • markGitLogVerifiedProcessedBulk

      public void markGitLogVerifiedProcessedBulk(String siteId, List<String> commitIds)
      Description copied from interface: ContentRepository
      Mark Git logs as verified
      Specified by:
      markGitLogVerifiedProcessedBulk in interface ContentRepository
      Parameters:
      siteId - site identifier
      commitIds - list of commit ids
    • insertGitLog

      public void insertGitLog(String siteId, String commitId, int processed)
      Description copied from interface: ContentRepository
      Insert Git Log
      Specified by:
      insertGitLog in interface ContentRepository
      Parameters:
      siteId - site
      commitId - commit ID
      processed - processed
    • insertGitLog

      public void insertGitLog(String siteId, String commitId, int processed, int audited)
      Description copied from interface: ContentRepository
      Insert Git Log
      Specified by:
      insertGitLog in interface ContentRepository
      Parameters:
      siteId - site
      commitId - commit ID
      processed - processed
      audited - audited
    • 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
    • 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
      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
    • getChangeSetPathsFromDelta

      public Map<String,String> getChangeSetPathsFromDelta(String site, String commitIdFrom, String commitIdTo)
      Description copied from interface: ContentRepository
      Get a list of paths that changed since the commit ID provided to commit ID provided
      Specified by:
      getChangeSetPathsFromDelta in interface ContentRepository
      Parameters:
      site - site to use
      commitIdFrom - commit ID to start at
      commitIdTo - commit ID to end at
      Returns:
      list of paths of files that changed between two commits
    • markGitLogAudited

      public void markGitLogAudited(String siteId, String commitId)
      Description copied from interface: ContentRepository
      Mark Git log as audited
      Specified by:
      markGitLogAudited in interface ContentRepository
      Parameters:
      siteId - site identifier
      commitId - commit id
    • updateGitlog

      public void updateGitlog(String siteId, String lastProcessedCommitId, int batchSize)
      Description copied from interface: ContentRepository
      Update gitlog table with commit ids from repository
      Specified by:
      updateGitlog in interface ContentRepository
      Parameters:
      siteId - site identifier
      lastProcessedCommitId - last processed commit id
      batchSize - size of a batch to update
    • getUnauditedCommits

      public List<GitLog> getUnauditedCommits(String siteId, int batchSize)
      Description copied from interface: ContentRepository
      Get unaudited commits from database
      Specified by:
      getUnauditedCommits in interface ContentRepository
      Parameters:
      siteId - site identifier
      batchSize - size of a batch to retrieve
      Returns:
      list of gitlog records
    • getUnprocessedCommits

      public List<GitLog> getUnprocessedCommits(String siteId, long marker)
      Description copied from interface: ContentRepository
      Get unprocessed commits from database
      Specified by:
      getUnprocessedCommits in interface ContentRepository
      Parameters:
      siteId - site identifier
      marker - 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: 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
    • countUnprocessedCommits

      public int countUnprocessedCommits(String siteId, long marker)
      Description copied from interface: ContentRepository
      Count unprocessed commits from database
      Specified by:
      countUnprocessedCommits in interface ContentRepository
      Parameters:
      siteId - site identifier
      marker - id of last verified commit Id
      Returns:
      number of unprocessed gitlog records
    • markGitLogProcessedBeforeMarker

      public void markGitLogProcessedBeforeMarker(String siteId, long marker, int processed)
      Description copied from interface: ContentRepository
      Mark all git logs as processed if they are inserted before marker
      Specified by:
      markGitLogProcessedBeforeMarker in interface ContentRepository
      Parameters:
      siteId - site identifier
      marker - marker git commit
      processed - value for processed
    • 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
    • upsertGitLogList

      public void upsertGitLogList(String siteId, List<String> commitIds, boolean processed, boolean audited)
      Description copied from interface: ContentRepository
      Upsert git logs as processed and audited
      Specified by:
      upsertGitLogList in interface ContentRepository
      Parameters:
      siteId - site identifier
      commitIds - commit ids
      processed - true if already processed
      audited - true if already audited
    • 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
    • populateGitLog

      public void populateGitLog(String siteId) throws org.eclipse.jgit.api.errors.GitAPIException, IOException
      Description copied from interface: ContentRepository
      Populates the full git log of the sandbox repository into the database
      Specified by:
      populateGitLog in interface ContentRepository
      Parameters:
      siteId - the id of the site
      Throws:
      org.eclipse.jgit.api.errors.GitAPIException - if there is any error reading the git log
      IOException - 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: ContentRepository
      Get 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:
      getContentItemHistory in interface ContentRepository
      Parameters:
      site - site id
      path - 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 commits
      org.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: 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)
    • setGitLogDao

      public void setGitLogDao(GitLogDAO gitLogDao)
    • 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)
    • setStudioUtils

      public void setStudioUtils(StudioUtils studioUtils)
    • setRetryingRepositoryOperationFacade

      public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade)
    • setRetryingDatabaseOperationFacade

      public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)
    • setPublishingProgressServiceInternal

      public void setPublishingProgressServiceInternal(PublishingProgressServiceInternal publishingProgressServiceInternal)
    • setSiteFeedMapper

      public void setSiteFeedMapper(SiteFeedMapper siteFeedMapper)
    • setServicesConfig

      public void setServicesConfig(ServicesConfig servicesConfig)
    • setScriptRunnerFactory

      public void setScriptRunnerFactory(StudioDBScriptRunnerFactory scriptRunnerFactory)