Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.saholic.profittill;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.mixpanel.android.mpmetrics.MixpanelAPI;
import com.saholic.profittill.Constants.ProfitTillConstants;
import com.saholic.profittill.Network.NotificationCount;
import com.saholic.profittill.Utils.AnalyticsUtility;
import com.saholic.profittill.Utils.UtilityFunctions;
import com.saholic.profittill.Volley.Analytics;
import com.saholic.profittill.Volley.AnalyticsErrorResponse;
import com.saholic.profittill.Volley.AnalyticsJsonResponse;
import com.saholic.profittill.main.GoogleAnalyticsTracker;
import com.saholic.profittill.main.LoginActivity;
import com.saholic.profittill.main.MainActivity;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;

/**
 * Created by rajender on 5/4/17.
 */
public class MyFirebaseMessagingService extends FirebaseMessagingService {
    SharedPreferences userData;
    SharedPreferences apiData;
    MixpanelAPI mixpanel;
    SharedPreferences.Editor userDataEditor;
    SharedPreferences.Editor apiSettingsEditor;
  ArrayList<NameValuePair> nameValuePairsGcm;
    public static int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;
    SharedPreferences notificationData;
    SharedPreferences.Editor notificationDataEditor;
    private static final String TAG = "MyFirebaseMsgService";
    Intent intent;
  Bitmap bitmap;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        userData = this.getSharedPreferences("User_Data", Context.MODE_PRIVATE);
        apiData = this.getSharedPreferences("API_Data", Context.MODE_PRIVATE);
        userDataEditor = userData.edit();
        apiSettingsEditor = apiData.edit();
        notificationData = this.getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
        notificationDataEditor = notificationData.edit();
        mixpanel = MixpanelAPI.getInstance(getApplicationContext(), ProfitTillConstants.MIX_PANEL_TOKEN);
        Map<String, String> data = remoteMessage.getData();
        if (data.containsKey("image")) {
            String imageUri = data.get("image");
            bitmap = getBitmapfromUrl(imageUri);

        }
            try {
               if(data.get("type").equalsIgnoreCase("update")){
                    new CheckNotificationExpiry().execute(data);
                }
                String campaignUserId = data.get("url").split("user_id=")[1];
                if (userData.getString("id", "0").equalsIgnoreCase(campaignUserId)) {
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
                            AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Check Expiry", data.get("cid") + ""),
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
                    new CheckNotificationExpiry().execute(data);
                }


            }
            catch (Exception e) {
                e.printStackTrace();
                Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
                        GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
                t.send(new HitBuilders.ExceptionBuilder()
                        .setDescription("Exception while Checking" + e.getMessage())
                        .build());
            }

        }

        class CheckNotificationExpiry extends AsyncTask<Map, Integer, String> {
            Map extras;

            @Override
            protected String doInBackground(Map... params) {
                extras = params[0];
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    String notificationCheckUrl = apiData.getString("notification.check.url", "http://api.profittill.com/notification_campaigns/notificationactive");
                    HttpPost httppost = new HttpPost(notificationCheckUrl + "?cid=" + extras.get("cid") + "&imeinumber=" + UtilityFunctions.getImeiNumber(getApplicationContext()));
                    httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
                    int status = response.getStatusLine().getStatusCode();
                    return String.valueOf(jObjGmail.getString("success"));
                    // return jObjGmail.getString("success");
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("Fail 1", e.toString());
                    return "true";
                }

            }

            @Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
                if (result.isEmpty() || result.equals(null) || result.equalsIgnoreCase("true")) {
                    if (notificationData.getString("cid", "").equalsIgnoreCase(extras.get("cid").toString().split("_")[0])) {
                        Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + extras.get("cid").toString().split("_")[0]);
                    }
                    else {
                        notificationDataEditor.putString("cid", extras.get("cid").toString().split("_")[0]);
                        notificationDataEditor.commit();
                        sendNotification(extras.get("message") + "", extras.get("type") + "", extras.get("title") + "", extras.get("url") + "", extras.get("cid") + "", bitmap);
                    }
                } else {
                    new Analytics(ProfitTillConstants.ANALYTICS_URL,
                            AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Expired", extras.get("cid") + ""),
                            AnalyticsJsonResponse.getAnalyticsRequestInstance(),
                            AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
                    nameValuePairsGcm = new ArrayList<>();
                    nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
                    nameValuePairsGcm.add(new BasicNameValuePair("cid", extras.get("cid") + ""));
                    nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
                    nameValuePairsGcm.add(new BasicNameValuePair("result", "expired"));
                    new NotificationRecievedData().execute(nameValuePairsGcm);
                }
            }
        }

    private void sendNotification(String msg, String type, String title, String url, String cid, Bitmap image) {
        JSONObject propsNotificationRecieved = new JSONObject();
        Bundle bundle;
        try {
            mixpanel.identify(userData.getString("id", null));
            propsNotificationRecieved.put("Screen", "Notification Reached");
            mixpanel.track("Notification Recieved", propsNotificationRecieved
            );
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (title.isEmpty()) {
            title = "ProfitMandi";
        }
        Intent resultIntent;
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        if (userData.getString("id", "").isEmpty()) {
            resultIntent = new Intent(this, LoginActivity.class);
            resultIntent.setAction("Login");
            bundle = new Bundle();
            bundle.putString("cid", cid);
            resultIntent.putExtras(bundle);
        } /*else if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
            //resultIntent = new Intent(this, ReferrerActivity.class);
            //resultIntent.setAction("Login");
            //bundle = new Bundle();
           // bundle.putString("cid", cid);
            //resultIntent.putExtras(bundle);} */
            else {
            if (type.equalsIgnoreCase("Url")) {
                resultIntent = new Intent(this, MainActivity.class);
                bundle = new Bundle();
                bundle.putString("cid", cid);
                resultIntent.putExtras(bundle);
                resultIntent.setAction("20");

                if (url.isEmpty()) {
                    resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
                } else {
                    resultIntent.setData(Uri.parse(url));
                }

            } else if (type.equalsIgnoreCase("Update")) {
                final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
                try {
                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
                } catch (android.content.ActivityNotFoundException anfe) {
                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
                }
            } else {
                if (url.contains("Profile")) {
                    resultIntent = new Intent(this, MainActivity.class);
                    bundle = new Bundle();
                    bundle.putString("cid", cid);
                    resultIntent.putExtras(bundle);
                    resultIntent.setAction("15");
                } else if (url.contains("Tutorial")) {
                    resultIntent = new Intent(this, MainActivity.class);
                    bundle = new Bundle();
                    bundle.putString("cid", cid);
                    resultIntent.putExtras(bundle);
                    resultIntent.setAction("7");
                } else if (url.contains("Contact")) {
                    resultIntent = new Intent(this, MainActivity.class);
                    bundle = new Bundle();
                    bundle.putString("cid", cid);
                    resultIntent.putExtras(bundle);
                    resultIntent.setAction("6");
                } else {
                    resultIntent = new Intent(this, MainActivity.class);
                    bundle = new Bundle();
                    bundle.putString("cid", cid);
                    resultIntent.putExtras(bundle);
                }
            }
        }
        PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, resultIntent, 0);
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.pmlauncher);
        if (image==null) {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                mBuilder.setSmallIcon(R.drawable.navigation_bar);
            } else{
                mBuilder.setSmallIcon(R.drawable.pmnotification3);
            }
            mBuilder.setContentTitle(title);
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
            mBuilder.setContentText(msg);
            mBuilder.setLargeIcon(bm);
            mBuilder.setAutoCancel(true);
            mBuilder.setSound(alarmSound);
            mBuilder.setContentIntent(contentIntent);
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        } else {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                mBuilder.setSmallIcon(R.drawable.navigation_bar);
            } else{
                mBuilder.setSmallIcon(R.drawable.pmnotification3);
            }
            mBuilder.setContentTitle(title);
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
            mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image));
            mBuilder.setContentText(msg);
            mBuilder.setLargeIcon(bm);
            mBuilder.setAutoCancel(true);
            mBuilder.setSound(alarmSound);
            mBuilder.setContentIntent(contentIntent);
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }

        Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
                GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
        t.send(new HitBuilders.EventBuilder()
                .setCategory("Notification")
                .setAction("Building Notification for campaign Id " + cid)
                .setLabel("For User Id " + userData.getString("id", "0"))
                .build());
        new Analytics(ProfitTillConstants.ANALYTICS_URL,
                AnalyticsUtility.getAnalyticsRequest(getApplicationContext(), userData.getString("id", ""), "Notification", "Notification Received", cid),
                AnalyticsJsonResponse.getAnalyticsRequestInstance(),
                AnalyticsErrorResponse.getAnalyitcsResponseInstance()).anlyticsRequest(getApplicationContext());
        ++NOTIFICATION_ID;
        nameValuePairsGcm = new ArrayList<>();
        nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
        nameValuePairsGcm.add(new BasicNameValuePair("cid", cid));
        nameValuePairsGcm.add(new BasicNameValuePair("timestamp", UtilityFunctions.notificationDate()));
        nameValuePairsGcm.add(new BasicNameValuePair("result", "recieved"));
        String userId = userData.getString("id", "");
        String androidId = UtilityFunctions.androidId(GoogleAnalyticsTracker.getAppContext());
        if (!userId.isEmpty() && !androidId.isEmpty()) {
            String notificationUrl = apiData.getString("notification.count", "http://45.33.50.227:3001/getNotificationCount") + "?user_id=" + userId + "&android_id=" + androidId;
            new NotificationCount().getCount(GoogleAnalyticsTracker.getAppContext(), null, notificationUrl);
        }
        new NotificationRecievedData().execute(nameValuePairsGcm);
    }

    class NotificationRecievedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
                    GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
            t.send(new HitBuilders.EventBuilder()
                    .setCategory("Notification")
                    .setAction("Received Notification")
                    .setLabel("For User Id " + userData.getString("id", "0"))
                    .build());
        }

        @Override
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(apiData.getString("notification.data.url", "http://api.profittill.com/pushnotifications/add"));
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
                httppost.setEntity(new UrlEncodedFormEntity(arg0[0]));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                int status = response.getStatusLine().getStatusCode();
                nameValuePairsGcm.clear();
            } catch (Exception e) {
            }
            return "success";
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
        }
    }

    public void sendNotificationByPolling(JSONArray objects,Context c) {
        userData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("User_Data", Context.MODE_PRIVATE);
        apiData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("API_Data", Context.MODE_PRIVATE);
        notificationData = GoogleAnalyticsTracker.getAppContext().getSharedPreferences("Notification_Data", Context.MODE_PRIVATE);
        userDataEditor = userData.edit();
        apiSettingsEditor = apiData.edit();
        notificationDataEditor = notificationData.edit();

        Bundle bundle;

        try {
            if (objects.length() != 0) {
                JSONObject obj = new JSONObject();
                JSONArray jsArray = new JSONArray();
                for (int i = 0; i < objects.length(); i++) {
                    JSONObject j = objects.getJSONObject(i);
                    String msg = j.getString("message");
                    String type = j.getString("type");
                    String title = j.getString("title");
                    String url = j.getString("url");
                    String cid = j.getString("cid");
                    String image=null;
                    if(j.has("image")) {
                        image = j.getString("image");
                        bitmap=getBitmapfromUrl(image);
                    }
                    if (notificationData.getString("cid", "").equalsIgnoreCase(cid.split("_")[0])) {
                        Log.d("Campaign Id is same " + notificationData.getString("cid", ""), "Campaign Id is same " + cid.split("_")[0]);
                    } else {
                        notificationDataEditor.putString("cid", cid.split("_")[0]);
                        notificationDataEditor.commit();
                        if (title.isEmpty()) {
                            title = "ProfitMandi";
                        }
                        Intent resultIntent;
                        mNotificationManager = (NotificationManager) GoogleAnalyticsTracker.getAppContext().getSystemService(NOTIFICATION_SERVICE);
                        if (userData.getString("id", "").isEmpty()) {
                            resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), LoginActivity.class);
                            resultIntent.setAction("Login");
                            bundle = new Bundle();
                            bundle.putString("cid", cid);
                            resultIntent.putExtras(bundle);
                        }
                        /*else if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
                            resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), ReferrerActivity.class);
                            resultIntent.setAction("Login");
                            bundle = new Bundle();
                            bundle.putString("cid", cid);
                            resultIntent.putExtras(bundle);
                        }*/
                        else {
                            if (type.equalsIgnoreCase("Url")) {
                                resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
                                bundle = new Bundle();
                                bundle.putString("cid", cid);
                                resultIntent.putExtras(bundle);
                                resultIntent.setAction("20");

                                if (url.isEmpty()) {
                                    resultIntent.setData(Uri.parse(apiData.getString("mobile.website.url", "") + "?user_id=" + userData.getString("id", "")));
                                } else {
                                    resultIntent.setData(Uri.parse(url));
                                }

                            } else if (type.equalsIgnoreCase("Update")) {
                                final String appPackageName = GoogleAnalyticsTracker.getAppContext().getPackageName();
                                try {
                                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
                                } catch (android.content.ActivityNotFoundException anfe) {
                                    resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
                                }
                            } else {
                                if (url.contains("Profile")) {
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
                                    bundle = new Bundle();
                                    bundle.putString("cid", cid);
                                    resultIntent.putExtras(bundle);
                                    resultIntent.setAction("15");
                                } else if (url.contains("Tutorial")) {
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
                                    bundle = new Bundle();
                                    bundle.putString("cid", cid);
                                    resultIntent.putExtras(bundle);
                                    resultIntent.setAction("7");
                                } else if (url.contains("Contact")) {
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
                                    bundle = new Bundle();
                                    bundle.putString("cid", cid);
                                    resultIntent.putExtras(bundle);
                                    resultIntent.setAction("6");
                                } else {
                                    resultIntent = new Intent(GoogleAnalyticsTracker.getAppContext(), MainActivity.class);
                                    bundle = new Bundle();
                                    bundle.putString("cid", cid);
                                    resultIntent.putExtras(bundle);
                                }
                            }
                        }
                        PendingIntent contentIntent = PendingIntent.getActivity(GoogleAnalyticsTracker.getAppContext(), NOTIFICATION_ID, resultIntent, 0);
                        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                        Bitmap bm = BitmapFactory.decodeResource(GoogleAnalyticsTracker.getAppContext().getResources(), R.drawable.pmlauncher);
                        if (bitmap==null) {
                            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                                  c )
                                    .setSmallIcon(R.drawable.navigation_bar)
                                    .setContentTitle(title)
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                                    .setContentText(msg)
                                    .setLargeIcon(bm)
                                    .setAutoCancel(true)
                                    .setSound(alarmSound);
                            mBuilder.setContentIntent(contentIntent);
                            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
                        }

                        else {
                            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                                    GoogleAnalyticsTracker.getAppContext())
                                    .setSmallIcon(R.drawable.pmnotification3)
                                    .setContentTitle(title)
                                    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                                    .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap))
                                    .setContentText(msg)
                                    .setLargeIcon(bm)
                                    .setAutoCancel(true)
                                    .setSound(alarmSound);
                            mBuilder.setContentIntent(contentIntent);
                            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
                        }
                        ++NOTIFICATION_ID;
                        JSONObject data = new JSONObject();
                        data.put("cid", cid);
                        data.put("user_id", userData.getString("id", null));
                        data.put("timestamp", UtilityFunctions.notificationDate());
                        data.put("result", "recieved");
                        jsArray.put(data);
                    }
                    obj.put("pushdata", jsArray);
                    String userId = userData.getString("id", "");
                    String androidId = UtilityFunctions.androidId(GoogleAnalyticsTracker.getAppContext());
                    if (!userId.isEmpty() && !androidId.isEmpty()) {
                        String notificationUrl = apiData.getString("notification.count", "") + "?user_id=" + userId + "&android_id=" + androidId;
                        new NotificationCount().getCount(GoogleAnalyticsTracker.getAppContext(), null, notificationUrl);
                    }
                }
                new PollNotificationRecievedData().execute(obj);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    class PollNotificationRecievedData extends AsyncTask<JSONObject, Integer, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(JSONObject... arg0) {

            try {
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
                nameValuePairs.add(new BasicNameValuePair("pushdata", arg0[0].toString()));
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(apiData.getString("pollnotification.url.received", "http://45.79.106.95:3001/addPollNotification"));
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return "success";
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
        }
    }


    public Bitmap getBitmapfromUrl(String imageUrl) {
        try {
            URL url = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap bitmap = BitmapFactory.decodeStream(input);
            return bitmap;
        }
        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;

        }
    }
}