Package org.opencms.publish
Class CmsPublishManager
- java.lang.Object
-
- org.opencms.publish.CmsPublishManager
-
public class CmsPublishManager extends java.lang.Object
This manager provide access to the publish engine runtime information.- Since:
- 6.5.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsPublishManager.PublishListRemoveMode
Enum for the different publish list remove modes.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_HISTORY_SIZE
The default history size.static boolean
DEFAULT_QUEUE_PERSISTANCE
The default persistence setting for the publish queue.static int
DEFAULT_QUEUE_SHUTDOWNTIME
The default shutdown time for the running publish job.
-
Constructor Summary
Constructors Constructor Description CmsPublishManager()
Default constructor used in digester initialization.CmsPublishManager(int historySize, boolean queuePersistance, int queueShutdowntime)
Constructor used to create a pre-initialized instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abandonThread()
Abandons the current publish thread.void
abortPublishJob(CmsObject cms, CmsPublishJobEnqueued publishJob, boolean removeJob)
Aborts the given publish job.void
addPublishListener(I_CmsPublishEventListener listener)
Adds a publish listener to listen on publish events.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.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.int
cleanupPublishHistory(CmsObject cms)
Cleans up all unreferenced publish history entries except for the ones with a history id provided by the special history id providers.int
cleanupPublishHistory(CmsObject cms, java.util.List<CmsUUID> exceptions)
Cleans up all unreferenced publish history entries except for the ones with a history id from the given list of exceptions.int
cleanupPublishHistory(CmsObject cms, CmsUUID historyId)
Removes publish history entries for the given history id.void
disablePublishing()
Disables the publishing of resources.void
enablePublishing()
Enables the enqeueing of resources for publishing.CmsPublishJobRunning
getCurrentPublishJob()
Returns the current running publish job.protected CmsPublishEngine
getEngine()
Returns the currently used publish engine.CmsPublishJobBase
getJobByPublishHistoryId(CmsUUID publishHistoryId)
Returns a publish job based on its publish history id.java.util.List<CmsPublishJobFinished>
getPublishHistory()
Returns the publish history list with already publish jobs.java.util.List<CmsPublishJobFinished>
getPublishHistory(CmsUser user)
Returns the publish history list with already publish jobs, filtered by the given user.int
getPublishHistorySize()
Returns the publish History Size.CmsPublishList
getPublishList(CmsObject cms)
Returns a publish list with all new/changed/deleted resources of the current (offline) project that actually get published.CmsPublishList
getPublishList(CmsObject cms, java.util.List<CmsResource> directPublishResources, boolean directPublishSiblings)
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.CmsPublishList
getPublishList(CmsObject cms, java.util.List<CmsResource> directPublishResources, boolean directPublishSiblings, boolean publishSubResources)
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.CmsPublishList
getPublishList(CmsObject cms, CmsResource directPublishResource, boolean directPublishSiblings)
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.CmsPublishList
getPublishListAll(CmsObject cms, java.util.List<CmsResource> directPublishResources, boolean directPublishSiblings, boolean isUserPublishList)
Returns a publish list with all the given resources, filtered only by state.CmsPublishManager.PublishListRemoveMode
getPublishListRemoveMode()
Gets the publish list remove mode.CmsPublishListVerifier
getPublishListVerifier()
Gets the publish job verifier.java.util.List<CmsPublishJobEnqueued>
getPublishQueue()
Returns the queue with still waiting publish jobs.int
getPublishQueueShutdowntime()
Returns the amount of time in seconds the system will wait during shutdown for a running publish job.CmsPublishList
getRelatedResourcesToPublish(CmsObject cms, CmsPublishList publishList)
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.byte[]
getReportContents(CmsPublishJobFinished publishJob)
Returns the content of the publish report assigned to the given publish job.java.util.List<CmsResource>
getUsersPubList(CmsObject cms)
Returns the current user's publish list.void
initialize(CmsObject cms)
Initializes the publish manager and the publish engine finally.boolean
isAutoCleanupHistoryEntries()
Returns true if publish history entries should be automatically removed when the corresponding publish job is removed.boolean
isPublishQueuePersistanceEnabled()
Returns if the publish queue is persisted an will be re-initialized on startup.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.CmsPublishList
mergePublishLists(CmsObject cms, CmsPublishList pubList1, CmsPublishList pubList2)
Returns a new publish list that contains all resources of both given publish lists.CmsUUID
publishProject(CmsObject cms)
Publishes the current project, printing messages to a shell report.CmsUUID
publishProject(CmsObject cms, I_CmsReport report)
Publishes the current project.CmsUUID
publishProject(CmsObject cms, I_CmsReport report, CmsPublishList publishList)
Publishes the resources of a specified publish list.CmsUUID
publishProject(CmsObject cms, I_CmsReport report, CmsResource directPublishResource, boolean directPublishSiblings)
Direct publishes a specified resource.CmsUUID
publishResource(CmsObject cms, java.lang.String resourcename)
Publishes a single resource, printing messages to a shell report.CmsUUID
publishResource(CmsObject cms, java.lang.String resourcename, boolean publishSiblings, I_CmsReport report)
Publishes a single resource.void
removePublishListener(I_CmsPublishEventListener listener)
Removes the given publish listener.void
removeResourceFromUsersPubList(CmsObject cms, java.util.Collection<CmsUUID> structureIds)
Removes the given resource to the given user's publish list.void
setAutoCleanupHistoryEntries(java.lang.String val)
Configures automatic removal of publish history entries.void
setPublishEngine(CmsPublishEngine publishEngine)
Sets the publish engine during initialization.void
setPublishHistorySize(java.lang.String publishHistorySize)
Sets the publish History Size.void
setPublishListRemoveMode(CmsPublishManager.PublishListRemoveMode publishListRemoveMode)
Sets the publish list remove mode.void
setPublishQueuePersistance(java.lang.String publishQueuePersistance)
Sets if the publish queue is re-initialized on startup.void
setPublishQueueShutdowntime(java.lang.String publishQueueShutdowntime)
Sets the publish queue shutdown time.void
setSecurityManager(CmsSecurityManager securityManager)
Sets the security manager during initialization.void
startPublishing()
Starts publishing of enqueued publish jobs.void
stopPublishing()
Stops the publishing of enqueued publish jobs.java.util.Map<java.lang.String,java.util.List<CmsRelation>>
validateRelations(CmsObject cms, CmsPublishList publishList, I_CmsReport report)
Validates the relations for the given resources.void
waitWhileRunning()
Waits until no publish jobs remain.void
waitWhileRunning(long ms)
Waits until no publish jobs remain or the given max milliseconds.
-
-
-
Field Detail
-
DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_SIZE
The default history size.- See Also:
- Constant Field Values
-
DEFAULT_QUEUE_PERSISTANCE
public static final boolean DEFAULT_QUEUE_PERSISTANCE
The default persistence setting for the publish queue.- See Also:
- Constant Field Values
-
DEFAULT_QUEUE_SHUTDOWNTIME
public static final int DEFAULT_QUEUE_SHUTDOWNTIME
The default shutdown time for the running publish job.- See Also:
- Constant Field Values
-
-
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 historyqueuePersistance
- indicates if the queue is re-initialized on startupqueueShutdowntime
- 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.
-
abortPublishJob
public void abortPublishJob(CmsObject cms, CmsPublishJobEnqueued publishJob, boolean removeJob) throws CmsException, CmsSecurityException, CmsPublishException
Aborts the given publish job.- Parameters:
cms
- the cms contextpublishJob
- the publish job to abortremoveJob
- indicates if the job will be removed or added to history- Throws:
CmsException
- if there is some problem during unlocking the resourcesCmsSecurityException
- if the current user has not enough permissionsCmsPublishException
- if the publish job can not been aborted
-
addPublishListener
public void addPublishListener(I_CmsPublishEventListener listener)
Adds a publish listener to listen on publish events.- Parameters:
listener
- the publish listener to add
-
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 contexthistoryId
- 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 contextexceptions
- 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
public CmsPublishJobRunning getCurrentPublishJob()
Returns the current running publish job.- Returns:
- the current running publish job
-
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
-
getPublishHistory
public java.util.List<CmsPublishJobFinished> getPublishHistory()
Returns the publish history list with already publish jobs.- Returns:
- a list of
CmsPublishJobFinished
objects
-
getPublishHistory
public java.util.List<CmsPublishJobFinished> getPublishHistory(CmsUser user)
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
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 contextdirectPublishResource
- the resource which will be directly publisheddirectPublishSiblings
-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 contextdirectPublishResources
- the resources which will be directly publisheddirectPublishSiblings
-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 contextdirectPublishResources
- theCmsResource
objects which will be directly publisheddirectPublishSiblings
-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 contextdirectPublishResources
- theCmsResource
objects which will be directly publisheddirectPublishSiblings
-true
, if all eventual siblings of the direct published resources should also get publishedisUserPublishList
- 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
public CmsPublishManager.PublishListRemoveMode getPublishListRemoveMode()
Gets the publish list remove mode.- Returns:
- the publish list remove mode
-
getPublishListVerifier
public CmsPublishListVerifier getPublishListVerifier()
Gets the publish job verifier.- Returns:
- the publish job verifier
-
getPublishQueue
public java.util.List<CmsPublishJobEnqueued> getPublishQueue()
Returns the queue with still waiting publish jobs.- Returns:
- a list of
CmsPublishJobEnqueued
objects
-
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 contextpublishList
- 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
public java.util.List<CmsResource> getUsersPubList(CmsObject cms) throws CmsException
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
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 contextpubList1
- the first publish listpubList2
- 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) throws CmsException
Publishes the current project.- Parameters:
cms
- the cms request contextreport
- an instance of
to print messagesI_CmsReport
- 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 contextreport
- an instance of
to print messagesI_CmsReport
publishList
- a publish list- Returns:
- the publish history id of the published project
- Throws:
CmsException
- if something goes wrong- See Also:
getPublishList(CmsObject)
,getPublishList(CmsObject, CmsResource, boolean)
,getPublishList(CmsObject, List, boolean)
-
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 contextreport
- an instance of
to print messagesI_CmsReport
directPublishResource
- a
that gets directly published; orCmsResource
null
if an entire project gets published.directPublishSiblings
- if a
that should get published directly is provided as an argument, all eventual siblings of this resource get publish too, if this flag isCmsResource
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 contextresourcename
- 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 contextresourcename
- the name of the resource to be publishedpublishSiblings
- iftrue
, all siblings of the resource are also publishedreport
- 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
-
removePublishListener
public void removePublishListener(I_CmsPublishEventListener listener)
Removes the given publish listener.- Parameters:
listener
- the publish listener to remove
-
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 contextstructureIds
- 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
-
setPublishListRemoveMode
public void setPublishListRemoveMode(CmsPublishManager.PublishListRemoveMode publishListRemoveMode)
Sets the publish list remove mode.- Parameters:
publishListRemoveMode
- the publish list remove mode
-
setPublishQueuePersistance
public void setPublishQueuePersistance(java.lang.String publishQueuePersistance)
Sets if the publish queue is re-initialized on startup.- Parameters:
publishQueuePersistance
- the persistence flag, parsed asboolean
-
setPublishQueueShutdowntime
public void setPublishQueueShutdowntime(java.lang.String publishQueueShutdowntime)
Sets the publish queue shutdown time.- Parameters:
publishQueueShutdowntime
- the shutdown time to set, parsed asint
-
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 contextpublishList
- the publish list to validate against the online projectreport
- a report to write the messages to- Returns:
- a map with lists of invalid links
(
objects) keyed by root paths TODO: change return value to List of CmsRelationCmsRelation
} - 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
-
getEngine
protected CmsPublishEngine getEngine()
Returns the currently used publish engine.- Returns:
- the publish engine
-
-