Class DefaultContentEntityManager
- java.lang.Object
-
- com.atlassian.confluence.impl.content.DefaultContentEntityManager
-
- All Implemented Interfaces:
ContentEntityManager
,ContentDraftManagerInternal
,ContentEntityManagerInternal
- Direct Known Subclasses:
DefaultCommentManager
,DefaultCustomContentManager
,DefaultPageManager
,DefaultPersonalInformationManager
,DefaultSpaceDescriptionManager
@ParametersAreNonnullByDefault public class DefaultContentEntityManager extends Object implements ContentEntityManagerInternal
- Since:
- 7.15
-
-
Field Summary
-
Fields inherited from interface com.atlassian.confluence.core.ContentEntityManager
ITERATE_ALL
-
-
Constructor Summary
Constructors Constructor Description DefaultContentEntityManager(ContentEntityObjectDao<? extends ContentEntityObject> contentEntityObjectDao, org.hibernate.SessionFactory sessionFactory, WikiToStorageConverter wikiToStorageConverter, com.atlassian.event.api.EventPublisher eventPublisher, RelationManager relationManager, CollaborativeEditingHelper collaborativeEditingHelper, AuditingContext auditingContext, RetentionFeatureChecker retentionFeatureChecker)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected @NonNull BodyContent
convertFromWikiToStorageFormatIfRequired(ContentEntityObject historicalVersion)
<T extends ContentEntityObject>
TcreateDraft(T draft, SaveContext saveContext)
This method sets the common properties of theContentEntityObject
to be saved as a draftstatic <T extends ConfluenceEntityObject>
PageResponse<T>filteredResponseWithCursor(LimitedRequest originalRequest, @Nullable Predicate<? super T> filter, List<T> pages)
<T extends ContentEntityObject>
List<T>findAllDraftsFor(long contentId)
Retrieves a list of drafts for the given content ID if any exist.List<ContentEntityObject>
findAllDraftsWithUnpublishedChangesForUser(String creatorName)
Retrieves the drafts for the givenUser
<T extends ContentEntityObject>
TfindDraftFor(long contentId)
Retrieves the draft for the given content ID if it exists<T extends ContentEntityObject>
TfindDraftFor(@NonNull T ceo)
Retrieves the draft for the given content if exists.List<ContentEntityObject>
findUnpublishedContentWithUserContributions(String username)
Retrieves the drafts for the givenUser
IMPORTANT: this method doesn't return published shared drafts, only personal drafts and unpublished shared drafts@Nullable ContentEntityObject
getById(long id)
@Nullable ContentEntityObject
getById(ContentId id)
@Nullable ContentEntityObject
getById(ContentId id, int version)
PageResponse<ContentEntityObject>
getByIdsAndFilters(List<ContentId> contentIds, LimitedRequest limitedRequest, Predicate<? super ContentEntityObject>... filters)
Map<Long,ContributionStatus>
getContributionStatusByUser(@NonNull Collection<ContentId> contentIds, @Nullable com.atlassian.sal.api.user.UserKey userKey)
Identifies the most recent contributions made to a set of content by the given user.@Nullable ContentEntityObject
getNextVersion(ContentEntityObject ceo)
Get the next version of the entity in the sequence ofVersioned
.@Nullable ContentEntityObject
getOtherVersion(ContentEntityObject ceo, int version)
@NonNull PageResponse<AbstractPage>
getPageAndBlogPostsVersionsLastEditedByUser(com.atlassian.sal.api.user.UserKey userKey, LimitedRequest request)
Retrieve a page of entities that have been modified by the user, in order of the user's most recent modification.@NonNull PageResponse<AbstractPage>
getPageAndBlogPostsVersionsLastEditedByUserIncludingDrafts(@Nullable com.atlassian.sal.api.user.UserKey userKey, LimitedRequest request)
Retrieve a page of entities that have been modified by the user, in order of the user's most recent modification.@Nullable ContentEntityObject
getPreviousVersion(ContentEntityObject ceo)
Get the previous version of the entity in the sequence ofVersioned
.@NonNull Iterator
getRecentlyAddedEntities(@Nullable String spaceKey, int maxResults)
Retrieve an iterator of recently added entities, in order of most recent to last.@NonNull Iterator
getRecentlyModifiedEntities(String spaceKey, int maxResults)
Retrieve an iterator of recently modified entities, in order of most recent to last.@NonNull Iterator
getRecentlyModifiedEntitiesForUser(String username)
Retrieve an iterator of recently modified entities, in order of most recent to last.@NonNull List
getRecentlyModifiedForChangeDigest(Date fromDate)
Retrieves a list ofContentEntityObject
s that have been newly added or modified since the date specified.@NonNull PageResponse<VersionHistorySummary>
getVersionHistorySummaries(ContentId contentId, LimitedRequest limitedRequest)
Get a VersionHistorySummary for all previous versions of a ContentEntityObject, list is ordered by Version number descending.@NonNull List<VersionHistorySummary>
getVersionHistorySummaries(ContentEntityObject ceo)
Get a VersionHistorySummary for all previous versions of a ContentEntityObject, starting with the current content.@NonNull Map<Long,ContentEntityObject>
getVersionsLastEditedByUser(@NonNull Collection<ContentId> contentIds, @Nullable com.atlassian.sal.api.user.UserKey userKey)
Gets theContentEntityObject
objects relating to the version of the given contentIds that were last edited by the given user.protected void
publishCreateEvent(ContentEntityObject obj, @Nullable SaveContext saveContext)
protected void
publishRemoveEvent(ContentEntityObject obj)
protected void
publishUpdateEvent(ContentEntityObject obj, @Nullable ContentEntityObject origObj, @Nullable SaveContext saveContext)
void
refreshContentEntity(ContentEntityObject obj)
Refreshes the specified entity (including content) in the Hibernate session to ensure that subsequent retrievals are up-to-date.protected void
removeContentEntities(Iterable<? extends ContentEntityObject> contentEntityObjects)
void
removeContentEntity(ContentEntityObject obj)
Removes given content entity object and all associated domain objects i.e.void
removeHistoricalVersion(ContentEntityObject historicalVersion)
Removes a historical ContentEntityObject.void
revertContentEntityBackToVersion(ContentEntityObject entity, int version, @Nullable String revertComment, boolean revertTitle)
Reverts aContentEntityObject
back to its state at the version specified byversion
.void
revertContentEntityBackToVersion(ContentEntityObject entity, int version, @Nullable String revertComment, boolean revertTitle, Function<ContentEntityObject,BodyContent> revertBodyContentFactory)
void
saveContentEntity(ContentEntityObject obj, @Nullable ContentEntityObject origObj, @Nullable SaveContext saveContext)
In order to create a history for this object, we need to pass in the modified as well as the original version of the object.void
saveContentEntity(ContentEntityObject obj, @Nullable SaveContext saveContext)
<T extends ContentEntityObject>
voidsaveNewVersion(T current, Modification<T> modification)
Applies the state changes supplied by modification and persists those changes to a new version.<T extends ContentEntityObject>
voidsaveNewVersion(T current, Modification<T> modification, @Nullable SaveContext saveContext)
Applies the state changes supplied by modification and persists those changes to a new version.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.internal.ContentEntityManagerInternal
getByIds
-
-
-
-
Constructor Detail
-
DefaultContentEntityManager
public DefaultContentEntityManager(ContentEntityObjectDao<? extends ContentEntityObject> contentEntityObjectDao, org.hibernate.SessionFactory sessionFactory, WikiToStorageConverter wikiToStorageConverter, com.atlassian.event.api.EventPublisher eventPublisher, RelationManager relationManager, CollaborativeEditingHelper collaborativeEditingHelper, AuditingContext auditingContext, RetentionFeatureChecker retentionFeatureChecker)
-
-
Method Detail
-
filteredResponseWithCursor
public static <T extends ConfluenceEntityObject> PageResponse<T> filteredResponseWithCursor(LimitedRequest originalRequest, @Nullable Predicate<? super T> filter, List<T> pages)
-
refreshContentEntity
public void refreshContentEntity(ContentEntityObject obj)
Description copied from interface:ContentEntityManager
Refreshes the specified entity (including content) in the Hibernate session to ensure that subsequent retrievals are up-to-date.- Specified by:
refreshContentEntity
in interfaceContentEntityManager
- Parameters:
obj
- the object to be refreshed in the Hibernate session.
-
createDraft
public <T extends ContentEntityObject> T createDraft(T draft, SaveContext saveContext)
Description copied from interface:ContentDraftManagerInternal
This method sets the common properties of theContentEntityObject
to be saved as a draft- Specified by:
createDraft
in interfaceContentDraftManagerInternal
- Parameters:
draft
- - theContentEntityObject
to save as draftsaveContext
- - aSaveContext
holding additional parameters for the manager to use when saving.- Returns:
- the obj created as draft
- See Also:
ContentEntityObject.DRAFT
-
findDraftFor
public <T extends ContentEntityObject> T findDraftFor(@NonNull T ceo)
Description copied from interface:ContentDraftManagerInternal
Retrieves the draft for the given content if exists.- Specified by:
findDraftFor
in interfaceContentDraftManagerInternal
- Parameters:
ceo
- the entity object to retrieve the draft for- Returns:
- the draft for the given content if exists, null otherwise
- See Also:
ContentEntityObject.DRAFT
-
findDraftFor
public <T extends ContentEntityObject> T findDraftFor(long contentId)
Description copied from interface:ContentDraftManagerInternal
Retrieves the draft for the given content ID if it exists- Specified by:
findDraftFor
in interfaceContentDraftManagerInternal
- Parameters:
contentId
- The content ID used to identify the draft- Returns:
- the draft for the given content ID if it exists, null otherwise
- See Also:
ContentEntityObject.DRAFT
-
findAllDraftsFor
public <T extends ContentEntityObject> List<T> findAllDraftsFor(long contentId)
Description copied from interface:ContentDraftManagerInternal
Retrieves a list of drafts for the given content ID if any exist.- Specified by:
findAllDraftsFor
in interfaceContentDraftManagerInternal
- Parameters:
contentId
- The content ID used to identify the drafts- Returns:
- A non-null list of drafts with 0 or more elements
- See Also:
ContentEntityObject.DRAFT
-
findUnpublishedContentWithUserContributions
public List<ContentEntityObject> findUnpublishedContentWithUserContributions(String username)
Description copied from interface:ContentDraftManagerInternal
Retrieves the drafts for the givenUser
IMPORTANT: this method doesn't return published shared drafts, only personal drafts and unpublished shared drafts- Specified by:
findUnpublishedContentWithUserContributions
in interfaceContentDraftManagerInternal
- Parameters:
username
- the owner of the drafts- Returns:
- a list of
ContentEntityObject
with theContentEntityObject.DRAFT
status
-
findAllDraftsWithUnpublishedChangesForUser
public List<ContentEntityObject> findAllDraftsWithUnpublishedChangesForUser(String creatorName)
Description copied from interface:ContentDraftManagerInternal
Retrieves the drafts for the givenUser
- Specified by:
findAllDraftsWithUnpublishedChangesForUser
in interfaceContentDraftManagerInternal
- Parameters:
creatorName
- the owner of the drafts- Returns:
- a list of user's drafts (
ContentEntityObject
objejcts)
-
saveContentEntity
public void saveContentEntity(ContentEntityObject obj, @Nullable SaveContext saveContext)
- Specified by:
saveContentEntity
in interfaceContentEntityManager
- Parameters:
obj
- - theContentEntityObject
to savesaveContext
- - aSaveContext
holding additional parameters for the manager to use when saving.
-
saveContentEntity
public void saveContentEntity(ContentEntityObject obj, @Nullable ContentEntityObject origObj, @Nullable SaveContext saveContext)
Description copied from interface:ContentEntityManager
In order to create a history for this object, we need to pass in the modified as well as the original version of the object.- Specified by:
saveContentEntity
in interfaceContentEntityManager
saveContext
- - aSaveContext
holding additional parameters for the manager to use when saving.
-
saveNewVersion
public <T extends ContentEntityObject> void saveNewVersion(T current, Modification<T> modification)
Description copied from interface:ContentEntityManager
Applies the state changes supplied by modification and persists those changes to a new version.manager.<Page>saveNewVersion(page, new Modification<Page>() { public void modify(Page page) { page.setTitle("foobar"); } });
- Specified by:
saveNewVersion
in interfaceContentEntityManager
- Type Parameters:
T
- the type content. This ensures that the type of current is the same as the type passed to the modification- Parameters:
current
- the current / latest versionmodification
- an implementation ofModification
which describes the state changes you require
-
saveNewVersion
public <T extends ContentEntityObject> void saveNewVersion(T current, Modification<T> modification, @Nullable SaveContext saveContext)
Description copied from interface:ContentEntityManager
Applies the state changes supplied by modification and persists those changes to a new version.manager.<Page>saveNewVersion(page, new Modification<Page>() { public void modify(Page page) { page.setTitle("foobar"); } }, new DefaultSaveContext());
- Specified by:
saveNewVersion
in interfaceContentEntityManager
- Type Parameters:
T
- the type content. This ensures that the type of current is the same as the type passed to the modification- Parameters:
current
- the current / latest versionmodification
- an implementation ofModification
which describes the state changes you requiresaveContext
- the save context (null if you have no specific requirements - or just useContentEntityManager.saveNewVersion(ContentEntityObject, Modification)
).
-
removeContentEntities
protected void removeContentEntities(Iterable<? extends ContentEntityObject> contentEntityObjects)
-
removeContentEntity
public void removeContentEntity(ContentEntityObject obj)
Description copied from interface:ContentEntityManager
Removes given content entity object and all associated domain objects i.e. if we remove a page it removes all its labels and attachments- Specified by:
removeContentEntity
in interfaceContentEntityManager
-
getById
public @Nullable ContentEntityObject getById(long id)
- Specified by:
getById
in interfaceContentEntityManager
- Returns:
- ContentEntityObject with the given id.
-
getById
public @Nullable ContentEntityObject getById(ContentId id)
- Specified by:
getById
in interfaceContentEntityManagerInternal
- Returns:
- ContentEntityObject with the given id.
-
getById
public @Nullable ContentEntityObject getById(ContentId id, int version)
- Specified by:
getById
in interfaceContentEntityManagerInternal
- Parameters:
id
- the id of the last version CEO. Previous version ids will make this method return null- Returns:
- the ContentEntityObject with the corresponding id and version or null if the object with that id and version does not exist. null will also be returned if the id points to a CEO which version is not the last one.
-
getByIdsAndFilters
public PageResponse<ContentEntityObject> getByIdsAndFilters(List<ContentId> contentIds, LimitedRequest limitedRequest, Predicate<? super ContentEntityObject>... filters)
- Specified by:
getByIdsAndFilters
in interfaceContentEntityManagerInternal
- Parameters:
contentIds
- the contentIds of the candidate ContentEntityObjectslimitedRequest
- the page request to applyfilters
- an optional predicate- Returns:
- fetch multiple contentEntityObjects by id that match the provided predicate
-
getVersionHistorySummaries
public @NonNull PageResponse<VersionHistorySummary> getVersionHistorySummaries(ContentId contentId, LimitedRequest limitedRequest)
Description copied from interface:ContentEntityManagerInternal
Get a VersionHistorySummary for all previous versions of a ContentEntityObject, list is ordered by Version number descending. e.g. the list is started with the most recent content version as item 0.- Specified by:
getVersionHistorySummaries
in interfaceContentEntityManagerInternal
- Parameters:
contentId
- the entity Id of the object to return the version history of- Returns:
- the full version history of that object, as VersionHistorySummary objects.
-
revertContentEntityBackToVersion
public void revertContentEntityBackToVersion(ContentEntityObject entity, int version, @Nullable String revertComment, boolean revertTitle)
Description copied from interface:ContentEntityManager
Reverts a
ContentEntityObject
back to its state at the version specified byversion
. Creates a new latest version that resembles the previous state.Since Confluence 4.0 most ContentEntityObjects are assumed to be XHTML formatted. So in reverting a ContentEntityObject which actually has a WIKI
BodyType
this will be migrated on the fly to XHTML.- Specified by:
revertContentEntityBackToVersion
in interfaceContentEntityManager
- Parameters:
entity
- The ContentEntityObject to revertversion
- The version to revert torevertComment
- A comment to be associated with the revertrevertTitle
- If true, the ContentEntityObject title will be reverted to the old state
-
revertContentEntityBackToVersion
public void revertContentEntityBackToVersion(ContentEntityObject entity, int version, @Nullable String revertComment, boolean revertTitle, Function<ContentEntityObject,BodyContent> revertBodyContentFactory)
-
convertFromWikiToStorageFormatIfRequired
protected @NonNull BodyContent convertFromWikiToStorageFormatIfRequired(ContentEntityObject historicalVersion)
-
getRecentlyAddedEntities
public @NonNull Iterator getRecentlyAddedEntities(@Nullable String spaceKey, int maxResults)
Description copied from interface:ContentEntityManager
Retrieve an iterator of recently added entities, in order of most recent to last. The iterator is lazy-loading, so you can filter the output and return the first 'n' that interest you.For performance reasons, it's a VERY bad idea to supply both a space key, and infinite results.
If you supply a space key, this WILL NOT RETURN ANY COMMENTS. There is currently no way around this, you have to retrieve comments separately and splice the results together. Sorry.
- Specified by:
getRecentlyAddedEntities
in interfaceContentEntityManager
- Parameters:
spaceKey
- the space key to look up the entities for. If spaceKey is null, there is assumed to be no space, and things like user info and space descriptions will also be returned.maxResults
- the maximum number of entities to return in the iterator. Any number zero or less (Use the ITERATE_ALL constant) will cause the iterator to go over every entity.
-
getRecentlyModifiedEntities
public @NonNull Iterator getRecentlyModifiedEntities(String spaceKey, int maxResults)
Description copied from interface:ContentEntityManager
Retrieve an iterator of recently modified entities, in order of most recent to last. The iterator is lazy-loading, so you can filter the output and return the first 'n' that interest you.For performance reasons, it's a VERY bad idea to supply both a space key, and infinite results.
- Specified by:
getRecentlyModifiedEntities
in interfaceContentEntityManager
- Parameters:
spaceKey
- the space key to look up the entities for.maxResults
- the maximum number of entities to return in the iterator. Any number zero or less (Use the ITERATE_ALL constant) will cause the iterator to go over every entity.
-
getPageAndBlogPostsVersionsLastEditedByUser
public @NonNull PageResponse<AbstractPage> getPageAndBlogPostsVersionsLastEditedByUser(com.atlassian.sal.api.user.UserKey userKey, LimitedRequest request)
Description copied from interface:ContentEntityManager
Retrieve a page of entities that have been modified by the user, in order of the user's most recent modification. Only content with a "current" status are returned.- Specified by:
getPageAndBlogPostsVersionsLastEditedByUser
in interfaceContentEntityManager
- Parameters:
userKey
- the key for the user for whom to retrieve the modified contentrequest
- the request
-
getPageAndBlogPostsVersionsLastEditedByUserIncludingDrafts
public @NonNull PageResponse<AbstractPage> getPageAndBlogPostsVersionsLastEditedByUserIncludingDrafts(@Nullable com.atlassian.sal.api.user.UserKey userKey, LimitedRequest request)
Description copied from interface:ContentEntityManager
Retrieve a page of entities that have been modified by the user, in order of the user's most recent modification. Only content with "current" or "draft" status are returned.- Specified by:
getPageAndBlogPostsVersionsLastEditedByUserIncludingDrafts
in interfaceContentEntityManager
- Parameters:
userKey
- the key for the user for whom to retrieve the modified contentrequest
- the request
-
getRecentlyModifiedEntitiesForUser
public @NonNull Iterator getRecentlyModifiedEntitiesForUser(String username)
Description copied from interface:ContentEntityManager
Retrieve an iterator of recently modified entities, in order of most recent to last. The iterator is lazy-loading, so you can filter the output and return the first 'n' that interest you.- Specified by:
getRecentlyModifiedEntitiesForUser
in interfaceContentEntityManager
- Parameters:
username
- the user for which to retrieve the modified content
-
getRecentlyModifiedForChangeDigest
public @NonNull List getRecentlyModifiedForChangeDigest(Date fromDate)
Description copied from interface:ContentEntityManager
Retrieves a list ofContentEntityObject
s that have been newly added or modified since the date specified. This list excludes drafts, space descriptions and mail.- Specified by:
getRecentlyModifiedForChangeDigest
in interfaceContentEntityManager
- Parameters:
fromDate
- content modified after this date will be returned- Returns:
- a list of
ContentEntityObject
s that have been newly added or modified since the date specified
-
getPreviousVersion
public @Nullable ContentEntityObject getPreviousVersion(ContentEntityObject ceo)
Description copied from interface:ContentEntityManager
Get the previous version of the entity in the sequence ofVersioned
.Returns null for
ContentEntityObject.DRAFT
s.- Specified by:
getPreviousVersion
in interfaceContentEntityManager
-
getNextVersion
public @Nullable ContentEntityObject getNextVersion(ContentEntityObject ceo)
Description copied from interface:ContentEntityManager
Get the next version of the entity in the sequence ofVersioned
.Returns null for
ContentEntityObject.DRAFT
s.- Specified by:
getNextVersion
in interfaceContentEntityManager
-
getOtherVersion
public @Nullable ContentEntityObject getOtherVersion(ContentEntityObject ceo, int version)
- Specified by:
getOtherVersion
in interfaceContentEntityManager
-
getVersionsLastEditedByUser
public @NonNull Map<Long,ContentEntityObject> getVersionsLastEditedByUser(@NonNull Collection<ContentId> contentIds, @Nullable com.atlassian.sal.api.user.UserKey userKey)
Description copied from interface:ContentEntityManager
Gets theContentEntityObject
objects relating to the version of the given contentIds that were last edited by the given user. Only content with a "current" status are returned.- Specified by:
getVersionsLastEditedByUser
in interfaceContentEntityManager
- Parameters:
contentIds
- the ids of the content we're interested in. These *must* be ids of the latest version.userKey
- the userKey of the user that we're interested in- Returns:
- the
ContentEntityObject
objects relating to the version of the given contentIds that were last edited by the given user.
-
getContributionStatusByUser
public Map<Long,ContributionStatus> getContributionStatusByUser(@NonNull Collection<ContentId> contentIds, @Nullable com.atlassian.sal.api.user.UserKey userKey)
Description copied from interface:ContentEntityManager
Identifies the most recent contributions made to a set of content by the given user. A contribution can either be a page publish, or a set of unpublished changes which have been saved to a draft. Does not return aContributionStatus
for a content ID if the user has never contributed to the content.- Specified by:
getContributionStatusByUser
in interfaceContentEntityManager
- Parameters:
contentIds
- the IDs of the content we want to query. These *must* be IDs of the latest versionuserKey
- the userKey of the user who's changes we are interested in- Returns:
- the
ContributionStatus
of each content
-
getVersionHistorySummaries
public @NonNull List<VersionHistorySummary> getVersionHistorySummaries(ContentEntityObject ceo)
Description copied from interface:ContentEntityManager
Get a VersionHistorySummary for all previous versions of a ContentEntityObject, starting with the current content.- Specified by:
getVersionHistorySummaries
in interfaceContentEntityManager
- Parameters:
ceo
- the entity object to return the version history of- Returns:
- the full version history of that object, as VersionHistorySummary objects.
-
removeHistoricalVersion
public void removeHistoricalVersion(ContentEntityObject historicalVersion)
Description copied from interface:ContentEntityManager
Removes a historical ContentEntityObject.- Specified by:
removeHistoricalVersion
in interfaceContentEntityManager
- Parameters:
historicalVersion
- a historical entity object to remove
-
publishCreateEvent
protected void publishCreateEvent(ContentEntityObject obj, @Nullable SaveContext saveContext)
-
publishUpdateEvent
protected void publishUpdateEvent(ContentEntityObject obj, @Nullable ContentEntityObject origObj, @Nullable SaveContext saveContext)
-
publishRemoveEvent
protected void publishRemoveEvent(ContentEntityObject obj)
-
-