Class ProfilePropertyValueUtil

java.lang.Object
io.meeds.social.core.profileproperty.util.ProfilePropertyValueUtil

public class ProfilePropertyValueUtil extends Object
Rules on profile attribute names shared by the listing cascade of the attribute settings, the forms' allow-list and the attribute form, and on how a stored attribute value reads back.
  • Field Details

    • UNLISTABLE_NAMES

      public static final List<String> UNLISTABLE_NAMES
      Names no form lists, compared ignoring case: the default fields, always present in the forms, and the profile keys the forms never write.
    • MAX_LISTABLE_NAME_LENGTH

      public static final int MAX_LISTABLE_NAME_LENGTH
      The size of SOC_IDENTITY_PROPERTIES.NAME, where a value is stored
      See Also:
    • MAX_GROUP_ID_LENGTH

      public static final int MAX_GROUP_ID_LENGTH
      The size of SOC_USER_PERMISSION.GROUP_ID, which holds the group a group-synchronized value grants
      See Also:
    • SYNCHRONIZED_GROUP_ID_PREFIX

      public static final String SYNCHRONIZED_GROUP_ID_PREFIX
      The parent of the groups a group-synchronized attribute's values grant, as GroupSynchronizationSocialProfileListener builds their ids: this prefix, the attribute's cleaned name, a slash and the value's cleaned text.
      See Also:
    • MAX_SYNCHRONIZED_NAME_LENGTH

      public static final int MAX_SYNCHRONIZED_NAME_LENGTH
      The longest cleaned name a group-synchronized attribute can have to be listed: its prefix, a slash and a one-character value then take the whole group id bound.
    • MAX_STORED_VALUE_LENGTH

      public static final int MAX_STORED_VALUE_LENGTH
      The size of SOC_IDENTITY_PROPERTIES.VALUE, which holds an attribute's stored form, in UTF-16 units
      See Also:
    • UTILS_EMAIL_PATTERN

      public static final Pattern UTILS_EMAIL_PATTERN
      The e-mail rule of $utils.isValidEmail (vue-apps/common/js/Utils.js), which the profile's e-mail fields apply; only an ASCII value passes INPUT_EMAIL_PATTERN too, so Java's ASCII \s is enough here
    • INPUT_EMAIL_PATTERN

      public static final Pattern INPUT_EMAIL_PATTERN
      The WHATWG valid e-mail address production, which the browser applies to the profile's e-mail fields, whose input is of type email. The labels' repetition is possessive: a greedy one recurses once per label, and a value of a few thousand labels, checked before its size, overflows the stack; since a label holds no dot, giving one back never helps the match
  • Method Details

    • isUnlistableName

      public static boolean isUnlistableName(String propertyName)
      Parameters:
      propertyName - an attribute's technical name
      Returns:
      true when the name is one of UNLISTABLE_NAMES, ignoring case
    • isListableName

      public static boolean isListableName(String propertyName, boolean groupSynchronized)
      Parameters:
      propertyName - an attribute's technical name
      groupSynchronized - whether the attribute's values grant group memberships
      Returns:
      true when an attribute of that name can be listed in a form: neither unlistable nor longer than MAX_LISTABLE_NAME_LENGTH UTF-16 units, and, when group-synchronized, a cleaned name of 1 to MAX_SYNCHRONIZED_NAME_LENGTH characters
    • getCleanedLength

      public static int getCleanedLength(String text)
      Parameters:
      text - a name or a value
      Returns:
      the length of the text as it appears in a synchronized group's id, 0 when nothing of it remains
    • getSynchronizedGroupIdLength

      public static int getSynchronizedGroupIdLength(String propertyName, String value)
      Parameters:
      propertyName - a group-synchronized attribute's technical name
      value - one of its values
      Returns:
      the length of the id of the group the value makes, as GroupSynchronizationSocialProfileListener builds it: SYNCHRONIZED_GROUP_ID_PREFIX, the cleaned name, a slash and the cleaned value
    • isValidEmail

      public static boolean isValidEmail(String value)
      Parameters:
      value - a single value
      Returns:
      true when the value passes both e-mail rules the profile's e-mail fields apply
    • matchesUtilsEmail

      public static boolean matchesUtilsEmail(String value)
      Parameters:
      value - a single value
      Returns:
      true when the whole value matches UTILS_EMAIL_PATTERN
    • matchesInputEmail

      public static boolean matchesInputEmail(String value)
      Parameters:
      value - a single value
      Returns:
      true when the whole value matches INPUT_EMAIL_PATTERN
    • storedLength

      public static int storedLength(Object value)
      Parameters:
      value - an attribute's value in the storage shape: a text, or a list of maps for a multi-valued attribute
      Returns:
      the length, in UTF-16 units, of the text the identity storage writes for it: the text itself, or the JSON array org.json serialises the list's maps to, escapes included
    • readsBackAsList

      public static boolean readsBackAsList(String value)
      Every list the identity storage writes is a JSON array of JSON objects, so only such a text is read back as a list; any other text, a bracketed one included, is read back as the text it is. The text is parsed under JSON's own grammar, a repeated name refused: org.json, which converts it, accepts unquoted or single-quoted names, extra commas and semicolons, and ignores what follows the array, so a text it accepts can come back changed, while it refuses a repeated name, so a text it refuses would come back empty.
      Parameters:
      value - a profile attribute's stored text
      Returns:
      true when the whole text, from its first to its last character, is a JSON array whose entries are all JSON objects, the empty array included