You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Adrian Crum <ad...@sandglass-software.com> on 2013/02/18 14:47:31 UTC

Re: svn commit: r1447246 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java

Please don't hide thrown exceptions. Calling code needs to know if 
something went wrong.

-Adrian

On 2/18/2013 1:26 PM, sascharodekamp@apache.org wrote:
> Author: sascharodekamp
> Date: Mon Feb 18 13:26:00 2013
> New Revision: 1447246
>
> URL: http://svn.apache.org/r1447246
> Log:
> 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.
>
> Modified:
>      ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
>
> Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=1447246&r1=1447245&r2=1447246&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
> +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Mon Feb 18 13:26:00 2013
> @@ -20,11 +20,11 @@ package org.ofbiz.service;
>   
>   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.entity.util.EntityListI
>   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 @@ public class ServiceUtil {
>   
>           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;
> +    }
>   }
>
>