Push Notifications - Back End Services

Back-End Modeling with WebRatio Mobile Platform
337 views Published on Apr 08, 2015 | Time 9 min
Applies to: 8.0 or higher

The interaction between a mobile application and an external data source is useful for certain functions. In our example, your mobile application receives Push Notifications by using the back-end to send Push Notifications. This lesson shows you how to enable your back-end to send Push Notification to a mobile application.

Transcript

Table of contents

Introduction

The interaction between a mobile application and an external data source is useful for certain functions. In our example the back-end application sends Push Notification to the devices hang installed a specific mobile application. This lesson shows you how to enable your back-end to send Push Notification to a mobile application.

How to Model the "Send Notification" Feature

Let’s suppose you want to expose a Web service that send as notification the programmed events. The events are stored in the database.

To access to the database let's use the "CRM" dataservice project. Click on "File" menu, choose the "New" and then "DataService Project" option. Give a meaningful name for the DataService Project, such as "CRMDataService" and then press the "Finish" button.

Let's open the "Domain Model" of the DataService Project to see the structure. Click on the "Domain Model" tab.

The Domain Model contains some predefined classes, such as "Device". The "Device" class contains information about the physical devices on which a mobile application is installed. These information will be used for sending notifications.

Now let's add the "Event" class. Click the "Class" in the toolbar and place it in the Domain Model area. Type a meaningful name for the class, such as "Event". Let’s add the properties we think that characterize an event. Right-click on the "Event" class, then choose the "Edit Class..." option. Press the "Add" button and type a name for the attribute, for example "Title". Use the same procedure to add the other attributes. Then press the "OK" button to confirm.

Now let's add a database in the Domain Model to store the events. Right-click on the Domain Model node to add the database, choose the "Add" and then "Database" option. Type a name for the database, such as "CRMEvents" and then configure the database connection.

Now let's configure the methods published as Data Service for the "Event" class. Right-click on the "Data Services" node, then "Configure Service..." option. Select the checkbox corresponding to the "Read" service, press the "OK" button.

Let's use the Synchronization process to export the "Event" Class in the database. To learn more about the synchronization process see the "Domain Model Synchronization: Exporting the Domain Model" online training.

Let's open the "Project" tab and add the "Notification Provider". Click on the "Project" tab. Right-click on the "Service/Data Provider" node to add a Notification Provider, choose the "Add" and then "Notification Provider" option. You can add one or more "Notification Provider" depending on the device type. For our example, we create the provider for Android devices.

Let's configure the "Notification Provider". You can refer about the configuration to these articles of our Knowledge Base depending on the device type:

In the Properties View, set the "Android" value as Platform and set the "API Key" value.

Let’s suppose you want to expose a REST Web service that contains an operation chain for sending the notification of events. The method receives the event key provided as search criteria and gives back the details of that event as notification.

Let's now add a Service View to start model the web service. Press the "Add Service View..." button, type a name for the "Service View", such as "Notifications" and then the "Finish" button to confirm the procedure.

First of all, let's add a "Service Port" service container where you model the web service. Click "Service Containers" section of the toolbar, choose the "Service Port" and click inside the work area. Type a meaningful name for the "Service Port", for example "Notification Events".

To model the REST Web service, let's configure the entry point, which is the "Solicit" operation. Double-click on the solicit component, give a name for the solicit component, such as "forceNotification". In its Properties View, set the REST value to the "Invocation Property" and then set the "GET" request method.

Let's suppose to pass to the Web Service the key of the event to display by notification. Let's add only one "Query String Parameter" that correspond to the event key as input parameter. Right-click on the "forceNotification" solicit component, choose the "Add" and then "Query String Parameter" option. Type a name for the parameter, such as "eventOid". Press the "Edit" button to associate the database next to the "XSD Type" property, choose the "integer" Type and press the "OK" button.

To retrieve a specific event for the notification, let's use the "Selector" component based on "Event" class. Click "Utility Components" section of the toolbar, choose the "Selector" item and click inside the Service Port to add the Component. In its Properties View, press the "Select" button next to the "Data Binding" property to choose the class, in this case the "Event" class and then press the "OK" button. Let's add a "Key Condition" on the "Select Event" component. Right-click on the "Selector" component, choose the "Add" and then the "Key Condition" option.

