Class CmsPublishManager


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

    Since:
    6.5.5
    • Constructor Detail

      • CmsPublishManager

        public 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 Detail

      • addSpecialHistoryIdProvider

        public static void addSpecialHistoryIdProvider​(java.util.function.Supplier<java.util.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.

      • checkCurrentPublishJobThread

        public void 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,
                                         java.util.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.

      • getJobByPublishHistoryId

        public CmsPublishJobBase getJobByPublishHistoryId​(CmsUUID publishHistoryId)
        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
      • getPublishHistorySize

        public int getPublishHistorySize()
        Returns the publish History Size.

        Returns:
        the publish History Size
      • getPublishList

        public CmsPublishList getPublishList​(CmsObject cms)
                                      throws CmsException
        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,
                                             java.util.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,
                                             java.util.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,
                                                java.util.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
      • getPublishQueueShutdowntime

        public int 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

        public CmsPublishList getRelatedResourcesToPublish​(CmsObject cms,
                                                           CmsPublishList publishList)
                                                    throws CmsException
        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
      • 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

        public boolean 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

        public CmsPublishList mergePublishLists​(CmsObject cms,
                                                CmsPublishList pubList1,
                                                CmsPublishList pubList2)
                                         throws CmsException
        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

        public CmsUUID publishProject​(CmsObject cms)
                               throws java.lang.Exception
        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:
        java.lang.Exception - if something goes wrong
        See Also:
        CmsShellReport
      • 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,
                                       java.lang.String resourcename)
                                throws java.lang.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:
        java.lang.Exception - if something goes wrong
        See Also:
        CmsShellReport
      • publishResource

        public CmsUUID publishResource​(CmsObject cms,
                                       java.lang.String resourcename,
                                       boolean publishSiblings,
                                       I_CmsReport report)
                                throws java.lang.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:
        java.lang.Exception - if something goes wrong
      • removeResourceFromUsersPubList

        public void removeResourceFromUsersPubList​(CmsObject cms,
                                                   java.util.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

        public void setAutoCleanupHistoryEntries​(java.lang.String val)
        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​(java.lang.String publishHistorySize)
        Sets the publish History Size.

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

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

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

        public void setPublishQueueShutdowntime​(java.lang.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

        public java.util.Map<java.lang.String,​java.util.List<CmsRelation>> validateRelations​(CmsObject cms,
                                                                                                   CmsPublishList publishList,
                                                                                                   I_CmsReport report)
                                                                                            throws java.lang.Exception
        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:
        java.lang.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