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
-
Constructor Summary
Constructors Constructor Description ContentDAO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
_addOrRemoveReaction(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType, boolean remove)
protected void
_copyACL(Content srcContent, Content targetContent)
Copy the ACL of a contentprotected void
_copyAttachments(Content srcContent, Content targetContent)
Copy the attachments of a contentprivate String
_getContentDeletionStatus(Content content, String deleteRightId)
protected Map<String,Object>
_getEventParametersForDeletion(Content content)
Get parameters for content deletedEvent
private Map<String,Object>
_initializeResultsMap()
protected boolean
_isContentReferenced(Content content)
Test if content is still referenced before removing itboolean
_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 createdprivate String
_reallyDeleteContent(Content content)
private void
_removeAllTagsInReplaceMode(TaggableAmetysObject mContent, ContentDAO.TagMode tagMode, Set<String> oldTags)
private boolean
_removeReferences(Content content)
private Map<String,Object>
_transformContentToParams(Content content)
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>
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 descriptionList<Map<String,Object>>
getContentMetadataSets(String contentId, boolean edition, boolean includeInternal)
Get the metadata sets of a contentMap<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 propertiesSet<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
private static final String __CONTENT_DELETION_STATUS_DELETED
Deletion status- See Also:
- Constant Field Values
-
__CONTENT_DELETION_STATUS_UNDELETED
private static final String __CONTENT_DELETION_STATUS_UNDELETED
- See Also:
- Constant Field Values
-
__CONTENT_DELETION_STATUS_REFERENCED
private static final String __CONTENT_DELETION_STATUS_REFERENCED
- See Also:
- Constant Field Values
-
__CONTENT_DELETION_STATUS_UNAUTHORIZED
private static final String __CONTENT_DELETION_STATUS_UNAUTHORIZED
- See Also:
- Constant Field Values
-
__CONTENT_DELETION_STATUS_LOCKED
private static final String __CONTENT_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
-
_removeReferences
private boolean _removeReferences(Content content)
-
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
private Map<String,Object> _initializeResultsMap()
-
_reallyDeleteContent
private String _reallyDeleteContent(Content content)
-
_transformContentToParams
private Map<String,Object> _transformContentToParams(Content content)
-
_getContentDeletionStatus
private String _getContentDeletionStatus(Content content, String deleteRightId)
-
_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
-
getContentMetadataSets
public List<Map<String,Object>> getContentMetadataSets(String contentId, boolean edition, boolean includeInternal)
Get the metadata sets of a content- Parameters:
contentId
- the content's idedition
- Set to true to get edition metadata set. False otherwise.includeInternal
- Set to true to include internal metadata sets.- Returns:
- the metadata sets
-
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
private void _removeAllTagsInReplaceMode(TaggableAmetysObject mContent, ContentDAO.TagMode tagMode, Set<String> oldTags)
-
_isTagValid
public 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
private boolean _addOrRemoveReaction(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType, boolean remove)
-
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
-
-