Fixes Issue 0023883 : At least one field should be visible in grid view
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Mon, 27 May 2013 15:59:41 +0530
changeset 20471 20388faf6420
parent 20470 7c61b34d581b
child 20472 d8cc7de67a13
Fixes Issue 0023883 : At least one field should be visible in grid view

Export fails now if there is a tab with no fields visible in grid view.
Also an error in log is raised when the tab is opened.
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
src/org/openbravo/service/system/DatabaseValidator.java
src/org/openbravo/service/system/SystemValidationResult.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Fri May 24 12:39:17 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java	Mon May 27 15:59:41 2013 +0530
@@ -31,6 +31,7 @@
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
@@ -46,6 +47,7 @@
 import org.openbravo.client.kernel.reference.UIDefinitionController;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.Sqlc;
 import org.openbravo.erpCommon.obps.ActivationKey;
@@ -282,6 +284,15 @@
     // force a load all the columns of the table
     getTab().getTable().getADColumnList().size();
 
+    // check at least one field is visible in grid view, does not stop the execution
+    OBCriteria<Field> fieldCriteria = OBDal.getInstance().createCriteria(Field.class);
+    fieldCriteria.add(Restrictions.eq(Field.PROPERTY_TAB, getTab()));
+    fieldCriteria.add(Restrictions.eq(Field.PROPERTY_SHOWINGRIDVIEW, true));
+    if (fieldCriteria.count() == 0) {
+      log.error("No Fields are visible in grid view for Tab " + tab.getWindow().getName() + " - "
+          + tab.getName());
+    }
+
     final OBViewGridComponent viewGridComponent = createComponent(OBViewGridComponent.class);
     viewGridComponent.setParameters(getParameters());
     viewGridComponent.setTab(tab);
--- a/src/org/openbravo/service/system/DatabaseValidator.java	Fri May 24 12:39:17 2013 +0200
+++ b/src/org/openbravo/service/system/DatabaseValidator.java	Mon May 27 15:59:41 2013 +0530
@@ -49,6 +49,8 @@
 import org.openbravo.model.ad.module.Module;
 import org.openbravo.model.ad.module.ModuleDBPrefix;
 import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.ad.ui.Field;
+import org.openbravo.model.ad.ui.Tab;
 import org.openbravo.model.ad.utility.DataSet;
 import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.service.system.SystemValidationResult.SystemValidationType;
@@ -221,6 +223,7 @@
         }
         matchColumns(adTable, dbTable, result);
         tmpDBTablesByName.remove(dbTable.getName().toUpperCase());
+        checkFieldsInGridView(adTable, result);
       }
     }
     for (int i = 0; i < database.getTableCount(); i++) {
@@ -850,4 +853,26 @@
     this.dbsmExecution = dbsmExecution;
   }
 
+  /*
+   * Check at least one field is visible in grid view
+   */
+  public void checkFieldsInGridView(Table adTable, SystemValidationResult result) {
+    OBCriteria<Tab> tabCriteria = OBDal.getInstance().createCriteria(Tab.class);
+    tabCriteria.add(Restrictions.eq(Tab.PROPERTY_TABLE, adTable));
+    for (Tab tab : tabCriteria.list()) {
+      if ("Field Sequence".equals(tab.getName()) || ("Grid Sequence".equals(tab.getName()))) {
+        continue;
+      }
+      OBCriteria<Field> fieldCriteria = OBDal.getInstance().createCriteria(Field.class);
+      fieldCriteria.add(Restrictions.eq(Field.PROPERTY_TAB, tab));
+      fieldCriteria.add(Restrictions.eq(Field.PROPERTY_SHOWINGRIDVIEW, true));
+      if (fieldCriteria.count() == 0) {
+        result.addError(
+            SystemValidationType.NOFIELDSINGRIDVIEW,
+            "No Fields are visible in grid view for Tab " + tab.getWindow().getName() + " - "
+                + tab.getName());
+      }
+    }
+
+  }
 }
--- a/src/org/openbravo/service/system/SystemValidationResult.java	Fri May 24 12:39:17 2013 +0200
+++ b/src/org/openbravo/service/system/SystemValidationResult.java	Mon May 27 15:59:41 2013 +0530
@@ -32,7 +32,7 @@
 public class SystemValidationResult {
 
   public enum SystemValidationType {
-    NAME_TOO_LONG, MODULE_ERROR, CUSTOMIZATION_ID, INCORRECT_DEFAULT_VALUE, WRONG_NAME, WRONG_LENGTH, NO_PRIMARY_KEY_COLUMNS, NOT_NULL_IN_DB_NOT_MANDATORY_IN_AD, MANDATORY_IN_AD_NULLABLE_IN_DB, NOT_EXIST_IN_AD, NOT_EXIST_IN_DB, NOT_PART_OF_FOREIGN_KEY, WRONG_TYPE, INCORRECT_CLIENT_ORG_PROPERTY_NAME, UNEQUAL_DEFAULTVALUE, INCORRECT_PK_NAME, INCORRECT_FK_NAME, INCORRECT_CHECK_NAME, INCORRECT_UNIQUE_NAME, INCORRECT_INDEX_NAME, INCORRECT_NAME_LENGTH, INCORRECT_DATASET_NAME, DEPENDENCY_PROBLEM, HAS_PROPERTY_CONFIGURATION, OLDSTYLE_PASSWORD_COLUMNS, DUPLICATED_INCLUSION;
+    NAME_TOO_LONG, MODULE_ERROR, CUSTOMIZATION_ID, INCORRECT_DEFAULT_VALUE, WRONG_NAME, WRONG_LENGTH, NO_PRIMARY_KEY_COLUMNS, NOT_NULL_IN_DB_NOT_MANDATORY_IN_AD, MANDATORY_IN_AD_NULLABLE_IN_DB, NOT_EXIST_IN_AD, NOT_EXIST_IN_DB, NOT_PART_OF_FOREIGN_KEY, WRONG_TYPE, INCORRECT_CLIENT_ORG_PROPERTY_NAME, UNEQUAL_DEFAULTVALUE, INCORRECT_PK_NAME, INCORRECT_FK_NAME, INCORRECT_CHECK_NAME, INCORRECT_UNIQUE_NAME, INCORRECT_INDEX_NAME, INCORRECT_NAME_LENGTH, INCORRECT_DATASET_NAME, DEPENDENCY_PROBLEM, HAS_PROPERTY_CONFIGURATION, OLDSTYLE_PASSWORD_COLUMNS, DUPLICATED_INCLUSION, NOFIELDSINGRIDVIEW;
 
     public String getName() {
       return this.getClass().getSimpleName();