Author: jacopoc
Date: Mon Jul 9 22:24:32 2007 New Revision: 554828 URL: http://svn.apache.org/viewvc?view=rev&rev=554828 Log: Applied patch (with some differences) by Marco Risaliti to convert a service into an event (part of Google Product interface implementation, OFBIZ-1095) Modified: ofbiz/trunk/applications/product/servicedef/services.xml ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Modified: ofbiz/trunk/applications/product/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?view=diff&rev=554828&r1=554827&r2=554828 ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services.xml Mon Jul 9 22:24:32 2007 @@ -1126,14 +1126,4 @@ <attribute type="String" mode="IN" name="statusId" optional="false"/> <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/> </service> - <service name="searchExportProductListToGoogle" engine="java" - location="org.ofbiz.product.product.ProductSearchEvents" invoke="searchExportProductListToGoogle" auth="true"> - <description>Export products to Google Base</description> - <attribute type="String" mode="IN" name="webSiteUrl" optional="false"/> - <attribute type="String" mode="IN" name="imageUrl" optional="false"/> - <attribute type="String" mode="IN" name="actionType" optional="false"/> - <attribute type="String" mode="IN" name="statusId" optional="false"/> - <attribute type="List" mode="IN" name="selectResult" optional="true"/> - <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/> - </service> </services> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java?view=diff&rev=554828&r1=554827&r2=554828 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java Mon Jul 9 22:24:32 2007 @@ -45,7 +45,6 @@ import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.product.ProductSearch.ProductSearchContext; import org.ofbiz.product.product.ProductSearch.ResultSortOrder; -import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; @@ -454,20 +453,25 @@ return "success"; } - public static Map searchExportProductListToGoogle(DispatchContext dctx, Map context) { - LocalDispatcher dispatcher = dctx.getDispatcher(); - HttpServletRequest request = (HttpServletRequest) context.get("request"); - Locale locale = (Locale)context.get("locale"); - List productExportList = (List) context.get("selectResult"); - + public static String searchExportProductListToGoogle(HttpServletRequest request, HttpServletResponse response) { + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + Locale locale = UtilHttp.getLocale(request); + GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); + String selectResult = (String) request.getParameter("selectResult"); + List productExportList = new ArrayList(); + String errMsg = null; + try { boolean beganTransaction = TransactionUtil.begin(DEFAULT_TX_TIMEOUT); try { - if (UtilValidate.isEmpty(productExportList)) { + if (UtilValidate.isEmpty(selectResult)) { // If the passed list of product ids is empty, get the list from the search parameters in the request EntityListIterator eli = getProductSearchResults(request); if (eli == null) { - return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsearchevents.no_results_found_probably_error_constraints", locale)); + errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request)); + Debug.logError(errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; } GenericValue searchResultView = null; @@ -475,34 +479,53 @@ productExportList.add(searchResultView.getString("mainProductId")); } eli.close(); + } else { + productExportList = UtilMisc.toList(selectResult); } - String webSiteUrl = (String)context.get("webSiteUrl"); - String imageUrl = (String)context.get("imageUrl"); - String actionType = (String)context.get("actionType"); - String statusId = (String)context.get("statusId"); - String trackingCodeId = (String)context.get("trackingCodeId"); + String webSiteUrl = (String) request.getParameter("webSiteUrl"); + String imageUrl = (String) request.getParameter("imageUrl"); + String actionType = (String) request.getParameter("actionType"); + String statusId = (String) request.getParameter("statusId"); + String trackingCodeId = (String) request.getParameter("trackingCodeId"); - // Export all the products to Google Base + // Export all or selected products to Google Base try { - Map exportResult = dispatcher.runSync("exportProductsToGoogle", UtilMisc.toMap("selectResult", productExportList, "webSiteUrl", webSiteUrl, - "imageUrl", imageUrl, "actionType", actionType, "statusId", statusId, "trackingCodeId", trackingCodeId)); + Map inMap = UtilMisc.toMap("selectResult", productExportList, + "webSiteUrl", webSiteUrl, + "imageUrl", imageUrl, + "actionType", actionType, + "statusId", statusId, + "trackingCodeId", trackingCodeId); + inMap.put("userLogin", userLogin); + Map exportResult = dispatcher.runSync("exportToGoogle", inMap); if (ServiceUtil.isError(exportResult)) { - return ServiceUtil.returnError(ServiceUtil.getErrorMessage(exportResult)); + errMsg = ServiceUtil.getErrorMessage(exportResult); + Debug.logError(errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; } } catch (GenericServiceException e) { - Debug.logError(e, "Exception calling exportToGoogle", module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, "productsearchevents.exceptionCallingExportToGoogle", locale)); + errMsg = UtilProperties.getMessage(resource, "productsearchevents.exceptionCallingExportToGoogle", locale); + Debug.logError(e, errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; } } catch (GenericEntityException e) { - return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", locale)); + errMsg = UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", locale); + Debug.logError(e, errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; } finally { TransactionUtil.commit(beganTransaction); } } catch (GenericTransactionException e) { - return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", locale)); + errMsg = UtilProperties.getMessage(resource, "productsearchevents.error_getting_search_results", locale); + Debug.logError(e, errMsg, module); + request.setAttribute("_ERROR_MESSAGE_", errMsg); + return "error"; } - - return ServiceUtil.returnSuccess(); + + return "success"; } public static EntityListIterator getProductSearchResults(HttpServletRequest request) { Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml?view=diff&rev=554828&r1=554827&r2=554828 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml (original) +++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Mon Jul 9 22:24:32 2007 @@ -2387,7 +2387,7 @@ <request-map uri="searchExportProductListToGoogle"> <security https="true" auth="true"/> - <event type="service" path="" invoke="searchExportProductListToGoogle"/> + <event type="java" path="org.ofbiz.product.product.ProductSearchEvents" invoke="searchExportProductListToGoogle"/> <response name="success" type="view" value="ProductsExportToGoogle"/> <response name="error" type="view" value="ProductsExportToGoogle"/> </request-map> |
Free forum by Nabble | Edit this page |