svn commit: r948697 - in /ofbiz/trunk/framework/common: servicedef/services.xml src/org/ofbiz/common/preferences/PreferenceServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r948697 - in /ofbiz/trunk/framework/common: servicedef/services.xml src/org/ofbiz/common/preferences/PreferenceServices.java

jonesde
Author: jonesde
Date: Thu May 27 07:18:59 2010
New Revision: 948697

URL: http://svn.apache.org/viewvc?rev=948697&view=rev
Log:
Added removeUserPreference service, needed because you can't pass an empty value to the set service to clear out preferences, also this actually removes the record

Modified:
    ofbiz/trunk/framework/common/servicedef/services.xml
    ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java

Modified: ofbiz/trunk/framework/common/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/servicedef/services.xml?rev=948697&r1=948696&r2=948697&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/servicedef/services.xml (original)
+++ ofbiz/trunk/framework/common/servicedef/services.xml Thu May 27 07:18:59 2010
@@ -439,7 +439,14 @@ under the License.
         <attribute name="userPrefGroupTypeId" type="String" mode="IN" optional="true"/>
         <attribute name="userPrefLoginId" type="String" mode="IN" optional="true"/>
     </service>
-
+    <service name="removeUserPreference" engine="java"
+        location="org.ofbiz.common.preferences.PreferenceServices" invoke="removeUserPreference" auth="true">
+        <description>Sets a single user preference.</description>
+        <permission-service service-name="preferenceGetSetPermission" main-action="CREATE"/>
+        <attribute name="userPrefTypeId" type="String" mode="IN" optional="false"/>
+        <attribute name="userPrefLoginId" type="String" mode="IN" optional="true"/>
+    </service>
+    
     <service name="setUserPreferenceGroup" engine="java"
             location="org.ofbiz.common.preferences.PreferenceServices" invoke="setUserPreferenceGroup" auth="true">
         <description>Sets a group of user preferences.</description>

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=948697&r1=948696&r2=948697&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 May 27 07:18:59 2010
@@ -195,6 +195,31 @@ public class PreferenceServices {
         return ServiceUtil.returnSuccess();
     }
 
+    public static Map<String, Object> removeUserPreference(DispatchContext ctx, Map<String, ?> context) {
+        Delegator delegator = ctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+
+        String userLoginId = PreferenceWorker.getUserLoginId(context, false);
+        String userPrefTypeId = (String) context.get("userPrefTypeId");
+        //Debug.logError("In removeUserPreference userLoginId=" + userLoginId + ", userPrefTypeId=" + userPrefTypeId, module);
+        if (UtilValidate.isEmpty(userLoginId) || UtilValidate.isEmpty(userPrefTypeId)) {
+            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "setPreference.invalidArgument", locale));
+        }
+
+        try {
+            GenericValue rec = delegator.findOne("UserPreference",
+                    UtilMisc.toMap("userLoginId", userLoginId, "userPrefTypeId", userPrefTypeId), false);
+            if (rec != null) {
+                rec.remove();
+            }
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e.getMessage(), module);
+            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "setPreference.writeFailure", new Object[] { e.getMessage() }, locale));
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
+
     /**
      * Stores a user preference group in persistent storage. Call with
      * userPrefMap, userPrefGroupTypeId and optional userPrefLoginId. If userPrefLoginId