Author: mrisaliti
Date: Mon Feb 18 14:07:26 2008 New Revision: 628882 URL: http://svn.apache.org/viewvc?rev=628882&view=rev Log: Create a new service to storeQuote in a single transaction like storeOrder (Part of issue OFBIZ-1657) Modified: ofbiz/trunk/applications/order/servicedef/services_quote.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/quote/QuoteServices.java Modified: ofbiz/trunk/applications/order/servicedef/services_quote.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_quote.xml?rev=628882&r1=628881&r2=628882&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_quote.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_quote.xml Mon Feb 18 14:07:26 2008 @@ -224,4 +224,12 @@ <attribute name="note" type="String" mode="IN" optional="true"/> <attribute name="body" type="String" mode="OUT" optional="true"/> </service> + <service name="storeQuote" engine="java" default-entity-name="Quote" validate="true" auth="true" + location="org.ofbiz.order.quote.QuoteServices" invoke="storeQuote"> + <description>Creates quote entities</description> + <auto-attributes include="nonpk" mode="IN" optional="true"/> + <attribute name="quoteItems" type="List" mode="IN" optional="true"/> + <attribute name="quoteAttributes" type="List" mode="IN" optional="true"/> + <attribute name="quoteId" type="String" mode="OUT" optional="false"/> + </service> </services> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/quote/QuoteServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/quote/QuoteServices.java?rev=628882&r1=628881&r2=628882&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/quote/QuoteServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/quote/QuoteServices.java Mon Feb 18 14:07:26 2008 @@ -18,6 +18,9 @@ *******************************************************************************/ package org.ofbiz.order.quote; +import java.sql.Timestamp; +import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -33,6 +36,7 @@ import org.ofbiz.service.DispatchContext; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; +import org.ofbiz.service.GenericServiceException; public class QuoteServices { @@ -125,4 +129,77 @@ return sendResp; } -} + public static Map storeQuote(DispatchContext dctx, Map context) { + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + + String quoteTypeId = (String) context.get("quoteTypeId"); + String partyId = (String) context.get("partyId"); + Timestamp issueDate = (Timestamp) context.get("issueDate"); + String statusId = (String) context.get("statusId"); + String currencyUomId = (String) context.get("currencyUomId"); + String productStoreId = (String) context.get("productStoreId"); + String salesChannelEnumId = (String) context.get("salesChannelEnumId"); + Timestamp validFromDate = (Timestamp) context.get("validFromDate"); + Timestamp validThruDate = (Timestamp) context.get("validThruDate"); + String quoteName = (String) context.get("quoteName"); + String description = (String) context.get("description"); + List quoteItems = (List) context.get("quoteItems"); + List quoteAttributes = (List) context.get("quoteAttributes"); + + + Map result = FastMap.newInstance(); + + try { + Map quoteIn = UtilMisc.toMap("quoteTypeId", quoteTypeId, "partyId", partyId, "issueDate", issueDate, "statusId", statusId, "currencyUomId", currencyUomId); + quoteIn.put("productStoreId", productStoreId); + quoteIn.put("salesChannelEnumId", salesChannelEnumId); + quoteIn.put("productStoreId", productStoreId); + quoteIn.put("validFromDate", validFromDate); + quoteIn.put("validThruDate", validThruDate); + quoteIn.put("quoteName", quoteName); + quoteIn.put("description", description); + quoteIn.put("userLogin", userLogin); + + // create Quote + Map quoteOut = dispatcher.runSync("createQuote", quoteIn); + + if (UtilValidate.isNotEmpty(quoteOut) && UtilValidate.isNotEmpty(quoteOut.get("quoteId"))) { + String quoteId = (String)quoteOut.get("quoteId"); + result.put("quoteId", quoteId); + + // create Quote Items + if (UtilValidate.isNotEmpty(quoteItems)) { + Iterator quoteIt = quoteItems.iterator(); + while (quoteIt.hasNext()) { + GenericValue quoteItem = (GenericValue)quoteIt.next(); + quoteItem.set("quoteId", quoteId); + Map quoteItemIn = UtilMisc.toMap(quoteItem); + quoteItemIn.put("userLogin", userLogin); + + dispatcher.runSync("createQuoteItem", quoteItemIn); + } + } + + // create Quote Attributes + if (UtilValidate.isNotEmpty(quoteAttributes)) { + Iterator quoteAttrIt = quoteAttributes.iterator(); + while (quoteAttrIt.hasNext()) { + GenericValue quoteAttr = (GenericValue)quoteAttrIt.next(); + quoteAttr.set("quoteId", quoteId); + Map quoteAttrIn = UtilMisc.toMap(quoteAttr); + quoteAttrIn.put("userLogin", userLogin); + + dispatcher.runSync("createQuoteAttribute", quoteAttrIn); + } + } + } else { + return ServiceUtil.returnFailure("Could not storing Quote"); + } + } catch (GenericServiceException e) { + Debug.logError(e, "Problem storing Quote", module); + } + + return result; + } +} \ No newline at end of file |
Free forum by Nabble | Edit this page |