Class ContentDAO

All Implemented Interfaces:
Component, Contextualizable, LogEnabled, Serviceable
Direct Known Subclasses:
HierarchicalReferenceTablesDeleteContentDAO, WebContentDAO

DAO for manipulating contents
  • Field Details

  • Constructor Details

  • Method Details

    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • service

      public void service(ServiceManager smanager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • forceTrashContents

      public Map<String,Object> forceTrashContents(List<String> contentsId)
      Trash contents if possible or delete it and force the deletion of invert relations.
      Parameters:
      contentsId - The ids of contents to delete
      Returns:
      the deleted and undeleted contents
    • forceDeleteContents

      Delete contents and force the deletion of invert relations.
      Parameters:
      contentsId - The ids of contents to delete
      Returns:
      the deleted and undeleted contents
    • forceTrashContentsObj

      public Map<String,Object> forceTrashContentsObj(List<Content> contents, String deleteRightId)
      Trash contents if possible or delete it and force the deletion of invert relations.
      Parameters:
      contents - The contents to delete
      deleteRightId - The deletion right's id to check. Can be null to ignore rights
      Returns:
      the deleted and undeleted contents
    • forceDeleteContentsObj

      public Map<String,Object> forceDeleteContentsObj(Iterable<Content> contents, String deleteRightId)
      Delete contents and force the deletion of invert relations.
      Parameters:
      contents - The contents to delete
      deleteRightId - 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
    • trashContents

      public Map<String,Object> trashContents(List<String> contentsId)
      Trash contents if possible or delete it
      Parameters:
      contentsId - The ids of contents to delete
      Returns:
      the deleted and undeleted contents
    • trashContents

      public Map<String,Object> trashContents(List<String> contentsId, boolean ignoreRights)
      Trash contents if possible or delete it
      Parameters:
      contentsId - The ids of contents to delete
      ignoreRights - true to ignore user rights
      Returns:
      the deleted and undeleted contents
    • trashContents

      public Map<String,Object> trashContents(List<String> contentsId, String deleteRightId)
      Trash contents if possible or delete it
      Parameters:
      contentsId - The ids of contents to delete
      deleteRightId - The deletion right's id to check. Can be null to ignore rights
      Returns:
      the deleted and undeleted contents
    • 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 delete
      ignoreRights - 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 delete
      deleteRightId - 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

      protected String _reallyDeleteContent(Content content, boolean onlyDeletion)
      Delete the content and notify observers.
      Parameters:
      content - The content to delete
      onlyDeletion - true to really delete the content, otherwise the content will be trashed if trashable
      Returns:
      The deletion status "deleted" or "undeleted" if an exception occurs
    • _transformContentToParams

      Transform the content to a Map 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 content
      deleteRightId - 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

      Get parameters for content deleted Event
      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 contents
      workspaceName - 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 content
      workspaceName - 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

      public Map<String,Object> getContentDescription(String contentId, String workspaceName)
      Get the content's properties for description
      Parameters:
      contentId - The id of content
      workspaceName - 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 id
      includeInternal - Set to true to include internal views.
      Returns:
      the views
    • getContentViews

      public List<Map<String,Object>> getContentViews(String contentId, boolean includeInternal)
      Get the views of a content
      Parameters:
      contentId - the content's id
      includeInternal - 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 tag
      tagNames - The tags
      contextualParameters - 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 tag
      tagNames - The tags
      mode - 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 tag
      tagNames - The tags
      mode - The mode for updating tags: 'REPLACE' to replace tags, 'INSERT' to add tags or 'REMOVE' to remove tags.
      contextualParameters - The contextual parameters
      ignoreRights - 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 content
      tagMode - The tag
      oldTags - Tags to remove
    • _isTagValid

      protected boolean _isTagValid(String tagName, Map<String,Object> contextualParameters)
      Is the tag a content tag
      Parameters:
      tagName - The tag name
      contextualParameters - 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 id
      context - 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 content
      initWorkflowActionId - The initial workflow action id
      context - 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 content
      initWorkflowActionId - The initial workflow action id
      notifyObservers - Set to false to do not fire observer events
      checkpoint - true to check the content in if it is versionable
      waitAsyncObservers - true to wait for asynchronous observers to complete
      copyACL - true to copy ACL of source content
      context - The context of the data to copy
      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 content
      targetContent - The target content
    • _copyACL

      protected void _copyACL(Content srcContent, Content targetContent)
      Copy the ACL of a content
      Parameters:
      srcContent - The source content
      targetContent - 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 added
      waitAsyncObservers - 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

      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 content
      deleteRightId - 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 id
      reactionName - 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
    • getReactionUsers

      public List<Map<String,Object>> getReactionUsers(String contentId, String reactionName)
      Get the list of users who react to content
      Parameters:
      contentId - The content id
      reactionName - the reaction name (ex: LIKE)
      Returns:
      the list of users
    • react

      public boolean react(Content content, UserIdentity userIdentity, ReactionableObject.ReactionType reactionType)
      Add a reaction on a Content.
      Parameters:
      content - the content
      userIdentity - the issuer of reaction
      reactionType - 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 a Content.
      Parameters:
      content - the content
      userIdentity - the issuer of reaction
      reactionType - 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 content
      userIdentity - the issuer of reaction
      reactionType - the reaction type
      remove - 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 a ReportableObject
      AccessDeniedException - if the current user has not read access on the given content
    • forceTrashContentsWithLog

      public int forceTrashContentsWithLog(List<Content> contents, String deleteRightId, org.slf4j.Logger logger)
      Trash contents if possible or delete it and force the deletion of invert relations, then log the result.
      Parameters:
      contents - The contents to delete
      deleteRightId - The deletion right's id to check. Can be null to ignore rights
      logger - The logger
      Returns:
      the number of deleted contents
    • 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 delete
      deleteRightId - The deletion right's id to check. Can be null to ignore rights
      logger - The logger
      Returns:
      the number of deleted contents