org.ofbiz.common.preferences
Class PreferenceWorker

java.lang.Object
  extended by org.ofbiz.common.preferences.PreferenceWorker

public class PreferenceWorker
extends java.lang.Object

User preference worker methods.


Field Summary
static java.lang.String ADMIN_PERMISSION
          User preference administrator permission.
static java.lang.String DEFAULT_UID
          Default userLoginId.
static java.lang.String LOGINID_PARAMETER_NAME
          User login ID parameter name.
static java.lang.String module
           
 
Constructor Summary
PreferenceWorker()
           
 
Method Summary
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(GenericValue rec)
          Convert a UserPreference GenericValue to a userPrefMap.
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.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
 

Field Detail

module

public static final java.lang.String module

ADMIN_PERMISSION

public static final java.lang.String ADMIN_PERMISSION
User preference administrator permission. Currently set to "USERPREF_ADMIN".

See Also:
Constant Field Values

LOGINID_PARAMETER_NAME

public static final java.lang.String LOGINID_PARAMETER_NAME
User login ID parameter name. Currently set to "userPrefLoginId". This parameter name is used in preference service definitions to specify a user login ID that is different than the currently logged in user.

See Also:
Constant Field Values

DEFAULT_UID

public static final java.lang.String DEFAULT_UID
Default userLoginId. Currently set to "_NA_". This userLoginId is used to retrieve default preferences when the user is not logged in.

See Also:
Constant Field Values
Constructor Detail

PreferenceWorker

public PreferenceWorker()
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:

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:

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