Skip to content
Anil Gupta edited this page Mar 23, 2017 · 21 revisions

Generic Partner Application

Generic Partner App is a distribution of data between Ekstep(Genie) and it's partner.

Generic Partner App will launch from Genie App and the Partner Apps to register, manage sessions and send partner data to Genie via Genie-Service SDK. After completion of all the process then the Partner app should launch a Genie App.

Generic Partner App will register one time after successful registration, it could be start session and send partner data to Genie Services.

Genie Service Usage:

The Genie service sdk is used by the Partner Apps to register, manage sessions and send partner data to Genie.

1. Add dependencies in your build.gradle(app module) files

	buildscript {
		repositories {
			maven { url "https://platform.ekstep.in/downloads/content/repositories/releases" }
		}
	}
    
	repositories {
		maven { url "https://platform.ekstep.in/downloads/content/repositories/releases" }
	}

	dependencies {
		compile "org.ekstep.genieservices:sdks:1.0.+@aar"
		compile "org.ekstep.genieservices:aidls:1.0.+@aar"
	}

2. Register Partner: Partner App will register only once. After successful registration it could be start session and send partner data to Genie Services

    //Sample code
    Partner partner = new Partner(context);
	partner.register(partnerID, PublicKey, IResponseHandler);
   
    /**
     * Register a partner with the specified partnerID and  publicKey
     *
     * @param partnerID       Unique Identifier of the Partner
     * @param publicKey       Provide an appropriate RSA Public Key as a String in PEM format
     *                        with the delimiter.
     *                        <p>Example:</p>
     *                        <p/>
     *                        <p>-----BEGIN PUBLIC KEY-----
     *                        MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGdo5VYOK9cTrQQ+ajOxfHMgg/
     *                        TDX77o/eVTUjcErLLYKBQ6qb8t/jCCuRNexIexRBldk4gC9STyuVWN8x2xkSildf
     *                        Nch3KUTvwgJx1n2y/03tIHkimOxEONCg3rWPdiWx7nLdW4TuHbwZTZmMdhLjM4lI
     *                        OSyoyYpX/JmDnxjq4QIDAQAB
     *                        -----END PUBLIC KEY-----</p>
     *                        <p/>
     *                        <p>To generate an RSA Private key pair use,</p>
     *                        <pre>openssl genrsa -out rsa_1024_priv.pem 1024</pre>
     *                        <p>To generate the Public Key in PEM format use,</p>
     *                        <pre>openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem</pre>
     *                        <p/>
     * @param responseHandler {@link IResponseHandler} Handler to receive response data
     * <p>
     * <p>
     * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful.
     * <p>
     * <p>In case of a failed response, response.getError() could return one of the following:
     * <p>MISSING_PARTNER_ID - partnerID is not provided</p>
     * <p>MISSING_PUBLIC_KEY - publicKey is not provided</p>
     * <p>INVALID_RSA_PUBLIC_KEY - publicKey is not as per specs</p>
     * <p>INVALID_DATA - some data is still invalid</p>
     * */
    public void register(String partnerID, String publicKey, IResponseHandler responseHandler)

3. Start Partner Session:

    //Sample code
    Partner partner = new Partner(context);
	partner.startPartnerSession(partnerID, IResponseHandler);
   
    /**
     * Start the partner session with the specified partnerID
     *
     * @param partnerID       Unique Identifier of the Partner
     * @param responseHandler Callback handler to manage SDK async response
     * <p>
     * <p>
     * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful.
     * <p>
     * <p>In case of a failed response, response.getError() could return one of the following:
     * <p>UNREGISTERED_PARTNER - partnerID is not registered</p>
     * */
    public void startPartnerSession(String partnerID, IResponseHandler responseHandler)

4. Create Profile:

    //Sample code
        Profile profile=new Profile("Name","Avatar","en");
        profile.setStandard(5);
        profile.setGender("Male");
        profile.setAge(10);
		
        UserProfile userProfile=new UserProfile(context);
        userProfile.createUserProfile(profile, IResponseHandler);

    /**
     * Create a new user with the specified {@link Profile}.
     *
     * @param profile         {@link Profile} Pass the profile object
     * @param responseHandler {@link IResponseHandler} Handler to receive the response of the createUserProfile action.
     * <p>
     * <p>
     * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful and response.getResult() will be a Map representation of the following JSON string:
     * <pre>
     * {
            "age ":-1,
            "avatar ":"@drawable/ic_avatar1 ",
            "createdAt ":"Oct 12, 2016 10:54:26 PM ",
            "day ":-1,
            "handle ":"Ninja94 ",
            "isGroupUser ":false,
            "language ":"en ",
            "month ":-1,
            "standard ":-1,
            "uid ":"d840cfc3-4638-4b0e-8032-56e9bc0fc77e "
     * }
     * </pre>
     *
     * */
    public void createUserProfile(Profile profile, IResponseHandler responseHandler)

