You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ri...@apache.org on 2019/03/13 10:02:15 UTC

svn commit: r1855389 - in /ofbiz/ofbiz-framework/trunk: applications/datamodel/entitydef/ framework/common/ framework/common/config/ framework/common/data/ framework/common/entitydef/ framework/common/servicedef/ framework/common/src/main/java/org/apac...

Author: rishi
Date: Wed Mar 13 10:02:15 2019
New Revision: 1855389

URL: http://svn.apache.org/viewvc?rev=1855389&view=rev
Log:
Implemented: Short Messaging Service(SMS) Gateway Integration. Added data model, configuration settings, data and services to support the sms services. For the specific service provider user of this implementaion needs to go for custom implementation. That means ticket contains the example of the integration how to use with sample plugin for message91 services. 
(OFBIZ-10457)
Thanks to Pritam Kute for your contribution. 
Thanks to Pierre Smits and Michael Brohi for your review and inputs.

Added:
    ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml   (with props)
    ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/
    ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java   (with props)
Modified:
    ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/product-entitymodel.xml
    ofbiz/ofbiz-framework/trunk/framework/common/config/general.properties
    ofbiz/ofbiz-framework/trunk/framework/common/data/CommonSystemPropertyData.xml
    ofbiz/ofbiz-framework/trunk/framework/common/data/CommonTypeData.xml
    ofbiz/ofbiz-framework/trunk/framework/common/entitydef/entitymodel.xml
    ofbiz/ofbiz-framework/trunk/framework/common/ofbiz-component.xml

Modified: ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/product-entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/product-entitymodel.xml?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/product-entitymodel.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/product-entitymodel.xml Wed Mar 13 10:02:15 2019
@@ -4963,4 +4963,32 @@ under the License.
         <key-map field-name="jobId"/>
       </relation>
     </entity>
+
+    <entity entity-name="ProductStoreTelecomSetting"
+            package-name="org.apache.ofbiz.product.store"
+            title="Product Store Telecom Settings">
+        <field name="productStoreId" type="id"></field>
+        <field name="telecomMethodTypeId" type="id"></field>
+        <field name="telecomMsgTypeEnumId" type="id"></field>
+        <field name="telecomCustomMethodId" type="id"></field>
+        <field name="telecomGatewayConfigId" type="id"></field>
+        <prim-key field="productStoreId"/>
+        <prim-key field="telecomMethodTypeId"/>
+        <prim-key field="telecomMsgTypeEnumId"/>
+        <relation type="one" fk-name="PRDS_TS_PRDS" rel-entity-name="ProductStore">
+            <key-map field-name="productStoreId"/>
+        </relation>
+        <relation type="one" fk-name="PRDS_TS_TELTP" rel-entity-name="TelecomMethodType">
+            <key-map field-name="telecomMethodTypeId"/>
+        </relation>
+        <relation type="one" fk-name="PRDS_TS_ENUM" rel-entity-name="Enumeration">
+            <key-map field-name="telecomMsgTypeEnumId" rel-field-name="enumId"/>
+        </relation>
+        <relation type="one" fk-name="PRDS_TS_PGC" rel-entity-name="TelecomGatewayConfig">
+            <key-map field-name="telecomGatewayConfigId"/>
+        </relation>
+        <relation type="one" fk-name="PRDS_TS_CUS_MET" rel-entity-name="CustomMethod">
+            <key-map field-name="telecomCustomMethodId" rel-field-name="customMethodId"/>
+        </relation>
+    </entity>
 </entitymodel>

