Initial Commit
authorMartin Taal <martin.taal@openbravo.com>
Wed, 11 Nov 2015 14:00:22 +0100
changeset 0 fa16f0610f7b
child 1 c3b286dfee66
Initial Commit
src-db/database/sourcedata/AD_MODULE.xml
src-db/database/sourcedata/AD_MODULE_DBPREFIX.xml
src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml
src-db/database/sourcedata/AD_PACKAGE.xml
src-db/database/sourcedata/OBMOBC_SERVICES.xml
src/org/openbravo/retail/storeserver/howto/StoreServerHowToComponentProvider.java
src/org/openbravo/retail/storeserver/howto/central/CheckProductCentral.java
src/org/openbravo/retail/storeserver/howto/store/CheckProductStore.java
web/org.openbravo.retail.storeserver.howto/js/ob-storeserver-howto-add-button.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_MODULE.xml	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--ED6F408F7E85415A961E06275EDE3028--><AD_MODULE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <NAME><![CDATA[Store Server Howto Module]]></NAME>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <VERSION><![CDATA[1.0.0]]></VERSION>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <DESCRIPTION><![CDATA[Module to support howtos for developing store server functionality]]></DESCRIPTION>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <URL><![CDATA[http://www.openbravo.com/]]></URL>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <TYPE><![CDATA[M]]></TYPE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <LICENSE><![CDATA[Copyright (C) 2015 Openbravo S.L.U.
+Licensed under the Openbravo Commercial License version 1.0
+You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html or in the legal folder of this module distribution.]]></LICENSE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <JAVAPACKAGE><![CDATA[org.openbravo.retail.storeserver.howto]]></JAVAPACKAGE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <LICENSETYPE><![CDATA[OBCL]]></LICENSETYPE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <AUTHOR><![CDATA[Openbravo S.L.U.]]></AUTHOR>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <ISTRANSLATIONREQUIRED><![CDATA[N]]></ISTRANSLATIONREQUIRED>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <AD_LANGUAGE><![CDATA[en_US]]></AD_LANGUAGE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <HASCHARTOFACCOUNTS><![CDATA[N]]></HASCHARTOFACCOUNTS>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <ISTRANSLATIONMODULE><![CDATA[N]]></ISTRANSLATIONMODULE>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <HASREFERENCEDATA><![CDATA[N]]></HASREFERENCEDATA>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <ISCOMMERCIAL><![CDATA[Y]]></ISCOMMERCIAL>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <COMMERCIAL_TIER><![CDATA[2]]></COMMERCIAL_TIER>
+<!--ED6F408F7E85415A961E06275EDE3028-->  <ISTRIALALLOWED><![CDATA[Y]]></ISTRIALALLOWED>
+<!--ED6F408F7E85415A961E06275EDE3028--></AD_MODULE>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_MODULE_DBPREFIX.xml	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22--><AD_MODULE_DBPREFIX>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <AD_MODULE_DBPREFIX_ID><![CDATA[B6BA5CF83A9A4FE491FAAF9DF43F1B22]]></AD_MODULE_DBPREFIX_ID>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22-->  <NAME><![CDATA[OBSTHOW]]></NAME>
+<!--B6BA5CF83A9A4FE491FAAF9DF43F1B22--></AD_MODULE_DBPREFIX>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_MODULE_DEPENDENCY.xml	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--072FD0D6165549EE8C9E1C34B77A37DD--><AD_MODULE_DEPENDENCY>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <AD_MODULE_DEPENDENCY_ID><![CDATA[072FD0D6165549EE8C9E1C34B77A37DD]]></AD_MODULE_DEPENDENCY_ID>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <AD_DEPENDENT_MODULE_ID><![CDATA[FF808181326CC34901326D53DBCF0018]]></AD_DEPENDENT_MODULE_ID>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <STARTVERSION><![CDATA[1.2.3110]]></STARTVERSION>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <ISINCLUDED><![CDATA[N]]></ISINCLUDED>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <DEPENDANT_MODULE_NAME><![CDATA[Web POS]]></DEPENDANT_MODULE_NAME>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <DEPENDENCY_ENFORCEMENT><![CDATA[MAJOR]]></DEPENDENCY_ENFORCEMENT>
+<!--072FD0D6165549EE8C9E1C34B77A37DD-->  <USER_EDITABLE_ENFORCEMENT><![CDATA[N]]></USER_EDITABLE_ENFORCEMENT>
+<!--072FD0D6165549EE8C9E1C34B77A37DD--></AD_MODULE_DEPENDENCY>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_PACKAGE.xml	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,13 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2--><AD_PACKAGE>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <AD_PACKAGE_ID><![CDATA[20FA4E9A2D7A4644A6DB6E9ED27328E2]]></AD_PACKAGE_ID>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <NAME><![CDATA[org.openbravo.retail.storeserver.howto]]></NAME>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <JAVAPACKAGE><![CDATA[org.openbravo.retail.storeserver.howto]]></JAVAPACKAGE>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--20FA4E9A2D7A4644A6DB6E9ED27328E2--></AD_PACKAGE>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/OBMOBC_SERVICES.xml	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,25 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--13E3955B83F348F7B60AAACEE6A7BE86--><OBMOBC_SERVICES>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <OBMOBC_SERVICES_ID><![CDATA[13E3955B83F348F7B60AAACEE6A7BE86]]></OBMOBC_SERVICES_ID>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <SERVICE><![CDATA[org.openbravo.retail.posterminal.CheckProductStore]]></SERVICE>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <DESCRIPTION><![CDATA[Example code for the store server documentation on code running in the store server]]></DESCRIPTION>
+<!--13E3955B83F348F7B60AAACEE6A7BE86-->  <ROUTINGTYPE><![CDATA[Failover]]></ROUTINGTYPE>
+<!--13E3955B83F348F7B60AAACEE6A7BE86--></OBMOBC_SERVICES>
+
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173--><OBMOBC_SERVICES>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <OBMOBC_SERVICES_ID><![CDATA[3EA7B669022F4F1EA7DFCCE70EA4A173]]></OBMOBC_SERVICES_ID>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <AD_MODULE_ID><![CDATA[ED6F408F7E85415A961E06275EDE3028]]></AD_MODULE_ID>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <SERVICE><![CDATA[org.openbravo.retail.posterminal.CheckProductCentral]]></SERVICE>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <DESCRIPTION><![CDATA[Example code for the store server documentation on code running in the central server]]></DESCRIPTION>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173-->  <ROUTINGTYPE><![CDATA[Failover]]></ROUTINGTYPE>
+<!--3EA7B669022F4F1EA7DFCCE70EA4A173--></OBMOBC_SERVICES>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/retail/storeserver/howto/StoreServerHowToComponentProvider.java	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,55 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+package org.openbravo.retail.storeserver.howto;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.openbravo.client.kernel.BaseComponentProvider;
+import org.openbravo.client.kernel.BaseComponentProvider.ComponentResource.ComponentResourceType;
+import org.openbravo.client.kernel.Component;
+import org.openbravo.client.kernel.ComponentProvider;
+
+/**
+ */
+@ApplicationScoped
+@ComponentProvider.Qualifier(StoreServerHowToComponentProvider.QUALIFIER)
+public class StoreServerHowToComponentProvider extends BaseComponentProvider {
+
+  public static final String QUALIFIER = "STORESERVERHOWTO";
+
+  private List<ComponentResource> globalResources = null;
+
+  @Override
+  public Component getComponent(String componentId, Map<String, Object> parameters) {
+    throw new IllegalArgumentException("Component id " + componentId + " not supported.");
+  }
+
+  @Override
+  public synchronized List<ComponentResource> getGlobalComponentResources() {
+    if (globalResources != null) {
+      return globalResources;
+    }
+    globalResources = new ArrayList<ComponentResource>();
+
+    final String prefix = "web/org.openbravo.retail.storeserver.howto/js/";
+
+    final String[] resourceDependency = { "ob-storeserver-howto-add-button" };
+
+    for (final String resource : resourceDependency) {
+      globalResources.add(createComponentResource(ComponentResourceType.Static, prefix + resource
+          + ".js", "WebPOS"));
+    }
+
+    return globalResources;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/retail/storeserver/howto/central/CheckProductCentral.java	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,64 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+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.dal.service.OBDal;
+import org.openbravo.mobile.core.servercontroller.MobileServerJSONProcess;
+import org.openbravo.service.json.JsonConstants;
+
+/**
+ * Example code to show that code is called for the store server/central server.
+ * 
+ * This code is called from the store server, the central server executes the same code if it is
+ * online or offline. In other scenarios it can call an ERP or other external system.
+ */
+public class CheckProductCentral extends MobileServerJSONProcess {
+  public static final Logger log = Logger.getLogger(CheckProductCentral.class);
+
+  @Override
+  protected boolean bypassPreferenceCheck() {
+    return true;
+  }
+
+  protected JSONObject executeWhenOffline(JSONObject json) throws JSONException, ServletException {
+    return execute(json);
+  }
+
+  protected JSONObject executeWhenOnline(JSONObject json) throws JSONException, ServletException {
+    return execute(json);
+  }
+
+  protected JSONObject execute(JSONObject json) throws JSONException, ServletException {
+    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);
+
+    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;
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/retail/storeserver/howto/store/CheckProductStore.java	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,74 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+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.dal.service.OBDal;
+import org.openbravo.mobile.core.servercontroller.MobileServerController;
+import org.openbravo.mobile.core.servercontroller.MobileServerJSONProcess;
+import org.openbravo.mobile.core.servercontroller.MobileServerRequestExecutor;
+import org.openbravo.mobile.core.servercontroller.MobileServerUtils;
+import org.openbravo.service.json.JsonConstants;
+
+/**
+ * Example code to show that code is called for the store server/central server.
+ * 
+ * If the store is offline then the code will do a local query, if it is online it will call the
+ * central server service.
+ */
+public class CheckProductStore extends MobileServerJSONProcess {
+  public static final Logger log = Logger.getLogger(CheckProductStore.class);
+
+  @Override
+  protected boolean bypassPreferenceCheck() {
+    return true;
+  }
+
+  protected JSONObject executeWhenOffline(JSONObject json) throws JSONException, ServletException {
+    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);
+
+    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;
+  }
+
+  protected JSONObject executeWhenOnline(JSONObject json) throws JSONException, ServletException {
+    // 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
+      // but in practive any other behavior can be used
+      return executeWhenOffline(json);
+    }
+
+    // this is a store server, call the central server
+    return MobileServerRequestExecutor.getInstance().executeRequest(
+        MobileServerUtils.OBWSPATH
+            + "org.openbravo.retail.storeserver.howto.central.CheckProductCentral", json);
+  }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/org.openbravo.retail.storeserver.howto/js/ob-storeserver-howto-add-button.js	Wed Nov 11 14:00:22 2015 +0100
@@ -0,0 +1,37 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+/*global enyo, Backbone, $, _ */
+
+(function () {
+
+  enyo.kind({
+    kind: 'OB.UI.SmallButton',
+    name: 'OB.OBPOSPointOfSale.UI.EditLine.StoreServerProductCheck',
+    content: 'Product Check',
+    classes: 'btnlink-orange',
+    tap: function () {
+      var process = new OB.DS.Process('org.openbravo.retail.posterminal.CheckProductStore');
+      process.exec({
+        productId: this.owner.line.get('product'),
+        authenticationClient: decodeURIComponent(localStorage.authenticationClient),
+        authenticationToken: decodeURIComponent(localStorage.authenticationToken)
+      }, function (data) {
+        OB.UTIL.showSuccess("CONTROLLER OFFLINE SUCCESS");
+      });
+    }
+  });
+
+  //Register the button...
+  OB.OBPOSPointOfSale.UI.EditLine.prototype.actionButtons.push({
+    kind: 'OB.OBPOSPointOfSale.UI.EditLine.StoreServerProductCheck',
+    name: 'storeServerProductCheck'
+  });
+
+}());
\ No newline at end of file