5. Set Current User:

 //Sample code
 UserProfile userProfile=new UserProfile(context);
 userProfile.setCurrentUser(UID, IResponseHandler) //This UID will get it from CreateUserProfile response data...

 /**
  * Set the current(active) user with the specified user id.
  *
  * @param uid             Unique identifier of the user
  * @param responseHandler {@link IResponseHandler} Handler to receive the response of the setCurrentUser action.
  * <p>
  * <p>
  * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful.
  *
  * */
 public void setCurrentUser(String uid, IResponseHandler responseHandler)

Finish UserProfile service

//Sample code
    UserProfile userProfile=new UserProfile(context);
    userProfile.finish();
/**
Clears the connection with the genie service for user profile service. It must be invoked when the service is no longer required, but after the service has responded back with all the requests. So depending on the need, it might be either called in 
    * 'onDestroy' of the activity(if service finishes before the activity) 
    * 'onSuccess' & 'onFailure' of the responseHandler (if there is one request, for multiple request you need to handle it appropriately).
**/
public void finish()

6. Send Partner Data to Genie Services:

    //Sample code
	Map<String,Object> partnerData = new HashMap<>();
	partnerData.put("userId", UID); //Child user id generated by Genie Services...
	
	partnerData.put("child_name", "TestUser");
    partnerData.put("father_name","Gupta");
    partnerData.put("_class", 5);
    partnerData.put("sex", "Male");
    partnerData.put("dob", "31-12-1998");
    partnerData.put("district", "Bangalore-urban");
    partnerData.put("block","Bangalore");
    partnerData.put("clust","Bommanahalli");
    partnerData.put("school_name", "Govt school");
    partnerData.put("school_code", "123");

    Partner partner = new Partner(context);
    partner.sendData(partnerID, partnerData, IResponseHandler);
   
   
     /**
     * Send partner data to Genie Services with the specified arguments data. This api will encrypt the partnerData with the publicKey given earlier during registration.
     *
     * @param partnerID       Unique Identifier of the Partner
     * @param partnerData     A Map representation of the data which the Partner wants to send
     * @param responseHandler Callback handler to manage SDK async response
     * <p>
     * <p>
     * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful and response.getResult() will be a Map representation of the following JSON string:
     * <pre>
     * {
     *     "encrypted_data":"..."
     * }
     * </pre>
     * <p>
     * In case of a failed response, response.getError() could return one
     * of the following:
     * <p>UNREGISTERED_PARTNER - partnerID is not registered</p>
     * <p>ENCRYPTION_FAILURE   - Genie Services could not encrypt data</p>
     */
    public void sendData(String partnerID, Map<String, Object> partnerData, IResponseHandler responseHandler)

7. Send Telemetry Data to Genie services

 String event = "{
   "eid": "OE_END", // unique event ID
   "ets": 1442816723,
   "ver": "2.0",
   "gdata": {
 	 "id": "lit.scrnr.kan.android",
 	 "ver": "1.0"
   },
   "sid": "de305d54-75b4-431b-adb2-eb6b9e546013",
   "uid": "123e4567-e89b-12d3-a456-426655440000",
   "did": "ff305d54-85b4-341b-da2f-eb6b9e5460fa",
   "edata": {
 	 "eks":{
 		"length": 1234567 // length of the game session in seconds
 	 }
   }
 }";

 //Sample code
 Telemetry telemetry = new Telemetry(context);
 telemetry.send("TELEMETRY_EVENTS", IResponseHandler);


/**
  * Send a telemetry event to genie-services
  *
  * @param event           {@link String} The telemetry event will be a json string.
  * @param responseHandler {@link IResponseHandler} This is the callback. The class needs to be defined in client  handling both success and failure scenario
  * <p>
  * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful.
  */
public void send(String event, IResponseHandler responseHandler);	

