IDEMPIERE-4694 Implement thread safe, annotation based osgi event han… (#571)

* IDEMPIERE-4694 Implement thread safe, annotation based osgi event handling

Make sure the component register in the event handler unit test cases
wouldn't have impact on other unit test cases.
This commit is contained in:
hengsin 2021-02-10 23:12:16 +08:00 committed by GitHub
parent c757fbaab7
commit ee77620186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 3470 additions and 24 deletions

View File

@ -21,8 +21,14 @@ Export-Package: bsh,
it.sauronsoftware.cron4j, it.sauronsoftware.cron4j,
org.adempiere.apps.graph, org.adempiere.apps.graph,
org.adempiere.base, org.adempiere.base,
org.adempiere.base.ds,
org.adempiere.base.equinox, org.adempiere.base.equinox,
org.adempiere.base.event, 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.exceptions,
org.adempiere.impexp, org.adempiere.impexp,
org.adempiere.model, org.adempiere.model,

View File

@ -29,6 +29,7 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import org.adempiere.base.event.IEventManager;
import org.adempiere.model.IAddressValidation; import org.adempiere.model.IAddressValidation;
import org.adempiere.model.IShipmentProcessor; import org.adempiere.model.IShipmentProcessor;
import org.adempiere.model.ITaxProvider; import org.adempiere.model.ITaxProvider;
@ -1024,4 +1025,26 @@ public class Core {
} }
return factoryService; return factoryService;
} }
private static IServiceReferenceHolder<IEventManager> 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<IEventManager> serviceReference = Service.locator().locate(IEventManager.class).getServiceReference();
if (serviceReference != null) {
eventManager = serviceReference.getService();
s_eventManagerReference = serviceReference;
}
return eventManager;
}
} }

View File

@ -13,7 +13,6 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.base.event; package org.adempiere.base.event;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.compiere.model.PO; import org.compiere.model.PO;
@ -127,7 +126,7 @@ public abstract class AbstractEventHandler implements EventHandler {
* @return PO * @return PO
*/ */
protected PO getPO(Event event) { 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 * @return ProcessInfo
*/ */
protected ProcessInfo getProcessInfo(Event event) { 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 * @param event
*/ */
protected <T> T getEventData(Event event) { protected <T> 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 event
* @param property * @param property
*/ */
@SuppressWarnings("unchecked")
protected <T> T getEventProperty(Event event, String property) { protected <T> 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 * @param e
*/ */
protected void addError(Event event, Throwable e) { protected void addError(Event event, Throwable e) {
String msg = e.getLocalizedMessage(); EventHelper.addError(event, e);
if (msg == null)
msg = e.toString();
addErrorMessage(event, msg);
} }
/** /**
@ -174,8 +169,6 @@ public abstract class AbstractEventHandler implements EventHandler {
* @param errorMessage * @param errorMessage
*/ */
protected void addErrorMessage(Event event, String errorMessage) { protected void addErrorMessage(Event event, String errorMessage) {
List<String> errors = getEventProperty(event, IEventManager.EVENT_ERROR_MESSAGES); EventHelper.addErrorMessage(event, errorMessage);
if (errors != null)
errors.add(errorMessage);
} }
} }

View File

@ -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 <T>
* @param event
*/
public static <T> T getEventData(Event event) {
return getEventProperty(event, IEventManager.EVENT_DATA);
}
/**
*
* @param <T>
* @param event
* @param property
*/
@SuppressWarnings("unchecked")
public static <T> 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<String> errors = getEventProperty(event, IEventManager.EVENT_ERROR_MESSAGES);
if (errors != null)
errors.add(errorMessage);
}
}

View File

@ -24,7 +24,7 @@ import org.compiere.model.PO;
* @author hengsin * @author hengsin
* *
*/ */
public class FactsEventData { public class FactsEventData implements POEventData {
private MAcctSchema acctSchema; private MAcctSchema acctSchema;
private List<Fact> facts; private List<Fact> facts;
private PO po; private PO po;

View File

@ -13,6 +13,7 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.base.event; package org.adempiere.base.event;
import org.adempiere.base.event.annotations.BaseEventHandler;
import org.osgi.service.event.Event; import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler; 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_DATA = "event.data";
public static final String EVENT_ERROR_MESSAGES = "event.errorMessages"; 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 * 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 * @return true if unregistration is done, false otherwise
*/ */
public abstract boolean unregister(EventHandler eventHandler); public abstract boolean unregister(EventHandler eventHandler);
/**
*
* @param eventHandler
* @return
*/
public default boolean register(BaseEventHandler eventHandler) {
return register(eventHandler.getTopics(), eventHandler.getFilter(), eventHandler);
}
} }

View File

@ -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();
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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);
}

