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
Nested Classes Modifier and Type Class Description static class
ContentDAO.TagMode
The mode for tag edition
-
Field Summary
Fields Modifier and Type Field Description protected static String
_CONTENT_DELETION_STATUS_DELETED
Deletion status : deletedprotected static String
_CONTENT_DELETION_STATUS_LOCKED
Deletion status : lockedprotected static String
_CONTENT_DELETION_STATUS_REFERENCED
Deletion status : referencedprotected static String
_CONTENT_DELETION_STATUS_UNAUTHORIZED
Deletion status : unauthorizedprotected static String
_CONTENT_DELETION_STATUS_UNDELETED
Deletion status : undeletedprotected ContentHelper
_contentHelper
Content helperprotected ContentTypeExtensionPoint
_contentTypeEP
Content-type extension pointprotected ContentWorkflowHelper
_contentWorkflowHelper
Workflow helper componentprotected Context
_context
Cocoon contextprotected ContentTypesHelper
_cTypesHelper
Content types helperprotected CurrentUserProvider
_currentUserProvider
Component to get current userprotected HierarchicalReferenceTablesHelper
_hierarchicalSimpleContentsHelper
The helper component for hierarchical simple contentsprotected LockContentManager
_lockManager
Component to manager lockprotected ModifiableContentHelper
_modifiableContentHelper
The modifiable content helperprotected ObservationManager
_observationManager
Ametys observation mangerprotected AmetysObjectResolver
_resolver
Ametys resolverprotected RightManager
_rightManager
Rights managerprotected TagProviderExtensionPoint
_tagProvider
Component to get tagsprotected UserHelper
_userHelper
Helper for usersprotected UserManager
_usersManager
The user managerprotected WorkflowProvider
_workflowProvider
Workflow componentstatic String
ROLE
Avalon Role
-
Constructor Summary
Constructors Constructor Description ContentDAO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_addOrRemoveReaction(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType, boolean remove)
Add or remove reaction if exists on the given content.protected void
_copyACL(Content srcContent, Content targetContent)
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 referencesprotected Map<String,Object>
_getEventParametersForDeletion(Content content)
Get parameters for content deletedEvent
protected int
_getInvertActionId()
Get the invert action id (used for forced deletion).protected Map<String,Object>
_initializeResultsMap()
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 void
_notifyContentCopied(Content content, boolean waitAsyncObservers)
Notify observers that the content has been createdprotected 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.protected Map<String,Object>
_transformContentToParams(Content content)
Transform the content to aMap
with id, title and name.boolean
canDelete(Content content)
Determines if the current user has right to delete the contentboolean
canDelete(Content content, String deleteRightId)
Determines if the current user has right to delete the contentvoid
contextualize(Context context)
ModifiableContent
copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, int initWorkflowActionId)
Copy a content.ModifiableContent
copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId)
Copy a content.ModifiableContent
copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId, boolean notifyObservers, boolean waitAsyncObservers, boolean copyACL)
Copy a content.Map<String,Object>
deleteContents(List<String> contentsId)
Delete contentsMap<String,Object>
deleteContents(List<String> contentsId, boolean ignoreRights)
Delete contentsMap<String,Object>
deleteContents(List<String> contentsId, String deleteRightId)
Delete contentsMap<String,Object>
forceDeleteContents(List<String> contentsId)
Delete contents and force the deletion of invert relations.Map<String,Object>
forceDeleteContentsObj(List<Content> contents, String deleteRightId)
Delete contents and force the deletion of invert relations.int
forceDeleteContentsWithLog(List<Content> contents, String deleteRightId, org.slf4j.Logger logger)
Delete contents and force the deletion of invert relations, then log the result.Map<String,Object>
getAttachmentsRootNode(String id)
Returns the content's attachments root nodeMap<String,Object>
getContentDescription(String contentId, String workspaceName)
Get the content's properties for descriptionMap<String,Object>
getContentDescription(Content content)
Get the content's properties for descriptionMap<String,Object>
getContentProperties(String contentId, String workspaceName)
Get the content propertiesMap<String,Object>
getContentProperties(Content content)
Get the content propertiesMap<String,Object>
getContentsProperties(List<String> contentIds, String workspaceName)
Get the contents propertiesList<Map<String,Object>>
getContentViews(String contentId, boolean includeInternal)
Get the views of a contentprotected String
getRightToDelete()
Get the right to delete a content.Set<String>
getTags(List<String> contentIds)
Get the tags of contentsprotected Set<String>
getUserRights(Content content)
Get the user rights on contentMap<String,Object>
react(String contentId, String reactionName, boolean remove)
Add or remove a reaction on a contentboolean
react(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType)
Add a reaction on aContent
.void
report(Content content)
Add a report on a contentvoid
service(ServiceManager smanager)
Map<String,Object>
tag(List<String> contentIds, List<String> tagNames, String mode, Map<String,Object> contextualParameters)
Tag a list of contentsMap<String,Object>
tag(List<String> contentIds, List<String> tagNames, Map<String,Object> contextualParameters)
Tag a list of contents with the given tagsboolean
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 Detail
-
_CONTENT_DELETION_STATUS_DELETED
protected static final String _CONTENT_DELETION_STATUS_DELETED
Deletion status : deleted- See Also:
- Constant Field Values
-
_CONTENT_DELETION_STATUS_UNDELETED
protected static final String _CONTENT_DELETION_STATUS_UNDELETED
Deletion status : undeleted- See Also:
- Constant Field Values
-
_CONTENT_DELETION_STATUS_REFERENCED
protected static final String _CONTENT_DELETION_STATUS_REFERENCED
Deletion status : referenced- See Also:
- Constant Field Values
-
_CONTENT_DELETION_STATUS_UNAUTHORIZED
protected static final String _CONTENT_DELETION_STATUS_UNAUTHORIZED
Deletion status : unauthorized- See Also:
- Constant Field Values
-
_CONTENT_DELETION_STATUS_LOCKED
protected static final String _CONTENT_DELETION_STATUS_LOCKED
Deletion status : locked- See Also:
- Constant Field Values
-
_resolver
protected AmetysObjectResolver _resolver
Ametys resolver
-
_observationManager
protected ObservationManager _observationManager
Ametys observation manger
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
Component to get current user
-
_tagProvider
protected TagProviderExtensionPoint _tagProvider
Component to get tags
-
_workflowProvider
protected WorkflowProvider _workflowProvider
Workflow component
-
_contentWorkflowHelper
protected ContentWorkflowHelper _contentWorkflowHelper
Workflow helper component
-
_lockManager
protected LockContentManager _lockManager
Component to manager lock
-
_contentTypeEP
protected ContentTypeExtensionPoint _contentTypeEP
Content-type extension point
-
_contentHelper
protected ContentHelper _contentHelper
Content helper
-
_cTypesHelper
protected ContentTypesHelper _cTypesHelper
Content types helper
-
_rightManager
protected RightManager _rightManager
Rights manager
-
_usersManager
protected UserManager _usersManager
The user manager
-
_userHelper
protected UserHelper _userHelper
Helper for users
-
_hierarchicalSimpleContentsHelper
protected HierarchicalReferenceTablesHelper _hierarchicalSimpleContentsHelper
The helper component for hierarchical simple contents
-
_modifiableContentHelper
protected ModifiableContentHelper _modifiableContentHelper
The modifiable content helper
-
-
Constructor Detail
-
ContentDAO
public ContentDAO()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
forceDeleteContents
public Map<String,Object> forceDeleteContents(List<String> contentsId)
Delete contents and force the deletion of invert relations.- Parameters:
contentsId
- The ids of contents to delete- Returns:
- the deleted and undeleted contents
-
forceDeleteContentsObj
public Map<String,Object> forceDeleteContentsObj(List<Content> contents, String deleteRightId)
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
protected int _getInvertActionId()
Get the invert action id (used for forced deletion).- Returns:
- The invert action id
-
getRightToDelete
protected String getRightToDelete()
Get the right to delete a content.- Returns:
- The right ID to delete a content
-
_removeReferences
protected boolean _removeReferences(Content content)
Remove all the references to the given content.- Parameters:
content
- The content- Returns:
true
if references have been all removed successfully
-
deleteContents
public Map<String,Object> deleteContents(List<String> contentsId)
Delete contents- Parameters:
contentsId
- The ids of contents to delete- Returns:
- the deleted and undeleted contents
-
deleteContents
public Map<String,Object> deleteContents(List<String> contentsId, boolean ignoreRights)
Delete contents- Parameters:
contentsId
- The ids of contents to deleteignoreRights
- true to ignore user rights- Returns:
- the deleted and undeleted contents
-
deleteContents
public Map<String,Object> deleteContents(List<String> contentsId, String deleteRightId)
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
protected Map<String,Object> _initializeResultsMap()
Initialize the result map.- Returns:
- The empty result map.
-
_reallyDeleteContent
protected String _reallyDeleteContent(Content content)
Delete the content and notify observers.- Parameters:
content
- The content to delete- Returns:
- The deletion status "deleted" or "undeleted" if an exception occurs
-
_transformContentToParams
protected Map<String,Object> _transformContentToParams(Content content)
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
protected 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- 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
protected boolean _isContentReferenced(Content content)
Test if content is still referenced before removing it- Parameters:
content
- The content to remove- Returns:
- true if content is still referenced
-
_getEventParametersForDeletion
protected Map<String,Object> _getEventParametersForDeletion(Content content)
Get parameters for content deletedEvent
- Parameters:
content
- the removed content- Returns:
- the event's parameters
-
getContentsProperties
public Map<String,Object> getContentsProperties(List<String> contentIds, String workspaceName)
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
public Map<String,Object> getContentProperties(String contentId, String workspaceName)
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
public Map<String,Object> getContentProperties(Content content)
Get the content properties- Parameters:
content
- The content- Returns:
- The content properties
-
getContentDescription
public Map<String,Object> getContentDescription(String contentId, String workspaceName)
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
public Map<String,Object> getContentDescription(Content content)
Get the content's properties for description- Parameters:
content
- The content- Returns:
- The content's properties for description
-
getContentViews
public List<Map<String,Object>> getContentViews(String contentId, boolean includeInternal)
Get the views of a content- Parameters:
contentId
- the content's idincludeInternal
- Set to true to include internal views.- Returns:
- the views
-
getUserRights
protected Set<String> getUserRights(Content content)
Get the user rights on content- Parameters:
content
- The content- Returns:
- The user's rights
-
getTags
public Set<String> getTags(List<String> contentIds)
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
-
_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
protected boolean _isTagValid(String tagName, Map<String,Object> contextualParameters)
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) 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 id- Returns:
- the copied content.
- Throws:
AmetysRepositoryException
- If an error occured
-
copy
public ModifiableContent copy(DefaultContent originalContent, ModifiableTraversableAmetysObject parent, String name, String lang, int initWorkflowActionId) 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 id- 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 waitAsyncObservers, boolean copyACL) 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 eventswaitAsyncObservers
- true to wait for asynchronous observers to completecopyACL
- true to copy ACL of source content- Returns:
- the copied content.
- Throws:
AmetysRepositoryException
- If an error occured
-
_copyAttachments
protected void _copyAttachments(Content srcContent, Content targetContent)
Copy the attachments of a content- Parameters:
srcContent
- The source contenttargetContent
- The target content
-
_copyACL
protected void _copyACL(Content srcContent, Content targetContent)
Copy the ACL of a content- Parameters:
srcContent
- The source contenttargetContent
- The target content
-
_notifyContentCopied
protected 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
public Map<String,Object> getAttachmentsRootNode(String id)
Returns the content's attachments root node- Parameters:
id
- the content's id- Returns:
- The attachments' root node informations
-
canDelete
public boolean canDelete(Content content)
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
public boolean canDelete(Content content, String deleteRightId)
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
public Map<String,Object> react(String contentId, String reactionName, boolean remove)
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
public void report(Content content) throws IllegalArgumentException, AccessDeniedException
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
public int forceDeleteContentsWithLog(List<Content> contents, String deleteRightId, org.slf4j.Logger logger)
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
-
-