To state that the "Select Event" component is the first operation to be executed, let’s use a "Success Flow". Click "Flows", choose the "Success Flow" item, click first on the "Solicit" component and then on the "Selector" component. The "Success Flow" also provides information to the "Select Event" component. In this case, it must provide the event key. Double-click on the "Success Flow" to see the "Parameters Binding" dialog. Uncheck the "Enable Default Binding" property. To send the key of the event passed to the web service, bind the "eventOid" query string parameter with the "Key Condition". Then press the "OK" button.

In order to extract the Android devices let's use the "Selector" component based on "Device" class. Click "Utility Components" section of the toolbar, choose the "Selector" item and click inside the Service Port to add it. In its Properties View, press the "Select" button next to the "Data Binding" property to choose the Class, in this case the "Device" class and then press the "OK" button. Now let's add the attribute conditions to allow retrieve only the existing Android device.

Right-click on the "Selector" component, choose the "Add" and then "Attribute Condition" option. Type a name for the attribute condition, such as "notificationID". Press the "Select" button next to the "Attributes" property to choose the attribute to associate, in this case the "Notification Device ID" attribute. The "Notification Device ID" is a registration code of a device for notification on Google or Apple depending on the platform. If this code has not been set the app makes a call to register itself for notification. Then press the "OK" button to confirm. Set the "Is Not Null" value as Predicate.

Right-click on the "Selector" component, choose the "Add" and then "Attribute Condition" option. Type a name for the attribute condition, such as "platform". Choose the "Platform" attribute. Press the "OK" button to confirm. Set the "android" value.

To state that the "Select Device" component must be executed after the "Select Event" component, let’s use a "Success Flow". Click "Flows", choose the "Success Flow", click first on the "Select Event" component and then on the "Select Device" component.

To send a notification to the device, let's use the "Send Notification" operation. Click "Utility Components" section of the toolbar, choose "Send Notification" component and click inside the Service Port to add it.

The "Send Notification" operation sends Push Notifications through the Apple Push Notifications Service or Google Cloud Messaging Service. In our example the operation sends the event information to the available devices. The "Send Notification" has by default as input parameters the "Title" and the "Message". The "Send Notification" operation has two specific properties:

  • "Notification Name" to identify the notification.
  • "Notification Provider" to send the notification.

In this case the provider is automatically associated with the one available. If there are more then one and you don't associate one, the operation uses all the one declared in the DataService Project. Let's choose a "Notification Name" for this operation.

You can configure on the operation the notification message structure by adding "Parameters". Each "Parameter" has a "Name" and a "Value". In our example, let's add a parameter for the "EventOid" value. Right-click on the "Send Notification" component, choose the "Add" and then "Parameter" option. Type a name for the parameter, such as "Event Oid".

To state that the "Send Notification" operation must be executed after the "Select Device" component, let’s use a "Success Flow". Click "Flows", choose "Success Flow", click first on the "Selector Device" component and then on the "Send Notification" component. Double-click on the "Success Flow" to see the "Parameters Binding" dialog to pass the device information. Uncheck the "Enable Default Binding" property. To send the information about device, bind each attributes with the corresponding parameters by pressing the "Guess Binding" button. Then press the "OK" button.

To pass the event information to the "Send Notification" operation, let's use a "Data Flow" for this purpose. Click "Flows", choose the "Data Flow", click first on the "Select Event" component, then on the "Send Notification" component. Double-click on the "Data Flow" to see the "Parameters Binding" dialog and provide the event information. Uncheck the "Enable Default Binding" property. To send the information of the selected event, bind each attribute with the corresponding parameters, by pressing the "Guess Binding" button. Also bind the "oid" attribute with the "Event Oid" parameter and then press the "OK" button.

Finally, let's add the Web Service Response. Click "Service Components", choose the "Response" component and click inside the Service Port to add it. Give a meaningful name for the "Response" component, such as "Response Notification". In its Properties View, set the "JSON" value as Content Type.

Finally, to state that the "Response Notification" component must be executed after the "Send Notification" operation, let’s use a "Success Flow". Click "Flows", choose the "Success Flow", click first on the "Send Notification" component and then on the "Response" Component.

To complete the "Push Notification" operation see the "Push Notification - Mobile Project" online training.