Check that exists a query defined to prevent a NPE.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 14 Dec 2010 14:12:02 +0100
changeset 9126 ad4fb64a6f27
parent 9125 63908817afee
child 9127 81d93d29ae90
Check that exists a query defined to prevent a NPE.
modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListUtils.java
--- a/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListUtils.java	Tue Dec 14 14:11:26 2010 +0100
+++ b/modules/org.openbravo.client.querylist/src/org/openbravo/client/querylist/QueryListUtils.java	Tue Dec 14 14:12:02 2010 +0100
@@ -39,35 +39,37 @@
   public static String getWidgetClassFields(WidgetClass widgetClass, IncludeIn includeIn) {
     try {
       final List<JSONObject> jsonFields = new ArrayList<JSONObject>();
-      for (OBCQL_QueryColumn column : QueryListUtils.getColumns(widgetClass
-          .getOBCQLWidgetQueryList().get(0), includeIn)) {
-        final JSONObject field = new JSONObject();
-        field.put("name", column.getName());
-        final Reference reference;
-        if (column.getReferenceSearchKey() != null) {
-          reference = column.getReferenceSearchKey();
-        } else {
-          reference = column.getReference();
+      if (!widgetClass.getOBCQLWidgetQueryList().isEmpty()) {
+        for (OBCQL_QueryColumn column : QueryListUtils.getColumns(widgetClass
+            .getOBCQLWidgetQueryList().get(0), includeIn)) {
+          final JSONObject field = new JSONObject();
+          field.put("name", column.getName());
+          final Reference reference;
+          if (column.getReferenceSearchKey() != null) {
+            reference = column.getReferenceSearchKey();
+          } else {
+            reference = column.getReference();
+          }
+          final UIDefinition uiDefinition = UIDefinitionController.getInstance().getUIDefinition(
+              reference);
+          field.put("type", uiDefinition.getName());
+          try {
+            final String fieldProperties = uiDefinition.getFieldProperties(null);
+            if (fieldProperties != null && fieldProperties.trim().length() > 0) {
+              final JSONObject fieldPropertiesObject = new JSONObject(fieldProperties);
+              field.put("fieldProperties", fieldPropertiesObject);
+            }
+          } catch (NullPointerException e) {
+            // handle non-careful implementors of ui definitions
+            log.error("Error when processing column: " + column, e);
+            // ignore this field properties for now
+          }
+
+          field.put("title", getColumnLabel(column));
+
+          field.put("width", column.getWidth());
+          jsonFields.add(field);
         }
-        final UIDefinition uiDefinition = UIDefinitionController.getInstance().getUIDefinition(
-            reference);
-        field.put("type", uiDefinition.getName());
-        try {
-          final String fieldProperties = uiDefinition.getFieldProperties(null);
-          if (fieldProperties != null && fieldProperties.trim().length() > 0) {
-            final JSONObject fieldPropertiesObject = new JSONObject(fieldProperties);
-            field.put("fieldProperties", fieldPropertiesObject);
-          }
-        } catch (NullPointerException e) {
-          // handle non-careful implementors of ui definitions
-          log.error("Error when processing column: " + column, e);
-          // ignore this field properties for now
-        }
-
-        field.put("title", getColumnLabel(column));
-
-        field.put("width", column.getWidth());
-        jsonFields.add(field);
       }
       final JSONArray fields = new JSONArray(jsonFields);
       return fields.toString();
@@ -81,8 +83,8 @@
     OBCriteria<OBCQL_QueryColumn> obcColumns = OBDal.getInstance().createCriteria(
         OBCQL_QueryColumn.class);
     obcColumns.add(Expression.eq(OBCQL_QueryColumn.PROPERTY_WIDGETQUERY, query));
-    obcColumns.add(Expression.in(OBCQL_QueryColumn.PROPERTY_INCLUDEIN,
-        includeIn.getIncludedValues()));
+    obcColumns.add(Expression.in(OBCQL_QueryColumn.PROPERTY_INCLUDEIN, includeIn
+        .getIncludedValues()));
     obcColumns.addOrderBy(OBCQL_QueryColumn.PROPERTY_SEQUENCENUMBER, true);
     return obcColumns.list();
   }