Putting It All Together


Options



Before You Begin

Purpose

In this tutorial, you'll create a mobile backend, which organizes backend services for a mobile app. You'll learn about:

  • Logging in to Mobile Cloud Service (MCS)

  • Cloud Storage for Mobile Apps

  • Custom APIs

  • Connectors

  • The Database Management API

  • Diagnostics

Time to Complete

Approximately 60 minutes.

Background

Oracle Mobile Cloud Service (MCS) is a cloud-based service that provides a unified hub for developing, deploying, maintaining, monitoring, and analyzing your mobile apps.

Scenario

The Fix-it-Fast (FiF) mobile app enables field repairmen to respond quickly to various large appliance-related emergencies by providing the following functions:

  • Getting all incident reports.

  • Returning a specific incident report.

  • Updating an incident report.

  • Getting driving directions.

This tutorial covers how to create the mobile backend for the FiF mobile app. To enable the field technician to see an image of a customer's service sticker and update incident reports (IRs) by prioritizing them and adding notes, you'll need to first create the field technician user, create cloud storage for the mobile app (and access permissions to the stored objects), and also add an API that manages the IRs. To give the technician driving directions to each client site, you'll configure a connector to the Google Maps API. When you test the mobile app, you'll deploy it to an emulator (an Android Virtual Device, or AVD), or to an Android device, and then use MCS diagnostics to monitor the endpoints.

What Do You Need?

To complete this tutorial, you'll need the following:

  • A user name and password to MCS. Refer to the email that you received. If you haven't received it yet, log a service request (SR) through My Oracle Support (support.oracle.com). Have your CSI (Customer Support Identifier) or your SI (Support Identifier) ready.

  • Android 4.4.2 or higher

  • A configured AVD

  • Android Studio

  • FIF_incidents.raml

  • FIF_incidents.zip

  • FixItFastTechnicianApp_v1.0.zip

Click here to download a ZIP of these files.

Logging Into Oracle Mobile Cloud Service

The mobile backend not only enables the mobile app to connect with third-party geolocation services, but also provides diagnostics, analytics, notification, security, offline data, and storage services.

  1. In your browser, open https://cloud.oracle.com/mobile.

  2. Enter your user Mobile Cloud Service name, password, and domain.

    The Oracle Cloud login dialog
    Description of this image
  3. Click Sign In to My Account and enter your user name and password.

  4. From the Dashboard, choose a Mobile Cloud Service.

    The OMCS Welcome page

Creating Users and User Roles

In this step, you will create a mobile user for the FiF Technician app. You'll use this user name and password to log in to the mobile app and use it to update customer incident reports and view images uploaded by customers.

Creating the User Role

  1. Click Development.

    The Development tab
  2. Click User Management.

    The User Management icon
  3. Click Realms in the left navbar to take a quick look at the user realms page. A realm partitions users in an environment (in this case, the Development environment). A realm called Default 1.0 is created by default.

    The Realms page
  4. Click Roles in the left navbar and then click New Role.

    The New Roles button
  5. Enter FIF_Technician in the New Role dialog and then click Create.

    The New Role dialog
    Description of this image

Creating the Mobile App User

In this step, you'll create the FIF Technician user. You'll use this user's credentials to login in to the mobile app itself and also to test the API endpoints.

  1. Click Users in the left navbar and then click New User.

    New User button
  2. Enter the following in the Create User dialog:

    • Enter a user name. The user name and passwords must be unique. These are not are not case-sensitive, meaning that MCS views JJones as the same as jjones.

    • Enter an email address. For added security, Oracle Mobile Cloud sends users a confirmation email that contains a temporary password.

    • Enter the name by entering first and last names.

      Create User dialog
      Description of this image
  3. To give this user access permission to the mobile app's data, choose FIF_Technician role and then click Create.

    The Completed Create User dialog
    Description of this image

    By default, MCS creates the users in the Default 1.0 user realm.

    Listing of Mobile Cloud Service users
    Description of this image

    After you create a user, Mobile Cloud Service sends you a confirmation email with the subject line, New Account Information. This email includes a temporary password. Keep this email close at hand, as you'll need the password to log into the technician app. You'll also need it to test a custom API.

    The New Account Information email