Modified: ofbiz/ofbiz-framework/trunk/framework/common/config/general.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/config/general.properties?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/config/general.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/config/general.properties Wed Mar 13 10:02:15 2019
@@ -76,15 +76,24 @@ usps.address.match=(^.*?p[\\. ]*o[\\. ]*
 # -- general default 'fromEmailAddress' can be overridden in: EmailTemplateSetting
 defaultFromEmailAddress=ofbiztest@example.com
 
+# -- general default from address for telecom message communication event
+defaultFromTelecomAddress=IOFBIZ
+
 # -- The default domainname used in the notification emails links
 # as 'baseUrl' and 'baseSecureUrl' are set in the url.properties file. 
 
 # -- mail notifications enabled (Y|N)
 mail.notifications.enabled=N
 
+#-- telecom message notification enabled (Y|N)
+telecom.notifications.enabled=N
+
 # -- redirect all mail notifications to this address for testing
 #mail.notifications.redirectTo=
 
+# -- redirect all telecom notifications to this number for testing
+#telecom.notifications.redirectTo=
+
 # -- the default mail server to use
 mail.smtp.relay.host=localhost
 

Modified: ofbiz/ofbiz-framework/trunk/framework/common/data/CommonSystemPropertyData.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/data/CommonSystemPropertyData.xml?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/data/CommonSystemPropertyData.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/data/CommonSystemPropertyData.xml Wed Mar 13 10:02:15 2019
@@ -34,4 +34,5 @@
     <SystemProperty systemResourceId="general" systemPropertyId="mail.smtp.socketFactory.class" systemPropertyValue="javax.net.ssl.SSLSocketFactory" description="JSSE socket factory"/>
     <SystemProperty systemResourceId="general" systemPropertyId="mail.smtp.socketFactory.fallback" systemPropertyValue="false" description="Fallback [true|false] determines whether you will allow a non secure connection if you are unable to get a secure one"/>
     <SystemProperty systemResourceId="general" systemPropertyId="mail.smtp.sendpartial" systemPropertyValue="true" description="setting this property to false will abort sending the message"/>
+    <SystemProperty systemResourceId="general" systemPropertyId="telecom.notifications.enabled" systemPropertyValue="N" description="Telecom notifications enabled (Y|N)"/>
 </entity-engine-xml>

Modified: ofbiz/ofbiz-framework/trunk/framework/common/data/CommonTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/data/CommonTypeData.xml?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/data/CommonTypeData.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/data/CommonTypeData.xml Wed Mar 13 10:02:15 2019
@@ -148,4 +148,10 @@ under the License.
     <EnumerationType enumTypeId="JM_OFBIZ_INSTANCE" hasTable="N" description="OFBiz Instance"/>
     <Enumeration enumId="JM_OFBIZ_INS_0" enumTypeId="JM_OFBIZ_INSTANCE" enumCode="_NA_" sequenceId="00" description="ALL instance"/>
     <Enumeration enumId="JM_OFBIZ_INS_1" enumTypeId="JM_OFBIZ_INSTANCE" enumCode="ofbiz1" sequenceId="01" description="OFBiz instance 1"/>
+    
+    <!-- Telecom Services Seed Data -->
+    <EnumerationType enumTypeId="TELECOM_MSG" description="Telcom Message Type Enum" hasTable="N"/>
+    <TelecomMethodType telecomMethodTypeId="SMS" description="Short Messaging Service Method"/>
+    <TelecomMethodType telecomMethodTypeId="WHATSAPP" description="WhatsApp Messaging Service Method"/>
+    <CustomMethodType customMethodTypeId="TELECOM_GATEWAY" description="Telecom Gateway Custom Method"/>
 </entity-engine-xml>

Modified: ofbiz/ofbiz-framework/trunk/framework/common/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/entitydef/entitymodel.xml?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/entitydef/entitymodel.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/entitydef/entitymodel.xml Wed Mar 13 10:02:15 2019
@@ -892,4 +892,23 @@ under the License.
         <prim-key field="systemResourceId"/>
         <prim-key field="systemPropertyId"/>
     </entity>
+    
+    <!-- ============================ -->
+    <!-- org.apache.ofbiz.common.telecom -->
+    <!-- ============================ -->
+    <entity entity-name="TelecomMethodType" 
+            package-name="org.apache.ofbiz.common.telecom"
+            title="Telecom Method Type">
+        <field name="telecomMethodTypeId" type="id"></field>
+        <field name="description" type="description"></field>
+        <prim-key field="telecomMethodTypeId"/>
+    </entity>
+
+    <entity entity-name="TelecomGatewayConfig"
+            package-name="org.apache.ofbiz.common.telecom"
+            title="Telecom Gateway Config">
+        <field name="telecomGatewayConfigId" type="id"></field>
+        <field name="description" type="description"></field>
+        <prim-key field="telecomGatewayConfigId"/>
+    </entity>
 </entitymodel>

Modified: ofbiz/ofbiz-framework/trunk/framework/common/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/ofbiz-component.xml?rev=1855389&r1=1855388&r2=1855389&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/ofbiz-component.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/ofbiz-component.xml Wed Mar 13 10:02:15 2019
@@ -72,6 +72,7 @@ under the License.
     <service-resource type="model" loader="main" location="servicedef/services_qrcode.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services_security.xml"/>
     <service-resource type="model" loader="main" location="servicedef/services_test.xml"/>
+    <service-resource type="model" loader="main" location="servicedef/services_telecom.xml"/>
     <service-resource type="group" loader="main" location="servicedef/groups_test.xml"/>
     <service-resource type="eca" loader="main" location="servicedef/secas_test.xml"/>
     <service-resource type="eca" loader="main" location="servicedef/secas_cdyne.xml"/>

Added: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml?rev=1855389&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml (added)
+++ ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml Wed Mar 13 10:02:15 2019
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/services.xsd">
+    <description>Common Telecom Services</description>
+    <vendor>OFBiz</vendor>
+
+    <service name="sendTelecomMessageInterface" engine="interface">
+        <attribute name="numbers" type="List" mode="IN" optional="false" />
+        <attribute name="message" type="String" mode="IN" optional="false"/>
+        <attribute name="configId" type="String" mode="IN" optional="true"/>
+        <attribute name="response" type="String" mode="OUT" optional="true"/>
+    </service>
+    
+    <service name="sendTelecomMessage" engine="java" 
+             location="org.apache.ofbiz.common.telecom.TelecomServices" 
+             invoke="sendTelecomMessage" auth="true">
+        <description>Service to send telecom message</description>
+        <attribute name="productStoreId" type="String" mode="IN" optional="false" />
+        <attribute name="telecomMsgTypeEnumId" type="String" mode="IN" optional="false"/>
+        <attribute name="telecomMethodTypeId" type="String" mode="IN" optional="true" default-value="SMS"/>
+        <attribute name="telecomGatewayConfigId" type="String" mode="IN" optional="true"/>
+        <attribute name="numbers" type="List" mode="IN" optional="false" />
+        <attribute name="message" type="String" mode="IN" optional="true" />
+    </service>
+</services>
\ No newline at end of file

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_telecom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java?rev=1855389&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java (added)
+++ ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java Wed Mar 13 10:02:15 2019
@@ -0,0 +1,103 @@
+package org.apache.ofbiz.common.telecom;
+
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilValidate;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericEntityException;
+import org.apache.ofbiz.entity.GenericValue;
+import org.apache.ofbiz.entity.util.EntityQuery;
+import org.apache.ofbiz.entity.util.EntityUtilProperties;
+import org.apache.ofbiz.service.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
+
+public class TelecomServices {
+
+    public final static String module = TelecomServices.class.getName();
+
+    public static Map<String, Object> sendTelecomMessage(DispatchContext ctx, Map<String, ? extends Object> context) {
+        Delegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        Map<String, Object> results = ServiceUtil.returnSuccess();
+
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String productStoreId = (String) context.get("productStoreId");
+        String telecomMsgTypeEnumId = (String) context.get("telecomMsgTypeEnumId");
+        String telecomMethodTypeId = (String) context.get("telecomMethodTypeId");
+        String telecomGatewayConfigId = (String) context.get("telecomGatewayConfigId");
+        List<String> numbers = checkList(context.get("numbers"), String.class);;
+        String message = (String) context.get("message");
+        
+        String telecomEnabled = EntityUtilProperties.getPropertyValue("general", "telecom.notifications.enabled", delegator);
+        if (!"Y".equals(telecomEnabled)) {
+            Debug.logImportant("Telecom message not sent to " + numbers.toString() +" because telecom.notifications.enabled property is set to N or empty", module);
+            return ServiceUtil.returnSuccess("Telecom message not sent to " + numbers.toString() +" because sms.notifications.enabled property is set to N or empty");
+        }
+
+        String redirectNumber = EntityUtilProperties.getPropertyValue("general", "telecom.notifications.redirectTo", delegator);
+        if (UtilValidate.isNotEmpty(redirectNumber)) {
+            numbers.clear();
+            numbers.add(redirectNumber);
+        }
+
+
+        try {
+            Map<String, Object> createCommEventCtx = new HashMap<String, Object>();
+            createCommEventCtx = ctx.makeValidContext("createCommunicationEvent", ModelService.IN_PARAM, context);
+            createCommEventCtx.put("content", message);
+            createCommEventCtx.put("communicationEventTypeId", "PHONE_COMMUNICATION");
+            createCommEventCtx.put("fromString", EntityUtilProperties.getPropertyValue("general", "defaultFromTelecomAddress", delegator));
+            createCommEventCtx.put("subject", telecomMsgTypeEnumId);
+            createCommEventCtx.put("toString", numbers.toString());
+            Map<String, Object> createCommEventResult = dispatcher.runSync("createCommunicationEvent", createCommEventCtx);
+            if (!ServiceUtil.isSuccess(createCommEventResult)) {
+                Debug.logError(ServiceUtil.getErrorMessage(createCommEventResult), module);
+                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(createCommEventResult));
+            }
+            String communicationEventId = (String) createCommEventResult.get("communicationEventId");
+
+            Map<String, Object> conditions = new HashMap<String, Object>();
+            conditions.put("productStoreId", productStoreId);
+            conditions.put("telecomMsgTypeEnumId", telecomMsgTypeEnumId);
+            conditions.put("telecomMethodTypeId", telecomMethodTypeId);
+            GenericValue productStoreTelecomSetting = EntityQuery.use(delegator).from("ProductStoreTelecomSetting").where(conditions).queryOne();
+            if (productStoreTelecomSetting != null) {
+                GenericValue customMethod = productStoreTelecomSetting.getRelatedOne("CustomMethod", false);
+                if (UtilValidate.isNotEmpty(customMethod.getString("customMethodName"))) {
+                    Map<String, Object> serviceCtx = new HashMap<String, Object>();
+                    serviceCtx.put("numbers", numbers);
+                    serviceCtx.put("message", message);
+                    if (telecomGatewayConfigId != null) {
+                        serviceCtx.put("configId", telecomGatewayConfigId);
+                    }
+                    serviceCtx.put("userLogin", userLogin);
+                    Map<String, Object> customMethodResult = dispatcher.runSync(customMethod.getString("customMethodName"), serviceCtx);
+                    if (ServiceUtil.isError(customMethodResult) || ServiceUtil.isFailure(customMethodResult)) {
+                        String errorMessage = ServiceUtil.getErrorMessage(customMethodResult);
+                        Debug.logError(errorMessage, module);
+                        return ServiceUtil.returnError(errorMessage);
+                    }
+
+                    createCommEventCtx.clear();
+                    createCommEventCtx.put("communicationEventId", communicationEventId);
+                    if (UtilValidate.isNotEmpty(createCommEventResult.get("response")))
+                        createCommEventCtx.put("note", customMethodResult.get("response"));
+                    createCommEventCtx.put("statusId", "COM_COMPLETE");
+                    createCommEventCtx.put("userLogin", userLogin);
+                    dispatcher.runSync("updateCommunicationEvent", createCommEventCtx);
+                }
+            } else {
+                return ServiceUtil.returnError("Not sending SMS as no ProductStoreEmailSetting found for the passed inputs.");
+            }
+        } catch (GenericEntityException | GenericServiceException e) {
+            Debug.logError(e.getMessage(), module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        return results;
+    }
+}

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain