Class CmsPublishManager

java.lang.Object
org.opencms.publish.CmsPublishManager

public class CmsPublishManager extends Object
This manager provide access to the publish engine runtime information.

Since:
6.5.5
  • Field Details

  • Constructor Details

    • CmsPublishManager

      Default constructor used in digester initialization.

    • CmsPublishManager

      public CmsPublishManager(int historySize, boolean queuePersistance, int queueShutdowntime)
      Constructor used to create a pre-initialized instance.

      Parameters:
      historySize - the size of the publish history
      queuePersistance - indicates if the queue is re-initialized on startup
      queueShutdowntime - the amount of time to wait for a publish job during shutdown
  • Method Details

    • addSpecialHistoryIdProvider

      public static void addSpecialHistoryIdProvider(Supplier<List<CmsUUID>> provider)
      Adds provider for history ids that shouldn't be removed by bulk history cleanup operations.
      Parameters:
      provider - the provider for special history ids
    • abandonThread

      public void abandonThread()
      Abandons the current publish thread.

    • abortPublishJob

      public void abortPublishJob(CmsObject cms, CmsPublishJobEnqueued publishJob, boolean removeJob) throws CmsException, CmsSecurityException, CmsPublishException
      Aborts the given publish job.

      Parameters:
      cms - the cms context
      publishJob - the publish job to abort
      removeJob - indicates if the job will be removed or added to history
      Throws:
      CmsException - if there is some problem during unlocking the resources
      CmsSecurityException - if the current user has not enough permissions
      CmsPublishException - if the publish job can not been aborted
    • addPublishListener

      Adds a publish listener to listen on publish events.

      Parameters:
      listener - the publish listener to add
    • checkCurrentPublishJobThread

      Check if the thread for the current publish job is still active or was interrupted and so the next job in the queue can be started.

    • cleanupPublishHistory

      public int cleanupPublishHistory(CmsObject cms) throws CmsException
      Cleans up all unreferenced publish history entries except for the ones with a history id provided by the special history id providers.
      Parameters:
      cms - the CMS context
      Returns:
      the number of cleaned up rows
      Throws:
      CmsException - if something goes wrong
    • cleanupPublishHistory

      public int cleanupPublishHistory(CmsObject cms, CmsUUID historyId) throws CmsException
      Removes publish history entries for the given history id.
      Parameters:
      cms - the CMS context
      historyId - a publish history id
      Returns:
      the number of cleaned up rows
      Throws:
      CmsException - if something goes wrong
    • cleanupPublishHistory

      public int cleanupPublishHistory(CmsObject cms, List<CmsUUID> exceptions) throws CmsException
      Cleans up all unreferenced publish history entries except for the ones with a history id from the given list of exceptions.
      Parameters:
      cms - the CMS context
      exceptions - the list of exceptional history ids which shouldn't be removed
      Returns:
      the number of cleaned up rows
      Throws:
      CmsException - if something goes wrong
    • disablePublishing

      public void disablePublishing()
      Disables the publishing of resources.

    • enablePublishing

      public void enablePublishing()
      Enables the enqeueing of resources for publishing.

    • getCurrentPublishJob

      Returns the current running publish job.

      Returns:
      the current running publish job
    • getJobByPublishHistoryId

      Returns a publish job based on its publish history id.

      The returned publish job may be an enqueued, running or finished publish job.

      Parameters:
      publishHistoryId - the publish history id to search for
      Returns:
      the publish job with the given publish history id, or null
    • getPublishHistory

      Returns the publish history list with already publish jobs.

      Returns:
      a list of CmsPublishJobFinished objects
    • getPublishHistory

      Returns the publish history list with already publish jobs, filtered by the given user.

      Parameters:
      user - the user to filter the jobs with
      Returns:
      a list of CmsPublishJobFinished objects
    • getPublishHistorySize

      public int getPublishHistorySize()
      Returns the publish History Size.

      Returns:
      the publish History Size
    • getPublishList

      Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published.

      Parameters:
      cms - the cms request context
      Returns:
      a publish list
      Throws:
      CmsException - if something goes wrong
    • getPublishList

      public CmsPublishList getPublishList(CmsObject cms, CmsResource directPublishResource, boolean directPublishSiblings) throws CmsException
      Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a single resource.

      Parameters:
      cms - the cms request context
      directPublishResource - the resource which will be directly published
      directPublishSiblings - true, if all eventual siblings of the direct published resource should also get published.
      Returns:
      a publish list
      Throws:
      CmsException - if something goes wrong
    • getPublishList

      public CmsPublishList getPublishList(CmsObject cms, List<CmsResource> directPublishResources, boolean directPublishSiblings) throws CmsException
      Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.

      Parameters:
      cms - the cms request context
      directPublishResources - the resources which will be directly published
      directPublishSiblings - true, if all eventual siblings of the direct published resources should also get published.
      Returns:
      a publish list
      Throws:
      CmsException - if something goes wrong
    • getPublishList

      public CmsPublishList getPublishList(CmsObject cms, List<CmsResource> directPublishResources, boolean directPublishSiblings, boolean publishSubResources) throws CmsException
      Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published for a direct publish of a List of resources.

      Parameters:
      cms - the cms request context
      directPublishResources - the CmsResource objects which will be directly published
      directPublishSiblings - true, if all eventual siblings of the direct published resources should also get published.
      publishSubResources - indicates if sub-resources in folders should be published (for direct publish only)
      Returns:
      a publish list
      Throws:
      CmsException - if something goes wrong
    • getPublishListAll

      public CmsPublishList getPublishListAll(CmsObject cms, List<CmsResource> directPublishResources, boolean directPublishSiblings, boolean isUserPublishList) throws CmsException
      Returns a publish list with all the given resources, filtered only by state.

      Parameters:
      cms - the cms request context
      directPublishResources - the CmsResource objects which will be directly published
      directPublishSiblings - true, if all eventual siblings of the direct published resources should also get published
      isUserPublishList - if true, the publish list consists of resources directly selected by the user to publish
      Returns:
      a publish list
      Throws:
      CmsException - if something goes wrong
    • getPublishListRemoveMode

      Gets the publish list remove mode.

      Returns:
      the publish list remove mode
    • getPublishListVerifier

      Gets the publish job verifier.

      Returns:
      the publish job verifier
    • getPublishQueue

      Returns the queue with still waiting publish jobs.

      Returns:
      a list of CmsPublishJobEnqueued objects
    • getPublishQueueShutdowntime

      Returns the amount of time in seconds the system will wait during shutdown for a running publish job.

      Returns:
      the shutdown time for a running publish job
    • getRelatedResourcesToPublish

      Returns a new publish list that contains the unpublished resources related to all resources in the given publish list, the related resources exclude all resources in the given publish list and also locked (by other users) resources.

      Parameters:
      cms - the cms request context
      publishList - the publish list to exclude from result
      Returns:
      a new publish list that contains the related resources
      Throws:
      CmsException - if something goes wrong
    • getReportContents

      public byte[] getReportContents(CmsPublishJobFinished publishJob) throws CmsException
      Returns the content of the publish report assigned to the given publish job.

      Parameters:
      publishJob - the published job
      Returns:
      the content of the assigned publish report
      Throws:
      CmsException - if something goes wrong
    • getUsersPubList

      Returns the current user's publish list.

      Parameters:
      cms - the current cms context
      Returns:
      the current user's publish list
      Throws:
      CmsException - if something goes wrong
    • initialize

      public void initialize(CmsObject cms) throws CmsException
      Initializes the publish manager and the publish engine finally.

      Parameters:
      cms - an admin cms object
      Throws:
      CmsException - if something goes wrong
    • isAutoCleanupHistoryEntries

      public boolean isAutoCleanupHistoryEntries()
      Returns true if publish history entries should be automatically removed when the corresponding publish job is removed.
      Returns:
      true if publish history entries should autoamtically be removed
    • isPublishQueuePersistanceEnabled

      Returns if the publish queue is persisted an will be re-initialized on startup.

      Returns:
      true if the publish queue is persisted
    • isRunning

      public boolean isRunning()
      Returns the working state, that is if no publish job is waiting to be processed and there is no current running publish job.

      Returns:
      the working state
    • mergePublishLists

      Returns a new publish list that contains all resources of both given publish lists.

      Parameters:
      cms - the cms request context
      pubList1 - the first publish list
      pubList2 - the second publish list
      Returns:
      a new publish list that contains all resources of both given publish lists
      Throws:
      CmsException - if something goes wrong
    • publishProject

      Publishes the current project, printing messages to a shell report.

      Parameters:
      cms - the cms request context
      Returns:
      the publish history id of the published project
      Throws:
      Exception - if something goes wrong
      See Also:
    • publishProject

      Publishes the current project.

      Parameters:
      cms - the cms request context
      report - an instance of I_CmsReport to print messages
      Returns:
      the publish history id of the published project
      Throws:
      CmsException - if something goes wrong
    • publishProject

      public CmsUUID publishProject(CmsObject cms, I_CmsReport report, CmsPublishList publishList) throws CmsException
      Publishes the resources of a specified publish list.

      Parameters:
      cms - the cms request context
      report - an instance of I_CmsReport to print messages
      publishList - a publish list
      Returns:
      the publish history id of the published project
      Throws:
      CmsException - if something goes wrong
      See Also:
    • publishProject

      public CmsUUID publishProject(CmsObject cms, I_CmsReport report, CmsResource directPublishResource, boolean directPublishSiblings) throws CmsException
      Direct publishes a specified resource.

      Parameters:
      cms - the cms request context
      report - an instance of I_CmsReport to print messages
      directPublishResource - a CmsResource that gets directly published; or null if an entire project gets published.
      directPublishSiblings - if a CmsResource that should get published directly is provided as an argument, all eventual siblings of this resource get publish too, if this flag is true.
      Returns:
      the publish history id of the published project
      Throws:
      CmsException - if something goes wrong
    • publishResource

      public CmsUUID publishResource(CmsObject cms, String resourcename) throws Exception
      Publishes a single resource, printing messages to a shell report.

      The siblings of the resource will not be published.

      Parameters:
      cms - the cms request context
      resourcename - the name of the resource to be published
      Returns:
      the publish history id of the published project
      Throws:
      Exception - if something goes wrong
      See Also:
    • publishResource

      public CmsUUID publishResource(CmsObject cms, String resourcename, boolean publishSiblings, I_CmsReport report) throws Exception
      Publishes a single resource.

      Parameters:
      cms - the cms request context
      resourcename - the name of the resource to be published
      publishSiblings - if true, all siblings of the resource are also published
      report - the report to write the progress information to
      Returns:
      the publish history id of the published project
      Throws:
      Exception - if something goes wrong
    • removePublishListener

      Removes the given publish listener.

      Parameters:
      listener - the publish listener to remove
    • removeResourceFromUsersPubList

      public void removeResourceFromUsersPubList(CmsObject cms, Collection<CmsUUID> structureIds) throws CmsException
      Removes the given resource to the given user's publish list.

      Parameters:
      cms - the current cms context
      structureIds - the collection of structure IDs to remove
      Throws:
      CmsException - if something goes wrong
    • setAutoCleanupHistoryEntries

      Configures automatic removal of publish history entries.
      Parameters:
      val - the string value from the configuration
    • setPublishEngine

      public void setPublishEngine(CmsPublishEngine publishEngine)
      Sets the publish engine during initialization.

      Parameters:
      publishEngine - the publish engine instance
    • setPublishHistorySize

      public void setPublishHistorySize(String publishHistorySize)
      Sets the publish History Size.

      Parameters:
      publishHistorySize - the publish History Size to set
    • setPublishListRemoveMode

      Sets the publish list remove mode.

      Parameters:
      publishListRemoveMode - the publish list remove mode
    • setPublishQueuePersistance

      public void setPublishQueuePersistance(String publishQueuePersistance)
      Sets if the publish queue is re-initialized on startup.

      Parameters:
      publishQueuePersistance - the persistence flag, parsed as boolean
    • setPublishQueueShutdowntime

      public void setPublishQueueShutdowntime(String publishQueueShutdowntime)
      Sets the publish queue shutdown time.
      Parameters:
      publishQueueShutdowntime - the shutdown time to set, parsed as int
    • setSecurityManager

      public void setSecurityManager(CmsSecurityManager securityManager)
      Sets the security manager during initialization.

      Parameters:
      securityManager - the security manager
    • startPublishing

      public void startPublishing()
      Starts publishing of enqueued publish jobs.

    • stopPublishing

      public void stopPublishing()
      Stops the publishing of enqueued publish jobs.

    • validateRelations

      Validates the relations for the given resources.

      Parameters:
      cms - the cms request context
      publishList - the publish list to validate against the online project
      report - a report to write the messages to
      Returns:
      a map with lists of invalid links (CmsRelation} objects) keyed by root paths TODO: change return value to List of CmsRelation
      Throws:
      Exception - if something goes wrong
    • waitWhileRunning

      public void waitWhileRunning()
      Waits until no publish jobs remain.

    • waitWhileRunning

      public void waitWhileRunning(long ms)
      Waits until no publish jobs remain or the given max milliseconds.

      Parameters:
      ms - the max milliseconds to wait
    • getEngine

      Returns the currently used publish engine.

      Returns:
      the publish engine