View File

@ -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<String, Method> eventTopicMap = new HashMap<String, Method>();
private String filter;
/**
*
* @param delegateClass
*/
public BaseEventHandler(Class<? extends EventDelegate> 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);
}

View File

@ -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 {
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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 <T>
*/
public class ModelEventDelegate<T extends PO> 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;
}
}

View File

@ -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<T extends PO> extends BaseEventHandler {
private Class<T> modelClassType;
private String tableName;
private BiFunction<T, Event, ? extends ModelEventDelegate<T>> supplier;
/**
* @param modelClassType
*/
public ModelEventHandler(Class<T> modelClassType, Class<? extends ModelEventDelegate<T>> delegateClass,
BiFunction<T, Event, ? extends ModelEventDelegate<T>> 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);
}
}

View File

@ -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 {
}

View File

@ -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);
}

View File

@ -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<Event, ? extends EventDelegate> supplier;
/**
*
* @param delegateClass
* @param supplier
*/
public SimpleEventHandler(Class<? extends EventDelegate> delegateClass, Function<Event, ? extends EventDelegate> supplier) {
super(delegateClass);
this.supplier = supplier;
}
@Override
protected EventDelegate newEventDelegate(Event event) {
return supplier.apply(event);
}
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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<T extends PO> extends ModelEventDelegate<T> {
/**
*
* @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);
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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);
}
}

View File

@ -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<Event, ? extends ImportEventDelegate> supplier;
/**
*
* @param delegateClass
* @param importTableName
* @param supplier
*/
public ImportEventHandler(Class<? extends ImportEventDelegate> delegateClass, String importTableName, Function<Event, ? extends ImportEventDelegate> 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);
}
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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);
}
}

View File

@ -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<Event, ? extends ProcessEventDelegate> supplier;
/**
*
* @param delegateClass
* @param processUUID filter by process uuid (null for all process)
* @param supplier
*/
public ProcessEventHandler(Class<? extends ProcessEventDelegate> delegateClass, String processUUID, Function<Event, ? extends ProcessEventDelegate> 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);
}
}

View File

@ -407,7 +407,7 @@ public class ModelValidationEngine
//now process osgi event handlers //now process osgi event handlers
Event event = EventManager.newEvent(ModelValidator.tableEventTopics[changeType], 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); EventManager.getInstance().sendEvent(event);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES);
@ -574,7 +574,7 @@ public class ModelValidationEngine
//now process osgi event handlers //now process osgi event handlers
Event event = EventManager.newEvent(ModelValidator.documentEventTopics[docTiming], 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); EventManager.getInstance().sendEvent(event);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES);
@ -724,7 +724,7 @@ public class ModelValidationEngine
//process osgi event handlers //process osgi event handlers
FactsEventData eventData = new FactsEventData(schema, facts, po); FactsEventData eventData = new FactsEventData(schema, facts, po);
Event event = EventManager.newEvent(IEventTopics.ACCT_FACTS_VALIDATE, 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); EventManager.getInstance().sendEvent(event);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES); List<String> errors = (List<String>) event.getProperty(IEventManager.EVENT_ERROR_MESSAGES);
@ -802,7 +802,8 @@ public class ModelValidationEngine
topic = IEventTopics.IMPORT_BEFORE_IMPORT; topic = IEventTopics.IMPORT_BEFORE_IMPORT;
else if (timing == ImportValidator.TIMING_BEFORE_VALIDATE) else if (timing == ImportValidator.TIMING_BEFORE_VALIDATE)
topic = IEventTopics.IMPORT_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); EventManager.getInstance().sendEvent(event);
} }

