Fixes Issue 0023915: Java class name for a table cannot contain spaces
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Mon, 27 May 2013 19:16:03 +0530
changeset 20472 d8cc7de67a13
parent 20471 20388faf6420
child 20473 ee752250a37d
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.
modules/org.openbravo.client.application/src/org/openbravo/client/application/event/TableEventHandler.java
src-db/database/sourcedata/AD_MESSAGE.xml
--- /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
--- 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>