Setting Up the Mobile Backend for the Mobile App

A mobile backend acts as the cloud companion for a mobile app. It provides such services as user management, storage for mobile app data, and access to remote data.

To create the mobile backend:

  1. Click Development.

    The Development tab
  2. Click Mobile Backends.

    The Mobile Backends icon
  3. Click New Mobile Backend.

    The New Mobile Backend button
  4. Name the mobile backend FIF_Technician and then click Create.

    The New Mobile Backend dialog
    Description of this image

    The Settings page opens by default. This page confirms that you've create the mobile backend. Because this is a new mobile backend, it exists in the Development environment. You can refer to the Settings page for the following:

    • Base URL: This is the URL used for calling services.

    • Mobile Backend ID: The unique identifier assigned to a mobile backend. This ID, which associates a mobile app with its mobile backend, is passed in the REST header of every call made from a mobile app to MCS. All mobile apps associated with a mobile backend use the same mobile backend ID.

    • Anonymous Key: A unique string that allows your app to access anonymous APIs without sending an encoded username and password combination. The Anonymous Access Key is passed to MCS instead.

      The Environment Details section of the mobile backend Settings page
      Description of this image
    • Application Key: The unique ID that MCS issues to each mobile app that is registered to a mobile backend. This is used for tracking purposes.

      The Application Key in the Client Applications section of the mobile backend Settings page
      Description of this image

      Note: To enable the Technician's mobile app to communicate with the FIF_Technician mobile backend, you'll need to update the app's code with the base URL, mobile backend ID, anonymous key, and application key. You'll do this in Connecting the Mobile App to the Mobile Backend.

  5. Notice the icons in the navbar on the left side of the page, which enable you to configure various services for the mobile backend. You'll be using these throughout this tutorial. Click Diagnostics.

    The navbar for a mobile backend
    Description of this image

    Right now, the chart on the Diagnostics page is empty, because no calls have been made. Later, after you test the APIs, you'll return to this page to get a glimpse of how Diagnostics logging works.

    The Diagnsotics overview page (no API calls)
    Description of this image

Creating Cloud Storage for the Mobile App

Storage persists objects (JSON, images) sent from a device to the cloud. In this step, you'll create a collection to store the images of the customer identification sticker that is attached to an incident report. The sticker shows the customer number, the model number of the appliance that needs repair, and a barcode.

The Fix-It-Fast customer service sticker
Description of this image

Creating the Collection

  1. Click Storage.

    The Storage icon for mobile backends
  2. You don't have any collections created for this mobile backend, so click New Collection.

    The New Collection button
  3. Complete the New Collection dialog as follows:

    1. Name the collection FIF_UserData.

    2. Choose User Isolated so that customers cannot override each other's images when they upload.

  4. Click Create.

    The New Collection dialog
    Description of this image
  5. Now, you're going to assign the access permissions to this collection so that it can be used by the mobile app. In the Properties page (which opens by default), give the FIF_Technician role Read/Write access to incident report images by selecting FIF_Technician in the Read-Write field.

    The Properties page
    Description of this image
  6. The Make this collection available when the client is offline option makes the data available offline. This option is selected by default. Accept this setting.

Creating a Connector