View File

@ -1254,7 +1254,7 @@ public class DocumentEngine implements DocAction
DocActionEventData eventData = new DocActionEventData(docStatus, processing, orderType, isSOTrx, AD_Table_ID, docActionsArray, optionsArray, indexObj, po); DocActionEventData eventData = new DocActionEventData(docStatus, processing, orderType, isSOTrx, AD_Table_ID, docActionsArray, optionsArray, indexObj, po);
Event event = EventManager.newEvent(IEventTopics.DOCACTION, Event event = EventManager.newEvent(IEventTopics.DOCACTION,
new EventProperty(EventManager.EVENT_DATA, eventData), 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); EventManager.getInstance().sendEvent(event);
index = indexObj.get(); index = indexObj.get();
for (int i = 0; i < optionsArray.size(); i++) for (int i = 0; i < optionsArray.size(); i++)

View File

@ -298,9 +298,9 @@ public abstract class SvrProcess implements ProcessCall
private Event sendProcessEvent(String topic) { private Event sendProcessEvent(String topic) {
Event event = EventManager.newEvent(topic, Event event = EventManager.newEvent(topic,
new EventProperty(EventManager.EVENT_DATA, m_pi), new EventProperty(EventManager.EVENT_DATA, m_pi),
new EventProperty("processUUID", m_pi.getAD_Process_UU()), new EventProperty(EventManager.PROCESS_UID_PROPERTY, m_pi.getAD_Process_UU()),
new EventProperty("className", m_pi.getClassName()), new EventProperty(EventManager.CLASS_NAME_PROPERTY, m_pi.getClassName()),
new EventProperty("processClassName", this.getClass().getName())); new EventProperty(EventManager.PROCESS_CLASS_NAME_PROPERTY, this.getClass().getName()));
EventManager.getInstance().sendEvent(event); EventManager.getInstance().sendEvent(event);
return event; return event;
} }

View File

@ -25,6 +25,11 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.pde.PluginNature</nature>

View File

@ -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

View File

@ -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.converter;version="5.6.0",
org.junit.jupiter.params.provider;version="5.6.0", org.junit.jupiter.params.provider;version="5.6.0",
org.junit.jupiter.params.support;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", Require-Bundle: org.adempiere.base;bundle-version="8.2.0",
org.adempiere.base.callout;bundle-version="8.2.0", org.adempiere.base.callout;bundle-version="8.2.0",
org.adempiere.base.process;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-ActivationPolicy: lazy
Bundle-Activator: org.idempiere.test.TestActivator Bundle-Activator: org.idempiere.test.TestActivator
Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: org.idempiere.test
Service-Component: OSGI-INF/org.idempiere.test.event.MyComponent.xml

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" immediate="true" name="org.idempiere.test.event.MyComponent">
<reference bind="bindService" cardinality="1..1" field="eventManager" interface="org.adempiere.base.event.IEventManager" name="eventManager" unbind="unbindService"/>
<implementation class="org.idempiere.test.event.MyComponent"/>
</scr:component>

View File

@ -1,4 +1,5 @@
source.. = src/ source.. = src/
output.. = target/classes/ output.. = target/classes/
bin.includes = META-INF/,\ bin.includes = META-INF/,\
. .,\
OSGI-INF/org.idempiere.test.event.MyComponent.xml

View File

@ -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<MBPartner> handler = new ModelEventHandler<MBPartner>(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<MOrder> handler = new ModelEventHandler<MOrder>(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<MOrder> handler = new ModelEventHandler<MOrder>(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<MInOut> handler = new ModelEventHandler<MInOut>(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<MBPartner> {
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<MOrder> {
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<MInOut> {
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);
}
}
}

View File

@ -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<MBPartner> handler;
public MyComponent() {
}
/**
*
* @param eventManager
*/
public void bindService(IEventManager eventManager) {
this.eventManager = eventManager;
handler = new ModelEventHandler<MBPartner>(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<MBPartner> {
public MyBpBeforeChangeDelegate(MBPartner po, Event event) {
super(po, event);
}
@BeforeChange
public void beforeChange() {
Env.setContext(Env.getCtx(), getClass().getName(), getModel().toString());
}
}
}