Class PreferenceWorker
java.lang.Object
org.apache.ofbiz.common.preferences.PreferenceWorker
User preference worker methods.
-
Method Summary
Modifier and TypeMethodDescriptionaddPrefToMap
(GenericValue rec, Map<String, Object> userPrefMap) Add a UserPreference GenericValue to a Map.checkCopyPermission
(DispatchContext ctx, Map<String, ?> context) Checks preference copy permissions.checkPermission
(DispatchContext ctx, Map<String, ?> context) Checks preference get/set permissions.createUserPrefMap
(List<GenericValue> recList) Convert a List of UserPreference GenericValues to a userPrefMap.Convert a UserPreference GenericValue to a userPrefMap.static String
getUserLoginId
(Map<String, ?> context, boolean returnDefault) Gets a valid userLoginId parameter from the context Map.static boolean
isValidGetId
(DispatchContext ctx, Map<String, ?> context) Checks for valid userLoginId to get preferences.static boolean
isValidSetId
(DispatchContext ctx, Map<String, ?> context) Checks for valid userLoginId to set preferences.toFieldMap
(String userLoginId, String userPrefTypeId, String userPrefGroupTypeId, Object userPrefValue) Creates a field Map to be used in GenericValue create or store methods.
-
Method Details
-
addPrefToMap
public static Map<String,Object> addPrefToMap(GenericValue rec, Map<String, Object> userPrefMap) throws GeneralExceptionAdd a UserPreference GenericValue to a Map.- Parameters:
rec
- GenericValue to convertuserPrefMap
- user preference Map- Returns:
- user preference map
- Throws:
GeneralException
-
checkCopyPermission
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
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
Convert a UserPreference GenericValue to a userPrefMap.- Parameters:
rec
- GenericValue to convert- Returns:
- user preference map
- Throws:
GeneralException
-
createUserPrefMap
public static Map<String,Object> createUserPrefMap(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
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
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
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 Map<String,Object> toFieldMap(String userLoginId, String userPrefTypeId, String userPrefGroupTypeId, Object userPrefValue) throws GeneralException Creates a field Map to be used in GenericValue create or store methods.- Parameters:
userLoginId
- The user's login IDuserPrefTypeId
- The preference IDuserPrefGroupTypeId
- 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
-