8.Terminate Partner Session:

    //Sample code
    Partner partner = new Partner(context);
    partner.terminatePartnerSession(partnerID, IResponseHandler);
    
	/**
     * Terminate the partner session with the specified partnerID
     *
     * @param partnerID       Unique Identifier of the Partner
     * @param responseHandler Callback handler to manage SDK async response
     * <p>
     * <p>
     * <p> In case of a successful response onSuccess will be called, response.getStatus() will return successful.
     * <p>
     * In case of a failed response, response.getError() could return one
     * of the following:
     * <p>
     * UNREGISTERED_PARTNER - partnerID is not registered
     */
    public void terminatePartnerSession(String partnerID, IResponseHandler responseHandler)

Finish Partner service

//Sample code
 Partner partner = new Partner(context);
 partner.finish();
/**
Clears the connection with the genie service for partner service. It must be invoked when the service is no longer required, but after the service has responded back with all the requests. So depending on the need, it might be either called in 
 * 'onDestroy' of the activity(if service finishes before the activity) 
 * 'onSuccess' & 'onFailure' of the responseHandler (if there is one request, for multiple request you need to handle it appropriately).
**/
public void finish()

9. Launch Genie App:

private void launchGenieApp(Context context){
    PackageManager manager =context.getPackageManager();
     try {
         Intent intent = manager.getLaunchIntentForPackage("org.ekstep.genieservices");
         intent.addCategory(Intent.CATEGORY_LAUNCHER);
         context.startActivity(intent);
     } catch (Exception e) {}
}

Steps to Generate RSA public and private keys:

  1. Download openssl from this link:   http://www.indyproject.org/Sockets/fpc/OpenSSLforWin64.en.aspx
  2. Extract the downloaded folder and click on "openssl.exe" then it will open cmd prompt.(Right click and Run as a Administrator)
  3. To generate an RSA Private key pair use: (Type below cmd in the cmd prompt)    
    genrsa -out rsa_1024_priv.pem 1024
  4. This private key file "rsa_1024_priv.pem" will be generated on your extracted folder.
  5. To generate the Public Key in PEM format use:(Type below cmd in the cmd prompt)    
    rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem
  6. This public key file "rsa_1024_pub.pem" will be generated on your extracted folder.

Sample Source code:

The minimum requirements for Android Studio are:
Windows

  1. Microsoft Windows 10/8/7/Vista/2003 (32 or 64-bit)
    2.Java Development Kit (JDK) 7

Mac OS X

  1. Mac OS X 10.8.5 or higher, up to 10.9 (Mavericks)
  2. Java Runtime Environment (JRE) 6
    Java Development Kit (JDK) 7

Linux

  1. GNOME or KDE desktop
  2. Oracle Java Development Kit (JDK) 7

Software required
1.Android studio
http://developer.android.com/sdk/index.html
2. JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Installation
1.Install JDK
2.Set Path of JDK in Windows follow below links
http://www.javatpoint.com/how-to-set-path-in-java

After setting path restart system.
3.Install Android studio
After successful installation open Android studio.

Source Code
1.Download the source code
https://github.com/ekstep/EkStep-Partner-App

  1. Unzip(extract) it

    After successful this, You have source-code of Generic partner app.

Import Source Code into Android Studio
1.Open Android Studio

2.Select File option(from Top left corner) then select Open.. Option
Then select path of source code( e.g. E:\EkStep-Partner-App-master)

3.Left SIDE-BAR there is option project click on Project
You will see EkStep-Partner-App-master(Project-name)

4.Click on EkStep-Partner-App-master ->app->src->main->assets->config.json

5.Open Config.json file
a. Configuration file(config.json) where Partner can define their name and own set of rules like number of fields with description with their data types.
b. Change in this file according to your requirements.

6 . To Change Logo of App
a). Go inside particular folder
C:\Generic-Scripts-PUBLIC-master\app\src\main\res
b). Copy icon inside
drawable-hdpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxhdpi

With respective dimensions name as partner_logo each image(there is already partner_logo just overwrite it)
7. Change App Name

  1. Open String.xml file, You will find this file
    Generic-Partner-App\app\src\main\res\values
  2. Inside String.xml file
    you will find "GPA "
    change GPA by Partner-Name

8.Run option on Top toolbars
Click Run->Run app
After successful running it will build apk at following locations

C:\Generic-Scripts-PUBLIC-master\app\build\outputs\apk
Generic-Partner-App-1.0.local-debug.apk

Now you can install this apk .
Enjoy :)

Here example of Config.json file