To add driving directions to the mobile app, you're going to add a connector to the Google Maps API.

  1. Click Development.

    The Development tab
  2. Click Connectors.

    The Connectors icon
  3. Click New Connector and then REST.

    The New Connector button with the connector type menu
  4. Define the connector by providing the following information and then click Create.

    The New REST Connector dialog
    Description of this image
    • Display API Name and API Name: GoogleDirections

    • Remote URL: https://maps.googleapis.com/maps/api/directions/json

    • Short Description: Enter something like Displays driving directions using the Google Maps REST API.

  5. Click Create.

  6. On the navigation bar, click Rules.

    The Create Connector dialog navigation bar, with Rules selected
  7. Click New Rule.

    The New Rule button
  8. Create two parameters called origin and destination. To do this:

    1. Click Add Parameter.

      The Add Parameter button
    2. Accept the default Query property as the parameter type.

    3. Enter origin and then enter a starting location, like San Carlos, CA.

    4. Enter destination and then enter and ending location, like Redwood City, CA.

      The Default Parameters section
      Description of this image
  9. Click Save.

  10. On the navigation bar, click Test.

    The Create Connector dialog navigation bar, with Test selected
  11. Because these directions will be called from the Technician's mobile app, you'll test the connector by entering the Technician's user name and password. In the Authentication section, enter the following:

    • Mobile Backend: FIF_Technician

    • Version: 1.0 (Accept the default value.)

    • Username and Password: The FIF_Technician username and password.

      The new REST Connector dialog
      Description of this image
  12. Click Test Endpoint.

    The Test Endpoint button
  13. Take a look at the HTTP response and the returned JSON.

    The HTTP response code and returned JSON for the Google API connector
    Description of this image
  14. Click Done.

    The Done button

Associating APIs with the Mobile Backend

MCS provides a set of platform APIs that include:

  • Analytics Collector -- Monitors and API traffic for one or more mobile backends.

  • Data Offline -- Enables mobile apps to synchronize locally stored data with data managed by the mobile backend.

  • Push Notifications -- Manages push notifications sent to mobile apps.

  • User Management -- Manages mobile users and enables user and user role creation.

  • Storage -- Persists mobile app data to the cloud.

  • Database -- Creates the persistence layer for the mobile app.

To enable a mobile app to access data from some external source, you need to add a custom API. For the mobile app, the custom API manages incident reports. Normally, you connect to your enterprise system, but for this tutorial, you'll be connecting to the database.

In this step, you'll create a custom API using the FIF_incidents.raml and FIF_incidents.zip files with the API Designer, which steps you through creating and testing a custom API.

Creating the Custom API

  1. Click Development.

    The Development tab
  2. Click APIs.

    The APIs icon
  3. Click New API.

    The New API button
  4. Drag the FIF_incidents.raml file into the upload field. Although you're using a RESTful API Modeling Language (RAML) document in this tutorial, you don't need to know RAML to use the API Designer. The API Designer creates a RAML document for you.

    Drag or upload a RAML file
  5. In the Short Description field, enter a description, like Fix it Fast Incident Reports API and then click Create.

  6. In the Designer page, click Security.

    The Security tab of the API Designer's Designer page
  7. In the API Access section, add FIF_Technician to the Roles field to allow your technician mobile user access to the endpoints.

    .The API Access of the Security page.
  8. Click Implementations in the left navbar.

    Click to open the Implementations page
  9. Click Upload an Implementation archive and then browse to, and select, the fif_incidents.zip file.

    The upload window
  10. Click Save.

Associating the API with the Mobile Backend

  1. Click Development.

    The Development tab
  2. Click Mobile Backends.

    The Mobile Backends icon
  3. Choose the FIF_Technician mobile backend and then click Open.

    The Mobile Backends page
  4. Choose APIs from the left navbar.

    The mobile backend-level APIs icon

    Right now, the FiF_Technician mobile backend isn't using any custom APIs.

    The mobile backend API page with no APIs selected
  5. To open the API catalog, click Select APIs.

    The Select APIs button
  6. In the API Catalog, click FiF Incidents.

    Select the Custom API

    After you select the FIF Incidents API, it appears in the Selected APIs panel.

    The FiF_Incidents API displaying in the Selected APIs panel

Seeding the Incident Reports Data

In this step, you'll get acquainted with the MCS API explorer, which lets you test endpoints and see the returned results. Normally, you'd create a connector to get application data, but for this tutorial, you're going to add a table called FIF_Incidents that contains the incident reports by testing the POST /populate endpoint. Call this endpoint if you need to reset the data.

