Class GitContentRepository

java.lang.Object
org.craftercms.studio.impl.v1.repository.git.GitContentRepository
All Implemented Interfaces:
ContentRepository, org.springframework.beans.factory.Aware, org.springframework.web.context.ServletContextAware

public class GitContentRepository extends Object implements ContentRepository, org.springframework.web.context.ServletContextAware
  • Field Details

  • Constructor Details

    • GitContentRepository

      public GitContentRepository()
  • Method Details

    • 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 - path to check if content exists
      Returns:
      true if site has content object at path
    • shallowContentExists

      public boolean shallowContentExists(String site, String path)
      Description copied from interface: ContentRepository
      This is a faster, but less accurate, version of contentExists. This prioritizes performance over checking the actual underlying repository if the content is actually in the store or we simply hold a reference to the object in the actual store.
      Specified by:
      shallowContentExists in interface ContentRepository
      Returns:
      true if site has content object at path
    • shallowGetContent

      protected InputStream shallowGetContent(String site, String path) throws ContentNotFoundException
      Throws:
      ContentNotFoundException
    • getContent

      public InputStream getContent(String site, String path, boolean shallow) throws ContentNotFoundException
      Description copied from interface: ContentRepository
      Get content from the repository
      Specified by:
      getContent in interface ContentRepository
      Parameters:
      site - the site id
      path - the path of the content
      shallow - if true, it will load the file from disk directly, instead of retrieving it from git repository
      Returns:
      InputStream to read the content
      Throws:
      ContentNotFoundException - if the content is not found
    • writeContent

      public String writeContent(String siteId, String path, InputStream content)
      Description copied from interface: ContentRepository
      write content
      Specified by:
      writeContent in interface ContentRepository
      Parameters:
      siteId - site id where the operation will be executed
      path - path to content
      content - stream of content to write
      Returns:
      Commit Id if successful, null otherwise
    • createFolder

      public String createFolder(String siteId, String path, String name)
      Description copied from interface: ContentRepository
      create a folder
      Specified by:
      createFolder in interface ContentRepository
      Parameters:
      siteId - site id where the operation will be executed
      path - path to create a folder in
      name - a folder name to create
      Returns:
      Commit Id if successful, null otherwise
    • deleteContent

      public String deleteContent(String siteId, String path, String approver)
      Description copied from interface: ContentRepository
      delete content
      Specified by:
      deleteContent in interface ContentRepository
      Parameters:
      siteId - site id where the operation will be executed
      path - path to content
      approver - user that approves delete content
      Returns:
      Commit ID if successful, null otherwise
    • moveContent

      public String moveContent(String siteId, String fromPath, String toPath, String newName)
      Description copied from interface: ContentRepository
      move content from PathA to pathB
      Specified by:
      moveContent in interface ContentRepository
      Parameters:
      siteId - site id where the operation will be executed
      fromPath - source content
      toPath - target path
      newName - new file name for rename
      Returns:
      Commit ID if successful, empty string otherwise
    • copyContent

      public String copyContent(String siteId, String fromPath, String toPath)
      Description copied from interface: ContentRepository
      copy content from PathA to pathB
      Specified by:
      copyContent in interface ContentRepository
      Parameters:
      siteId - site id where the operation will be executed
      fromPath - paths to content
      toPath - target path
      Returns:
      Commit ID if successful, empty string otherwise
    • getContentChildren

      public RepositoryItem[] getContentChildren(String site, String path)
      Description copied from interface: ContentRepository
      get immediate children for path
      Specified by:
      getContentChildren in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - path to content
      Returns:
      a list of children
    • getContentVersionHistory

      public VersionTO[] getContentVersionHistory(String site, String path)
      Description copied from interface: ContentRepository
      get the version history for an item
      Specified by:
      getContentVersionHistory in interface ContentRepository
      Parameters:
      site - - the project ID
      path - - the path of the item
      Returns:
      a list of versions
    • createVersion

      public String createVersion(String site, String path, boolean majorVersion)
      Description copied from interface: ContentRepository
      create a version
      Specified by:
      createVersion in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - location of content
      majorVersion - true if major
      Returns:
      the created version ID or null on failure
    • createVersion

      public String createVersion(String site, String path, String comment, boolean majorVersion)
      Description copied from interface: ContentRepository
      create a version
      Specified by:
      createVersion in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - location of content
      comment - version history comment
      majorVersion - true if major
      Returns:
      the created version ID or null on failure
    • revertContent

      public String revertContent(String site, String path, String version, boolean major, String comment)
      Description copied from interface: ContentRepository
      revert a version (create a new version based on an old version)
      Specified by:
      revertContent in interface ContentRepository
      Parameters:
      site - site id where the operation will be executed
      path - - the path of the item to "revert"
      version - - old version ID to base to version on
      major - flag if it is major version
      comment - add comment when committing content
      Returns:
      Commit ID if successful, empty string otherwise
    • lockItemForPublishing

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

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

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

      @Order(1) @EventListener(org.springframework.context.event.ContextRefreshedEvent.class) public void bootstrap() throws Exception
      bootstrap the global repository
      Throws:
      Exception
    • deleteSite

      public boolean deleteSite(String site)
      Description copied from interface: ContentRepository
      Deletes an existing site.
      Specified by:
      deleteSite in interface ContentRepository
      Parameters:
      site - site to delete
      Returns:
      true if successful, false otherwise
    • initialPublish

      public void initialPublish(String site, String sandboxBranch, String environment, String author, String comment) throws DeploymentException
      Description copied from interface: ContentRepository
      Initial publish to specified environment.
      Specified by:
      initialPublish in interface ContentRepository
      Parameters:
      site - site identifier
      sandboxBranch - sandbox branch name
      environment - environment to publish
      author - author
      comment - comment
      Throws:
      DeploymentException - deployment error
    • getRepoLastCommitId

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

      public String getRepoFirstCommitId(String site)
      Description copied from interface: ContentRepository
      Get first id from repository for given site
      Specified by:
      getRepoFirstCommitId in interface ContentRepository
      Parameters:
      site - site id
      Returns:
      first commit id
    • addRemote

      public boolean addRemote(String siteId, String remoteName, String remoteUrl, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) throws InvalidRemoteUrlException, ServiceLayerException
      Description copied from interface: ContentRepository
      Add remote repository for site content repository
      Specified by:
      addRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      remoteName - remote name
      remoteUrl - remote url
      authenticationType - authentication type
      remoteUsername - remote username
      remotePassword - remote password
      remoteToken - remote token
      remotePrivateKey - remote private key
      Returns:
      true if operation was successful
      Throws:
      InvalidRemoteUrlException - invalid url for remote repository
      ServiceLayerException - general service error
    • removeRemoteRepositoriesForSite

      public void removeRemoteRepositoriesForSite(String siteId)
      Description copied from interface: ContentRepository
      Remove all remotes for given site
      Specified by:
      removeRemoteRepositoriesForSite in interface ContentRepository
      Parameters:
      siteId - site identifier
    • listRemote

      public List<RemoteRepositoryInfoTO> listRemote(String siteId, String sandboxBranch) throws ServiceLayerException
      Description copied from interface: ContentRepository
      List remote repositories for given site
      Specified by:
      listRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      sandboxBranch - sandbox branch name
      Returns:
      list of names of remote repositories
      Throws:
      ServiceLayerException - general service error
    • pushToRemote

      public boolean pushToRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException
      Description copied from interface: ContentRepository
      Push content to remote repository
      Specified by:
      pushToRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      remoteName - remote name
      remoteBranch - remote branch
      Returns:
      true if operation was successful
      Throws:
      ServiceLayerException - general service error
      InvalidRemoteUrlException - invalid url for remote repository
    • pullFromRemote

      public boolean pullFromRemote(String siteId, String remoteName, String remoteBranch) throws ServiceLayerException, InvalidRemoteUrlException
      Description copied from interface: ContentRepository
      Pull from remote repository
      Specified by:
      pullFromRemote in interface ContentRepository
      Parameters:
      siteId - site identifier
      remoteName - remote name
      remoteBranch - remote branch
      Returns:
      true if operation was successful
      Throws:
      ServiceLayerException - general service error
      InvalidRemoteUrlException - invalid url for remote repository
    • isFolder

      public boolean isFolder(String siteId, String path)
      Description copied from interface: ContentRepository
      Check if content at given path is folder
      Specified by:
      isFolder in interface ContentRepository
      Parameters:
      siteId - site identifier
      path - content path
      Returns:
      true if path is folder, otherwise false
    • resetStagingRepository

      public void resetStagingRepository(String siteId) throws ServiceLayerException
      Description copied from interface: ContentRepository
      Reset staging repository to live for given site
      Specified by:
      resetStagingRepository in interface ContentRepository
      Parameters:
      siteId - site identifier to use for resetting
      Throws:
      ServiceLayerException - general service error
    • cleanup

      protected void cleanup(String siteId, GitRepositories repository)
    • cleanupRepositories

      public void cleanupRepositories(String siteId)
      Performs a cleanup all repositories for the given site
      Specified by:
      cleanupRepositories in interface ContentRepository
      Parameters:
      siteId - site identifier
    • setServletContext

      public void setServletContext(jakarta.servlet.ServletContext ctx)
      Specified by:
      setServletContext in interface org.springframework.web.context.ServletContextAware
    • setStudioConfiguration

      public void setStudioConfiguration(StudioConfiguration studioConfiguration)
    • setServicesConfig

      public void setServicesConfig(ServicesConfig servicesConfig)
    • setRemoteRepositoryDAO

      public void setRemoteRepositoryDAO(RemoteRepositoryDAO remoteRepositoryDAO)
    • setSecurityService

      public void setSecurityService(SecurityService securityService)
    • setSiteDao

      public void setSiteDao(SiteDAO siteDao)
    • setEncryptor

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

      public void setContextManager(ContextManager contextManager)
    • setGeneralLockService

      public void setGeneralLockService(GeneralLockService generalLockService)
    • setHelper

      public void setHelper(GitRepositoryHelper helper)
    • setProcessedCommitsDao

      public void setProcessedCommitsDao(ProcessedCommitsDAO processedCommitsDao)
    • setRetryingRepositoryOperationFacade

      public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade)
    • setRetryingDatabaseOperationFacade

      public void setRetryingDatabaseOperationFacade(RetryingDatabaseOperationFacade retryingDatabaseOperationFacade)