Class HierarchicalReferenceTablesHelper
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.content.referencetable.HierarchicalReferenceTablesHelper
- All Implemented Interfaces:
LogEnabled
,Disposable
,Component
,Serviceable
public class HierarchicalReferenceTablesHelper
extends AbstractLogEnabled
implements Component, Serviceable, Disposable
Helper component for computing information about hierarchy of reference table Contents.
At the startup of the Ametys application, you must call
When all relations are registered, one or several hierarchy(ies) can be inferred, following some basic rules:
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'):
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
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
- 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 Summary
Modifier and TypeFieldDescriptionprotected ContentTypeExtensionPoint
The extension point for content typesprotected ContentTypesHelper
The content types helperprotected AmetysObjectResolver
The Ametys objet resolverstatic final String
the candidate content type idstatic final String
The Avalon rolestatic final String
The name of the view to defined attributes to filter the contents -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription_getStringValuesToFilter
(ViewItemContainer viewItemContainer, String prefix, Content content) Get all string value from the view.protected boolean
_isContentReferenced
(Content content, List<String> contentsId) Test if content is referenced by other contents than its parent and childrenprotected boolean
_isMatchingContent
(Content content, String filterValue) true
if the content match to the filter valueprotected boolean
Check if the referencing content is the parent of the contentvoid
dispose()
filterReferenceTablesByRegExp
(String value, String contentId, String leafContentType) Get the path of node which match filter regexpgetAllChildren
(Content content) Returns a Set of all the descendantsgetAllParents
(Content content) Recursively returns the "parent" metadata value for the given content, i.e; will return the parent, the parent of the parent, etc.getCandidates
(String cTypeId) Return the candidates for given content typegetCandidateValues
(String contentId) Get the metadata values of a candidategetChildContentTypes
(Content refTableEntry) Gets the content types the children of the given content can have.getDirectChildren
(Content content) Returns the direct children of a contentgetHierarchicalContentTypes
(String leafContentTypeId) Get the hierarchy of content types (distinct content types)Returns the "parent" attribute value for the given content, or null if it is not defined for its content types See alsoContentType.getParentAttributeDefinition()
getParentAttribute
(String contentId) Get the parent metadatagetParentAttribute
(Content content) Get the parent metadatagetPathInHierarchy
(String refTableEntryId) Get the path of reference table entry in its hierarchygetPathInHierarchy
(List<String> refTableEntryId) Get the path of reference table entry in its hierarchygetRootChildren
(ContentType rootContentType) Return the contents at the rootgetRootChildren
(ContentType rootContentType, boolean excludeCandidates) Return the contents at the rootgetTopLevelType
(ContentType leafContentType) Gets the top level content type for the given leaf content type (which defines the hierarchy)boolean
Returns true if at least one hierarchy was registered (i.e.boolean
hasChildContentType
(ContentType contentType) Returns true if the given content type has a child content typeboolean
isCandidate
(Content content) Check if the content is a candidateboolean
isHierarchical
(ContentType contentType) Returns true if the given content type is hierarchical, i.e.boolean
isHierarchical
(Content content) Returns true if the given content has a hierarchical content type, i.e.boolean
isHierarchicalSimpleTree
(String contentTypeLeaf) Return a boolean value to determine if all the contents are simpleboolean
isLeaf
(ContentType contentType) Returns true if the given content type is a leaf content typeboolean
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.void
service
(ServiceManager manager) boolean
supportCandidates
(String contentTypeId) Determines if this content type supports candidatesboolean
supportCandidates
(ContentType contentType) Determines if this content type supports candidatesMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role -
CANDIDATE_CONTENT_TYPE
the candidate content type id- See Also:
-
SEARCH_FILTERS_VIEW_NAME
The name of the view to defined attributes to filter the contents- See Also:
-
_contentTypeEP
The extension point for content types -
_resolver
The Ametys objet resolver -
_cTypeHelper
The content types helper
-
-
Constructor Details
-
HierarchicalReferenceTablesHelper
public HierarchicalReferenceTablesHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
dispose
- Specified by:
dispose
in interfaceDisposable
-
registerRelation
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 typechild
- The child content type- Returns:
- true if the relation is valid, i.e. in accordance with what was registered before
-
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
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
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
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
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
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
Get the hierarchy of content types (distinct content types)- Parameters:
leafContentTypeId
- The id of leaf content type- Returns:
- The content types of hierarchy
-
getPathInHierarchy
Get the path of reference table entry in its hierarchy- Parameters:
refTableEntryId
- The id of entry- Returns:
- The path from root parent
-
getPathInHierarchy
Get the path of reference table entry in its hierarchy- Parameters:
refTableEntryId
- The id of entry- Returns:
- The path from root parent
-
getChildContentTypes
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
Get the metadata values of a candidate- Parameters:
contentId
- the id of candidate- Returns:
- the candidate's values
-
getParentAttribute
Get the parent metadata- Parameters:
contentId
- The content id- Returns:
- the path of parent metadata or null if not found
-
getParentAttribute
Get the parent metadata- Parameters:
content
- The content- Returns:
- the path of parent metadata or null if not found
-
getParent
Returns the "parent" attribute value for the given content, or null if it is not defined for its content types See alsoContentType.getParentAttributeDefinition()
- Parameters:
content
- The content- Returns:
- the "parent" attribute value for the given content, or null
-
getAllParents
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
Returns a Set of all the descendants- Parameters:
content
- the content to get the children from- Returns:
- the Set of children
-
isHierarchicalSimpleTree
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 rootexcludeCandidates
- 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 matchcontentId
- the content id from where we will filterleafContentType
- the leaf content type- Returns:
- the matching paths
-
_isMatchingContent
true
if the content match to the filter value- Parameters:
content
- the contentfilterValue
- the filter value- Returns:
true
if the content match to the filter value
-
_getStringValuesToFilter
protected List<String> _getStringValuesToFilter(ViewItemContainer viewItemContainer, String prefix, Content content) Get all string value from the view. This method doesn't handle repeaters.- Parameters:
viewItemContainer
- the viewprefix
- the prefixcontent
- the content to get value- Returns:
- the list of string values
-
supportCandidates
Determines if this content type supports candidates- Parameters:
contentType
- the content type- Returns:
- true if the the candidates are allowed, false otherwise
-
supportCandidates
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
Check if the content is a candidate- Parameters:
content
- the content to test- Returns:
- true if the content is a candidate, false otherwise
-
_isParent
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 notcontent
- the child content- Returns:
- true if it's the parent, false otherwise
-
_isContentReferenced
Test if content is referenced by other contents than its parent and children- Parameters:
content
- The content to testcontentsId
- The list of contents id to delete- Returns:
- true if content is referenced
-