1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.ui.login.tasks;
20
21 import android.os.AsyncTask;
22 import android.util.Log;
23 import org.apache.http.HttpResponse;
24 import org.apache.http.HttpStatus;
25 import org.exoplatform.utils.ExoConnectionUtils;
26
27 import java.io.IOException;
28
29
30
31
32 public class RequestTenantTask extends AsyncTask<String, Void, Integer> {
33
34 private static final String TAG = "eXo____RequestTenantTask____";
35
36 private AsyncTaskListener mListener;
37
38 private String[] mResult;
39
40 @Override
41 protected Integer doInBackground(String... params) {
42 Log.i(TAG, "request tenant for email: " + params[0]);
43 String email = params[0];
44 try {
45 HttpResponse response = ExoConnectionUtils.requestTenantForEmail(email);
46 int responseCode = response.getStatusLine().getStatusCode();
47 Log.d(TAG, "status: " + responseCode);
48 mResult = ExoConnectionUtils.checkRequestTenant(response);
49
50
51 if (mResult == null) {
52 if (responseCode == HttpStatus.SC_SERVICE_UNAVAILABLE
53 || responseCode == HttpStatus.SC_NOT_FOUND)
54 return ExoConnectionUtils.SIGNIN_SERVER_NAV;
55
56 return ExoConnectionUtils.SIGNIN_NO_TENANT_FOR_EMAIL;
57 }
58
59 return ExoConnectionUtils.TENANT_OK;
60 }
61 catch (IOException e) {
62 Log.d(TAG, "IOException: " + e.getLocalizedMessage());
63 return ExoConnectionUtils.SIGNIN_SERVER_NAV;
64 }
65 }
66
67 public void onPostExecute(Integer result) {
68 if (mListener != null) mListener.onRequestingTenantFinished(result, mResult);
69 }
70
71 public void setListener(AsyncTaskListener listener) {
72 mListener = listener;
73 }
74
75 public interface AsyncTaskListener {
76
77 void onRequestingTenantFinished(int result, String[] userAndTenant);
78 }
79 }