details:   https://code.openbravo.com/erp/devel/pi/rev/d8cc7de67a13
changeset: 20472:d8cc7de67a13
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Mon May 27 19:16:03 2013 +0530
summary:   Fixes Issue 0023915: Java class name for a table cannot contain 
spaces

Added business event handler to validate that java class name in tables cannot 
contain spaces.

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableEventHandler.java
 |  80 ++++++++++
 src-db/database/sourcedata/AD_MESSAGE.xml                                      
                            |  13 +
 2 files changed, 93 insertions(+), 0 deletions(-)

diffs (108 lines):

diff -r 20388faf6420 -r d8cc7de67a13 
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableEventHandler.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableEventHandler.java
        Mon May 27 19:16:03 2013 +0530
@@ -0,0 +1,80 @@
+/*
+ *************************************************************************
+ * 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) 2013 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.client.application.event;
+
+import javax.enterprise.event.Observes;
+
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.model.Entity;
+import org.openbravo.base.model.ModelProvider;
+import org.openbravo.base.model.Property;
+import org.openbravo.client.kernel.event.EntityNewEvent;
+import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
+import org.openbravo.client.kernel.event.EntityUpdateEvent;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.model.ad.datamodel.Table;
+import org.openbravo.service.db.DalConnectionProvider;
+
+/**
+ * Checks that the java class name in table definition does not contain spaces
+ * 
+ * @author Shankar
+ */
+public class TableEventHandler extends EntityPersistenceEventObserver {
+  private static Entity[] entities = { 
ModelProvider.getInstance().getEntity(Table.ENTITY_NAME) };
+
+  public void onUpdate(@Observes
+  EntityUpdateEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    Property javaClass = entities[0].getProperty(Table.PROPERTY_JAVACLASSNAME);
+    String javaClassName = (String) event.getCurrentState(javaClass);
+    checkJavaClassName(javaClassName);
+
+  }
+
+  public void onNew(@Observes
+  EntityNewEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    Property javaClass = entities[0].getProperty(Table.PROPERTY_JAVACLASSNAME);
+    String javaClassName = (String) event.getCurrentState(javaClass);
+    checkJavaClassName(javaClassName);
+  }
+
+  @Override
+  protected Entity[] getObservedEntities() {
+    // TODO Auto-generated method stub
+    return entities;
+  }
+
+  private Boolean checkJavaClassName(String javaClassName) {
+    if (javaClassName != null && javaClassName.contains(" ")) {
+      String language = OBContext.getOBContext().getLanguage().getLanguage();
+      ConnectionProvider conn = new DalConnectionProvider(false);
+      throw new OBException(Utility.messageBD(conn, 
"JavaClassShouldNotContainSpaces", language));
+    }
+    return true;
+  }
+}
\ No newline at end of file
diff -r 20388faf6420 -r d8cc7de67a13 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Mon May 27 15:59:41 2013 +0530
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Mon May 27 19:16:03 2013 +0530
@@ -18549,6 +18549,19 @@
 <!--4D438024F33D44F099C813ABF6BFCAE2-->  
<ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--4D438024F33D44F099C813ABF6BFCAE2--></AD_MESSAGE>
 
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D--><AD_MESSAGE>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  
<AD_MESSAGE_ID><![CDATA[4D472B4DD1144DE3B5BA3AC9D47F751D]]></AD_MESSAGE_ID>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  
<VALUE><![CDATA[JavaClassShouldNotContainSpaces]]></VALUE>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  <MSGTEXT><![CDATA[Java class name 
should not contain spaces]]></MSGTEXT>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  <MSGTIP><![CDATA[Java class name 
should not contain spaces]]></MSGTIP>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D-->  
<ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--4D472B4DD1144DE3B5BA3AC9D47F751D--></AD_MESSAGE>
+
 <!--4D4E566D206546908DB84B065999789C--><AD_MESSAGE>
 <!--4D4E566D206546908DB84B065999789C-->  
<AD_MESSAGE_ID><![CDATA[4D4E566D206546908DB84B065999789C]]></AD_MESSAGE_ID>
 <!--4D4E566D206546908DB84B065999789C-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to