To seed the data:

  1. Return to the FiF Technician mobile backend page by clicking FiF_Technician 1.0 at the top of the page.

  2. Select APIs from the left navbar.

    The mobile backend-level APIs icon
  3. Click the FiF_Incidents API.

    The FiF_Incidents API selected in the APIs page
  4. In the Endpoints page, click the POST /populate endpoint.

    The list of endpoints for the FIF_Incidents API
    Description of this image
  5. Enter your MCS credentials.

    The Authentication section for the the POST /populate endpoint on the Test Endpoint page
    Description of this image
  6. Click Test Endpoint.

Testing the Endpoints

In this step, you can view methods and test the endpoints of the FiF Incidents API. By testing an endpoint, you can find out if it can return requests from a mobile app.

  1. Click the FiF_Incidents API.

    The FIF_Incidents API selected in the mobile backend's APIs page
  2. In the Endpoints page, click Default Test Credentials and enter the username and password for the user to whom you assigned the FIF_Technician role. You'll use these credentials for testing the calls that are made from the FIF Technician app. You'll configure and run this mobile app later.

    The FiF_Technician user credentials
    Description of this image

    The FIF_Incidents API uses the following endpoints. You can test each of these using the Endpoints page. Enter the appropriate parameters for each resource and then click Test Endpoint.

    Method Endpoint Description
    GET

    /mobile/custom/FIF_Incidents/incidents

    /mobile/custom/FIF_Incidents/incidents?customer={customer_username}

    /mobile/custom/FIF_Incidents/incidents?technician={technician_username}

    Gets all of the incident reports (filtered by customer name or technician name).
    POST /mobile/custom/FIF_Incidents/incidents Submits a new incident report.
    PUT /mobile/custom/FIF_Incidents/incidents Update an existing incident report (based on ID).
    GET /mobile/custom/FIF_Incidents/incidents/{id} Get a single incident report by ID.
    GET /mobile/custom/FIF_Incidents/directions?origin={o}&destination={d} Returns driving directions.
  3. Test GET /incidents:

    1. Go to the Get /incidents endpoint.

    2. Click Test Endpoint.

      The Endpoints testing page
      Description of this image
    3. Take a look at the HTTP 200 (OK) response. Click Test Endpoint a few more times.

      The returned JSON payload for an FIF_Incidents API endpoint
      Description of this image
  4. To test the Google Maps API, select the GET /directions endpoint.

  5. In the Parameters section, enter the following addresses:

    • origin: 200 Oracle Parkway Redwood City, CA 94065

    • destination: 20883 Stevens Creek Cupertino, CA 95014

      Parameters section of the Test Endpoints page for GET /directions
      Description of this image
  6. In the Response section, take a look at the JSON returned for a 200 response.

    The Response section Test Endpoints page for GET /directions
    Description of this image
  7. Return to the FiF Technician mobile backend page by clicking FiF_Technician 1.0 at the top left of the page.

    The FIF_Technician mobile backend nagivation link
  8. Choose Diagnostics. When you first created the mobile backend, the Diagnostics page had no data. Because you have tested some endpoints, MCS can graph the API calls.

    The Diagnostics overview page
    Description of this image
  9. In the Overview page, click Requests.

    The Requests link in the Overview page
  10. In the Requests page, click 2xx and then de-select 4xx and 5xx (which are selected by default) to enable the page to display only the 200 (Success) messages.

    The 2xx button
  11. To see more details about the request, click a timestamp.

    The Timestamp column in the Request page
  12. Take a look at the message details. These include:

    • The request details, such as the response code.

    • The mobile backend that made the request.

    • The API, its version number, and the method (such as GET or POST).

    • Performance data, such as the overall time for the request, the actual time servicing the request.

    • The Correlation ID, which associates log messages to a specific API request. Clicking the Request Correlation ID in the message details enables you to view log records from the API request history.

      Request message details page
      Description of this image

Taking a Look at the Table Structure (Optional Step)