{
  "partnerName": "LME",
  "partnerId": "org.ekstep.partner.lme",
  "partnerPublicKey": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvgDm/lRk4ZU4ZUAaLRqXhzxGbRzSFOjOsIEgGAMYkh3+pULK/9evvOhI5X2afbnLLTo6h9MzjzWKio/G5jTH8YRS61ohBnhL8TKkVwXlU9GYnvOZimIoizPXimhNrVcAYvo4GNwrB9sxGFyNPup0CBCnyWifdhKOWGo5LGhNCP9ehmJJchPw23RN+VeF/fsW9WVJNTZFXy4WYbsM7YVGcQWYgCZX4eNqBcckP3aXaFTej1pPHfti2n+BLmudGK60lnZ4ePBidEi6WoPzpMrdMnwzkYOnQ8KBV0LKJr0vzqATzxGMC85fo1OUm+ZMobdl8SCLAzn5+2WFnNKyct1mtwIDAQAB",
  "sections": [
    //------------------Section represented by[ ] --------------------
    [
      {
        "SectionHeading": "Employee Details",  //Section 1st heading it will display on Top
        "instructions": {
          "title": "Star(*) denotes Mandatory field.",  //if Any instruction you want to give inside partucular section  as title
          "displayOrder": 2  // displayOrder representing position of  field ,it will show  at 2nd position inside partucular section
        }
      },
      {
        "fieldName": "Email-Id",   //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "textEmailAddress", //where user will enter email  e.g. dhruvraj123@gmail.com
          "validation": {
            "flag": false,  //false represents don't validate field
            "minimum": 8,   // It represents mimimum '8' character should  be
            "maximum": 12   // It represents maximum '12' character should  be
          }
        },
        "fieldHint": "enter aplhabet character",  //fieldHint as Help what fieldInputType should be
        "displayOrder": 1,  //displayOrder representing position of  field, it will show  at 1st position inside first section
        "fieldValues": []
      },
      {
        "fieldName": "FirstName", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "text",//where user will enter FirstName  e.g. Dhruv
          "validation": {
            "flag": true,  //true represents  validate field
            "minimum": 3,  // It represents mimimum '3' character should  be
            "maximum": 25  // It represents maximum '25' character should  be
          }
        },
        "fieldHint": "enter aplhabet character",
        "displayOrder": 13,
        "fieldValues": []
      },
      {
        "fieldName": "Skills", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "MultipleChoiceMore", //MultipleChoiceMore means You can select one or more options
          "fieldInputType": "None", //fieldInputType None means where user has to select from given option
          "validation": {
            "flag": true,  //true represents  validate field
            "minimum": 1,  // It represents mimimum '1' field has to select
            "maximum": 2   // It represents maximum  '2' field has to select
          }
        },
        "fieldHint": "You can select one or more options",
        "displayOrder": 5,
        "fieldValues": ["Java","PHP","Android","SAP"] // It showing the option list corresponding to field
      },
      {
        "fieldName": "Gender", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "MultipleChoiceSingle", //MultipleChoiceSingle means You can select only one option
          "fieldInputType": "None",
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 1, // It represents mimimum '1' field has to select
            "maximum": 1  // It represents maximum '1' field has to select
          }
        },
        "fieldHint": "You can select one option only",
        "displayOrder": 6,
        "fieldValues": ["Male","Female"]
      },
      {
        "fieldName": "Password", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "textPassword", //textPassword means it will hide what user is enetered e.g. ********
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 6,  // It represents mimimum '6' character should be
            "maximum": 10  // It represents maximum '10' character should be
          }
        },
        "fieldHint": "enter password max 10 char",
        "displayOrder": 4,
        "fieldValues": []
      },
      {
        "fieldName": "Joining Date", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "date", //User has to select date from calander
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 1, // It represents mimimum '1' year should be from current date
            "maximum": 2 // It represents maximum '2' year should be from current date
          }
        },
        "fieldHint": "select date from calander",
        "displayOrder": 3,
        "fieldValues": []
      }
    ],
    //----------------------end of Section First-------------------------------------------
    //---------------------- Section Second-------------------------------------------

    [
      {
        "SectionHeading": "Address Details", //Section 2nd heading it will display below Section First
        "instructions": {
          "title": "",   //if Any instruction you want to give inside partucular section  as title, Here no instruction
          "displayOrder": 0 // displayOrder '0' means no title
        }
      },
      {
        "fieldName": "State", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "DropDown", //DropDown means You can select only one option
          "fieldInputType": "None",
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 1, // It represents mimimum '1' has to select
            "maximum": 1 // It represents maximum '1'  has to select
          }
        },
        "fieldHint": "please select one state",
        "displayOrder": 1,
        "fieldValues": [
          "Karnataka",
          "Tamilandu",
          "Bihar"
        ]
      },
      {
        "fieldName": "Street Address", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "TextComment",
          "fieldInputType": "textMultiLine", //textMultiLine means User can enter input more than one line
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 1, // It represents mimimum '1' line should be
            "maximum": 3  // It represents maximum '3' line should be
          }
        },
        "fieldHint": "enter address",
        "displayOrder": 2,
        "fieldValues": []
      }
    ],
    //----------------------end of Section Second----------------

    //------------------------Section third----------------------------
    [
      {
        "SectionHeading": "",// No heading
        "instructions": {
          "title": "",   //No title
          "displayOrder": 0 //No displaying position
        }
      },
      {
        "fieldName": "Age", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "number", //where user can enter age as integer like 12,24,35,36 etc
          "validation": {
            "flag": true, //true represents  validate field
            "minimum": 3, // It represents mimimum value should be 3
            "maximum": 10 // It represents maximum value should be 10
          }
        },
        "fieldHint": "enter age in years only",
        "displayOrder": 1,
        "fieldValues": []
      },


      {
        "fieldName": "Mobile Number", //It's fieldName which will display as Label
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "phone", //fieldInputType 'phone' means it will be integer like e.g. 8050691172
          "validation": {
            "flag": true, //true represents validate field
            "minimum": 10, // It represents mimimum '10' number should  be
            "maximum": 12  // It represents maximum '12' number should  be
          }
        },
        "fieldHint": "enter mobile number",
        "displayOrder": 2,
        "fieldValues": []
      },
      {
        "fieldName": "Price",
        "fieldvalue": {
          "fieldType": "Text",
          "fieldInputType": "numberDecimal", //where user can enter decimal values e.g. 50.65,75,85.82,
          "validation": {
            "flag": true,
            "minimum": 50,
            "maximum": 124
          }
        },
        "fieldHint": "enter Price ",
        "displayOrder": 10,
        "fieldValues": []
      }
    ]
  ]
}

