Class PreferenceWorker


  • public final class PreferenceWorker
    extends java.lang.Object
    User preference worker methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.lang.Object> addPrefToMap​(GenericValue rec, java.util.Map<java.lang.String,​java.lang.Object> userPrefMap)
      Add a UserPreference GenericValue to a Map.
      static java.util.Map<java.lang.String,​java.lang.Object> checkCopyPermission​(DispatchContext ctx, java.util.Map<java.lang.String,​?> context)
      Checks preference copy permissions.
      static java.util.Map<java.lang.String,​java.lang.Object> checkPermission​(DispatchContext ctx, java.util.Map<java.lang.String,​?> context)
      Checks preference get/set permissions.
      static java.util.Map<java.lang.String,​java.lang.Object> createUserPrefMap​(java.util.List<GenericValue> recList)
      Convert a List of UserPreference GenericValues to a userPrefMap.
      static java.util.Map<java.lang.String,​java.lang.Object> createUserPrefMap​(GenericValue rec)
      Convert a UserPreference GenericValue to a userPrefMap.
      static java.lang.String getUserLoginId​(java.util.Map<java.lang.String,​?> context, boolean returnDefault)
      Gets a valid userLoginId parameter from the context Map.
      static boolean isValidGetId​(DispatchContext ctx, java.util.Map<java.lang.String,​?> context)
      Checks for valid userLoginId to get preferences.
      static boolean isValidSetId​(DispatchContext ctx, java.util.Map<java.lang.String,​?> context)
      Checks for valid userLoginId to set preferences.
      static java.util.Map<java.lang.String,​java.lang.Object> toFieldMap​(java.lang.String userLoginId, java.lang.String userPrefTypeId, java.lang.String userPrefGroupTypeId, java.lang.Object userPrefValue)
      Creates a field Map to be used in GenericValue create or store methods.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addPrefToMap

        public static java.util.Map<java.lang.String,​java.lang.Object> addPrefToMap​(GenericValue rec,
                                                                                          java.util.Map<java.lang.String,​java.lang.Object> userPrefMap)
                                                                                   throws GeneralException
        Add a UserPreference GenericValue to a Map.
        Parameters:
        rec - GenericValue to convert
        userPrefMap - user preference Map
        Returns:
        user preference map
        Throws:
        GeneralException
      • checkCopyPermission

        public static java.util.Map<java.lang.String,​java.lang.Object> checkCopyPermission​(DispatchContext ctx,
                                                                                                 java.util.Map<java.lang.String,​?> context)
        Checks preference copy permissions. Returns hasPermission=true if permission is granted.

        Users can copy from any set of preferences to their own preferences. Copying to another user's preferences requires ADMIN_PERMISSION permission.

        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.
      • checkPermission

        public static java.util.Map<java.lang.String,​java.lang.Object> checkPermission​(DispatchContext ctx,
                                                                                             java.util.Map<java.lang.String,​?> context)
        Checks preference get/set permissions. Returns hasPermission=true if permission is granted.

        This method is a simple wrapper around the isValidxxxId methods.

        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.
      • createUserPrefMap

        public static java.util.Map<java.lang.String,​java.lang.Object> createUserPrefMap​(GenericValue rec)
                                                                                        throws GeneralException
        Convert a UserPreference GenericValue to a userPrefMap.
        Parameters:
        rec - GenericValue to convert
        Returns:
        user preference map
        Throws:
        GeneralException
      • createUserPrefMap

        public static java.util.Map<java.lang.String,​java.lang.Object> createUserPrefMap​(java.util.List<GenericValue> recList)
                                                                                        throws GeneralException
        Convert a List of UserPreference GenericValues to a userPrefMap.
        Parameters:
        recList - List of GenericValues to convert
        Returns:
        user preference map
        Throws:
        GeneralException
      • getUserLoginId

        public static java.lang.String getUserLoginId​(java.util.Map<java.lang.String,​?> context,
                                                      boolean returnDefault)
        Gets a valid userLoginId parameter from the context Map.

        This method searches the context Map for a userPrefLoginId key. If none is found, the method attempts to get the current user's userLoginId. If the user isn't logged in, then the method returns DEFAULT_UID if returnDefault is set to true, otherwise the method returns a null or empty string.

        Parameters:
        context - Map containing the input arguments.
        returnDefault - return DEFAULT_UID if no userLoginId is found.
        Returns:
        userLoginId String
      • isValidGetId

        public static boolean isValidGetId​(DispatchContext ctx,
                                           java.util.Map<java.lang.String,​?> context)
        Checks for valid userLoginId to get preferences. Returns true if valid.

        This method applies a small rule set to determine if user preferences can be retrieved by the current user:

        • If the user isn't logged in, then the method returns true
        • If the user is logged in and the userPrefLoginId specified in the context Map matches the user's userLoginId, then the method returns true.
        • If the user is logged in and the userPrefLoginId specified in the context Map is different than the user's userLoginId, then a security permission check is performed. If the user has the ADMIN_PERMISSION permission then the method returns true.
        Parameters:
        ctx - The DispatchContext that this service is operating in.
        context - Map containing the input arguments.
        Returns:
        true if the userLoginId arguments are valid
      • isValidSetId

        public static boolean isValidSetId​(DispatchContext ctx,
                                           java.util.Map<java.lang.String,​?> context)
        Checks for valid userLoginId to set preferences. Returns true if valid.

        This method applies a small rule set to determine if user preferences can be set by the current user:

        • If the user isn't logged in, then the method returns false
        • If the user is logged in and the userPrefLoginId specified in the context Map matches the user's userLoginId, then the method returns true.
        • If the user is logged in and the userPrefLoginId specified in the context Map is different than the user's userLoginId, then a security permission check is performed. If the user has the ADMIN_PERMISSION permission then the method returns true.
        Parameters:
        ctx - The DispatchContext that this service is operating in.
        context - Map containing the input arguments.
        Returns:
        true if arguments are valid
      • toFieldMap

        public static java.util.Map<java.lang.String,​java.lang.Object> toFieldMap​(java.lang.String userLoginId,
                                                                                        java.lang.String userPrefTypeId,
                                                                                        java.lang.String userPrefGroupTypeId,
                                                                                        java.lang.Object userPrefValue)
                                                                                 throws GeneralException
        Creates a field Map to be used in GenericValue create or store methods.
        Parameters:
        userLoginId - The user's login ID
        userPrefTypeId - The preference ID
        userPrefGroupTypeId - The preference group ID (may be null or empty)
        userPrefValue - The preference value (will be converted to java.lang.String data type)
        Returns:
        field map
        Throws:
        GeneralException