Package org.ametys.cms.repository
Class ContentDAO
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.cms.repository.ContentDAO
- All Implemented Interfaces:
Component
,Contextualizable
,LogEnabled
,Serviceable
- Direct Known Subclasses:
HierarchicalReferenceTablesDeleteContentDAO
,WebContentDAO
public class ContentDAO
extends AbstractLogEnabled
implements Serviceable, Component, Contextualizable
DAO for manipulating contents
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Deletion status : deletedprotected static final String
Deletion status : lockedprotected static final String
Deletion status : referencedprotected static final String
Deletion status : unauthorizedprotected static final String
Deletion status : undeletedprotected ContentHelper
Content helperprotected ContentTypeExtensionPoint
Content-type extension pointprotected ContentWorkflowHelper
Workflow helper componentprotected Context
Cocoon contextprotected ContentTypesHelper
Content types helperprotected CurrentUserProvider
Component to get current userprotected HierarchicalReferenceTablesHelper
The helper component for hierarchical simple contentsprotected LockContentManager
Component to manager lockprotected ModifiableContentHelper
The modifiable content helperprotected ObservationManager
Ametys observation mangerprotected AmetysObjectResolver
Ametys resolverprotected RightManager
Rights managerprotected TagProviderExtensionPoint
Component to get tagsprotected UserHelper
Helper for usersprotected UserManager
The user managerprotected WorkflowProvider
Workflow componentstatic final String
Avalon Role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_addOrRemoveReaction
(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType, boolean remove) Add or remove reaction if exists on the given content.protected void
Copy the ACL of a contentprotected void
_copyAttachments
(Content srcContent, Content targetContent) Copy the attachments of a contentprotected String
_getContentDeletionStatus
(Content content, String deleteRightId) Get the deletion status of the content : - unauthorized: The content can't be deleted because of rights - locked: The content is locked - referenced: The content has ingoing references_getEventParametersForDeletion
(Content content) Get parameters for content deletedEvent
protected int
Get the invert action id (used for forced deletion).Initialize the result map.protected boolean
_isContentReferenced
(Content content) Test if content is still referenced before removing itprotected boolean
_isTagValid
(String tagName, Map<String, Object> contextualParameters) Is the tag a content tagprotected String
_reallyDeleteContent
(Content content) Delete the content and notify observers.protected void
_removeAllTagsInReplaceMode
(TaggableAmetysObject mContent, ContentDAO.TagMode tagMode, Set<String> oldTags) Remove all tags from the given content if tagMode is equals to REPLACE.protected boolean
_removeReferences
(Content content) Remove all the references to the given content._transformContentToParams
(Content content) Transform the content to aMap
with id, title and name.boolean
Determines if the current user has right to delete the contentboolean
Determines if the current user has right to delete the contentvoid
contextualize
(Context context) copy
(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, int initWorkflowActionId, DataContext context) Copy a content.copy
(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId, boolean notifyObservers, boolean checkpoint, boolean waitAsyncObservers, boolean copyACL, DataContext context) Copy a content.copy
(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId, DataContext context) Copy a content.deleteContents
(List<String> contentsId) Delete contentsdeleteContents
(List<String> contentsId, boolean ignoreRights) Delete contentsdeleteContents
(List<String> contentsId, String deleteRightId) Delete contentsforceDeleteContents
(List<String> contentsId) Delete contents and force the deletion of invert relations.forceDeleteContentsObj
(List<Content> contents, String deleteRightId) Delete contents and force the deletion of invert relations.int
forceDeleteContentsWithLog
(List<Content> contents, String deleteRightId, Logger logger) Delete contents and force the deletion of invert relations, then log the result.Returns the content's attachments root nodegetContentDescription
(String contentId, String workspaceName) Get the content's properties for descriptiongetContentDescription
(Content content) Get the content's properties for descriptiongetContentProperties
(String contentId, String workspaceName) Get the content propertiesgetContentProperties
(Content content) Get the content propertiesgetContentsProperties
(List<String> contentIds, String workspaceName) Get the contents propertiesgetContentViews
(String contentId, boolean includeInternal) Get the views of a contentgetContentViewsAndAllData
(String contentId, boolean includeInternal) Get the views of a content plus a view of all the content's dataprotected String
Get the right to delete a content.Get the tags of contentsgetUserRights
(Content content) Get the user rights on contentvoid
notifyContentCopied
(Content content, boolean waitAsyncObservers) Notify observers that the content has been createdAdd or remove a reaction on a contentboolean
react
(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType) Add a reaction on aContent
.void
Add a report on a contentvoid
service
(ServiceManager smanager) tag
(List<String> contentIds, List<String> tagNames, String mode, Map<String, Object> contextualParameters) Tag a list of contentsTag a list of contents with the given tagstag
(List<String> contentIds, List<String> tagNames, ContentDAO.TagMode mode, Map<String, Object> contextualParameters, boolean ignoreRights) Tag a list of contentsboolean
unreact
(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType) Remove reaction if exists on aContent
.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
ROLE
Avalon Role -
_CONTENT_DELETION_STATUS_DELETED
Deletion status : deleted- See Also:
-
_CONTENT_DELETION_STATUS_UNDELETED
Deletion status : undeleted- See Also:
-
_CONTENT_DELETION_STATUS_REFERENCED
Deletion status : referenced- See Also:
-
_CONTENT_DELETION_STATUS_UNAUTHORIZED
Deletion status : unauthorized- See Also:
-
_CONTENT_DELETION_STATUS_LOCKED
Deletion status : locked- See Also:
-
_resolver
Ametys resolver -
_observationManager
Ametys observation manger -
_currentUserProvider
Component to get current user -
_tagProvider
Component to get tags -
_workflowProvider
Workflow component -
_contentWorkflowHelper
Workflow helper component -
_lockManager
Component to manager lock -
_contentTypeEP
Content-type extension point -
_contentHelper
Content helper -
_cTypesHelper
Content types helper -
_rightManager
Rights manager -
_context
Cocoon context -
_usersManager
The user manager -
_userHelper
Helper for users -
_hierarchicalSimpleContentsHelper
The helper component for hierarchical simple contents -
_modifiableContentHelper
The modifiable content helper
-
-
Constructor Details
-
ContentDAO
public ContentDAO()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
forceDeleteContents
Delete contents and force the deletion of invert relations.- Parameters:
contentsId
- The ids of contents to delete- Returns:
- the deleted and undeleted contents
-
forceDeleteContentsObj
Delete contents and force the deletion of invert relations.- Parameters:
contents
- The contents to deletedeleteRightId
- The deletion right's id to check. Can be null to ignore rights- Returns:
- the deleted and undeleted contents
-
_getInvertActionId
Get the invert action id (used for forced deletion).- Returns:
- The invert action id
-
getRightToDelete
Get the right to delete a content.- Returns:
- The right ID to delete a content
-
_removeReferences
Remove all the references to the given content.- Parameters:
content
- The content- Returns:
true
if references have been all removed successfully
-
deleteContents
Delete contents- Parameters:
contentsId
- The ids of contents to delete- Returns:
- the deleted and undeleted contents
-
deleteContents
Delete contents- Parameters:
contentsId
- The ids of contents to deleteignoreRights
- true to ignore user rights- Returns:
- the deleted and undeleted contents
-
deleteContents
Delete contents- Parameters:
contentsId
- The ids of contents to deletedeleteRightId
- The deletion right's id to check. Can be null to ignore rights- Returns:
- the deleted and undeleted contents
-
_initializeResultsMap
Initialize the result map.- Returns:
- The empty result map.
-
_reallyDeleteContent
Delete the content and notify observers.- Parameters:
content
- The content to delete- Returns:
- The deletion status "deleted" or "undeleted" if an exception occurs
-
_transformContentToParams
Transform the content to aMap
with id, title and name.- Parameters:
content
- The content to transform- Returns:
- A
Map
with essentials informations of the content
-
_getContentDeletionStatus
Get the deletion status of the content : - unauthorized: The content can't be deleted because of rights - locked: The content is locked - referenced: The content has ingoing references- Parameters:
content
- The contentdeleteRightId
- The right ID- Returns:
null
if content deletion can be done or the status if there is something wrong for deletion
-
_isContentReferenced
Test if content is still referenced before removing it- Parameters:
content
- The content to remove- Returns:
- true if content is still referenced
-
_getEventParametersForDeletion
Get parameters for content deletedEvent
- Parameters:
content
- the removed content- Returns:
- the event's parameters
-
getContentsProperties
Get the contents properties- Parameters:
contentIds
- The ids of contentsworkspaceName
- The workspace name. Can be null to get contents in current workspace.- Returns:
- The contents' properties
-
getContentProperties
Get the content properties- Parameters:
contentId
- The id of contentworkspaceName
- The workspace name. Can be null to get content in current workspace.- Returns:
- The content's properties
-
getContentProperties
Get the content properties- Parameters:
content
- The content- Returns:
- The content properties
-
getContentDescription
Get the content's properties for description- Parameters:
contentId
- The id of contentworkspaceName
- The workspace name. Can be null to get content in current workspace.- Returns:
- The content's properties for description
-
getContentDescription
Get the content's properties for description- Parameters:
content
- The content- Returns:
- The content's properties for description
-
getContentViewsAndAllData
public List<Map<String,Object>> getContentViewsAndAllData(String contentId, boolean includeInternal) Get the views of a content plus a view of all the content's data- Parameters:
contentId
- the content's idincludeInternal
- Set to true to include internal views.- Returns:
- the views
-
getContentViews
Get the views of a content- Parameters:
contentId
- the content's idincludeInternal
- Set to true to include internal views.- Returns:
- the views
-
getUserRights
Get the user rights on content- Parameters:
content
- The content- Returns:
- The user's rights
-
getTags
Get the tags of contents- Parameters:
contentIds
- The content's ids- Returns:
- the tags
-
tag
public Map<String,Object> tag(List<String> contentIds, List<String> tagNames, Map<String, Object> contextualParameters) Tag a list of contents with the given tags- Parameters:
contentIds
- The ids of contents to tagtagNames
- The tagscontextualParameters
- The contextual parameters- Returns:
- the result
-
tag
public Map<String,Object> tag(List<String> contentIds, List<String> tagNames, String mode, Map<String, Object> contextualParameters) Tag a list of contents- Parameters:
contentIds
- The ids of contents to tagtagNames
- The tagsmode
- The mode for updating tags: 'REPLACE' to replace tags, 'INSERT' to add tags or 'REMOVE' to remove tags.contextualParameters
- The contextual parameters- Returns:
- the result
-
tag
public Map<String,Object> tag(List<String> contentIds, List<String> tagNames, ContentDAO.TagMode mode, Map<String, Object> contextualParameters, boolean ignoreRights) Tag a list of contents- Parameters:
contentIds
- The ids of contents to tagtagNames
- The tagsmode
- The mode for updating tags: 'REPLACE' to replace tags, 'INSERT' to add tags or 'REMOVE' to remove tags.contextualParameters
- The contextual parametersignoreRights
-true
to ignore the rights on tag- Returns:
- the result
-
_removeAllTagsInReplaceMode
protected void _removeAllTagsInReplaceMode(TaggableAmetysObject mContent, ContentDAO.TagMode tagMode, Set<String> oldTags) Remove all tags from the given content if tagMode is equals to REPLACE.- Parameters:
mContent
- The contenttagMode
- The tagoldTags
- Tags to remove
-
_isTagValid
Is the tag a content tag- Parameters:
tagName
- The tag namecontextualParameters
- The contextual parameters- Returns:
- true if the tag is a valid content tag
-
copy
public ModifiableContent copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, int initWorkflowActionId, DataContext context) throws AmetysRepositoryException Copy a content.- Parameters:
originalContent
- the original content.parent
- the object in which to create a content.name
- the content name.initWorkflowActionId
- The initial workflow action idcontext
- The context of the data to copy- Returns:
- the copied content.
- Throws:
AmetysRepositoryException
- If an error occured
-
copy
public ModifiableContent copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId, DataContext context) throws AmetysRepositoryException Copy a content.- Parameters:
originalContent
- the original content.parent
- the object in which to create a content.name
- the content name.lang
- the content language. If null, the content language will be the same of the original contentinitWorkflowActionId
- The initial workflow action idcontext
- The context of the data to copy- Returns:
- the copied content.
- Throws:
AmetysRepositoryException
- If an error occured
-
copy
public ModifiableContent copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId, boolean notifyObservers, boolean checkpoint, boolean waitAsyncObservers, boolean copyACL, DataContext context) throws AmetysRepositoryException Copy a content.- Parameters:
originalContent
- the original content.parent
- the object in which to create a content.name
- the content name.lang
- the content language. If null, the content language will be the same of the original contentinitWorkflowActionId
- The initial workflow action idnotifyObservers
- Set to false to do not fire observer eventscheckpoint
- true to check the content in if it is versionablewaitAsyncObservers
- true to wait for asynchronous observers to completecopyACL
- true to copy ACL of source contentcontext
- The context of the data to copy- Returns:
- the copied content.
- Throws:
AmetysRepositoryException
- If an error occured
-
_copyAttachments
Copy the attachments of a content- Parameters:
srcContent
- The source contenttargetContent
- The target content
-
_copyACL
Copy the ACL of a content- Parameters:
srcContent
- The source contenttargetContent
- The target content
-
notifyContentCopied
public void notifyContentCopied(Content content, boolean waitAsyncObservers) throws com.opensymphony.workflow.WorkflowException Notify observers that the content has been created- Parameters:
content
- The content addedwaitAsyncObservers
- true to wait for asynchonous observers to finish- Throws:
com.opensymphony.workflow.WorkflowException
- If an error occurred
-
getAttachmentsRootNode
Returns the content's attachments root node- Parameters:
id
- the content's id- Returns:
- The attachments' root node informations
-
canDelete
Determines if the current user has right to delete the content- Parameters:
content
- The content- Returns:
- true if current user is authorized to delete the content
-
canDelete
Determines if the current user has right to delete the content- Parameters:
content
- The contentdeleteRightId
- The right's id to check for deletion- Returns:
- true if current user is authorized to delete the content
-
react
Add or remove a reaction on a content- Parameters:
contentId
- The content idreactionName
- the reaction name (ex: LIKE)remove
- true to remove the reaction, false to add reaction- Returns:
- the result with the current actors of this reaction
-
react
public boolean react(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType) Add a reaction on aContent
.- Parameters:
content
- the contentuserIdentity
- the issuer of reactionreactionType
- the reaction type- Returns:
- true if a change was made
-
unreact
public boolean unreact(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType) Remove reaction if exists on aContent
.- Parameters:
content
- the contentuserIdentity
- the issuer of reactionreactionType
- the reaction type- Returns:
true
if a change was made
-
_addOrRemoveReaction
protected boolean _addOrRemoveReaction(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType, boolean remove) Add or remove reaction if exists on the given content.- Parameters:
content
- the contentuserIdentity
- the issuer of reactionreactionType
- the reaction typeremove
-true
if it's to remove the reaction- Returns:
true
if a change was made
-
report
Add a report on a content- Parameters:
content
- The content- Throws:
IllegalArgumentException
- if the content is not aReportableObject
AccessDeniedException
- if the current user has not read access on the given content
-
forceDeleteContentsWithLog
Delete contents and force the deletion of invert relations, then log the result.- Parameters:
contents
- The contents to deletedeleteRightId
- The deletion right's id to check. Can be null to ignore rightslogger
- The logger- Returns:
- the number of deleted contents
-