Skip to content

Commit

Permalink
application finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
tharinda221 committed Oct 21, 2016
1 parent 67ed1fe commit dec76c9
Show file tree
Hide file tree
Showing 14 changed files with 714 additions and 24 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<scope>system</scope>
<systemPath>${ideamart.lib}/sdp.app.api-1.0.183-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>hms</groupId>
<artifactId>sdp.app.api</artifactId>
<version>1.0.11-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${ideamart.lib}/sdp.app.api-1.0.144.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -49,7 +56,13 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.22</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>

</dependencies>
<build>
<finalName>ideamart-ussd-tracking-application</finalName>
<plugins>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/ideamart/sample/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,25 @@ public static final class ApplicationConstants {

//Specific Version
public static final String VERSION = "1.0";

public static final String LBS_URL = "http://127.0.0.1:7000/lbs/locate";
}

public static final class ApplicationMessages {
public static final String WELCOME_MSG = "1. Subscribe\n99. Exit";
public static final String SUBSCRIBE_MESSAGE = "1. Search Location\n2. Register For Pin\n3. Forget Pin\n4. Help\n5. Contact us\n0. Back\n99. Exit";
public static final String SEARCH_LOCATION = "obata soyanna awashya kenage pin ankaya athulath karanna";
public static final String REGISTER_FOR_PIN = "keti paniwidayakin obe pin ankaya labenu atha.\n" +
"0. Back\n" +
"99. Exit";
public static final String HELP_MESSAGE = "Keti Paniwidayak Magein Siyalu Thorathuru Labenu Atha.\n0. Back\n99. Exit";
public static final String CONTACT = "Sp Name:-S.M.P.K Senevirathna\n" +
" App Developer Details: [email protected].\n" +
" \n0. Back\n99.Exit";
public static final String HELP_SMS = "welcome to (app eke name) ussd application.\n" +
" Inna Thana Balaganimata :- (app keyword) <space> GPS <space> oba soyana kenage Pin Ankaya.\n" +
" sent to(app number)\n";
public static final String ExIT_MESSAGE = "Thank you for using. come again!";

}
}
12 changes: 12 additions & 0 deletions src/main/java/com/ideamart/sample/dashboard/Dashboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ideamart.sample.dashboard;

/**
* Created by tharinda on 10/21/16.
*/
public class Dashboard {
private String totalUsers;
private String pendingUser;
private String activeUsers;


}
77 changes: 77 additions & 0 deletions src/main/java/com/ideamart/sample/lbs/LBS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.ideamart.sample.lbs;


import com.google.gson.*;
import com.ideamart.sample.common.Constants;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

import java.io.*;
import java.net.URI;
import java.util.Scanner;

/**
* Created by tharinda on 10/21/16.
*/
public class LBS {

private String APIkey = "AIzaSyDfPfRnA7qzQe5Qhg9SQkNxhGVryguhN3w";

public String getLocation(String address) throws Exception {

LBSbean lbSbean = new LBSbean();
lbSbean.setApplicationId(Constants.ApplicationConstants.APP_ID);
lbSbean.setPassword(Constants.ApplicationConstants.PASSWORD);
lbSbean.setSubscriberId(address);
lbSbean.setFreshness("HIGH");
lbSbean.setHorizontalAccuracy("1500");
lbSbean.setResponseTime("NO_DELAY");
lbSbean.setVersion("2.0");
String postUrl = Constants.ApplicationConstants.LBS_URL;
Gson gson = new Gson();
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(postUrl);
StringEntity postingString = new StringEntity(gson.toJson(lbSbean));//gson.tojson() converts your pojo to json
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
post.setHeader("Accept", "application/json");
HttpResponse response = httpClient.execute(post);
System.out.println(response.getStatusLine());
InputStream inputStream = response.getEntity().getContent();
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
return getMessage(result);

}

public String getMessage(String jsonLine) throws IOException {
JsonElement jelement = new JsonParser().parse(jsonLine);
JsonObject jobject = jelement.getAsJsonObject();
String lat = String.valueOf(jobject.get("latitude")).replaceAll("['\"]", "");
String lon = String.valueOf(jobject.get("longitude")).replaceAll("['\"]", "");
return getMapLocation(lat, lon);
}

public String getMapLocation(String lat, String lon) throws IOException {
String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&key=" + APIkey;
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet get = new HttpGet();
get.setURI(URI.create(url));
HttpResponse response = httpClient.execute(get);
System.out.println(response.getStatusLine());
InputStream inputStream = response.getEntity().getContent();
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
JsonElement jelement = new JsonParser().parse(result);
JsonObject jobject = jelement.getAsJsonObject();
JsonArray array = jobject.getAsJsonArray("results");
String address = array.get(0).getAsJsonObject().get("formatted_address").toString().replaceAll("['\"]", "");
String mapURL = "http://maps.google.com/?ll=" + lat + "," + lon;
return address + "\n" + mapURL;

}
}
81 changes: 81 additions & 0 deletions src/main/java/com/ideamart/sample/lbs/LBSbean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.ideamart.sample.lbs;

/**
* Created by tharinda on 10/21/16.
*/
public class LBSbean {
private String applicationId;
private String password;
private String subscriberId;
private String serviceType;
private String responseTime;
private String freshness;
private String horizontalAccuracy;

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getApplicationId() {
return applicationId;
}

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getSubscriberId() {
return subscriberId;
}

public void setSubscriberId(String subscriberId) {
this.subscriberId = subscriberId;
}

public String getServiceType() {
return serviceType;
}

public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}

