Class PreferenceServices

java.lang.Object
org.apache.ofbiz.common.preferences.PreferenceServices

public class PreferenceServices extends Object
User preference services.

User preferences are stored as key-value pairs.

User preferences can be grouped - so that multiple preference pairs can be handled at once. Preference groups also allow a single userPrefTypeId to be used more than once - with each occurence having a unique userPrefGroupTypeId.

User preference values are stored as Strings, so the easiest and most efficient way to handle user preference values is to keep them as strings. This class handles any data conversion needed.

  • Constructor Details

    • PreferenceServices

      public PreferenceServices()
  • Method Details

    • getUserPreference

      public static Map<String,Object> getUserPreference(DispatchContext ctx, Map<String,?> context)
      Retrieves a single user preference from persistent storage. Call with userPrefTypeId and optional userPrefLoginId. If userPrefLoginId isn't specified, then the currently logged-in user's userLoginId will be used. The retrieved preference is contained in the userPrefMap element.
      Parameters:
      ctx - The DispatchContext that this service is operating in.
      context - Map containing the input arguments.
      Returns:
      Map with the result of the service, the output parameters.
    • getUserPreferenceGroup

      public static Map<String,Object> getUserPreferenceGroup(DispatchContext ctx, Map<String,?> context)
      Retrieves a group of user preferences from persistent storage. Call with userPrefGroupTypeId and optional userPrefLoginId. If userPrefLoginId isn't specified, then the currently logged-in user's userLoginId will be used. The retrieved preferences group is contained in the userPrefMap element.
      Parameters:
      ctx - The DispatchContext that this service is operating in.
      context - Map containing the input arguments.
      Returns:
      Map with the result of the service, the output parameters.
    • setUserPreference

      public static Map<String,Object> setUserPreference(DispatchContext ctx, Map<String,?> context)
      Stores a single user preference in persistent storage. Call with userPrefTypeId, userPrefGroupTypeId, userPrefValue and optional userPrefLoginId. If userPrefLoginId isn't specified, then the currently logged-in user's userLoginId will be used.
      Parameters:
      ctx - The DispatchContext that this service is operating in.
      context - Map containing the input arguments.
      Returns:
      Map with the result of the service, the output parameters.
    • removeUserPreference

      public static Map<String,Object> removeUserPreference(DispatchContext ctx, Map<String,?> context)
    • setUserPreferenceGroup

      public static Map<String,Object> setUserPreferenceGroup(DispatchContext ctx, Map<String,?> context)
      Stores a user preference group in persistent storage. Call with userPrefMap, userPrefGroupTypeId and optional userPrefLoginId. If userPrefLoginId isn't specified, then the currently logged-in user's userLoginId will be used.
      Parameters:
      ctx - The DispatchContext that this service is operating in.
      context - Map containing the input arguments.
      Returns:
      Map with the result of the service, the output parameters.
    • copyUserPreferenceGroup

      public static Map<String,Object> copyUserPreferenceGroup(DispatchContext ctx, Map<String,?> context)
      Copies a user preference group. Call with fromUserLoginId, userPrefGroupTypeId and optional userPrefLoginId. If userPrefLoginId isn't specified, then the currently logged-in user's userLoginId will be used.
      Parameters:
      ctx - The DispatchContext that this service is operating in.
      context - Map containing the input arguments.
      Returns:
      Map with the result of the service, the output parameters.