diff --git a/org.adempiere.base/META-INF/MANIFEST.MF b/org.adempiere.base/META-INF/MANIFEST.MF index 1a07bdf726..4caadf80e9 100644 --- a/org.adempiere.base/META-INF/MANIFEST.MF +++ b/org.adempiere.base/META-INF/MANIFEST.MF @@ -21,8 +21,14 @@ Export-Package: bsh, it.sauronsoftware.cron4j, org.adempiere.apps.graph, org.adempiere.base, + org.adempiere.base.ds, org.adempiere.base.equinox, org.adempiere.base.event, + org.adempiere.base.event.annotations, + org.adempiere.base.event.annotations.doc, + org.adempiere.base.event.annotations.imp, + org.adempiere.base.event.annotations.po, + org.adempiere.base.event.annotations.process, org.adempiere.exceptions, org.adempiere.impexp, org.adempiere.model, diff --git a/org.adempiere.base/src/org/adempiere/base/Core.java b/org.adempiere.base/src/org/adempiere/base/Core.java index 48bb1afc2d..268f68d8b0 100644 --- a/org.adempiere.base/src/org/adempiere/base/Core.java +++ b/org.adempiere.base/src/org/adempiere/base/Core.java @@ -29,6 +29,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; +import org.adempiere.base.event.IEventManager; import org.adempiere.model.IAddressValidation; import org.adempiere.model.IShipmentProcessor; import org.adempiere.model.ITaxProvider; @@ -1024,4 +1025,26 @@ public class Core { } return factoryService; } + + private static IServiceReferenceHolder s_eventManagerReference = null; + + /** + * + * @return {@link IEventManager} + */ + public static IEventManager getEventManager() { + IEventManager eventManager = null; + if (s_eventManagerReference != null) { + eventManager = s_eventManagerReference.getService(); + if (eventManager != null) + return eventManager; + } + IServiceReferenceHolder serviceReference = Service.locator().locate(IEventManager.class).getServiceReference(); + if (serviceReference != null) { + eventManager = serviceReference.getService(); + s_eventManagerReference = serviceReference; + } + + return eventManager; + } } diff --git a/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java index 955acc9f8e..9d049627d0 100644 --- a/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java +++ b/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java @@ -13,7 +13,6 @@ *****************************************************************************/ package org.adempiere.base.event; -import java.util.List; import java.util.UUID; import org.compiere.model.PO; @@ -127,7 +126,7 @@ public abstract class AbstractEventHandler implements EventHandler { * @return PO */ protected PO getPO(Event event) { - return getEventProperty(event, IEventManager.EVENT_DATA); + return EventHelper.getPO(event); } /** @@ -135,7 +134,7 @@ public abstract class AbstractEventHandler implements EventHandler { * @return ProcessInfo */ protected ProcessInfo getProcessInfo(Event event) { - return getEventProperty(event, IEventManager.EVENT_DATA); + return EventHelper.getProcessInfo(event); } /** @@ -144,7 +143,7 @@ public abstract class AbstractEventHandler implements EventHandler { * @param event */ protected T getEventData(Event event) { - return getEventProperty(event, IEventManager.EVENT_DATA); + return EventHelper.getEventData(event); } /** @@ -153,9 +152,8 @@ public abstract class AbstractEventHandler implements EventHandler { * @param event * @param property */ - @SuppressWarnings("unchecked") protected T getEventProperty(Event event, String property) { - return (T) event.getProperty(property); + return EventHelper.getEventProperty(event, property); } /** @@ -163,10 +161,7 @@ public abstract class AbstractEventHandler implements EventHandler { * @param e */ protected void addError(Event event, Throwable e) { - String msg = e.getLocalizedMessage(); - if (msg == null) - msg = e.toString(); - addErrorMessage(event, msg); + EventHelper.addError(event, e); } /** @@ -174,8 +169,6 @@ public abstract class AbstractEventHandler implements EventHandler { * @param errorMessage */ protected void addErrorMessage(Event event, String errorMessage) { - List errors = getEventProperty(event, IEventManager.EVENT_ERROR_MESSAGES); - if (errors != null) - errors.add(errorMessage); + EventHelper.addErrorMessage(event, errorMessage); } } diff --git a/org.adempiere.base/src/org/adempiere/base/event/EventHelper.java b/org.adempiere.base/src/org/adempiere/base/event/EventHelper.java new file mode 100644 index 0000000000..ca4f38d13e --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/EventHelper.java @@ -0,0 +1,107 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event; + +import java.util.List; + +import org.compiere.model.PO; +import org.compiere.process.ProcessInfo; +import org.osgi.service.event.Event; + +/** + * Helper methods for event handler + * @author hengsin + */ +public final class EventHelper { + + /** + * private constructor + */ + private EventHelper() { + } + + /** + * @param event + * @return PO + */ + public static PO getPO(Event event) { + PO po = null; + Object data = getEventData(event); + if (data instanceof PO) + po = (PO)data; + else if (data instanceof POEventData) + po = ((POEventData) data).getPo(); + return po; + } + + /** + * @param event + * @return ProcessInfo + */ + public static ProcessInfo getProcessInfo(Event event) { + return getEventProperty(event, IEventManager.EVENT_DATA); + } + + /** + * + * @param + * @param event + */ + public static T getEventData(Event event) { + return getEventProperty(event, IEventManager.EVENT_DATA); + } + + /** + * + * @param + * @param event + * @param property + */ + @SuppressWarnings("unchecked") + public static T getEventProperty(Event event, String property) { + return (T) event.getProperty(property); + } + + /** + * @param event + * @param e + */ + public static void addError(Event event, Throwable e) { + String msg = e.getLocalizedMessage(); + if (msg == null) + msg = e.toString(); + addErrorMessage(event, msg); + } + + /** + * @param event + * @param errorMessage + */ + public static void addErrorMessage(Event event, String errorMessage) { + List errors = getEventProperty(event, IEventManager.EVENT_ERROR_MESSAGES); + if (errors != null) + errors.add(errorMessage); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/FactsEventData.java b/org.adempiere.base/src/org/adempiere/base/event/FactsEventData.java index 014eb58ae2..2bb920980d 100644 --- a/org.adempiere.base/src/org/adempiere/base/event/FactsEventData.java +++ b/org.adempiere.base/src/org/adempiere/base/event/FactsEventData.java @@ -24,7 +24,7 @@ import org.compiere.model.PO; * @author hengsin * */ -public class FactsEventData { +public class FactsEventData implements POEventData { private MAcctSchema acctSchema; private List facts; private PO po; diff --git a/org.adempiere.base/src/org/adempiere/base/event/IEventManager.java b/org.adempiere.base/src/org/adempiere/base/event/IEventManager.java index e337830e12..99b29fec86 100644 --- a/org.adempiere.base/src/org/adempiere/base/event/IEventManager.java +++ b/org.adempiere.base/src/org/adempiere/base/event/IEventManager.java @@ -13,6 +13,7 @@ *****************************************************************************/ package org.adempiere.base.event; +import org.adempiere.base.event.annotations.BaseEventHandler; import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; @@ -25,6 +26,11 @@ public interface IEventManager { public static final String EVENT_DATA = "event.data"; public static final String EVENT_ERROR_MESSAGES = "event.errorMessages"; + public static final String IMPORT_TABLE_NAME_PROPERTY = "importTableName"; + public static final String TABLE_NAME_PROPERTY = "tableName"; + public static final String PROCESS_UID_PROPERTY = "processUUID"; + public static final String CLASS_NAME_PROPERTY = "className"; + public static final String PROCESS_CLASS_NAME_PROPERTY = "processClassName"; /** * Initiate asynchronous delivery of an event. This method returns to the @@ -94,5 +100,14 @@ public interface IEventManager { * @return true if unregistration is done, false otherwise */ public abstract boolean unregister(EventHandler eventHandler); + + /** + * + * @param eventHandler + * @return + */ + public default boolean register(BaseEventHandler eventHandler) { + return register(eventHandler.getTopics(), eventHandler.getFilter(), eventHandler); + } } \ No newline at end of file diff --git a/org.adempiere.base/src/org/adempiere/base/event/POEventData.java b/org.adempiere.base/src/org/adempiere/base/event/POEventData.java new file mode 100644 index 0000000000..25493c0701 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/POEventData.java @@ -0,0 +1,40 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event; + +import org.compiere.model.PO; + +/** + * + * Event data that contains PO + * @author hengsin + * + */ +public interface POEventData { + /** + * @return {@link PO} + */ + public PO getPo(); +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoadPref.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoadPref.java new file mode 100644 index 0000000000..87d9ea8e9d --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoadPref.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PREF_AFTER_LOAD) +/** + * + * @author hengsin + * + */ +public @interface AfterLoadPref { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLogin.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLogin.java new file mode 100644 index 0000000000..78fbd2f430 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLogin.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.AFTER_LOGIN) +/** + * + * @author hengsin + * + */ +public @interface AfterLogin { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoginEventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoginEventDelegate.java new file mode 100644 index 0000000000..ad1ed275f4 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/AfterLoginEventDelegate.java @@ -0,0 +1,63 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.LoginEventData; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public abstract class AfterLoginEventDelegate extends EventDelegate { + + /** + * @param event + */ + public AfterLoginEventDelegate(Event event) { + super(event); + } + + /** + * + * @return {@link LoginEventData} + */ + protected LoginEventData getLoginEventData() { + return EventHelper.getEventData(event); + } + + @AfterLogin + public final void onEvent() { + onAfterLogin(getLoginEventData()); + } + + /** + * override this to handle after login event + * @param data + */ + protected abstract void onAfterLogin(LoginEventData data); +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/BaseEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/BaseEventHandler.java new file mode 100644 index 0000000000..15cc17ec49 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/BaseEventHandler.java @@ -0,0 +1,157 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.adempiere.base.event.EventHelper; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +/** + * + * Base class for event handler that works with annotation driven event delegate. + * The implementation of event delegate doesn't have to be thread safe as a new instance of delegate is created for each event call. + * @author hengsin + * + */ +public abstract class BaseEventHandler implements EventHandler { + + //event topic to method mapping + protected final Map eventTopicMap = new HashMap(); + private String filter; + + /** + * + * @param delegateClass + */ + public BaseEventHandler(Class delegateClass) { + filter = null; + createTopicMap(delegateClass); + } + + /** + * create event to topic to method mapping from annotations + * @param delegateClass + */ + protected void createTopicMap(Class delegateClass) { + Method[] methods = delegateClass.getMethods(); + for(Method method : methods) { + if (method.isBridge()) + continue; + Annotation[] annotations = method.getAnnotations(); + for (Annotation annotation : annotations) { + if (annotation.annotationType().isAnnotationPresent(EventTopic.class)) { + String topic = annotation.annotationType().getAnnotation(EventTopic.class).topic(); + if (!eventTopicMap.containsKey(topic)) { + method.setAccessible(true); + eventTopicMap.put(topic, method); + } + } + } + } + } + + /** + * + * @return arrays of event topic + */ + public String[] getTopics() { + String[] topics = null; + if (!eventTopicMap.isEmpty()) + topics = eventTopicMap.keySet().toArray(new String[0]); + return topics; + } + + /** + * + * @return event filter + */ + public String getFilter() { + return filter; + } + + /** + * set event filter + * @param filter + */ + public void setFilter(String filter) { + this.filter = filter; + } + + /** + * + * @param propertyName + * @param value + */ + public void setEventPropertyFilter(String propertyName, String value) { + StringBuilder builder = new StringBuilder(); + builder.append("(") + .append(propertyName) + .append("=") + .append(value) + .append(")"); + setFilter(builder.toString()); + } + + @Override + public void handleEvent(Event event) { + Method method = eventTopicMap.get(event.getTopic()); + if (method != null) { + try { + EventDelegate delegate = newEventDelegate(event); + method.invoke(delegate); + } catch (RuntimeException e) { + EventHelper.addError(event, e); + throw e; + } catch (Exception e) { + Throwable t = e; + if (e.getCause() != null) + t = e.getCause(); + EventHelper.addError(event, t); + if (t instanceof RuntimeException) + throw (RuntimeException)t; + else + throw new RuntimeException(t); + } catch (Error e) { + EventHelper.addError(event, e); + throw e; + } catch (Throwable e) { + EventHelper.addError(event, e); + throw new Error(e); + } + } + } + + /** + * create new instance of event delegate + * @param event + * @return {@link EventDelegate} + */ + protected abstract EventDelegate newEventDelegate(Event event); +} \ No newline at end of file diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/BroadcastMsg.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/BroadcastMsg.java new file mode 100644 index 0000000000..c7cad53eff --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/BroadcastMsg.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.BROADCAST_MESSAGE) +/** + * + * @author hengsin + * + */ +public @interface BroadcastMsg { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/EventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/EventDelegate.java new file mode 100644 index 0000000000..f0b515d673 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/EventDelegate.java @@ -0,0 +1,56 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import org.osgi.service.event.Event; + +/** + * + * Annotation driven event delegate base class that works together with {@link BaseEventHandler}. + * Subclass implementation doesn't have to be thread safe as event delegate is create and throw away for each event call. + * @author hengsin + * + */ +public class EventDelegate { + + protected Event event; + + /** + * + * @param event + */ + public EventDelegate(Event event) { + this.event = event; + } + + /** + * + * @return {@link Event} + */ + protected Event getEvent() { + return event; + } + +} \ No newline at end of file diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/EventTopic.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/EventTopic.java new file mode 100644 index 0000000000..6dd048da6e --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/EventTopic.java @@ -0,0 +1,43 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target({ METHOD, ANNOTATION_TYPE }) +/** + * + * @author hengsin + * + */ +public @interface EventTopic { + String topic(); +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventDelegate.java new file mode 100644 index 0000000000..0104e796b6 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventDelegate.java @@ -0,0 +1,58 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import org.compiere.model.PO; +import org.osgi.service.event.Event; + +/** + * + * event delegate for PO related event (po_before_change, doc_before_complete, etc) + * @author hengsin + * + * @param + */ +public class ModelEventDelegate extends EventDelegate { + + private T model; + + /** + * + * @param po + * @param event + */ + public ModelEventDelegate(T po, Event event) { + super(event); + this.model = po; + } + + /** + * + * @return po model (mbpartner, morder, etc) + */ + protected T getModel() { + return model; + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventHandler.java new file mode 100644 index 0000000000..7c3b882544 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/ModelEventHandler.java @@ -0,0 +1,90 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import java.lang.reflect.Field; +import java.util.function.BiFunction; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.EventManager; +import org.compiere.model.PO; +import org.osgi.service.event.Event; + +/** + * + * Event handler for PO related events (po_before_change, doc_before_complete, etc). + * Delegate to {@link ModelEventDelegate} instance created for each event call + * @author hengsin + * + */ +public final class ModelEventHandler extends BaseEventHandler { + + private Class modelClassType; + private String tableName; + private BiFunction> supplier; + + /** + * @param modelClassType + */ + public ModelEventHandler(Class modelClassType, Class> delegateClass, + BiFunction> supplier) { + super(delegateClass); + this.supplier = supplier; + this.modelClassType = modelClassType; + findTableName(); + } + + private void findTableName() { + try { + Field field = modelClassType.getField("Table_Name"); + this.tableName = (String) field.get(null); + setEventPropertyFilter(EventManager.TABLE_NAME_PROPERTY, tableName); + } catch (Exception e) { + if (e instanceof RuntimeException) + throw (RuntimeException)e; + else + throw new RuntimeException(e); + } + } + + @Override + public void handleEvent(Event event) { + PO po = EventHelper.getPO(event); + if (po == null || modelClassType == null) + return; + + if (!modelClassType.isAssignableFrom(po.getClass())) + return; + + super.handleEvent(event); + } + + @SuppressWarnings("unchecked") + @Override + protected EventDelegate newEventDelegate(Event event) { + PO po = EventHelper.getPO(event); + return supplier.apply((T)po, event); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEMail.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEMail.java new file mode 100644 index 0000000000..53a6b9805a --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEMail.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.REQUEST_SEND_EMAIL) +/** + * + * @author hengsin + * + */ +public @interface RequestSendEMail { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEmailEventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEmailEventDelegate.java new file mode 100644 index 0000000000..9a888dfeeb --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/RequestSendEmailEventDelegate.java @@ -0,0 +1,64 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.RequestSendEMailEventData; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public abstract class RequestSendEmailEventDelegate extends EventDelegate { + + /** + * + * @param event + */ + public RequestSendEmailEventDelegate(Event event) { + super(event); + } + + /** + * + * @return {@link RequestSendEMailEventData} + */ + protected RequestSendEMailEventData getEventData() { + return EventHelper.getEventData(event); + } + + @RequestSendEMail + public final void onEvent() { + onRequestSendEmail(getEventData()); + } + + /** + * Override this to handle event + * @param requestSendEMailEventData + */ + protected abstract void onRequestSendEmail(RequestSendEMailEventData requestSendEMailEventData); +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/SimpleEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/SimpleEventHandler.java new file mode 100644 index 0000000000..bfb40297f1 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/SimpleEventHandler.java @@ -0,0 +1,55 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations; + +import java.util.function.Function; + +import org.osgi.service.event.Event; + +/** + * + * Event handler that delegate to {@link EventDelegate} instance (create for each event call) + * @author hengsin + * + */ +public final class SimpleEventHandler extends BaseEventHandler { + + private Function supplier; + + /** + * + * @param delegateClass + * @param supplier + */ + public SimpleEventHandler(Class delegateClass, Function supplier) { + super(delegateClass); + this.supplier = supplier; + } + + @Override + protected EventDelegate newEventDelegate(Event event) { + return supplier.apply(event); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterClose.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterClose.java new file mode 100644 index 0000000000..79b7344903 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterClose.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_CLOSE) +/** + * + * @author hengsin + * + */ +public @interface AfterClose { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterComplete.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterComplete.java new file mode 100644 index 0000000000..334bd8f284 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterComplete.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_COMPLETE) +/** + * + * @author hengsin + * + */ +public @interface AfterComplete { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPost.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPost.java new file mode 100644 index 0000000000..1f02c4b5b9 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPost.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_POST) +/** + * + * @author hengsin + * + */ +public @interface AfterPost { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPrepare.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPrepare.java new file mode 100644 index 0000000000..5ee86bad23 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterPrepare.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_PREPARE) +/** + * + * @author hengsin + * + */ +public @interface AfterPrepare { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReactivate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReactivate.java new file mode 100644 index 0000000000..1c20700b08 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReactivate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_REACTIVATE) +/** + * + * @author hengsin + * + */ +public @interface AfterReactivate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseAccrual.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseAccrual.java new file mode 100644 index 0000000000..de437dc922 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseAccrual.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_REVERSEACCRUAL) +/** + * + * @author hengsin + * + */ +public @interface AfterReverseAccrual { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseCorrect.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseCorrect.java new file mode 100644 index 0000000000..d3312b34d6 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterReverseCorrect.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_REVERSECORRECT) +/** + * + * @author hengsin + * + */ +public @interface AfterReverseCorrect { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterVoid.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterVoid.java new file mode 100644 index 0000000000..4cf9c6c9b7 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/AfterVoid.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_AFTER_VOID) +/** + * + * @author hengsin + * + */ +public @interface AfterVoid { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeClose.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeClose.java new file mode 100644 index 0000000000..fec5518b79 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeClose.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_CLOSE) +/** + * + * @author hengsin + * + */ +public @interface BeforeClose { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeComplete.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeComplete.java new file mode 100644 index 0000000000..87841e786d --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeComplete.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_COMPLETE) +/** + * + * @author hengsin + * + */ +public @interface BeforeComplete { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePost.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePost.java new file mode 100644 index 0000000000..a81cbcc38e --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePost.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_POST) +/** + * + * @author hengsin + * + */ +public @interface BeforePost { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePrepare.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePrepare.java new file mode 100644 index 0000000000..9098bf153e --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforePrepare.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_PREPARE) +/** + * + * @author hengsin + * + */ +public @interface BeforePrepare { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReactivate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReactivate.java new file mode 100644 index 0000000000..c85abd6012 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReactivate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_REACTIVATE) +/** + * + * @author hengsin + * + */ +public @interface BeforeReactivate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseAccrual.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseAccrual.java new file mode 100644 index 0000000000..5521f2915f --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseAccrual.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_REVERSEACCRUAL) +/** + * + * @author hengsin + * + */ +public @interface BeforeReverseAccrual { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseCorrect.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseCorrect.java new file mode 100644 index 0000000000..aefcb73f22 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeReverseCorrect.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_REVERSECORRECT) +/** + * + * @author hengsin + * + */ +public @interface BeforeReverseCorrect { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeVoid.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeVoid.java new file mode 100644 index 0000000000..3c98c0aa86 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/BeforeVoid.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOC_BEFORE_VOID) +/** + * + * @author hengsin + * + */ +public @interface BeforeVoid { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/DocAction.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/DocAction.java new file mode 100644 index 0000000000..7d32239ede --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/DocAction.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.DOCACTION) +/** + * + * @author hengsin + * + */ +public @interface DocAction { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidate.java new file mode 100644 index 0000000000..808841249b --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.ACCT_FACTS_VALIDATE) +/** + * + * @author hengsin + * + */ +public @interface FactsValidate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidateDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidateDelegate.java new file mode 100644 index 0000000000..40f129f6f7 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/doc/FactsValidateDelegate.java @@ -0,0 +1,67 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.doc; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.FactsEventData; +import org.adempiere.base.event.annotations.ModelEventDelegate; +import org.compiere.model.PO; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public abstract class FactsValidateDelegate extends ModelEventDelegate { + + /** + * + * @param po + * @param event + */ + public FactsValidateDelegate(T po, Event event) { + super(po, event); + } + + /** + * + * @return {@link FactsEventData} + */ + protected FactsEventData getFactsEventData() { + return EventHelper.getEventData(event); + } + + @FactsValidate + public final void onEvent() { + onFactsValidate(getFactsEventData()); + } + + /** + * override this to handle facts validate event + * @param data + */ + protected abstract void onFactsValidate(FactsEventData data); +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterImport.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterImport.java new file mode 100644 index 0000000000..959d6a10ae --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterImport.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.IMPORT_AFTER_IMPORT) +/** + * + * @author hengsin + * + */ +public @interface AfterImport { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterValidate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterValidate.java new file mode 100644 index 0000000000..770549bb11 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/AfterValidate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.IMPORT_AFTER_VALIDATE) +/** + * + * @author hengsin + * + */ +public @interface AfterValidate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeImport.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeImport.java new file mode 100644 index 0000000000..c2f54e3bbf --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeImport.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.IMPORT_BEFORE_IMPORT) +/** + * + * @author hengsin + * + */ +public @interface BeforeImport { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeValidate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeValidate.java new file mode 100644 index 0000000000..a7dd25d1d1 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/BeforeValidate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.IMPORT_BEFORE_VALIDATE) +/** + * + * @author hengsin + * + */ +public @interface BeforeValidate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventDelegate.java new file mode 100644 index 0000000000..ba432e090d --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventDelegate.java @@ -0,0 +1,53 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.ImportEventData; +import org.adempiere.base.event.annotations.EventDelegate; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public class ImportEventDelegate extends EventDelegate { + + /** + * @param event + */ + public ImportEventDelegate(Event event) { + super(event); + } + + /** + * + * @return {@link ImportEventData} + */ + protected ImportEventData getImportEventData() { + return EventHelper.getEventData(event); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventHandler.java new file mode 100644 index 0000000000..1ff6b8460c --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/imp/ImportEventHandler.java @@ -0,0 +1,61 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.imp; + +import java.util.function.Function; + +import org.adempiere.base.event.IEventManager; +import org.adempiere.base.event.annotations.BaseEventHandler; +import org.adempiere.base.event.annotations.EventDelegate; +import org.compiere.util.Util; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public class ImportEventHandler extends BaseEventHandler { + + private Function supplier; + + /** + * + * @param delegateClass + * @param importTableName + * @param supplier + */ + public ImportEventHandler(Class delegateClass, String importTableName, Function supplier) { + super(delegateClass); + this.supplier = supplier; + if (!Util.isEmpty(importTableName)) + setEventPropertyFilter(IEventManager.IMPORT_TABLE_NAME_PROPERTY, importTableName); + } + + @Override + protected EventDelegate newEventDelegate(Event event) { + return supplier.apply(event); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChange.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChange.java new file mode 100644 index 0000000000..8dee0f4b4f --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChange.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_AFTER_CHANGE) +/** + * + * @author hengsin + * + */ +public @interface AfterChange { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChangeReplication.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChangeReplication.java new file mode 100644 index 0000000000..a591d43d94 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterChangeReplication.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_AFTER_CHANGE_REPLICATION) +/** + * + * @author hengsin + * + */ +public @interface AfterChangeReplication { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterDelete.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterDelete.java new file mode 100644 index 0000000000..2b5c4cbe3f --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterDelete.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_AFTER_DELETE) +/** + * + * @author hengsin + * + */ +public @interface AfterDelete { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNew.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNew.java new file mode 100644 index 0000000000..19cebed68f --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNew.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_AFTER_NEW) +/** + * + * @author hengsin + * + */ +public @interface AfterNew { +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNewReplication.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNewReplication.java new file mode 100644 index 0000000000..fa04446a03 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/AfterNewReplication.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_AFTER_NEW_REPLICATION) +/** + * + * @author hengsin + * + */ +public @interface AfterNewReplication { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeChange.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeChange.java new file mode 100644 index 0000000000..7860502332 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeChange.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_BEFORE_CHANGE) +/** + * + * @author hengsin + * + */ +public @interface BeforeChange { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDelete.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDelete.java new file mode 100644 index 0000000000..207b89f927 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDelete.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_BEFORE_DELETE) +/** + * + * @author hengsin + * + */ +public @interface BeforeDelete { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDeleteReplication.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDeleteReplication.java new file mode 100644 index 0000000000..c530e266fe --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeDeleteReplication.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_BEFORE_DELETE_REPLICATION) +/** + * + * @author hengsin + * + */ +public @interface BeforeDeleteReplication { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeNew.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeNew.java new file mode 100644 index 0000000000..0d85ba67b3 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/BeforeNew.java @@ -0,0 +1,45 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +/** + * + * @author hengsin + * + */ +@EventTopic(topic = IEventTopics.PO_BEFORE_NEW) +public @interface BeforeNew { +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostCreate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostCreate.java new file mode 100644 index 0000000000..559d4c939a --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostCreate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_POST_CREATE) +/** + * + * @author hengsin + * + */ +public @interface PostCreate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostDelete.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostDelete.java new file mode 100644 index 0000000000..3c78808d5a --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostDelete.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_POST_DELETE) +/** + * + * @author hengsin + * + */ +public @interface PostDelete { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostUpdate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostUpdate.java new file mode 100644 index 0000000000..4ca7ad6c2e --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/po/PostUpdate.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.po; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.PO_POST_UPADTE) +/** + * + * @author hengsin + * + */ +public @interface PostUpdate { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/process/AfterProcess.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/AfterProcess.java new file mode 100644 index 0000000000..9ad97980ff --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/AfterProcess.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.process; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.AFTER_PROCESS) +/** + * + * @author hengsin + * + */ +public @interface AfterProcess { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/process/BeforeProcess.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/BeforeProcess.java new file mode 100644 index 0000000000..a2cf002662 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/BeforeProcess.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.process; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.BEFORE_PROCESS) +/** + * + * @author hengsin + * + */ +public @interface BeforeProcess { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/process/PostProcess.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/PostProcess.java new file mode 100644 index 0000000000..69c370e322 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/PostProcess.java @@ -0,0 +1,46 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.process; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import org.adempiere.base.event.IEventTopics; +import org.adempiere.base.event.annotations.EventTopic; + +@Retention(RUNTIME) +@Target(METHOD) +@EventTopic(topic = IEventTopics.POST_PROCESS) +/** + * + * @author hengsin + * + */ +public @interface PostProcess { + +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventDelegate.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventDelegate.java new file mode 100644 index 0000000000..08cc8c7297 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventDelegate.java @@ -0,0 +1,50 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.process; + +import org.adempiere.base.event.EventHelper; +import org.adempiere.base.event.annotations.EventDelegate; +import org.compiere.process.ProcessInfo; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public class ProcessEventDelegate extends EventDelegate { + + public ProcessEventDelegate(Event event) { + super(event); + } + + /** + * + * @return {@link ProcessInfo} + */ + protected ProcessInfo getProcessInfo() { + return EventHelper.getEventData(event); + } +} diff --git a/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventHandler.java new file mode 100644 index 0000000000..0b19e3bda4 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/event/annotations/process/ProcessEventHandler.java @@ -0,0 +1,63 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.adempiere.base.event.annotations.process; + +import java.util.function.Function; + +import org.adempiere.base.event.IEventManager; +import org.adempiere.base.event.annotations.BaseEventHandler; +import org.adempiere.base.event.annotations.EventDelegate; +import org.compiere.util.Util; +import org.osgi.service.event.Event; + +/** + * + * @author hengsin + * + */ +public class ProcessEventHandler extends BaseEventHandler { + + private Function supplier; + + /** + * + * @param delegateClass + * @param processUUID filter by process uuid (null for all process) + * @param supplier + */ + public ProcessEventHandler(Class delegateClass, String processUUID, Function supplier) { + super(delegateClass); + this.supplier = supplier; + if (!Util.isEmpty(processUUID)) { + setEventPropertyFilter(IEventManager.PROCESS_UID_PROPERTY, processUUID); + } + } + + @Override + protected EventDelegate newEventDelegate(Event event) { + return supplier.apply(event); + } + +} diff --git a/org.adempiere.base/src/org/compiere/model/ModelValidationEngine.java b/org.adempiere.base/src/org/compiere/model/ModelValidationEngine.java index de3c1e7385..93e7cbb114 100644 --- a/org.adempiere.base/src/org/compiere/model/ModelValidationEngine.java +++ b/org.adempiere.base/src/org/compiere/model/ModelValidationEngine.java @@ -407,7 +407,7 @@ public class ModelValidationEngine //now process osgi event handlers Event event = EventManager.newEvent(ModelValidator.tableEventTopics[changeType], - new EventProperty(EventManager.EVENT_DATA, po), new EventProperty("tableName", po.get_TableName())); + new EventProperty(EventManager.EVENT_DATA, po), new EventProperty(EventManager.TABLE_NAME_PROPERTY, po.get_TableName())); EventManager.getInstance().sendEvent(event); @SuppressWarnings("unchecked") List errors = (List) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); @@ -574,7 +574,7 @@ public class ModelValidationEngine //now process osgi event handlers Event event = EventManager.newEvent(ModelValidator.documentEventTopics[docTiming], - new EventProperty(EventManager.EVENT_DATA, po), new EventProperty("tableName", po.get_TableName())); + new EventProperty(EventManager.EVENT_DATA, po), new EventProperty(EventManager.TABLE_NAME_PROPERTY, po.get_TableName())); EventManager.getInstance().sendEvent(event); @SuppressWarnings("unchecked") List errors = (List) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); @@ -724,7 +724,7 @@ public class ModelValidationEngine //process osgi event handlers FactsEventData eventData = new FactsEventData(schema, facts, po); Event event = EventManager.newEvent(IEventTopics.ACCT_FACTS_VALIDATE, - new EventProperty(EventManager.EVENT_DATA, eventData), new EventProperty("tableName", po.get_TableName())); + new EventProperty(EventManager.EVENT_DATA, eventData), new EventProperty(EventManager.TABLE_NAME_PROPERTY, po.get_TableName())); EventManager.getInstance().sendEvent(event); @SuppressWarnings("unchecked") List errors = (List) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); @@ -802,7 +802,8 @@ public class ModelValidationEngine topic = IEventTopics.IMPORT_BEFORE_IMPORT; else if (timing == ImportValidator.TIMING_BEFORE_VALIDATE) topic = IEventTopics.IMPORT_BEFORE_VALIDATE; - Event event = EventManager.newEvent(topic, new EventProperty(EventManager.EVENT_DATA, eventData), new EventProperty("importTableName", process.getImportTableName())); + Event event = EventManager.newEvent(topic, new EventProperty(EventManager.EVENT_DATA, eventData), + new EventProperty(EventManager.IMPORT_TABLE_NAME_PROPERTY, process.getImportTableName())); EventManager.getInstance().sendEvent(event); } diff --git a/org.adempiere.base/src/org/compiere/process/DocumentEngine.java b/org.adempiere.base/src/org/compiere/process/DocumentEngine.java index 63fd3fe6fd..2a46483f9a 100644 --- a/org.adempiere.base/src/org/compiere/process/DocumentEngine.java +++ b/org.adempiere.base/src/org/compiere/process/DocumentEngine.java @@ -1254,7 +1254,7 @@ public class DocumentEngine implements DocAction DocActionEventData eventData = new DocActionEventData(docStatus, processing, orderType, isSOTrx, AD_Table_ID, docActionsArray, optionsArray, indexObj, po); Event event = EventManager.newEvent(IEventTopics.DOCACTION, new EventProperty(EventManager.EVENT_DATA, eventData), - new EventProperty("tableName", po.get_TableName())); + new EventProperty(EventManager.TABLE_NAME_PROPERTY, po.get_TableName())); EventManager.getInstance().sendEvent(event); index = indexObj.get(); for (int i = 0; i < optionsArray.size(); i++) diff --git a/org.adempiere.base/src/org/compiere/process/SvrProcess.java b/org.adempiere.base/src/org/compiere/process/SvrProcess.java index 44201b8132..a221517546 100644 --- a/org.adempiere.base/src/org/compiere/process/SvrProcess.java +++ b/org.adempiere.base/src/org/compiere/process/SvrProcess.java @@ -298,9 +298,9 @@ public abstract class SvrProcess implements ProcessCall private Event sendProcessEvent(String topic) { Event event = EventManager.newEvent(topic, new EventProperty(EventManager.EVENT_DATA, m_pi), - new EventProperty("processUUID", m_pi.getAD_Process_UU()), - new EventProperty("className", m_pi.getClassName()), - new EventProperty("processClassName", this.getClass().getName())); + new EventProperty(EventManager.PROCESS_UID_PROPERTY, m_pi.getAD_Process_UU()), + new EventProperty(EventManager.CLASS_NAME_PROPERTY, m_pi.getClassName()), + new EventProperty(EventManager.PROCESS_CLASS_NAME_PROPERTY, this.getClass().getName())); EventManager.getInstance().sendEvent(event); return event; } diff --git a/org.idempiere.test/.project b/org.idempiere.test/.project index 3dd557a8f9..a7c08fd3c9 100644 --- a/org.idempiere.test/.project +++ b/org.idempiere.test/.project @@ -25,6 +25,11 @@ + + org.eclipse.pde.ds.core.builder + + + org.eclipse.pde.PluginNature diff --git a/org.idempiere.test/.settings/org.eclipse.pde.ds.annotations.prefs b/org.idempiere.test/.settings/org.eclipse.pde.ds.annotations.prefs new file mode 100644 index 0000000000..73a356b6d0 --- /dev/null +++ b/org.idempiere.test/.settings/org.eclipse.pde.ds.annotations.prefs @@ -0,0 +1,8 @@ +classpath=true +dsVersion=V1_3 +eclipse.preferences.version=1 +enabled=true +generateBundleActivationPolicyLazy=true +path=OSGI-INF +validationErrorLevel=error +validationErrorLevel.missingImplicitUnbindMethod=error diff --git a/org.idempiere.test/META-INF/MANIFEST.MF b/org.idempiere.test/META-INF/MANIFEST.MF index d8f3a37f5b..40a5d670c6 100644 --- a/org.idempiere.test/META-INF/MANIFEST.MF +++ b/org.idempiere.test/META-INF/MANIFEST.MF @@ -17,7 +17,9 @@ Import-Package: org.junit.jupiter.api;version="5.6.0", org.junit.jupiter.params.converter;version="5.6.0", org.junit.jupiter.params.provider;version="5.6.0", org.junit.jupiter.params.support;version="5.6.0", - org.osgi.framework;version="1.9.0" + org.osgi.framework;version="1.9.0", + org.osgi.service.component.annotations;version="1.3.0", + org.osgi.service.event;version="1.4.0" Require-Bundle: org.adempiere.base;bundle-version="8.2.0", org.adempiere.base.callout;bundle-version="8.2.0", org.adempiere.base.process;bundle-version="8.2.0", @@ -25,3 +27,5 @@ Require-Bundle: org.adempiere.base;bundle-version="8.2.0", Bundle-ActivationPolicy: lazy Bundle-Activator: org.idempiere.test.TestActivator Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: org.idempiere.test +Service-Component: OSGI-INF/org.idempiere.test.event.MyComponent.xml diff --git a/org.idempiere.test/OSGI-INF/org.idempiere.test.event.MyComponent.xml b/org.idempiere.test/OSGI-INF/org.idempiere.test.event.MyComponent.xml new file mode 100644 index 0000000000..af0a5b8d69 --- /dev/null +++ b/org.idempiere.test/OSGI-INF/org.idempiere.test.event.MyComponent.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/org.idempiere.test/build.properties b/org.idempiere.test/build.properties index 56d7765555..bb4aa0998b 100644 --- a/org.idempiere.test/build.properties +++ b/org.idempiere.test/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = target/classes/ bin.includes = META-INF/,\ - . + .,\ + OSGI-INF/org.idempiere.test.event.MyComponent.xml diff --git a/org.idempiere.test/src/org/idempiere/test/event/EventHandlerTest.java b/org.idempiere.test/src/org/idempiere/test/event/EventHandlerTest.java new file mode 100644 index 0000000000..f57deea9f5 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/event/EventHandlerTest.java @@ -0,0 +1,395 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.event; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.math.BigDecimal; +import java.sql.Timestamp; + +import org.adempiere.base.Core; +import org.adempiere.base.event.FactsEventData; +import org.adempiere.base.event.annotations.AfterLogin; +import org.adempiere.base.event.annotations.EventDelegate; +import org.adempiere.base.event.annotations.ModelEventDelegate; +import org.adempiere.base.event.annotations.ModelEventHandler; +import org.adempiere.base.event.annotations.SimpleEventHandler; +import org.adempiere.base.event.annotations.doc.BeforeComplete; +import org.adempiere.base.event.annotations.doc.FactsValidateDelegate; +import org.adempiere.base.event.annotations.imp.AfterImport; +import org.adempiere.base.event.annotations.imp.ImportEventDelegate; +import org.adempiere.base.event.annotations.imp.ImportEventHandler; +import org.adempiere.base.event.annotations.po.BeforeNew; +import org.adempiere.base.event.annotations.process.AfterProcess; +import org.adempiere.base.event.annotations.process.ProcessEventDelegate; +import org.adempiere.base.event.annotations.process.ProcessEventHandler; +import org.adempiere.model.ImportValidator; +import org.compiere.model.MBPartner; +import org.compiere.model.MInOut; +import org.compiere.model.MInOutLine; +import org.compiere.model.MOrder; +import org.compiere.model.MOrderLine; +import org.compiere.model.MOrg; +import org.compiere.model.MProcess; +import org.compiere.model.MProduct; +import org.compiere.model.ModelValidationEngine; +import org.compiere.model.X_I_BPartner; +import org.compiere.model.X_I_Product; +import org.compiere.process.DocAction; +import org.compiere.process.DocumentEngine; +import org.compiere.process.ImportBPartner; +import org.compiere.process.ImportProduct; +import org.compiere.process.ProcessInfo; +import org.compiere.process.ServerProcessCtl; +import org.compiere.util.Env; +import org.compiere.util.KeyNamePair; +import org.compiere.util.Login; +import org.compiere.util.TimeUtil; +import org.compiere.util.Util; +import org.compiere.wf.MWorkflow; +import org.idempiere.test.AbstractTestCase; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.osgi.service.event.Event; + +@TestMethodOrder(OrderAnnotation.class) +/** + * + * @author hengsin + * + */ +public class EventHandlerTest extends AbstractTestCase { + + private final static int BP_JOE_BLOCK = 118; + private static final int PRODUCT_AZALEA = 128; + + public EventHandlerTest() { + } + + + @Test + @Order(1) + public void testModelEventHandler() { + //test1 - activator approach + ModelEventHandler handler = new ModelEventHandler(MBPartner.class, MyBPBeforeNewDelegate.class, (bp, event) -> new MyBPBeforeNewDelegate(bp, event)); + Core.getEventManager().register(handler); + + MBPartner bpartner = new MBPartner(Env.getCtx(), 0, getTrxName()); + String name = "BP_"+System.currentTimeMillis(); + bpartner.setName(name); + bpartner.setC_BP_Group_ID(103); + bpartner.saveEx(); + + String test = Env.getContext(Env.getCtx(), MyBPBeforeNewDelegate.class.getName()); + assertTrue(bpartner.getName().equals(test), "MyBPBeforeNewDelegate not called"); + + //test2 - MyComponent.MyBpBeforeChangeDelegate using osgi component mechanism + bpartner.setDescription(""); + bpartner.saveEx(); + + test = Env.getContext(Env.getCtx(), MyComponent.MyBpBeforeChangeDelegate.class.getName()); + assertTrue(bpartner.toString().equals(test), "MyComponent.MyBpBeforeChangeDelegate not called"); + } + + @Test + @Order(2) + public void testDocumentEventHandler() { + ModelEventHandler handler = new ModelEventHandler(MOrder.class, MyOrderBeforeCompleteDelegate.class, + (po, event) -> new MyOrderBeforeCompleteDelegate(po, event)); + Core.getEventManager().register(handler); + + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + //Joe Block + order.setBPartner(MBPartner.get(Env.getCtx(), BP_JOE_BLOCK)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.setDescription(null); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + //Azalea Bush + line1.setProduct(MProduct.get(Env.getCtx(), PRODUCT_AZALEA)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError(), info.getSummary()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + line1.load(getTrxName()); + assertEquals(1, line1.getQtyReserved().intValue()); + + Core.getEventManager().unregister(handler); + + String test = Env.getContext(Env.getCtx(), MyOrderBeforeCompleteDelegate.class.getName()); + assertEquals(order.toString(), test, "MyOrderBeforeCompleteDelegate not called"); + } + + @Test + @Order(3) + public void testDocumentEventHandlerException() { + ModelEventHandler handler = new ModelEventHandler(MOrder.class, MyOrderBeforeCompleteDelegate.class, + (po, event) -> new MyOrderBeforeCompleteDelegate(po, event)); + Core.getEventManager().register(handler); + + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + //Joe Block + order.setBPartner(MBPartner.get(Env.getCtx(), BP_JOE_BLOCK)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.setDescription(MyOrderBeforeCompleteDelegate.class.getName()); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + //Azalea Bush + line1.setProduct(MProduct.get(Env.getCtx(), PRODUCT_AZALEA)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertTrue(info.isError(), "DocAction Complete doesn't fail as expected"); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Invalid, order.getDocStatus(), "DocStatus Expected=Invalid. DocStatus Actual="+order.getDocStatus()); + line1.load(getTrxName()); + assertEquals(0, line1.getQtyReserved().intValue()); + assertTrue(info.getSummary() != null && info.getSummary().contains("Test Runtime Exception"), "Error message not as expected=" + info.getSummary()); + } + + @Test + @Order(4) + public void testAfterLogin() { + SimpleEventHandler handler = new SimpleEventHandler(MyAfterLoginDelegate.class, (event) -> new MyAfterLoginDelegate(event)); + Core.getEventManager().register(handler); + + KeyNamePair org = new KeyNamePair(getAD_Org_ID(), MOrg.get(getAD_Org_ID()).getName()); + Login login = new Login(Env.getCtx()); + login.validateLogin(org); + + assertTrue("y".equalsIgnoreCase(Env.getContext(Env.getCtx(), MyAfterLoginDelegate.class.getName())), + "MyAfterLoginDelegate not call. context="+Env.getContext(Env.getCtx(), MyAfterLoginDelegate.class.getName())); + } + + @Test + @Order(5) + public void testAfterProcess() { + int Verify_BOM=136; + int Patio_Chair=133; + + ProcessEventHandler handler = new ProcessEventHandler(MyAfterProcessDelegate.class, MProcess.get(Verify_BOM).getAD_Process_UU(), (event) -> new MyAfterProcessDelegate(event)); + Core.getEventManager().register(handler); + + MProcess process = MProcess.get(Env.getCtx(), Verify_BOM); + ProcessInfo pi = new ProcessInfo(process.getName(), process.get_ID()); + pi.setAD_Client_ID(getAD_Client_ID()); + pi.setAD_User_ID(getAD_User_ID()); + pi.setRecord_ID(Patio_Chair); + pi.setTransactionName(getTrxName()); + + ServerProcessCtl.process(pi, getTrx()); + if (pi.isError()) { + fail("Error running Verify BOM process" + (Util.isEmpty(pi.getSummary()) ? "" : " : "+pi.getSummary())); + return; + } + + assertTrue(pi.getTitle() != null && pi.getTitle().contains(MyAfterProcessDelegate.class.getName()), "MyAfterProcessDelegate not call. Title="+pi.getTitle()); + } + + @Test + @Order(6) + public void testFactValidate() + { + ModelEventHandler handler = new ModelEventHandler(MInOut.class, MyFactValidateDelegate.class, + (po, event) -> new MyFactValidateDelegate(po, event)); + Core.getEventManager().register(handler); + + MOrder order = new MOrder(Env.getCtx(), 0, getTrxName()); + //Joe Block + order.setBPartner(MBPartner.get(Env.getCtx(), BP_JOE_BLOCK)); + order.setC_DocTypeTarget_ID(MOrder.DocSubTypeSO_Standard); + order.setDeliveryRule(MOrder.DELIVERYRULE_CompleteOrder); + order.setDocStatus(DocAction.STATUS_Drafted); + order.setDocAction(DocAction.ACTION_Complete); + Timestamp today = TimeUtil.getDay(System.currentTimeMillis()); + order.setDateOrdered(today); + order.setDatePromised(today); + order.saveEx(); + + MOrderLine line1 = new MOrderLine(order); + line1.setLine(10); + //Azalea Bush + line1.setProduct(MProduct.get(Env.getCtx(), PRODUCT_AZALEA)); + line1.setQty(new BigDecimal("1")); + line1.setDatePromised(today); + line1.saveEx(); + + ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete); + assertFalse(info.isError()); + order.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, order.getDocStatus()); + line1.load(getTrxName()); + assertEquals(1, line1.getQtyReserved().intValue()); + + MInOut shipment = new MInOut(order, 120, order.getDateOrdered()); + shipment.setDocStatus(DocAction.STATUS_Drafted); + shipment.setDocAction(DocAction.ACTION_Complete); + shipment.saveEx(); + + MInOutLine shipmentLine = new MInOutLine(shipment); + shipmentLine.setOrderLine(line1, 0, new BigDecimal("1")); + shipmentLine.setQty(new BigDecimal("1")); + shipmentLine.saveEx(); + + info = MWorkflow.runDocumentActionWorkflow(shipment, DocAction.ACTION_Complete); + assertFalse(info.isError()); + shipment.load(getTrxName()); + assertEquals(DocAction.STATUS_Completed, shipment.getDocStatus()); + + line1.load(getTrxName()); + assertEquals(0, line1.getQtyReserved().intValue()); + + if (!shipment.isPosted()) { + String error = DocumentEngine.postImmediate(Env.getCtx(), shipment.getAD_Client_ID(), MInOut.Table_ID, shipment.get_ID(), false, getTrxName()); + assertTrue(error == null); + } + + assertTrue("y".equalsIgnoreCase(Env.getContext(Env.getCtx(), MyFactValidateDelegate.class.getName())), + "MyFactValidateDelegate not call. context="+Env.getContext(Env.getCtx(), MyFactValidateDelegate.class.getName())); + } + + @Test + @Order(7) + public void testAfterImport() { + ImportEventHandler handler = new ImportEventHandler(MyAfterImportDelegate.class, X_I_BPartner.Table_Name, (event) -> new MyAfterImportDelegate(event)); + Core.getEventManager().register(handler); + + ImportProduct ip = new ImportProduct(); + ModelValidationEngine.get().fireImportValidate(ip, new X_I_Product(Env.getCtx(), 0, getTrxName()), new MProduct(Env.getCtx(), 0, getTrxName()), ImportValidator.TIMING_AFTER_IMPORT); + assertTrue(Util.isEmpty(Env.getContext(Env.getCtx(), MyAfterImportDelegate.class.getName())), + "MyAfterImportDelegate call for different import table name. context="+Env.getContext(Env.getCtx(), MyAfterImportDelegate.class.getName())); + + ImportBPartner ibp = new ImportBPartner(); + ModelValidationEngine.get().fireImportValidate(ibp, new X_I_BPartner(Env.getCtx(), 0, getTrxName()), new MBPartner(Env.getCtx(), 0, getTrxName()), ImportValidator.TIMING_AFTER_IMPORT); + + assertTrue("y".equalsIgnoreCase(Env.getContext(Env.getCtx(), MyAfterImportDelegate.class.getName())), + "MyAfterImportDelegate not call. context="+Env.getContext(Env.getCtx(), MyAfterImportDelegate.class.getName())); + } + + private final static class MyBPBeforeNewDelegate extends ModelEventDelegate { + + public MyBPBeforeNewDelegate(MBPartner bp, Event event) { + super(bp, event); + } + + @BeforeNew + public void beforeNew() { + Env.setContext(Env.getCtx(), getClass().getName(), getModel().getName()); + } + } + + private final static class MyOrderBeforeCompleteDelegate extends ModelEventDelegate { + + public MyOrderBeforeCompleteDelegate(MOrder po, Event event) { + super(po, event); + } + + @BeforeComplete + public void beforeComplete() { + if (getClass().getName().equals(getModel().getDescription())) { + throw new RuntimeException("Test Runtime Exception"); + } else { + Env.setContext(Env.getCtx(), getClass().getName(), getModel().toString()); + } + } + } + + private final static class MyAfterLoginDelegate extends EventDelegate { + + public MyAfterLoginDelegate(Event event) { + super(event); + } + + @AfterLogin + public void afterLogin() { + Env.setContext(Env.getCtx(), getClass().getName(), true); + } + } + + private final static class MyAfterProcessDelegate extends ProcessEventDelegate { + + public MyAfterProcessDelegate(Event event) { + super(event); + } + + @AfterProcess + public void afterProcess() { + ProcessInfo pi = getProcessInfo(); + pi.setTitle(getClass().getName()); + } + } + + private final static class MyFactValidateDelegate extends FactsValidateDelegate { + + public MyFactValidateDelegate(MInOut po, Event event) { + super(po, event); + } + + @Override + protected void onFactsValidate(FactsEventData data) { + Env.setContext(Env.getCtx(), this.getClass().getName(), true); + } + + } + + private final static class MyAfterImportDelegate extends ImportEventDelegate { + + public MyAfterImportDelegate(Event event) { + super(event); + } + + @AfterImport + public void afterImport() { + Env.setContext(Env.getCtx(), getClass().getName(), true); + } + } +} diff --git a/org.idempiere.test/src/org/idempiere/test/event/MyComponent.java b/org.idempiere.test/src/org/idempiere/test/event/MyComponent.java new file mode 100644 index 0000000000..0a307f2299 --- /dev/null +++ b/org.idempiere.test/src/org/idempiere/test/event/MyComponent.java @@ -0,0 +1,83 @@ +/*********************************************************************** + * This file is part of iDempiere ERP Open Source * + * http://www.idempiere.org * + * * + * Copyright (C) Contributors * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * + * MA 02110-1301, USA. * + * * + * Contributors: * + * - hengsin * + **********************************************************************/ +package org.idempiere.test.event; + +import org.adempiere.base.event.IEventManager; +import org.adempiere.base.event.annotations.ModelEventDelegate; +import org.adempiere.base.event.annotations.ModelEventHandler; +import org.adempiere.base.event.annotations.po.BeforeChange; +import org.compiere.model.MBPartner; +import org.compiere.util.Env; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.event.Event; + +@Component(name = "org.idempiere.test.event.MyComponent", immediate = true) +/** + * + * @author hengsin + * + */ +public class MyComponent { + + @Reference(service = IEventManager.class, bind = "bindService", unbind = "unbindService") + private IEventManager eventManager; + private ModelEventHandler handler; + + public MyComponent() { + } + + /** + * + * @param eventManager + */ + public void bindService(IEventManager eventManager) { + this.eventManager = eventManager; + handler = new ModelEventHandler(MBPartner.class, MyBpBeforeChangeDelegate.class, + (po, event) -> new MyBpBeforeChangeDelegate(po, event)); + eventManager.register(handler.getTopics(), handler.getFilter(), handler); + } + + /** + * + * @param eventManager + */ + public void unbindService(IEventManager eventManager) { + if (eventManager != null && eventManager == this.eventManager && handler != null) + eventManager.unregister(handler); + } + + protected final static class MyBpBeforeChangeDelegate extends ModelEventDelegate { + + public MyBpBeforeChangeDelegate(MBPartner po, Event event) { + super(po, event); + } + + @BeforeChange + public void beforeChange() { + Env.setContext(Env.getCtx(), getClass().getName(), getModel().toString()); + } + } +}