public String getResponseTime() {
return responseTime;
}

public void setResponseTime(String responseTime) {
this.responseTime = responseTime;
}

public String getFreshness() {
return freshness;
}

public void setFreshness(String freshness) {
this.freshness = freshness;
}

public String getHorizontalAccuracy() {
return horizontalAccuracy;
}

public void setHorizontalAccuracy(String horizontalAccuracy) {
this.horizontalAccuracy = horizontalAccuracy;
}

private String version;

}
29 changes: 26 additions & 3 deletions src/main/java/com/ideamart/sample/sms/operations/Operations.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.ideamart.sample.sms.operations;

import com.ideamart.sample.common.Constants;
import com.ideamart.sample.sms.db.dbClass;
import com.ideamart.sample.lbs.LBS;
import com.ideamart.sample.sms.send.SendMessage;
import com.ideamart.sample.usermgt.UserDAO;
import hms.kite.samples.api.sms.messages.MoSmsReq;
import java.util.HashMap;

/**
* This class is created for do operations for messages.
Expand All @@ -30,6 +30,29 @@ public void passToDatabase(MoSmsReq moSmsReq) {

SendMessage sendMessage = new SendMessage();
sendMessage.SendMessage("Message received",moSmsReq.getApplicationId(),moSmsReq.getSourceAddress()
, Constants.ReceiverConstants.PASSWORD,Constants.ReceiverConstants.SMS_URL);
, Constants.ApplicationConstants.PASSWORD, Constants.ApplicationConstants.SMS_URL);
}

public void getLocation(String userAddress, String pin) throws Exception {
UserDAO userDAO = new UserDAO();
userDAO.updateCount(userAddress);
String address = userDAO.getUserAddressByPin(pin);
if(address.equals("null")) {
SendMessage sendMessage = new SendMessage();
sendMessage.SendMessage("Pin you Entered is not registered", Constants.ApplicationConstants.APP_ID , userAddress
, Constants.ApplicationConstants.PASSWORD, Constants.ApplicationConstants.SMS_URL);
} else {
LBS lbs = new LBS();
String finalMessage = lbs.getLocation(address);
SendMessage sendMessage = new SendMessage();
sendMessage.SendMessage(finalMessage, Constants.ApplicationConstants.APP_ID , userAddress
, Constants.ApplicationConstants.PASSWORD, Constants.ApplicationConstants.SMS_URL);
}
}

public void errorMessage(String address) {
SendMessage sendMessage = new SendMessage();
sendMessage.SendMessage("Message format error", Constants.ApplicationConstants.APP_ID , address
, Constants.ApplicationConstants.PASSWORD, Constants.ApplicationConstants.SMS_URL);
}
}
23 changes: 19 additions & 4 deletions src/main/java/com/ideamart/sample/sms/receive/Receiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@ public void init() {

@Override
public void onReceivedSms(MoSmsReq moSmsReq) {
String message = moSmsReq.getMessage();
String [] messageParts = message.split(" ");
Operations operations = new Operations();
operations.passToDatabase(moSmsReq);

try {
String message = moSmsReq.getMessage();
String [] messageParts = message.split(" ");
String operation = messageParts[1].toLowerCase();
Operations operations = new Operations();

if(operation.equals("gps")) {
operations.getLocation(moSmsReq.getSourceAddress(), messageParts[2]);
} else {
operations.errorMessage(moSmsReq.getSourceAddress());
}
} catch (Exception e) {
Operations operations = new Operations();
operations.errorMessage(moSmsReq.getSourceAddress());
e.printStackTrace();

}

}
}
40 changes: 40 additions & 0 deletions src/main/java/com/ideamart/sample/subcription/Subscription.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ideamart.sample.subcription;

import com.ideamart.sample.common.Constants;
import hms.kite.samples.api.SdpException;
import hms.kite.samples.api.subscription.SubscriptionRequestSender;
import hms.kite.samples.api.subscription.messages.SubscriptionRequest;
import hms.kite.samples.api.subscription.messages.SubscriptionResponse;

import java.net.MalformedURLException;
import java.net.URL;

/**
* Created by tharinda on 10/21/16.
*/
public class Subscription {

private String subscriptionStatus;

public String subscribeUser(String address) throws MalformedURLException {
SubscriptionRequestSender subscriptionRequestSender =
new SubscriptionRequestSender(new URL(Constants.ApplicationConstants.SUBSCRIPTION_MESSAGE_URL));

SubscriptionRequest subscriptionRequest = new SubscriptionRequest();
subscriptionRequest.setApplicationId(Constants.ApplicationConstants.APP_ID);
subscriptionRequest.setPassword(Constants.ApplicationConstants.PASSWORD);
subscriptionRequest.setSubscriberId(address);
subscriptionRequest.setAction(Constants.ApplicationConstants.REG_ACTION);
subscriptionRequest.setVersion(Constants.ApplicationConstants.VERSION);

try {
// Get SubscriptionResponse and assign Subscription Register Status to display
SubscriptionResponse subscriptionResponse
= subscriptionRequestSender.sendSubscriptionRequest(subscriptionRequest);
return subscriptionResponse.getStatusDetail();
} catch (SdpException e) {
System.out.println("Error Occurred due to" + e);
}
return null;
}
}
Loading

0 comments on commit dec76c9

Please sign in to comment.