Class DataHolderHelper
java.lang.Object
org.ametys.plugins.repository.data.holder.impl.DataHolderHelper
- All Implemented Interfaces:
Disposable,Component,Serviceable
Helper for implementations of data holder
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TaggregateMultipleValues(List<? extends ModelAwareDataHolder> dataHolders, String dataPath, Class managedClass) Aggregates multiple values of the data holders at the given pathstatic voidcommentsToSAX(ModelAwareDataHolder dataHolder, ContentHandler contentHandler, ViewItemAccessor viewItemAccessor, String dataPath) Generates SAX events for the data comments in the given viewstatic ObjectconvertValue(ElementDefinition definition, Object value) Converts the given value according to the given definition If the value is multiple, an array is retrieved with each value converted to the right typeconvertValues(ViewItemContainer viewItemContainer, Map<String, Object> values) Converts the given values according to the definitions in the givenViewItemContainerstatic voidcopyTo(DataHolder source, ModifiableDataHolder destination) Copies the sourceDataHolderto the givenModifiableDataHolderdestination.static voidcopyTo(DataHolder source, ModifiableDataHolder destination, String name) Copy the data name of the sourceDataHolderto the givenModifiableDataHolderdestination.static ValueContextcreateValueContextFromSynchronizationContext(ModelAwareDataHolder dataHolder, String dataPath, SynchronizationContext synchronizationContext) Creates a value context from the givenSynchronizationContextstatic ObjectdataToJSON(ModelLessDataHolder dataHolder, String relativeDataPath, DataContext context) Convert the data at the given relative path into a JSON objectdataToJSON(ModelLessDataHolder dataHolder, DataContext context) Convert the data contained in the givenDataHolderstatic voiddataToSAX(ModelLessDataHolder dataHolder, ContentHandler contentHandler, String relativeDataPath, DataContext context) Generates SAX events for data at the given relative path in thisDataHolderstatic voiddataToSAX(ModelLessDataHolder dataHolder, ContentHandler contentHandler, DataContext context) Generates SAX events for data contained in thisDataHoldervoiddispose()findEditableItemsByType(ModelAwareDataHolder dataHolder, String type) Find all modifiable data of the given type on aModelAwareDataHolder, including in composite or repeater entries.findItemsByType(ModelAwareDataHolder dataHolder, String type) Find all data of the given type on aModelAwareDataHolder, including in composite or repeater entries.findItemsByType(ModelAwareDataHolder dataHolder, ViewItemAccessor viewItemAccessor, String type) Find all data of the given type on aModelAwareDataHolder, including in composite or repeater entries.Retrieve theExternalizableDataProviderExtensionPointstatic RepeaterEntrygetRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) Retrieves the repeater entry at the given positiongetRepeaterNameAndEntryPosition(String pathSegment) Retrieves the pair of repeater name and entry position of the given path segment Returnnullif the given path does not represent a repeater entrystatic <T> TRetrieves the value at the given path for the data aware ametys object with given idstatic <T> TgetValue(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Retrieves the value of the data at the given pathstatic ObjectgetValueFromSynchronizableValue(Object value, ModelAwareDataHolder dataHolder, ModelItem modelItem, Optional<String> dataPath, SynchronizationContext context) Returns the value of the synchronized value corresponding of the future status If the value is not aSynchronizableValue, the value itself is returned The future status is determined from the synchronizable value itself or from the context if needed.static booleanhasNonEmptyRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) Checks if there is a non empty repeater entry at the given positionstatic booleanhasRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) Checks if there is a repeater entry at the given positionstatic booleanhasValue(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Checks if there is a non empty value, for the data at the given pathstatic booleanhasValueOrEmpty(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Checks if there is value, even empty, for the data at the given pathstatic booleanisMultiple(ModelItem item) Check if the givenModelItemis multivalued, either being itself mutlivalued or part of a repeaterstatic booleanisRepeaterEntryPath(String path) Test if the path is a repeater entry path (for example entries[1])static voidremoveValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, ValueContext context) Removes the stored value of the data at the given pathvoidservice(ServiceManager manager) static voidsetValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, Object value, ValueContext context) Sets the value of the data at the given pathstatic voidsetValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, Object value, ValueContext context, boolean forceStatus) Sets the value of the data at the given path
-
Field Details
-
REPEATER_ENTRY_PATTERN
Pattern for repeater entry : entryName[i]
-
-
Constructor Details
-
DataHolderHelper
public DataHolderHelper()
-
-
Method Details
-
service
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
dispose
- Specified by:
disposein interfaceDisposable
-
hasRepeaterEntry
public static boolean hasRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) throws BadItemTypeException Checks if there is a repeater entry at the given position- Parameters:
dataHolder- data holder that contains the repeater entry. The data holder must be the direct parent of the repeaterrepeaterName- the name of the repeaterentryPosition- the position of the entry- Returns:
trueif there is an entry at the given position,falseotherwise- Throws:
BadItemTypeException- if the value stored in the repository for the given repeater name is not a repeater
-
hasNonEmptyRepeaterEntry
public static boolean hasNonEmptyRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) throws BadItemTypeException Checks if there is a non empty repeater entry at the given position- Parameters:
dataHolder- data holder that contains the repeater entry. The data holder must be the direct parent of the repeaterrepeaterName- the name of the repeaterentryPosition- the position of the entry- Returns:
trueif there is a non empty entry at the given position,falseotherwise- Throws:
BadItemTypeException- if the value stored in the repository for the given repeater name is not a repeater
-
getRepeaterEntry
public static RepeaterEntry getRepeaterEntry(ModelAwareDataHolder dataHolder, String repeaterName, int entryPosition) throws BadItemTypeException Retrieves the repeater entry at the given position- Parameters:
dataHolder- data holder that contains the repeater entry. The data holder must be the direct parent of the repeaterrepeaterName- the name of the repeaterentryPosition- the position of the entry- Returns:
- the repeater entry
- Throws:
BadItemTypeException- if the value stored in the repository for the given repeater name is not a repeater
-
isRepeaterEntryPath
Test if the path is a repeater entry path (for example entries[1])- Parameters:
path- the path representing the repeater entry- Returns:
- true if the pathSegment is a repeater entry path
-
getRepeaterNameAndEntryPosition
Retrieves the pair of repeater name and entry position of the given path segment Returnnullif the given path does not represent a repeater entry- Parameters:
pathSegment- the path segment representing the repeater entry- Returns:
- the pair of repeater name and entry position
-
hasValue
public static boolean hasValue(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws IllegalArgumentException, BadDataPathCardinalityException Checks if there is a non empty value, for the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datacontext- the context of the value to check- Returns:
trueif the data at the given path is defined by the model, if there is a non empty value for the data, and if the type of this value matches the type of the definition.falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
hasValueOrEmpty
public static boolean hasValueOrEmpty(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws IllegalArgumentException, BadDataPathCardinalityException Checks if there is value, even empty, for the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datacontext- the context of the value to check- Returns:
trueif the data at the given path is defined by the model, if there is a value, even empty, for the data, and if the type of this value matches the type of the definition.falseotherwise- Throws:
IllegalArgumentException- if the given data path is null or emptyBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
getValue
public static <T> T getValue(String ametysObjectId, String dataPath) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException Retrieves the value at the given path for the data aware ametys object with given id- Type Parameters:
T- type of the value to retrieve- Parameters:
ametysObjectId- identifier of the data aware ametys objectdataPath- path of the data- Returns:
- the value of the data or
nullif not exists or is empty. - Throws:
IllegalArgumentException- if the given data path is null or emptyUndefinedItemPathException- if the given data path is not defined by the modelBadItemTypeException- if the type defined by the model doesn't match the type of the stored valueBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
getValue
public static <T> T getValue(ModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException Retrieves the value of the data at the given path- Type Parameters:
T- type of the value to retrieve- Parameters:
dataHolder- the data holderdataPath- path of the datacontext- the context of the value to retrieve- Returns:
- the value of the data or
nullif not exists or is empty. - Throws:
IllegalArgumentException- if the given data path is null or emptyUndefinedItemPathException- if the given data path is not defined by the modelBadItemTypeException- if the type defined by the model doesn't match the type of the stored valueBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
setValue
public static void setValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, Object value, ValueContext context) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException Sets the value of the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datavalue- the value to set. Givenullto empty the value.context- context of the data to set- Throws:
IllegalArgumentException- if the given data path is null or emptyUndefinedItemPathException- if the given data path is not defined by the modelBadItemTypeException- if the type defined by the model doesn't match the given value to setBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
setValue
public static void setValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, Object value, ValueContext context, boolean forceStatus) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, BadDataPathCardinalityException Sets the value of the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datavalue- the value to set. Givenullto empty the value.context- context of the data to setforceStatus-trueto force the status to the given status context if defined- Throws:
IllegalArgumentException- if the given data path is null or emptyUndefinedItemPathException- if the given data path is not defined by the modelBadItemTypeException- if the type defined by the model doesn't match the given value to setBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
removeValue
public static void removeValue(ModifiableModelAwareDataHolder dataHolder, String dataPath, ValueContext context) throws IllegalArgumentException, UndefinedItemPathException, BadItemTypeException, UnknownDataException, BadDataPathCardinalityException Removes the stored value of the data at the given path- Parameters:
dataHolder- the data holderdataPath- path of the datacontext- context of the data to remove- Throws:
IllegalArgumentException- if the given data path is null or emptyUnknownDataException- if the value at the given data path does not existBadItemTypeException- if the value of the parent of the given path is not an item containerUndefinedItemPathException- if the given data path is not defined by the modelBadDataPathCardinalityException- if the definition of a part of the data path is multiple. Only the last part can be multiple
-
createValueContextFromSynchronizationContext
public static ValueContext createValueContextFromSynchronizationContext(ModelAwareDataHolder dataHolder, String dataPath, SynchronizationContext synchronizationContext) Creates a value context from the givenSynchronizationContext- Parameters:
dataHolder- the data holderdataPath- the path of the value needing contextsynchronizationContext- theSynchronizationContext- Returns:
- the created
ValueContext
-
copyTo
Copies the sourceDataHolderto the givenModifiableDataHolderdestination.- Parameters:
source- the sourceDataHolderdestination- theModifiableDataHolderdestination
-
copyTo
Copy the data name of the sourceDataHolderto the givenModifiableDataHolderdestination.- Parameters:
source- the sourceDataHolderdestination- theModifiableDataHolderdestinationname- the name of the data
-
commentsToSAX
public static void commentsToSAX(ModelAwareDataHolder dataHolder, ContentHandler contentHandler, ViewItemAccessor viewItemAccessor, String dataPath) throws SAXException Generates SAX events for the data comments in the given view- Parameters:
dataHolder- theModelAwareDataHoldercontentHandler- theContentHandlerthat will receive the SAX eventsviewItemAccessor- theViewItemAccessorreferencing the items for which generate SAX eventsdataPath- the data path corresponding of the current data holder. Can benullor empty.- Throws:
SAXException- if an error occurs during the SAX events generation
-
dataToSAX
public static void dataToSAX(ModelLessDataHolder dataHolder, ContentHandler contentHandler, DataContext context) throws SAXException, UnknownTypeException, NotUniqueTypeException Generates SAX events for data contained in thisDataHolder- Parameters:
dataHolder- theModelLessDataHolderto SAXcontentHandler- theContentHandlerthat will receive the SAX eventscontext- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationUnknownTypeException- if there is no compatible type with the saxed valueNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one) with the saxed value
-
dataToSAX
public static void dataToSAX(ModelLessDataHolder dataHolder, ContentHandler contentHandler, String relativeDataPath, DataContext context) throws SAXException, UnknownTypeException, NotUniqueTypeException Generates SAX events for data at the given relative path in thisDataHolder- Parameters:
dataHolder- theModelLessDataHolderto SAXcontentHandler- theContentHandlerthat will receive the SAX eventsrelativeDataPath- the path of the data to SAX, relative to the given data holdercontext- The context of the data to SAX- Throws:
SAXException- if an error occurs during the SAX events generationUnknownTypeException- if there is no compatible type with the saxed valueNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one) with the saxed value
-
dataToJSON
public static Map<String,Object> dataToJSON(ModelLessDataHolder dataHolder, DataContext context) throws UnknownTypeException, NotUniqueTypeException Convert the data contained in the givenDataHolder- Parameters:
dataHolder- theModelLessDataHoldercontext- The context of the data to convert- Returns:
- The data of the given
DataHolderas JSON - Throws:
UnknownTypeException- if there is no compatible type with the value to convertNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one) with the value to convert
-
dataToJSON
public static Object dataToJSON(ModelLessDataHolder dataHolder, String relativeDataPath, DataContext context) throws UnknownTypeException, NotUniqueTypeException Convert the data at the given relative path into a JSON object- Parameters:
dataHolder- theModelLessDataHolderrelativeDataPath- the path of the data to convert, relative to the given data holdercontext- The context of the data to convert- Returns:
- The value as JSON
- Throws:
UnknownTypeException- if there is no compatible type with the value to convertNotUniqueTypeException- if there are many compatible types (there is no way to determine which type is the good one) with the value to convert
-
findEditableItemsByType
public static <T> Map<String,T> findEditableItemsByType(ModelAwareDataHolder dataHolder, String type) Find all modifiable data of the given type on aModelAwareDataHolder, including in composite or repeater entries. Properties are not modifiables, so they are excluded from the result- Type Parameters:
T- the actual type of the requested data.- Parameters:
dataHolder- the data holder.type- the type identifier.- Returns:
- a Map with all data paths as keys and corresponding data as values.
-
findItemsByType
Find all data of the given type on aModelAwareDataHolder, including in composite or repeater entries.- Type Parameters:
T- the actual type of the requested data.- Parameters:
dataHolder- the data holder.type- the type identifier.- Returns:
- a Map with all data paths as keys and corresponding data as values.
-
findItemsByType
public static <T> Map<String,T> findItemsByType(ModelAwareDataHolder dataHolder, ViewItemAccessor viewItemAccessor, String type) Find all data of the given type on aModelAwareDataHolder, including in composite or repeater entries.- Type Parameters:
T- the actual type of the requested data.- Parameters:
dataHolder- the data holder.viewItemAccessor- the view items to restrict totype- the type identifier.- Returns:
- a Map with all data paths as keys and corresponding data as values.
-
getExternalizableDataProviderExtensionPoint
public static ExternalizableDataProviderExtensionPoint getExternalizableDataProviderExtensionPoint()Retrieve theExternalizableDataProviderExtensionPoint- Returns:
- the
ExternalizableDataProviderExtensionPoint
-
getValueFromSynchronizableValue
public static Object getValueFromSynchronizableValue(Object value, ModelAwareDataHolder dataHolder, ModelItem modelItem, Optional<String> dataPath, SynchronizationContext context) Returns the value of the synchronized value corresponding of the future status If the value is not aSynchronizableValue, the value itself is returned The future status is determined from the synchronizable value itself or from the context if needed. As the returned value is extracted from the synchronizable value, it can be anUntouchedValue- Parameters:
value- the synchronizable valuedataHolder- the data holder concerned by the valuemodelItem- the model item corresponding to the valuedataPath- the current data path of the value. Can be empty if the data is in a repeater, in a not yet existing entrycontext- the synchronization context, used to compute the future status of the value- Returns:
- the value of the synchronized value corresponding of the future status
-
isMultiple
Check if the givenModelItemis multivalued, either being itself mutlivalued or part of a repeater- Parameters:
item- the model item to check- Returns:
- true if the model item is multivalued
-
convertValues
public static Map<String,Object> convertValues(ViewItemContainer viewItemContainer, Map<String, Object> values) Converts the given values according to the definitions in the givenViewItemContainer- Parameters:
viewItemContainer- the view item containervalues- the values to convert- Returns:
- the converted values
-
convertValue
public static Object convertValue(ElementDefinition definition, Object value) throws BadItemTypeException Converts the given value according to the given definition If the value is multiple, an array is retrieved with each value converted to the right type- Parameters:
definition- the definitionvalue- the value to convert- Returns:
- the converted value
- Throws:
BadItemTypeException- if the value to convert is not compatible with the data type
-
aggregateMultipleValues
public static <T> T aggregateMultipleValues(List<? extends ModelAwareDataHolder> dataHolders, String dataPath, Class managedClass) Aggregates multiple values of the data holders at the given path- Type Parameters:
T- type of the value to retrieve- Parameters:
dataHolders- the data holding the valuesdataPath- the path of the data to retrievemanagedClass- class of the retrieved values- Returns:
- aggregated multiple values
-