Permalink
Browse files

Add a small method to the ServiceUtil Class which checks all incoming…

… service attributes and look for fields with the same name in the incoming map and copy those onto the outgoing map. Also includes a userLogin if service requires one.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1447246 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 7f3ddce commit e3ea07f665d3fe6760c343da7ec045e617e4c4f3 Sascha Rodekamp committed Feb 18, 2013
Showing with 38 additions and 1 deletion.
  1. +38 −1 framework/service/src/org/ofbiz/service/ServiceUtil.java
@@ -20,11 +20,11 @@
import java.math.BigDecimal;
import java.sql.Timestamp;
-import com.ibm.icu.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transaction;
@@ -51,6 +51,8 @@
import org.ofbiz.security.Security;
import org.ofbiz.service.config.ServiceConfigUtil;
+import com.ibm.icu.util.Calendar;
+
/**
* Generic Service Utility Class
*/
@@ -685,4 +687,39 @@ private static Locale getLocale(Map<String, ? extends Object> context) {
return ServiceUtil.returnSuccess();
}
+
+ /**
+ * Checks all incoming service attributes and look for fields with the same
+ * name in the incoming map and copy those onto the outgoing map. Also
+ * includes a userLogin if service requires one.
+ *
+ * @param dispatcher
+ * @param serviceName
+ * @param fromMap
+ * @param userLogin
+ * (optional) - will be added to the map if is required
+ * @param timeZone
+ * @param locale
+ * @return filled Map or null on error
+ */
+ public static Map<String, Object> setServiceFields(LocalDispatcher dispatcher, String serviceName, Map<String, Object> fromMap, GenericValue userLogin,
+ TimeZone timeZone, Locale locale) {
+ Map<String, Object> outMap = FastMap.newInstance();
+
+ ModelService modelService = null;
+ try {
+ modelService = dispatcher.getDispatchContext().getModelService(serviceName);
+ } catch (GenericServiceException e) {
+ String errMsg = "Could not get service definition for service name [" + serviceName + "]: ";
+ Debug.logError(e, errMsg, module);
+ return null;
+ }
+ outMap.putAll(modelService.makeValid(fromMap, "IN", true, null, timeZone, locale));
+
+ if (userLogin != null && modelService.auth) {
+ outMap.put("userLogin", userLogin);
+ }
+
+ return outMap;
+ }
}

0 comments on commit e3ea07f

Please sign in to comment.