Class HierarchicalReferenceTablesHelper

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.content.referencetable.HierarchicalReferenceTablesHelper
All Implemented Interfaces:
LogEnabled, Disposable, Component, Serviceable

Helper component for computing information about hierarchy of reference table Contents.

At the startup of the Ametys application, you must call registerRelation(ContentType, ContentType) in order to register a relation between a parent content type and its child content type.
When all relations are registered, one or several hierarchy(ies) can be inferred, following some basic rules:
  • A hierarchy of two or more content types cannot be cyclic
  • A content type can have itself as its parent content type
  • A content type cannot have two different parent content types
  • A content type can have only one content type as children, plus possibly itself
From each hierarchy of content types, a tree of contents can be inferred.

For instance, the following examples of hierarchy are valid (where X←Y means 'X is the parent content type of Y';
and ⤹Z means 'Z is the parent content type of Z'):
  • B←A
  • E←D←C←B←A
  • ⤹B←A (content type B defines two different child content types, but one is itself, which is allowed)
  • ⤹E←D←C←B←A
  • ⤹A
; and the following examples of hierarchy are invalid:
  • C←B and C←A (a content type cannot have multiple content types as children, which are not itself)
  • C←A and B←A (a content type cannot have two different parent content types)
  • ⤹A and B←A (a content type cannot have two different parent content types, even if one is itself)
  • A←B and B←A (cyclic hierarchy)
  • A←C←B←A (cyclic hierarchy)
  • Field Details

  • Constructor Details

  • Method Details

    • service

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

      public void dispose()
      Specified by:
      dispose in interface Disposable
    • registerRelation

      public boolean registerRelation(ContentType parent, ContentType child)
      Register a relation between a parent and its child, and update the internal model if it is a valid one.
      Parameters:
      parent - The parent content type
      child - The child content type
      Returns:
      true if the relation is valid, i.e. in accordance with what was registered before
    • hasAtLeastOneHierarchy

      public boolean hasAtLeastOneHierarchy()
      Returns true if at least one hierarchy was registered (i.e. at least one content type defines a valid "parent" metadata)
      Returns:
      true if at least one hierarchy was registered
    • getTopLevelType

      public ContentType getTopLevelType(ContentType leafContentType)
      Gets the top level content type for the given leaf content type (which defines the hierarchy)
      Parameters:
      leafContentType - the leaf cotnent type
      Returns:
      the top level content type for the given leaf content type
    • hasChildContentType

      public boolean hasChildContentType(ContentType contentType)
      Returns true if the given content type has a child content type
      Parameters:
      contentType - The content type
      Returns:
      true if the given content type has a child content type
    • isHierarchical

      public boolean isHierarchical(Content content)
      Returns true if the given content has a hierarchical content type, i.e. is part of a hierarchy
      Parameters:
      content - The content
      Returns:
      true if the given content is part of a hierarchical reference table
    • isHierarchical

      public boolean isHierarchical(ContentType contentType)
      Returns true if the given content type is hierarchical, i.e. is part of a hierarchy
      Parameters:
      contentType - The content type
      Returns:
      true if the given content type is hierarchical, i.e. is part of a hierarchy
    • isLeaf

      public boolean isLeaf(ContentType contentType)
      Returns true if the given content type is a leaf content type
      Parameters:
      contentType - The content type
      Returns:
      true if the given content type is a leaf content type
    • getHierarchicalContentTypes

      public Set<String> getHierarchicalContentTypes(String leafContentTypeId)
      Get the hierarchy of content types (distinct content types)
      Parameters:
      leafContentTypeId - The id of leaf content type
      Returns:
      The content types of hierarchy
    • getPathInHierarchy

      public Map<String,String> getPathInHierarchy(List<String> refTableEntryId)
      Get the path of reference table entry in its hierarchy
      Parameters:
      refTableEntryId - The id of entry
      Returns:
      The path from root parent
    • getPathInHierarchy

      public String getPathInHierarchy(String refTableEntryId)
      Get the path of reference table entry in its hierarchy
      Parameters:
      refTableEntryId - The id of entry
      Returns:
      The path from root parent
    • getChildContentTypes

      public List<ContentType> getChildContentTypes(Content refTableEntry)
      Gets the content types the children of the given content can have. The result can contain 0, 1 or 2 content types
      Parameters:
      refTableEntry - The content
      Returns:
      the content types the children of the given content can have.
    • getCandidateValues

      public Map<String,Object> getCandidateValues(String contentId)
      Get the metadata values of a candidate
      Parameters:
      contentId - the id of candidate
      Returns:
      the candidate's values
    • getParentAttribute

      public String getParentAttribute(String contentId)
      Get the parent metadata
      Parameters:
      contentId - The content id
      Returns:
      the path of parent metadata or null if not found
    • getParentAttribute

      public String getParentAttribute(Content content)
      Get the parent metadata
      Parameters:
      content - The content
      Returns:
      the path of parent metadata or null if not found
    • getParent

      public String getParent(Content content)
      Returns the "parent" attribute value for the given content, or null if it is not defined for its content types See also ContentType.getParentAttributeDefinition()
      Parameters:
      content - The content
      Returns:
      the "parent" attribute value for the given content, or null
    • getAllParents

      public List<String> getAllParents(Content content)
      Recursively returns the "parent" metadata value for the given content, i.e; will return the parent, the parent of the parent, etc.
      Parameters:
      content - The content
      Returns:
      all the parents of the given content
    • getDirectChildren

      Returns the direct children of a content
      Parameters:
      content - the content to get the direct children from
      Returns:
      the AmetysObjectIterable of the direct children of the content
    • getAllChildren

      public Set<String> getAllChildren(Content content)
      Returns a Set of all the descendants
      Parameters:
      content - the content to get the children from
      Returns:
      the Set of children
    • isHierarchicalSimpleTree

      public boolean isHierarchicalSimpleTree(String contentTypeLeaf)
      Return a boolean value to determine if all the contents are simple
      Parameters:
      contentTypeLeaf - the contentType id of the leaf content
      Returns:
      true if all the contents in the tree are simple, false otherwise
    • getRootChildren

      Return the contents at the root
      Parameters:
      rootContentType - the content type of the contents at the root
      Returns:
      the contents at the root
    • getRootChildren

      public AmetysObjectIterable<Content> getRootChildren(ContentType rootContentType, boolean excludeCandidates)
      Return the contents at the root
      Parameters:
      rootContentType - the content type of the contents at the root
      excludeCandidates - true to exclude candidates
      Returns:
      the contents at the root
    • getCandidates

      Return the candidates for given content type
      Parameters:
      cTypeId - the id of content type
      Returns:
      the candidates
    • filterReferenceTablesByRegExp

      public List<String> filterReferenceTablesByRegExp(String value, String contentId, String leafContentType)
      Get the path of node which match filter regexp
      Parameters:
      value - the value to match
      contentId - the content id from where we will filter
      leafContentType - the leaf content type
      Returns:
      the matching paths
    • _isMatchingContent

      protected boolean _isMatchingContent(Content content, String filterValue)
      true if the content match to the filter value
      Parameters:
      content - the content
      filterValue - the filter value
      Returns:
      true if the content match to the filter value
    • _getStringValuesToFilter

      protected List<String> _getStringValuesToFilter(ModelAwareDataHolder dataHolder, ViewItemAccessor viewItemAccessor)
      Get all string value from the view. This method doesn't handle repeaters.
      Parameters:
      dataHolder - the data holder to get value
      viewItemAccessor - the view item accessor where to search string values
      Returns:
      the list of string values
    • supportCandidates

      public boolean supportCandidates(ContentType contentType)
      Determines if this content type supports candidates
      Parameters:
      contentType - the content type
      Returns:
      true if the the candidates are allowed, false otherwise
    • supportCandidates

      public boolean supportCandidates(String contentTypeId)
      Determines if this content type supports candidates
      Parameters:
      contentTypeId - the id of content type
      Returns:
      true if the the candidates are allowed, false otherwise
    • isCandidate

      public boolean isCandidate(Content content)
      Check if the content is a candidate
      Parameters:
      content - the content to test
      Returns:
      true if the content is a candidate, false otherwise
    • _isParent

      protected boolean _isParent(String referencingContentId, Content content)
      Check if the referencing content is the parent of the content
      Parameters:
      referencingContentId - The referencing content if to check if it's the parent or not
      content - the child content
      Returns:
      true if it's the parent, false otherwise
    • _isContentReferenced

      protected boolean _isContentReferenced(Content content, List<String> contentsId)
      Test if content is referenced by other contents than its parent and children
      Parameters:
      content - The content to test
      contentsId - The list of contents id to delete
      Returns:
      true if content is referenced