The Database Management API is a platform API that lets you curate database tables. In this step, you use the Database Management API explorer to see the rows and columns of the FIF_Incidents table as a JSON object. The explorer that you use in this step is similar to the ones provided for the other MCS platform APIs. Because the Database Management API is used by administrator-level users, you must use your MCS user name and password to test its endpoints instead of the FIF Technician credentials that you use to test the FIF_Incidents API endpoints.

  1. Click Development.

    The Development tab
  2. Click APIs.

    The APIs icon
  3. At the bottom of the page, expand Platform APIs and then click Database.

    The Platform APIs section of the APIs page
    Description of this image
  4. From the list of endpoints, choose GET /tables/{table}.

    The Database API endpoints
    Description of this image
  5. Enter FIF_Incidents as the table name.

    The Database API endpoints testing page
    Description of this image
  6. Expand Authentication. Enter your MCS user name and password and then click Test Endpoint.

    The Authentication section for the Database Management API Test Endpoints page
    Description of this image
  7. Take a look at the returned JSON.

    The returned JSON describing the FIF_Incidents table
    Description of this image

    The returned JSON looks like the following:

    {
      "name": "FIF_Incidents",
      "primaryKeys": [
        "id"
      ],
      "requiredColumns": [
        "id"
      ],
      "columns": [
        {
          "name": "id",
          "type": "decimal"
        },
        {
          "name": "phone",
          "size": 266,
          "type": "string"
        },
        {
          "name": "title",
          "size": 398,
          "type": "string"
        },
        {
          "name": "technician",
          "size": 258,
          "type": "string"
        },
        {
          "name": "status",
          "size": 256,
          "type": "string"
        },
        {
          "name": "address",
          "size": 299,
          "type": "string"
        },
        {
          "name": "priority",
          "type": "integer"
        },
        {
          "name": "imageLink",
          "size": 274,
          "type": "string"
        },
        {
          "name": "notes",
          "size": 615,
          "type": "string"
        },
        {
          "name": "customer",
          "size": 265,
          "type": "string"
        },
        {
          "name": "createdBy",
          "size": 80,
          "type": "string"
        },
        {
          "name": "createdOn",
          "type": "dateTime"
        },
        {
          "name": "modifiedBy",
          "size": 80,
          "type": "string"
        },
        {
          "name": "modifiedOn",
          "type": "dateTime"
        }
      ]
    }

Testing the Mobile Backend

You're now ready to test the mobile backend to see if it connects the FiF Technician mobile app to the backend services, and if it's graphing the diagnostics data.

Connecting the Mobile App to the Mobile Backend

To enable the mobile backend to act on behalf of the mobile app, you need to update the app's configuration with the values for the application key, the mobile backend's base URL, the mobile backend ID, and the anonymous key that displays in the mobile backend's Settings page. MCS generated these values when you created in the FIF_Technician mobile backend in Setting Up the Mobile Backend for the FIF Technician App.

To do this:

  1. Unzip FixItFastTechnicianApp_v1.0.zip.

  2. Start Android Studio.

  3. From the Quick Start menu, choose Import Non-Android Studio Project.

    The Quick Start menu in the Welcome to Android Studio dialog
  4. In the Select Eclipse or Gradle Project to Import dialog, navigate to the FixItFastTechnicianApp project and then click OK.

    The FixItFastTechnicianApp selected in the Select Eclipse or Gradle Project to Import dialog
  5. Wait for Gradle to build the project.

  6. In the Project tree, open app > src > main > assets > oracle_mobile_cloud_config.xml.

    The oracle_mobile_cloud_config.xml file selected in the Project tree
  7. Refer to the Settings page of the FIF_Technician mobile backend to update the following elements in theoracle_mobile_cloud_config.xml file:

    • <appKey>: Enter the Application Key that is displayed in the Client Application section of the mobile backend's Settings page. For example, enter <appKey>d91cc5ea-bada-48a9-a28e-93e7520b64e</appKey>.

      The Application Key in the Client Application section of the mobile backend Settings page
      Description of this image
    • <baseURL>: Enter the URL for the FIF_Technician mobile backend that's displayed in the Environment Details section of the mobile backend's Settings page. For example, enter <baseUrl>https://example.com:7001</baseUrl>.

    • <mobileBackendID>: Enter the mobile backend ID for the FIF_Technician mobile backend. For example, enter <mobileBackendID>ceff19d8-e1c7-422a-acfa-671ff5f3497</mobileBackendID>.

    • <anonymousKey>: Enter the Anonymous Key for the FIF_Technician mobile backend. For example, enter <anonymousKey>TU9CSUxFTEFCMklERE9NQUlOX01PQklMRUxBQjJERVZfTU9CSUxFX0FOT05ZTU9==</anonymousKey>.

      The Environment Details section of the mobile backend Settings page
      Description of this image
  8. Click the Sync Project with Gradle Files button in the tool bar.

    The Sync Files with Gradle Project button on the tool bar
  9. Click the Run button in the tool bar.

    The Run button on the tool bar

