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 callregisterRelation(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
Fields Modifier and Type Field Description private Set<ContentType>
_autoReferencingContentTypes
The content types pointing at themselvesprivate BiMap<ContentType,ContentType>
_childByContentType
The map parent -> child (excepted content types pointing on themselves)protected ContentTypeExtensionPoint
_contentTypeEP
The extension point for content typesprotected AmetysObjectResolver
_resolver
The Ametys objet resolverprivate BiMap<ContentType,ContentType>
_topLevelTypeByLeafType
The map leafContentType -> topLevelContentTypestatic String
CANDIDATE_CONTENT_TYPE
the candidate content type idstatic String
ROLE
The Avalon roleprivate static String
TAG_CANDIDATE
Tag for reference table
-
Constructor Summary
Constructors Constructor Description HierarchicalReferenceTablesHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
_checkNoCycle(ContentType parent, ContentType child)
private void
_getMatchingPathsFromContent(Content parent, String value, List<String> result)
protected boolean
_isContentReferenced(Content content, List<String> contentsId)
Test if content is referenced by other contents than its parent and childrenprivate boolean
_isContentReferenced(Content content, List<String> contentsId, Set<String> alreadyVisited)
protected boolean
_isParent(String referencingContentId, Content content)
Check if the referencing content is the parent of the contentvoid
dispose()
List<String>
filterReferenceTablesByRegExp(String value, String contentId, String leafContentType)
Get the path of node which match filter regexpSet<String>
getAllChildren(Content content)
Returns a Set of all the descendantsList<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.AmetysObjectIterable<Content>
getCandidates(String cTypeId)
Return the candidates for given content typeMap<String,Object>
getCandidateValues(String contentId)
Get the metadata values of a candidateList<ContentType>
getChildContentTypes(Content refTableEntry)
Gets the content types the children of the given content can have.AmetysObjectIterable<Content>
getDirectChildren(Content content)
Returns the direct children of a contentSet<String>
getHierarchicalContentTypes(String leafContentTypeId)
Get the hierarchy of content types (distinct content types)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 alsoContentType.getParentAttributeDefinition()
String
getParentAttribute(String contentId)
Get the parent metadataString
getParentAttribute(Content content)
Get the parent metadataString
getPathInHierarchy(String refTableEntryId)
Get the path of reference table entry in its hierarchyMap<String,String>
getPathInHierarchy(List<String> refTableEntryId)
Get the path of reference table entry in its hierarchyAmetysObjectIterable<Content>
getRootChildren(ContentType rootContentType)
Return the contents at the rootAmetysObjectIterable<Content>
getRootChildren(ContentType rootContentType, boolean excludeCandidates)
Return the contents at the rootContentType
getTopLevelType(ContentType leafContentType)
Gets the top level content type for the given leaf content type (which defines the hierarchy)boolean
hasAtLeastOneHierarchy()
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 candidates-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
CANDIDATE_CONTENT_TYPE
public static final String CANDIDATE_CONTENT_TYPE
the candidate content type id- See Also:
- Constant Field Values
-
TAG_CANDIDATE
private static final String TAG_CANDIDATE
Tag for reference table- See Also:
- Constant Field Values
-
_contentTypeEP
protected ContentTypeExtensionPoint _contentTypeEP
The extension point for content types
-
_resolver
protected AmetysObjectResolver _resolver
The Ametys objet resolver
-
_childByContentType
private BiMap<ContentType,ContentType> _childByContentType
The map parent -> child (excepted content types pointing on themselves)
-
_autoReferencingContentTypes
private Set<ContentType> _autoReferencingContentTypes
The content types pointing at themselves
-
_topLevelTypeByLeafType
private BiMap<ContentType,ContentType> _topLevelTypeByLeafType
The map leafContentType -> topLevelContentType
-
-
Constructor Detail
-
HierarchicalReferenceTablesHelper
public HierarchicalReferenceTablesHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
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 typechild
- 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
-
_checkNoCycle
private boolean _checkNoCycle(ContentType parent, ContentType child)
-
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 alsoContentType.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
public AmetysObjectIterable<Content> getDirectChildren(Content content)
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
public AmetysObjectIterable<Content> getRootChildren(ContentType rootContentType)
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
public AmetysObjectIterable<Content> getCandidates(String cTypeId)
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
-
_getMatchingPathsFromContent
private void _getMatchingPathsFromContent(Content parent, String value, List<String> result)
-
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 notcontent
- 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 testcontentsId
- The list of contents id to delete- Returns:
- true if content is referenced
-
-