details: https://code.openbravo.com/erp/devel/pi/rev/25be130e6d5e changeset: 34214:25be130e6d5e user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Tue Jun 19 16:54:43 2018 +0200 summary: Fixes issue 38703: Add a hook in Convert Quotation Into Order process
diffstat: src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHook.java | 40 +++++ src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHookManager.java | 78 ++++++++++ src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java | 12 + 3 files changed, 130 insertions(+), 0 deletions(-) diffs (161 lines): diff -r de5ea8bf7fce -r 25be130e6d5e src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHook.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHook.java Tue Jun 19 16:54:43 2018 +0200 @@ -0,0 +1,40 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2018 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.common.hooks; + +import org.openbravo.model.common.order.Order; + +public abstract class ConvertQuotationIntoOrderHook { + public static final String CONVERT_QUOTATION_INTO_ORDER_HOOK_QUALIFIER = "ConvertQuotationIntoOrderHookQualifier"; + + /** + * Returns the order when the concrete hook will be executed. + */ + public abstract int getOrder(); + + /** + * Executes the hook logic on the ConvertQuotationIntoOrder process + * + * @param order + * the order document with lines we are creating from Quotation + */ + public abstract void exec(Order order); + +} diff -r de5ea8bf7fce -r 25be130e6d5e src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHookManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openbravo/common/hooks/ConvertQuotationIntoOrderHookManager.java Tue Jun 19 16:54:43 2018 +0200 @@ -0,0 +1,78 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SLU + * All portions are Copyright (C) 2018 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.common.hooks; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Any; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import org.openbravo.client.kernel.ComponentProvider; +import org.openbravo.model.common.order.Order; + +@ApplicationScoped +public class ConvertQuotationIntoOrderHookManager { + @Inject + @Any + private Instance<ConvertQuotationIntoOrderHook> convertQuotationIntoOrderHooks; + + /** + * Executes hook list + * + * @param order + * the order document with lines we are creating from Quotation + * */ + public void executeHooks(Order order) { + if (convertQuotationIntoOrderHooks != null) { + final List<ConvertQuotationIntoOrderHook> hooks = new ArrayList<>(); + for (ConvertQuotationIntoOrderHook hook : convertQuotationIntoOrderHooks + .select(new ComponentProvider.Selector( + ConvertQuotationIntoOrderHook.CONVERT_QUOTATION_INTO_ORDER_HOOK_QUALIFIER))) { + if (hook != null) { + hooks.add(hook); + } + } + + Collections.sort(hooks, new ConvertQuotationIntoOrderHookComparator()); + for (ConvertQuotationIntoOrderHook hook : hooks) { + hook.exec(order); + } + } + } + + private class ConvertQuotationIntoOrderHookComparator implements + Comparator<ConvertQuotationIntoOrderHook> { + @Override + public int compare(final ConvertQuotationIntoOrderHook a, final ConvertQuotationIntoOrderHook b) { + if (a.getOrder() < b.getOrder()) { + return -1; + } else if (a.getOrder() == b.getOrder()) { + return 0; + } else { + return 1; + } + } + } +} diff -r de5ea8bf7fce -r 25be130e6d5e src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java --- a/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java Thu Jun 14 19:20:21 2018 -0400 +++ b/src/org/openbravo/erpCommon/ad_process/ConvertQuotationIntoOrder.java Tue Jun 19 16:54:43 2018 +0200 @@ -37,7 +37,9 @@ import org.openbravo.base.exception.OBException; import org.openbravo.base.provider.OBProvider; import org.openbravo.base.secureApp.VariablesSecureApp; +import org.openbravo.base.weld.WeldUtils; import org.openbravo.client.kernel.RequestContext; +import org.openbravo.common.hooks.ConvertQuotationIntoOrderHookManager; import org.openbravo.dal.core.DalUtil; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBDal; @@ -278,6 +280,9 @@ OBDal.getInstance().flush(); OBDal.getInstance().refresh(newSalesOrder); + // Hook entry point + executeHooks(newSalesOrder); + // If prices are going to be recalculated, call C_Order_Post callCOrderPost(newSalesOrder, recalculatePrices); OBDal.getInstance().flush(); @@ -477,4 +482,11 @@ return olDiscount; } + private void executeHooks(Order salesOrder) { + ConvertQuotationIntoOrderHookManager manager = WeldUtils + .getInstanceFromStaticBeanManager(ConvertQuotationIntoOrderHookManager.class); + + manager.executeHooks(salesOrder); + } + } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits