Class CustomFieldsService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCustomFieldsService(CustomFieldsRepository customFieldsRepository, EnumerationTypeRepository enumerationTypeRepository) -
Method Summary
Modifier and TypeMethodDescriptionstatic CustomFieldsEntityfromEntity(CustomFieldsEntity entity) Parses the canonical string representation back into custom field properties.getClassOptions(String term) Returns class name suggestions that contain the given search term.static List<CustomFieldsEntity>Retrieves custom fields for the given search context.static List<CustomFieldsEntity>getCustomFields(CustomFieldsSearchDto main, CustomFieldsSearchDto bonus) Retrieves custom fields for the given main and bonus search contexts.static Map<Character,CustomFieldsEntity> Retrieves custom fields as a map indexed by their character alphabet key.static List<LabelValue>getFieldsTypes(Prop prop) Returns all available custom field types with localized labels.static StringgetFieldTypeLabel(Prop prop, String fieldKey) Retrieves the localized label for a custom field type.Retrieves the alphabet characters of required custom fields for the given context.Retrieves the alphabet characters of required custom fields for the given contexts.static List<LabelValue>Returns the mapping of field types to their type-specific property names.static booleanisEnumerationStringAlphabet(String alphabet) Checks whether the alphabet value identifies a configurable enumeration string field.static booleanisSupportedFieldType(String type) Checks whether a custom field type can be persisted by this service.voidApplies class-specific derived values to a custom field configuration.static CustomFieldsEntitytoEntity(CustomFieldsEntity entity) Converts custom field configuration into its canonical string representation.booleanvalidateSpecificClass(CustomFieldsEntity entity, String action, org.springframework.validation.Errors errors, Long id, Prop prop) Runs additional validation selected by the configured entity class name.
-
Field Details
-
BONUS_PARAMS
-
-
Constructor Details
-
CustomFieldsService
@Autowired public CustomFieldsService(CustomFieldsRepository customFieldsRepository, EnumerationTypeRepository enumerationTypeRepository)
-
-
Method Details
-
getCustomFieldsMap
Retrieves custom fields as a map indexed by their character alphabet key.Combines global fields (no entityId), specific entity fields, and bonus context fields with appropriate priority handling. Specific fields override global fields, and bonus fields have the highest priority.
- Parameters:
main- the search context containing className and entityId- Returns:
- map of custom fields indexed by their single-character alphabet key, or empty map if invalid params
- See Also:
-
getCustomFields
Retrieves custom fields for the given search context.Fetches global fields (no entityId), specific entity fields, and bonus context fields when available. Specific fields override global fields, and bonus fields have the highest priority.
- Parameters:
main- the search context containing className and entityId- Returns:
- list of merged custom fields with priority handling, or empty list if invalid params
- See Also:
-
getCustomFields
public static List<CustomFieldsEntity> getCustomFields(CustomFieldsSearchDto main, CustomFieldsSearchDto bonus) Retrieves custom fields for the given main and bonus search contexts.Combines three field sources in priority order (lowest to highest):
- Global fields - no entityId, apply to all entities of a class
- Specific fields - have matching entityId, override global fields
- Bonus fields - from bonus class context, have highest priority
- Parameters:
main- primary search context with className and entityIdbonus- optional secondary context for bonus class fields; if null, only main context is used- Returns:
- merged list of custom fields with priority-based deduplication, or empty list if invalid params
-
toEntity
Converts custom field configuration into its canonical string representation.Transforms entity properties into a structured value format based on field type:
- text: "text" or "text-{maxLength}" or "text-{maxLength}, warningLength-{warningLength}"
- select/multiselect: options string with optional leading | for non-required fields
- enumeration: "enumeration{_option1_option2}" with optional _null suffix
- docsIn: "docsIn_{groupId}" with optional _null suffix
- autocomplete: "autocomplete:{options}"
- json_group/json_doc: type name with optional _null suffix
- Parameters:
entity- the custom field entity to convert- Returns:
- the same entity with updated value field, never null
- Throws:
IllegalStateException- if entity or its type is null/empty- See Also:
-
fromEntity
Parses the canonical string representation back into custom field properties.Reverse operation of
toEntity(CustomFieldsEntity). Extracts type-specific properties from the value field:- text: parses maxLength and warningLength from value
- select/multiselect: extracts selectOptions
- enumeration: parses enumeration options from underscore-separated format
- docsIn: resolves groupId to GroupDetails object
- autocomplete: extracts autocompleteOptions
- Parameters:
entity- the custom field entity with populated value field- Returns:
- the same entity with type-specific properties set, or original if type/value empty
- See Also:
-
getFieldsTypes
Returns all available custom field types with localized labels.Provides the complete list of supported field types for use in UI dropdowns or configuration interfaces. Labels are retrieved from the i18n property bundle using the key pattern "settings.custom-fields.type.{fieldType}".
- Parameters:
prop- the property bundle for label localization- Returns:
- list of LabelValue pairs with localized type names and their identifiers
- See Also:
-
isSupportedFieldType
Checks whether a custom field type can be persisted by this service.- Parameters:
type- custom field type- Returns:
- true for a supported field type
-
getFieldTypeLabel
Retrieves the localized label for a custom field type.- Parameters:
prop- the property bundle for label localizationfieldKey- the field type key (e.g., "text", "select", "enumeration")- Returns:
- the localized label, retrieved using key "settings.custom-fields.type.{fieldKey}"
-
getSpecificFieldVisibility
Returns the mapping of field types to their type-specific property names.Specifies which properties should be visible in the UI editor for each field type. Used to control which configuration options are shown when editing custom fields of different types.
- Returns:
- list of LabelValue pairs mapping field types to comma-separated property names
-
getRequiredFieldsAlphabets
Retrieves the alphabet characters of required custom fields for the given context.Returns only fields marked as required, extracting the first character from their alphabet identifier. Automatically derives bonus context when applicable.
- Parameters:
main- the search context containing className and entityId- Returns:
- list of single-character alphabet keys for required fields, or empty list if invalid params
- See Also:
-
getRequiredFieldsAlphabets
public static List<Character> getRequiredFieldsAlphabets(CustomFieldsSearchDto main, CustomFieldsSearchDto bonus) Retrieves the alphabet characters of required custom fields for the given contexts.Filters custom fields from both main and bonus contexts to return only those marked as required, extracting the first character from each field's alphabet identifier. Maintains insertion order via LinkedHashSet.
- Parameters:
main- primary search context with className and entityIdbonus- optional secondary context for bonus class fields- Returns:
- ordered list of single-character alphabet keys for required fields
- See Also:
-
validateSpecificClass
public boolean validateSpecificClass(CustomFieldsEntity entity, String action, org.springframework.validation.Errors errors, Long id, Prop prop) Runs additional validation selected by the configured entity class name.- Parameters:
entity- custom field configurationaction- datatable editor actionerrors- validation errorsid- custom field configuration IDprop- current translations- Returns:
- true when the class-specific validation passed or is not defined
-
synchronizeSpecificClassFields
Applies class-specific derived values to a custom field configuration.- Parameters:
entity- custom field configuration
-
isEnumerationStringAlphabet
Checks whether the alphabet value identifies a configurable enumeration string field.- Parameters:
alphabet- custom field alphabet value- Returns:
- true for values A through L
-
getClassOptions
Returns class name suggestions that contain the given search term.- Parameters:
term- search text- Returns:
- case-insensitively sorted list of matching class names
-