Package org.ametys.cms.data
Class ContentDataHelper
java.lang.Object
org.ametys.cms.data.ContentDataHelper
- All Implemented Interfaces:
Component
,Serviceable
Helper for data of type 'content'
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Invert relation manager (to add or remove a relation on a content -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addInvertRelation
(ModifiableModelAwareDataHolder dataHolder, String invertRelationPath, Collection<String> referencingContentIds, ValueContext context) Adds the invert relation to the givenDataHolder
static Collection<ReferencedContents>
checkBrokenInvertRelations
(Content content, boolean fix) Find any broken invert relation in a content attributes.checkBrokenReferences
(ModelAwareDataHolder dataHolder, boolean fix) Find any broken reference in data holder's content attributes.collectReferencedContents
(ViewItemContainer viewItemContainer, ModifiableContent content, Map<String, Object> values, SynchronizationContext context) Prepares a write operation in the givenModelAwareDataHolder
by traversing aView
with the values to be written.
The goal is to find content attributes and to extract added and removed values.static String
getContentIdFromContentData
(ModelAwareDataHolder dataHolder, String dataPath) Retrieves the content identifier of a content datastatic String
getContentIdFromContentData
(ModelAwareDataHolder dataHolder, String dataPath, String defaultValue) Retrieves the content identifier of a content datastatic String[]
getContentIdsArrayFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath) Retrieves the content identifiers in an array from a multiple content datastatic String[]
getContentIdsArrayFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Retrieves the content identifiers in an array from a multiple content datagetContentIdsListFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath) Retrieves the content identifiers in aList
from a multiple content datagetContentIdsListFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Retrieves the content identifiers in aList
from a multiple content datagetContentIdsStreamFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath) Retrieves aStream
of the content identifiers from a multiple content datagetContentIdsStreamFromMultipleContentData
(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Retrieves aStream
of the content identifiers from a multiple content datastatic boolean
isMultipleContentDataEmpty
(ModelAwareDataHolder dataHolder, String dataPath) Retrieves the content identifiers in an array from a multiple content datastatic boolean
isMultipleContentDataEmpty
(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Retrieves the content identifiers in an array from a multiple content datastatic 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 givenContentDataHelper.InvertRelationManager
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 givenContentDataHelper.InvertRelationManager
static boolean
removeInvertRelation
(ModifiableContent referencedContent, String invertRelationPath, Collection<String> referencingContentIds, ValueContext context) Removes the invert relation to the givenDataHolder
void
service
(ServiceManager manager)
-
Field Details
-
ROLE
Avalon role
-
-
Constructor Details
-
ContentDataHelper
public ContentDataHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- 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 datadataPath
- path to the content datadefaultValue
- The default value to return- Returns:
- the content identifier
- Throws:
BadItemTypeException
- if the data at the given path is not a content data
-
getContentIdFromContentData
public static String getContentIdFromContentData(ModelAwareDataHolder dataHolder, String dataPath) throws BadItemTypeException Retrieves the content identifier of a content data- Parameters:
dataHolder
- data holder that contains the content datadataPath
- 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 datadataPath
- 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 datadataPath
- path to the multiple content datacontext
- 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
public static List<String> getContentIdsListFromMultipleContentData(ModelAwareDataHolder dataHolder, String dataPath) throws BadItemTypeException Retrieves the content identifiers in aList
from a multiple content data- Parameters:
dataHolder
- data holder that contains the multiple content datadataPath
- 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
public static List<String> getContentIdsListFromMultipleContentData(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws BadItemTypeException Retrieves the content identifiers in aList
from a multiple content data- Parameters:
dataHolder
- data holder that contains the multiple content datadataPath
- path to the multiple content datacontext
- 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
public static String[] getContentIdsArrayFromMultipleContentData(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 datadataPath
- 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
public static String[] getContentIdsArrayFromMultipleContentData(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 datadataPath
- path to the multiple content datacontext
- 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
public static Stream<String> getContentIdsStreamFromMultipleContentData(ModelAwareDataHolder dataHolder, String dataPath) throws BadItemTypeException Retrieves aStream
of the content identifiers from a multiple content data- Parameters:
dataHolder
- data holder that contains the multiple content datadataPath
- 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
public static Stream<String> getContentIdsStreamFromMultipleContentData(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws BadItemTypeException Retrieves aStream
of the content identifiers from a multiple content data- Parameters:
dataHolder
- data holder that contains the multiple content datadataPath
- path to the multiple content datacontext
- 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
public Collection<ReferencedContents> collectReferencedContents(ViewItemContainer viewItemContainer, ModifiableContent content, Map<String, Object> values, SynchronizationContext context) Prepares a write operation in the givenModelAwareDataHolder
by traversing aView
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 throughcontent
- the sourceModifiableContent
values
- the new valuescontext
- 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
- theModelAwareDataHolder
to inspect.fix
- iftrue
, 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 thecheckBrokenReferences(ModelAwareDataHolder, boolean)
method- Parameters:
content
- the content to inspect.fix
- iftrue
, 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
. CallReferencedContents.getAddedContents()
to get all contents referenced by the given content that does not reference it in return CallReferencedContents.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 givenContentDataHelper.InvertRelationManager
- Parameters:
invertRelationPath
- the concerned invert relation pathreferencedContents
- aSet
containing the referenced contents to manage (add or remove the relation)referencingContentId
- the id of the content referencing the given contentsinvertRelationManager
- theContentDataHelper.InvertRelationManager
to use (to add or remove the invert relations)alreadyModifiedContents
- aMap
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 contextMap
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 givenContentDataHelper.InvertRelationManager
- Parameters:
invertRelationPath
- the concerned invert relation pathreferencedContents
- aMap
containing the referenced contents to manage (add or remove the relation) and the id of the content referencing this contentinvertRelationManager
- theContentDataHelper.InvertRelationManager
to use (to add or remove the invert relations)alreadyModifiedContents
- aMap
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 contextMap
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 givenDataHolder
- Parameters:
dataHolder
- the data holder where to add the invert relationinvertRelationPath
- the path of the invert relationreferencingContentIds
- the id of the contents that reference the data holdercontext
- 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 givenDataHolder
- Parameters:
referencedContent
- the content where to remove the invert relationinvertRelationPath
- the path of the invert relationreferencingContentIds
- the id of the contents that do not reference the given content anymorecontext
- the value's context- Returns:
true
if the referenced content has been modified,false
otherwise
-