details:   /erp/devel/pi/rev/94073d2a81f3
changeset: 10095:94073d2a81f3
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Mon Jan 24 14:26:52 2011 +0100
summary:   Added new persistence event framework

details:   /erp/devel/pi/rev/7a0d3db89d15
changeset: 10096:7a0d3db89d15
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Mon Jan 24 14:27:09 2011 +0100
summary:   Set document no event handler

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java
 |   83 +++++
 
modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
                            |   14 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelContextListener.java
                |   42 ++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelInitializer.java
                    |   53 +++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityDeleteEvent.java
              |   37 ++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityNewEvent.java
                 |   36 ++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityPersistenceEvent.java
         |  156 ++++++++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityPersistenceEventObserver.java
 |   56 +++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityUpdateEvent.java
              |   69 ++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/PersistenceEventOBInterceptor.java
  |  108 ++++++
 10 files changed, 654 insertions(+), 0 deletions(-)

diffs (truncated from 698 to 300 lines):

diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/SetDocumentNoHandler.java
     Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,83 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.client.application.event;
+
+import javax.enterprise.event.Observes;
+
+import org.openbravo.base.model.Entity;
+import org.openbravo.base.model.ModelProvider;
+import org.openbravo.base.model.Property;
+import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.client.kernel.event.EntityNewEvent;
+import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.common.enterprise.DocumentType;
+import org.openbravo.model.common.order.Order;
+import org.openbravo.service.db.DalConnectionProvider;
+
+/**
+ * Listens to save events on purchase and sales orders and sets the document 
no.
+ * 
+ * @see Utility#getDocumentNo(java.sql.Connection, 
org.openbravo.database.ConnectionProvider,
+ *      org.openbravo.base.secureApp.VariablesSecureApp, String, String, 
String, String, boolean,
+ *      boolean)
+ * 
+ * @author mtaal
+ */
+public class SetDocumentNoHandler extends EntityPersistenceEventObserver {
+
+  private static Entity[] entities = new Entity[] { 
ModelProvider.getInstance().getEntity(
+      Order.ENTITY_NAME) };
+  private static Property documentNoProperty = 
entities[0].getProperty(Order.PROPERTY_DOCUMENTNO);
+  private static Property docTypeTargetProperty = entities[0]
+      .getProperty(Order.PROPERTY_TRANSACTIONDOCUMENT);
+  private static Property docTypeProperty = 
entities[0].getProperty(Order.PROPERTY_DOCUMENTTYPE);
+
+  public void onSave(@Observes EntityNewEvent event) {
+
+    if (isValidEvent(event)) {
+      String documentNo = (String) event.getCurrentState(documentNoProperty);
+      if (documentNo == null || documentNo.startsWith("<")) {
+        final DocumentType docTypeTarget = (DocumentType) event
+            .getCurrentState(docTypeTargetProperty);
+        final DocumentType docType = (DocumentType) 
event.getCurrentState(docTypeProperty);
+        // use empty strings instead of null
+        final String docTypeTargetId = docTypeTarget != null ? 
docTypeTarget.getId() : "";
+        final String docTypeId = docType != null ? docType.getId() : "";
+        String windowId = RequestContext.get().getRequestParameter("windowId");
+        if (windowId == null) {
+          windowId = "";
+        }
+
+        // recompute it
+        documentNo = 
Utility.getDocumentNo(OBDal.getInstance().getConnection(false),
+            new DalConnectionProvider(false), 
RequestContext.get().getVariablesSecureApp(),
+            windowId, Order.TABLE_NAME, docTypeTargetId, docTypeId, false, 
true);
+        event.setCurrentState(documentNoProperty, documentNo);
+      }
+    }
+  }
+
+  @Override
+  protected Entity[] getObservedEntities() {
+    return entities;
+  }
+}
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
--- 
a/modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
        Mon Jan 24 14:18:25 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src-db/database/sourcedata/AD_MODEL_OBJECT.xml
        Mon Jan 24 14:27:09 2011 +0100
@@ -13,4 +13,18 @@
 <!--A761FF99519C45D1A4BEE9FA30B40AAC-->  <NAME><![CDATA[Client Kernel 
Servlet]]></NAME>
 <!--A761FF99519C45D1A4BEE9FA30B40AAC--></AD_MODEL_OBJECT>
 
