Updated to changed api
authorMartin Taal <martin.taal@openbravo.com>
Sat, 21 Nov 2015 22:39:10 +0100
changeset 3 b1dafc97de17
parent 2 4184d825caa1
child 4 52f356c919ef
Updated to changed api
src/org/openbravo/retail/storeserver/howto/central/CheckProductCentral.java
src/org/openbravo/retail/storeserver/howto/central/ProcessEntry.java
src/org/openbravo/retail/storeserver/howto/store/CheckProductStore.java
--- a/src/org/openbravo/retail/storeserver/howto/central/CheckProductCentral.java	Thu Nov 12 15:52:39 2015 +0100
+++ b/src/org/openbravo/retail/storeserver/howto/central/CheckProductCentral.java	Sat Nov 21 22:39:10 2015 +0100
@@ -8,13 +8,12 @@
  */
 package org.openbravo.retail.storeserver.howto.central;
 
-import javax.servlet.ServletException;
-
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.Query;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.mobile.core.servercontroller.MobileServerJSONProcess;
 import org.openbravo.service.json.JsonConstants;
@@ -33,32 +32,36 @@
     return true;
   }
 
-  protected JSONObject executeWhenOffline(JSONObject json) throws JSONException, ServletException {
+  protected JSONObject executeWhenOffline(JSONObject json) {
     return execute(json);
   }
 
-  protected JSONObject executeWhenOnline(JSONObject json) throws JSONException, ServletException {
+  protected JSONObject executeWhenOnline(JSONObject json) {
     return execute(json);
   }
 
-  protected JSONObject execute(JSONObject json) throws JSONException, ServletException {
-    JSONArray respArray = new JSONArray();
-    JSONObject result = new JSONObject();
+  protected JSONObject execute(JSONObject json) {
+    try {
+      JSONArray respArray = new JSONArray();
+      JSONObject result = new JSONObject();
 
-    String productId = json.getString("productId");
-    String hqlCheckProduct = "select count(p.id) from Product as p " + "where p.id='" + productId
-        + "' ";
-    Query checkProductQuery = OBDal.getInstance().getSession().createQuery(hqlCheckProduct);
+      String productId = json.getString("productId");
+      String hqlCheckProduct = "select count(p.id) from Product as p " + "where p.id='" + productId
+          + "' ";
+      Query checkProductQuery = OBDal.getInstance().getSession().createQuery(hqlCheckProduct);
 
-    for (Object objIter : checkProductQuery.list()) {
-      JSONObject objJson = new JSONObject();
-      objJson.put("count", objIter);
-      objJson.put("source", "central");
-      respArray.put(objJson);
+      for (Object objIter : checkProductQuery.list()) {
+        JSONObject objJson = new JSONObject();
+        objJson.put("count", objIter);
+        objJson.put("source", "central");
+        respArray.put(objJson);
+      }
+
+      result.put(JsonConstants.RESPONSE_DATA, respArray);
+      result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
+      return result;
+    } catch (JSONException e) {
+      throw new OBException(e);
     }
-
-    result.put(JsonConstants.RESPONSE_DATA, respArray);
-    result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
-    return result;
   }
-}
\ No newline at end of file
+}
--- a/src/org/openbravo/retail/storeserver/howto/central/ProcessEntry.java	Thu Nov 12 15:52:39 2015 +0100
+++ b/src/org/openbravo/retail/storeserver/howto/central/ProcessEntry.java	Sat Nov 21 22:39:10 2015 +0100
@@ -8,11 +8,10 @@
  */
 package org.openbravo.retail.storeserver.howto.central;
 
-import javax.servlet.ServletException;
-
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.mobile.core.servercontroller.MobileServerJSONProcess;
 import org.openbravo.service.json.JsonConstants;
 
@@ -30,18 +29,22 @@
     return true;
   }
 
-  protected JSONObject executeWhenOffline(JSONObject json) throws JSONException, ServletException {
+  protected JSONObject executeWhenOffline(JSONObject json) {
     return execute(json);
   }
 
-  protected JSONObject executeWhenOnline(JSONObject json) throws JSONException, ServletException {
+  protected JSONObject executeWhenOnline(JSONObject json) {
     return execute(json);
   }
 
-  protected JSONObject execute(JSONObject json) throws JSONException, ServletException {
-    System.err.println("Received json " + json);
-    JSONObject result = new JSONObject();
-    result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
-    return result;
+  protected JSONObject execute(JSONObject json) {
+    try {
+      System.err.println("Received json " + json);
+      JSONObject result = new JSONObject();
+      result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
+      return result;
+    } catch (JSONException e) {
+      throw new OBException(e);
+    }
   }
-}
\ No newline at end of file
+}
--- a/src/org/openbravo/retail/storeserver/howto/store/CheckProductStore.java	Thu Nov 12 15:52:39 2015 +0100
+++ b/src/org/openbravo/retail/storeserver/howto/store/CheckProductStore.java	Sat Nov 21 22:39:10 2015 +0100
@@ -8,13 +8,12 @@
  */
 package org.openbravo.retail.storeserver.howto.store;
 
-import javax.servlet.ServletException;
-
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONArray;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.Query;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.mobile.core.servercontroller.MobileServerController;
@@ -37,30 +36,34 @@
     return true;
   }
 
-  protected JSONObject executeWhenOffline(JSONObject json) throws JSONException, ServletException {
-    JSONArray respArray = new JSONArray();
-    JSONObject result = new JSONObject();
+  protected JSONObject executeWhenOffline(JSONObject json) {
+    try {
+      JSONArray respArray = new JSONArray();
+      JSONObject result = new JSONObject();
 
-    String productId = json.getString("productId");
-    String hqlCheckProduct = "select count(p.id) from Product as p " + "where p.id='" + productId
-        + "' ";
-    Query checkProductQuery = OBDal.getInstance().getSession().createQuery(hqlCheckProduct);
+      String productId = json.getString("productId");
+      String hqlCheckProduct = "select count(p.id) from Product as p " + "where p.id='" + productId
+          + "' ";
+      Query checkProductQuery = OBDal.getInstance().getSession().createQuery(hqlCheckProduct);
 
-    for (Object objIter : checkProductQuery.list()) {
-      JSONObject objJson = new JSONObject();
-      objJson.put("count", objIter);
-      objJson.put("source", MobileServerController.getInstance().isThisAStoreServer() ? "store"
-          : "central");
-      respArray.put(objJson);
+      for (Object objIter : checkProductQuery.list()) {
+        JSONObject objJson = new JSONObject();
+        objJson.put("count", objIter);
+        objJson.put("source", MobileServerController.getInstance().isThisAStoreServer() ? "store"
+            : "central");
+        respArray.put(objJson);
+      }
+
+      result.put(JsonConstants.RESPONSE_DATA, respArray);
+      result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
+
+      return result;
+    } catch (JSONException e) {
+      throw new OBException(e);
     }
-
-    result.put(JsonConstants.RESPONSE_DATA, respArray);
-    result.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
-
-    return result;
   }
 
-  protected JSONObject executeWhenOnline(JSONObject json) throws JSONException, ServletException {
+  protected JSONObject executeWhenOnline(JSONObject json) {
     // handle the case that the WebPOS calls the central server with this same service name
     if (MobileServerController.getInstance().isThisACentralServer()) {
       // in this example online behavior is the same as central behavior
@@ -78,4 +81,4 @@
         MobileServerUtils.OBWSPATH
             + "org.openbravo.retail.storeserver.howto.central.CheckProductCentral", json);
   }
-}
\ No newline at end of file
+}