View Javadoc
1   /*
2    * Copyright (C) 2003-2014 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 3 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  package org.exoplatform.ui.login.tasks;
20  
21  import java.io.IOException;
22  
23  import org.exoplatform.utils.ExoConnectionUtils;
24  
25  import android.os.AsyncTask;
26  import android.util.Log;
27  
28  /**
29   * Task performing checking status of tenant
30   */
31  public class CheckingTenantStatusTask extends AsyncTask<String, Void, Integer> {
32  
33    private AsyncTaskListener   mListener;
34  
35    private static final String TAG = "eXo____CheckingTenantStatusTask____";
36  
37    @Override
38    protected Integer doInBackground(String... params) {
39      String tenant = params[0];
40      String email = params[1];
41      Log.d(TAG, "Checking tenant status: " + tenant + " for " + email);
42  
43      try {
44        int status = ExoConnectionUtils.requestTenantStatus(tenant);
45        if (status == ExoConnectionUtils.LOGIN_SERVER_RESUMING)
46          return ExoConnectionUtils.LOGIN_SERVER_RESUMING;
47  
48        else if (status == ExoConnectionUtils.SIGNIN_SERVER_SUSPENDED) {
49          /** stimulate a sign up request to force restoring server */
50          ExoConnectionUtils.makeCloudSignUpRequest(email);
51          return ExoConnectionUtils.LOGIN_SERVER_RESUMING;
52        } else if (status == ExoConnectionUtils.SIGNIN_SERVER_ONLINE)
53          return ExoConnectionUtils.TENANT_OK;
54  
55        return status;
56      } catch (IOException e) {
57        Log.d(TAG, "IOException: " + e.getLocalizedMessage());
58        return ExoConnectionUtils.SIGNIN_SERVER_NAV;
59      }
60    }
61  
62    public void setListener(AsyncTaskListener listener) {
63      mListener = listener;
64    }
65  
66    @Override
67    protected void onPostExecute(Integer result) {
68      if (mListener != null)
69        mListener.onCheckingTenantStatusFinished(result);
70    }
71  
72    public interface AsyncTaskListener {
73  
74      void onCheckingTenantStatusFinished(int result);
75    }
76  }