Class ContentDataHelper

java.lang.Object
org.ametys.cms.data.ContentDataHelper
All Implemented Interfaces:
Component, Serviceable

public class ContentDataHelper extends Object implements Serviceable, Component
Helper for data of type 'content'
  • Field Details

    • ROLE

      public static final String ROLE
      Avalon role
  • Constructor Details

  • Method Details

    • service

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

      public static String getContentIdFromContentData(ModelAwareDataHolder dataHolder, String dataPath, String defaultValue) throws BadItemTypeException
      Retrieves the content identifier of a content data
      Parameters:
      dataHolder - data holder that contains the content data
      dataPath - path to the content data
      defaultValue - The default value to return
      Returns:
      the content identifier
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdFromContentData

      Retrieves the content identifier of a content data
      Parameters:
      dataHolder - data holder that contains the content data
      dataPath - path to the content data
      Returns:
      the content identifier, empty string if it is invalid
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • isMultipleContentDataEmpty

      public static boolean isMultipleContentDataEmpty(ModelAwareDataHolder dataHolder, String dataPath) throws BadItemTypeException
      Retrieves the content identifiers in an array from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      Returns:
      an array containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • isMultipleContentDataEmpty

      public static boolean isMultipleContentDataEmpty(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws BadItemTypeException
      Retrieves the content identifiers in an array from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      context - the context of the value to retrieve
      Returns:
      an array containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsListFromMultipleContentData

      Retrieves the content identifiers in a List from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      Returns:
      a List containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsListFromMultipleContentData

      Retrieves the content identifiers in a List from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      context - the context of the value to retrieve
      Returns:
      a List containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsArrayFromMultipleContentData

      Retrieves the content identifiers in an array from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      Returns:
      an array containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsArrayFromMultipleContentData

      Retrieves the content identifiers in an array from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      context - the context of the value to retrieve
      Returns:
      an array containing the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsStreamFromMultipleContentData

      Retrieves a Stream of the content identifiers from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      Returns:
      a Stream of the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • getContentIdsStreamFromMultipleContentData

      Retrieves a Stream of the content identifiers from a multiple content data
      Parameters:
      dataHolder - data holder that contains the multiple content data
      dataPath - path to the multiple content data
      context - the context of the value to retrieve
      Returns:
      a Stream of the content identifiers
      Throws:
      BadItemTypeException - if the data at the given path is not a content data
    • collectReferencedContents

      Prepares a write operation in the given ModelAwareDataHolder by traversing a View with the values to be written.
      The goal is to find content attributes and to extract added and removed values.
      Parameters:
      viewItemContainer - the view to walk through
      content - the source ModifiableContent
      values - the new values
      context - the synchronization context
      Returns:
      the contents to-be-added and to-be-removed
    • checkBrokenReferences

      public static Map<String,List<String>> checkBrokenReferences(ModelAwareDataHolder dataHolder, boolean fix)
      Find any broken reference in data holder's content attributes. A reference is considered as broken if the referenced content does not exist
      Parameters:
      dataHolder - the ModelAwareDataHolder to inspect.
      fix - if true, and the dataHolder is modifiable, broken references will be removed Warning: if modifications are made on the given data holder, the modifications won't be saved and the workflow won't change
      Returns:
      all broken references, by attribute path
    • checkBrokenInvertRelations

      public static Collection<ReferencedContents> checkBrokenInvertRelations(Content content, boolean fix)
      Find any broken invert relation in a content attributes. The invert relation is considered as broken if the referenced content does not reference the first one by the attribute with the invert relation path This check does not take nonexistent referenced contents into account. First call the checkBrokenReferences(ModelAwareDataHolder, boolean) method
      Parameters:
      content - the content to inspect.
      fix - if true, and the referenced contents are modifiable, broken invert relations will be fixed by adding the relation on the referenced content if the referenced content is referencing another content and the attribute is single (and not in a repeater), the third content will be modified too, to remove the relation to the second content. Warning: if modifications are made on some contents, the modifications won't be saved and the workflows won't change
      Returns:
      All broken invert relations in a collection of ReferencedContents. Call ReferencedContents.getAddedContents() to get all contents referenced by the given content that does not reference it in return Call ReferencedContents.getThirdPartyContents() to get contents referenced by content in added contents that reference it in return
    • manageInvertRelations

      public static Map<String,ModifiableContent> manageInvertRelations(String invertRelationPath, Set<ContentValue> referencedContents, String referencingContentId, ContentDataHelper.InvertRelationManager invertRelationManager, Map<String,ModifiableContent> alreadyModifiedContents, Map<String,Object> externalizableDataContext)
      Manages the invert relations concerned by the given path, through the given ContentDataHelper.InvertRelationManager
      Parameters:
      invertRelationPath - the concerned invert relation path
      referencedContents - a Set containing the referenced contents to manage (add or remove the relation)
      referencingContentId - the id of the content referencing the given contents
      invertRelationManager - the ContentDataHelper.InvertRelationManager to use (to add or remove the invert relations)
      alreadyModifiedContents - a Map of contents (indexed by their identifiers) that have already been modified. This map will be used to initialize the returned map and to search for contents that have already been resolved (to resolve each content only once, even if there are several modifications on a same content)
      externalizableDataContext - the context Map that is used to determine if a data is externalizable
      Returns:
      a Map containing the contents (indexed by their identifiers) that have been modified by this call and the ones that have already been modified
    • manageInvertRelations

      public static Map<String,ModifiableContent> manageInvertRelations(String invertRelationPath, Map<ContentValue,Collection<String>> referencedContents, ContentDataHelper.InvertRelationManager invertRelationManager, Map<String,ModifiableContent> alreadyModifiedContents, Map<String,Object> externalizableDataContext)
      Manages the invert relations concerned by the given path, through the given ContentDataHelper.InvertRelationManager
      Parameters:
      invertRelationPath - the concerned invert relation path
      referencedContents - a Map containing the referenced contents to manage (add or remove the relation) and the id of the content referencing this content
      invertRelationManager - the ContentDataHelper.InvertRelationManager to use (to add or remove the invert relations)
      alreadyModifiedContents - a Map of contents (indexed by their identifiers) that have already been modified. This map will be used to initialize the returned map and to search for contents that have already been resolved (to resolve each content only once, even if there are several modifications on a same content)
      externalizableDataContext - the context Map that is used to determine if a data is externalizable
      Returns:
      a Map containing the contents (indexed by their identifiers) that have been modified by this call and the ones that have already been modified
    • addInvertRelation

      public static boolean addInvertRelation(ModifiableModelAwareDataHolder dataHolder, String invertRelationPath, Collection<String> referencingContentIds, ValueContext context)
      Adds the invert relation to the given DataHolder
      Parameters:
      dataHolder - the data holder where to add the invert relation
      invertRelationPath - the path of the invert relation
      referencingContentIds - the id of the contents that reference the data holder
      context - the value's context
      Returns:
      true if the given data holder has been modified, false otherwise
    • removeInvertRelation

      public static boolean removeInvertRelation(ModifiableContent referencedContent, String invertRelationPath, Collection<String> referencingContentIds, ValueContext context)
      Removes the invert relation to the given DataHolder
      Parameters:
      referencedContent - the content where to remove the invert relation
      invertRelationPath - the path of the invert relation
      referencingContentIds - the id of the contents that do not reference the given content anymore
      context - the value's context
      Returns:
      true if the referenced content has been modified, false otherwise