Package org.cyclos.utils
Class CustomFieldHelper
- java.lang.Object
-
- org.cyclos.utils.CustomFieldHelper
-
public class CustomFieldHelper extends Object
Helper class for handling custom fields and their values
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<IDynamicFieldValue>DYNAMIC_VALUES_COMPARATORComparator for dynamic valuesstatic Comparator<ICustomFieldPossibleValue<?>>POSSIBLE_VALUES_COMPARATORComparator for possible values (any ICustomFieldPossibleValue with a null value will be placed first in the sorted result)static StringVALUE_SEPARATORSeparator used when multiple values are parsed from a String
-
Constructor Summary
Constructors Constructor Description CustomFieldHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidfillNewFieldValue(CustomFieldDetailedVO field, CustomFieldValueDTO customValue)Fills-in a new custom field value instance for a new value on the given field.static voidfillNewFieldValue(UserCustomFieldDetailedVO field, UserCustomFieldValueDTO customValue)Same asfillNewFieldValue(CustomFieldDetailedVO, CustomFieldValueDTO)but working withUserCustomFieldDetailedVOstatic UserProfileFieldActionsfindActions(ProfileField profileField, Iterable<UserProfileFieldActions> actions)Returns the actions collection for the given profile fieldstatic UserCustomFieldValueDTOfindUserValueOrNew(CustomFieldDetailedVO field, Collection<UserCustomFieldValueDTO> customValues)Finds a custom field value inside a collection.static <V extends ICustomFieldValue<?,?,?,?>>
VfindValue(ICustomField field, Collection<? extends V> values)Finds a custom field value inside a collection We assume that the values collection and the field passed are of the same entity, so we can unqualify both of themstatic <DTO extends CustomFieldValueDTO>
DTOfindValueOrNew(CustomFieldDetailedVO field, Collection<DTO> customValues, Function<CustomFieldDetailedVO,DTO> dtoFactory)Finds a custom field value inside a collection.static CustomFieldValueDTOfindValueOrNew(CustomFieldDetailedVO field, Collection<CustomFieldValueDTO> customValues)Finds a custom field value inside a collection.static List<UserCustomFieldDetailedVO>getCustomFields(Iterable<UserProfileFieldActions> actions)Returns the custom fields in the given collection of actionsstatic ObjectgetCustomFieldValue(CustomFieldType type, ICustomFieldValue value)Returns the property used to retrieve the value of a field given it's typestatic ObjectgetCustomFieldValue(ICustomFieldValue<?,?,?,?> value)Returns the property used to retrieve the value of a field given it's typestatic ObjectgetDefaultValue(CustomFieldDetailedVO field)Returns the default value for the given fieldstatic Collection<DynamicFieldValueVO>getDynamicValues(ICustomFieldValue<?,?,?,?> fieldValue)static Collection<CustomFieldPossibleValueVO>getEnumeratedValues(ICustomFieldValue<?,?,?,?> fieldValue)static EntityVOgetLinkedEntity(LinkedEntityVO vo)Returns the specificEntityVOassociated with the givenLinkedEntityVO, according to the subclass.static ProfileFieldgetProfileField(UserProfileFieldActions actions)Returns the profile field for the given actions collectionstatic StringgetReferenceValue(ICustomFieldValue<?,?,?,?> fieldValue)static Map<Long,UserSectionDetailedVO>getUserSectionsById(List<UserCustomFieldDetailedVO> fields)Returns a map with the sections found in the given fieldsstatic ObjectgetValue(Long customFieldId, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues)Returns the value of a custom field from a collection, finding the value by internal name.static ObjectgetValue(String internalName, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues)Returns the value of a custom field from a collection, finding the value by internal name.static ObjectgetValue(UserWithFieldsVO user, ProfileField profileField)Returns a profile field value for a givenUserWithFieldsVOstatic List<?>getValuesList(CustomFieldDetailedVO field)Returns the values list from a given custom fieldstatic booleanhasAnyFieldWithInformation(Collection<?> fieldActions)Returns whether at least one of the given fields (either field detailed or field actions) have information textstatic booleanhasValue(CustomFieldValueDTO fieldValue)static CustomFieldValueDTOnewFieldValue(CustomFieldDetailedVO field)Creates a new custom field value for the given fieldstatic voidqualifyInternalName(String customFieldInternalName, CustomFieldPossibleValueVO possibleValue)Qualifies the internal name of the given possible value with the custom field internal name.static <FV extends ICustomFieldValue>
FVsetCustomFieldValue(FV fieldValue, Object value)static booleansetValue(String internalName, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues, Object value)Sets the value of a custom field given the values collection, finding by field internal namestatic Map<String,ICustomField>toFieldsMap(Collection<? extends ICustomField> fields)Returns a Map, keyed by the custom field's unqualified internal name , whose value is the custom field of the received collection.static Map<ICustomField,ICustomFieldValue>toMap(Collection<? extends ICustomFieldValue> customValues)Returns a Map, keyed by the custom field , whose values are the custom field values of the received collection.static StringtoReference(ICustomFieldValue<CustomFieldPossibleValueVO,CustomFieldPossibleValueCategoryVO,RawFileVO,ImageVO> fieldValue)Converts aICustomFieldValueto a reference, that is, a string representation
-
-
-
Field Detail
-
VALUE_SEPARATOR
public static String VALUE_SEPARATOR
Separator used when multiple values are parsed from a String
-
POSSIBLE_VALUES_COMPARATOR
public static Comparator<ICustomFieldPossibleValue<?>> POSSIBLE_VALUES_COMPARATOR
Comparator for possible values (any ICustomFieldPossibleValue with a null value will be placed first in the sorted result)
-
DYNAMIC_VALUES_COMPARATOR
public static Comparator<IDynamicFieldValue> DYNAMIC_VALUES_COMPARATOR
Comparator for dynamic values
-
-
Method Detail
-
fillNewFieldValue
public static void fillNewFieldValue(CustomFieldDetailedVO field, CustomFieldValueDTO customValue)
Fills-in a new custom field value instance for a new value on the given field. Should be used when there are custom subclasses ofCustomFieldValueDTOandnewFieldValue(CustomFieldDetailedVO)is not enough. Sets the field reference and the default value.
-
fillNewFieldValue
public static void fillNewFieldValue(UserCustomFieldDetailedVO field, UserCustomFieldValueDTO customValue)
Same asfillNewFieldValue(CustomFieldDetailedVO, CustomFieldValueDTO)but working withUserCustomFieldDetailedVO
-
findActions
public static UserProfileFieldActions findActions(ProfileField profileField, Iterable<UserProfileFieldActions> actions)
Returns the actions collection for the given profile field
-
findUserValueOrNew
public static UserCustomFieldValueDTO findUserValueOrNew(CustomFieldDetailedVO field, Collection<UserCustomFieldValueDTO> customValues)
Finds a custom field value inside a collection. If none found, creates a new one and adds to the collection before returning
-
findValue
public static <V extends ICustomFieldValue<?,?,?,?>> V findValue(ICustomField field, Collection<? extends V> values)
Finds a custom field value inside a collection We assume that the values collection and the field passed are of the same entity, so we can unqualify both of them
-
findValueOrNew
public static CustomFieldValueDTO findValueOrNew(CustomFieldDetailedVO field, Collection<CustomFieldValueDTO> customValues)
Finds a custom field value inside a collection. If none found, creates a new one and adds to the collection before returning
-
findValueOrNew
public static <DTO extends CustomFieldValueDTO> DTO findValueOrNew(CustomFieldDetailedVO field, Collection<DTO> customValues, Function<CustomFieldDetailedVO,DTO> dtoFactory)
Finds a custom field value inside a collection. If none found, creates a new one and adds to the collection before returning
-
getCustomFields
public static List<UserCustomFieldDetailedVO> getCustomFields(Iterable<UserProfileFieldActions> actions)
Returns the custom fields in the given collection of actions
-
getCustomFieldValue
public static Object getCustomFieldValue(CustomFieldType type, ICustomFieldValue value)
Returns the property used to retrieve the value of a field given it's type
-
getCustomFieldValue
public static Object getCustomFieldValue(ICustomFieldValue<?,?,?,?> value)
Returns the property used to retrieve the value of a field given it's type
-
getDefaultValue
public static Object getDefaultValue(CustomFieldDetailedVO field)
Returns the default value for the given field
-
getDynamicValues
public static Collection<DynamicFieldValueVO> getDynamicValues(ICustomFieldValue<?,?,?,?> fieldValue)
-
getEnumeratedValues
public static Collection<CustomFieldPossibleValueVO> getEnumeratedValues(ICustomFieldValue<?,?,?,?> fieldValue)
-
getLinkedEntity
public static EntityVO getLinkedEntity(LinkedEntityVO vo)
Returns the specificEntityVOassociated with the givenLinkedEntityVO, according to the subclass.
-
getProfileField
public static ProfileField getProfileField(UserProfileFieldActions actions)
Returns the profile field for the given actions collection
-
getReferenceValue
public static String getReferenceValue(ICustomFieldValue<?,?,?,?> fieldValue)
-
getUserSectionsById
public static Map<Long,UserSectionDetailedVO> getUserSectionsById(List<UserCustomFieldDetailedVO> fields)
Returns a map with the sections found in the given fields
-
getValue
public static Object getValue(Long customFieldId, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues)
Returns the value of a custom field from a collection, finding the value by internal name.
-
getValue
public static Object getValue(String internalName, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues)
Returns the value of a custom field from a collection, finding the value by internal name.
-
getValue
public static Object getValue(UserWithFieldsVO user, ProfileField profileField)
Returns a profile field value for a givenUserWithFieldsVO
-
getValuesList
public static List<?> getValuesList(CustomFieldDetailedVO field)
Returns the values list from a given custom field
-
hasAnyFieldWithInformation
public static boolean hasAnyFieldWithInformation(Collection<?> fieldActions)
Returns whether at least one of the given fields (either field detailed or field actions) have information text
-
hasValue
public static boolean hasValue(CustomFieldValueDTO fieldValue)
-
newFieldValue
public static CustomFieldValueDTO newFieldValue(CustomFieldDetailedVO field)
Creates a new custom field value for the given field
-
qualifyInternalName
public static void qualifyInternalName(String customFieldInternalName, CustomFieldPossibleValueVO possibleValue)
Qualifies the internal name of the given possible value with the custom field internal name. For example if the custom field internal name is "a" and the internal name of tej possible value is "b" then it returns "a.b"
-
setCustomFieldValue
public static <FV extends ICustomFieldValue> FV setCustomFieldValue(FV fieldValue, Object value)
-
setValue
public static boolean setValue(String internalName, Collection<? extends ICustomFieldValue<?,?,?,?>> customValues, Object value)
Sets the value of a custom field given the values collection, finding by field internal name
-
toFieldsMap
public static Map<String,ICustomField> toFieldsMap(Collection<? extends ICustomField> fields)
Returns a Map, keyed by the custom field's unqualified internal name , whose value is the custom field of the received collection.
-
toMap
public static Map<ICustomField,ICustomFieldValue> toMap(Collection<? extends ICustomFieldValue> customValues)
Returns a Map, keyed by the custom field , whose values are the custom field values of the received collection.
-
toReference
public static String toReference(ICustomFieldValue<CustomFieldPossibleValueVO,CustomFieldPossibleValueCategoryVO,RawFileVO,ImageVO> fieldValue)
Converts aICustomFieldValueto a reference, that is, a string representation
-
-