+<!--FF8081812DB7706D012DB777A1AD0010--><AD_MODEL_OBJECT>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<AD_MODEL_OBJECT_ID><![CDATA[FF8081812DB7706D012DB777A1AD0010]]></AD_MODEL_OBJECT_ID>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--FF8081812DB7706D012DB777A1AD0010-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--FF8081812DB7706D012DB777A1AD0010-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--FF8081812DB7706D012DB777A1AD0010-->  <ACTION><![CDATA[M]]></ACTION>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<CLASSNAME><![CDATA[org.openbravo.client.kernel.KernelContextListener]]></CLASSNAME>
+<!--FF8081812DB7706D012DB777A1AD0010-->  <ISDEFAULT><![CDATA[N]]></ISDEFAULT>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<AD_MODULE_ID><![CDATA[4B828F4D03264080AA1D2057B13F613C]]></AD_MODULE_ID>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<OBJECT_TYPE><![CDATA[L]]></OBJECT_TYPE>
+<!--FF8081812DB7706D012DB777A1AD0010-->  <SEQNO><![CDATA[30]]></SEQNO>
+<!--FF8081812DB7706D012DB777A1AD0010-->  
<NAME><![CDATA[org.openbravo.client.kernel.KernelContextListener]]></NAME>
+<!--FF8081812DB7706D012DB777A1AD0010--></AD_MODEL_OBJECT>
+
 </data>
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelContextListener.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelContextListener.java
    Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,42 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.client.kernel;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.openbravo.base.weld.WeldUtils;
+
+/**
+ * Initializes the kernel layer in a servlet environment.
+ * 
+ * @see KernelInitializer
+ * 
+ * @author mtaal
+ */
+public class KernelContextListener implements ServletContextListener {
+
+  public void contextInitialized(ServletContextEvent event) {
+    
WeldUtils.getInstanceFromStaticBeanManager(KernelInitializer.class).initialize();
+  }
+
+  public void contextDestroyed(ServletContextEvent event) {
+  }
+}
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelInitializer.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelInitializer.java
        Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,53 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.client.kernel;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.client.kernel.event.PersistenceEventOBInterceptor;
+import org.openbravo.dal.core.OBInterceptor;
+
+/**
+ * Class responsible for initializing the kernel layer. Can be used in a 
servlet as well as a
+ * non-servlet environment.
+ * 
+ * @author mtaal
+ */
+@ApplicationScoped
+public class KernelInitializer {
+
+  @Inject
+  private PersistenceEventOBInterceptor persistenceEventOBInterceptor;
+
+  public void initialize() {
+    setInterceptor();
+  }
+
+  public synchronized void setInterceptor() {
+    final OBInterceptor interceptor = (OBInterceptor) 
SessionFactoryController.getInstance()
+        .getConfiguration().getInterceptor();
+    if (interceptor.getInterceptorListener() == null) {
+      interceptor.setInterceptorListener(persistenceEventOBInterceptor);
+    }
+  }
+
+}
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityDeleteEvent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityDeleteEvent.java
  Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,37 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.kernel.event;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * The event object send out when an entity gets deleted.
+ * 
+ * To receive this event, create a class with a method which has this 
signature:
+ * 
+ * public void onEvent(@Observes EntityDeleteEvent event) {
+ * 
+ * Note, the method name is unimportant, the @Observes EntityDeleteEvent 
specifies that this method
+ * will be called before persisting a new instance.
+ * 
+ * @author mtaal
+ */
+@ApplicationScoped
+public class EntityDeleteEvent extends EntityPersistenceEvent {
+}
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityNewEvent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityNewEvent.java
     Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,36 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.kernel.event;
+
+
+/**
+ * The event object send out when an entity gets saved for the first time.
+ * 
+ * To receive this event, create a class with a method which has this 
signature:
+ * 
+ * public void onSave(@Observes EntityNewEvent event) {
+ * 
+ * Note, the method name is unimportant, the @Observes EntityNewEvent 
specifies that this method
+ * will be called before persisting a new instance.
+ * 
+ * @author mtaal
+ */
+public class EntityNewEvent extends EntityPersistenceEvent {
+
+}
diff -r 4d859c79a1ae -r 7a0d3db89d15 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityPersistenceEvent.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/event/EntityPersistenceEvent.java
     Mon Jan 24 14:27:09 2011 +0100
@@ -0,0 +1,156 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to