Summary of Config.json

Any partner can change only following things
i)PartnerName
ii)PartnerId
iii)PartnerPublicKey
iv)Sections
1.SectionHeading
2.instructions
a)title b)Displayorder 3. fieldName
a)validation
-flag :true/false
minimum : integer value
maximum :integer value
4. fieldHint
5. fieldValues

Generic Partner App functionaliy( for partner developer)

  1. Register the partner(partner.register(String partnerID, String publicKey, IResponseHandler responseHandler))

  2. Read the configuration file(readConfigFile())

  3. Store the configuration file( storeConfigModel())

  4. To start OE_EVENT (generateOEStartEvent() )

  5. To display form (displayForm()) based on configuration file.

  6. To validate form data( isValidateData())

  7. Send data to Genie services( sendDataToGenieServices())
    i. End the partner session
    partner.terminatePartnerSession(Util.partnerId, endSessionResponseHandler)
    ii. Create Profile
    userProfile.createUserProfile(profile, userProfileResponseHandler)
    where you will get UID on succuess

    iv. Set current User
    userProfile.setCurrentUser(UID, currentuserSetResponseHandler)

    v. Get current User
    userProfile.getCurrentUser(currentGetuserResponseHandler);

    vi. Start session
    partner.startPartnerSession(Util.partnerId,startSessionResponseHandler);

    vii. Send partner data to Genie services
    partner.sendData(UID,partnerData,partnerDataResponseHandler);

    viii. To end OE_EVENT (generateOEEndEvent())

    ix.End the partner session
    partner.terminatePartnerSession(Util.partnerId, endSessionResponseHandler)

  8. To exit the app(exitApp())

How to use Genie service SDK:

https://community.ekstep.in/developer-knowledgebase/70-getting-started-with-genie-service-sdk

PARTNER App sample source code:

https://github.com/ekstep/EkStep-Partner-App

PARTNER App sample Implementation:

https://github.com/ekstep/Common-Design/wiki/PARTNER-SDK-IMPLEMENTATION

Telemtry V2 documentation:

https://community.ekstep.in/specifications-guides/53-telemetry-specification

Clone this wiki locally