Author: hansbak
Date: Thu Jul 3 06:12:31 2008
New Revision: 673671
URL:
http://svn.apache.org/viewvc?rev=673671&view=revLog:
copy usersettings from a template if not found for a certain user
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java?rev=673671&r1=673670&r2=673671&view=diff==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java Thu Jul 3 06:12:31 2008
@@ -35,6 +35,7 @@
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceUtil;
/**
@@ -112,6 +113,7 @@
*/
public static Map<String, Object> getUserPreferenceGroup(DispatchContext ctx, Map<String, ?> context) {
GenericDelegator delegator = ctx.getDelegator();
+ LocalDispatcher dispatcher = ctx.getDispatcher();
Locale locale = (Locale) context.get("locale");
String userPrefGroupId = (String) context.get("userPrefGroupId");
@@ -124,6 +126,13 @@
try {
Map<String, String> fieldMap = UtilMisc.toMap("userLoginId", userLoginId, "userPrefGroupId", userPrefGroupId);
userPrefMap = PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference", fieldMap));
+
+ // if preference map not found, copy from the "_NA_" userlogin being the default settings
+ if (UtilValidate.isEmpty(userPrefMap)) {
+ dispatcher.runSync("copyUserPrefGroup", UtilMisc.toMap("userLogin", context.get("userLogin"), "fromUserLoginId", "_NA_", "userPrefGroupId", userPrefGroupId));
+ userPrefMap = PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference", fieldMap));
+ }
+
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "getPreference.readFailure", new Object[] { e.getMessage() }, locale));