Testing the Deployed FIF Technician Mobile App

In this step, you'll launch the FIF Technician mobile app to see the custom code calls in action.

  1. Open the FiF application on a simulator or device.

    The technician mobile app icon
  2. Login as the FIF_Technician user.

    The login page of the technician mobile app
    Description of this image
  3. View the incident reports.

    The list of incident reports
    Description of this image
  4. Open an incident report and take a look at the Details page.

    An individual incident report displayed on the Details page
    Description of this image
  5. Take a look at the customer sticker.

    An image of the customer sticker
    Description of this image
  6. Re-prioritize this incident and then click OK.

    The Set Priority menu
    Description of this image
  7. Click Directions.

    Turn-by-turn driving directions displayed in the Directions page
    Description of this image
  8. Update the incident report with a note. Click POST.

    Note: To retrieve driving instructions, you must enable GPS on your phone or emulator. If a driving route is not available from your current location, or GPS is not activated, then you will see the Directions Unavailable message. You can also return driving directions using the Endpoints page described in Testing the Endpoints. To do this:

    1. In the Endpoints page, click POST /incidents.

    2. Click Use Example.

    3. Replace the address in the sample JSON with a location near you and then click Test Endpoint.

      { 
         "title": "Water heater is leaking",
         "customer": "Lynn Smith",
         "address": "475 Sansome Street, San Francisco, CA 94111",
         "phone": "(555) 212-4567",
         "technician": "jwhite",
         "status": "Open",
         "notes": "lynnf|2015-05-01T21:00:17.564727+00:00|Initial incident report description",
         "priority": 1,
         "imageLink": "http://link.to.storage"
      }
  9. Click Activity. In the Activity page, update the incident report with a note. Click POST.

    Adding a note to the log in the Activity page
    Description of this image
  10. Return to the Details page and then click the Status field. Use the Set Status dialog to change the incident report's status. Click OK.

    The Set Status dialog
    Description of this image

Viewing Diagnostic Data

In this step, you'll revisit MCS diagnostics. Before, you viewed logging data generated when testing the endpoints using the API Designer. This time, you'll review the logging for calls made from a mobile app to MCS.

  1. Click Diagnostics.

    The Diagnostics icon
  2. In the Overview page, click Requests.

    The Requests link in the Overview page
  3. In the Requests page, click 2xx and then de-select 4xx and 5xx (which are selected by default) to enable the page to display only the 200 (Success) messages.

    The 2xx button
  4. For any request to the FIF_Incidents API or to the connector, click a time stamp to drill down to the message details.

    The Requests page, toggled to display all 2xx messages for the APIs and connectors
    Description of this image
  5. Take a look at the message details for the request. The Overview tab, which appears by default, displays the 200 (Success) response code, and notes that the FIF_Technician mobile backend made the request. This page also shows the API that made the call (such as FIF_Incidents), its version number, the method (such as GET or POST), and any request parameters that were sent with the request. It also includes the name of the mobile user who logged into the FIF Technician mobile app and performance data, such as the overall time for the request, the actual time servicing the request in the custom code, and details about the number of bytes of returned data.

    The Message Details page
    Description of this image

Want to Know More?