Example #1
0
  private void countElements(String url) {

    datadownlooader =
        new RPCHandlerString(
            new IAsyncStringResponseHandler() {
              @Override
              public void onResponse(String stringResponse) throws Exception {
                stringResponse = stringResponse.replace(" ", "");
                stringResponse = stringResponse.replace("\n", "");
                count = Integer.parseInt(stringResponse);
              }

              @Override
              public void onRequest() {}

              @Override
              public void onException(Exception e) {}

              @Override
              public void continueProcessing() {}
            });
    datadownlooader.execute(url);
  }
Example #2
0
  private void backupCity(final int index) {
    getDialog().setTitle("Paso 11/13");
    datadownlooader =
        new RPCHandlerString(
            new IAsyncStringResponseHandler() {

              final class CityProcessor extends AsyncResponseProcessor {

                public CityProcessor(IAsyncStringResponseHandler handler, String data) {
                  super(handler, data);
                }

                @Override
                protected Void doInBackground(Object... params) {
                  super.doInBackground();
                  SQLiteOpenHelper helper = EduscoreOpenHelper.getInstance(mActivity.getMContext());
                  SQLiteDatabase dataBase = helper.getWritableDatabase();
                  try {
                    String sql =
                        "INSERT INTO "
                            + EduscoreOpenHelper.TABLE_DAT_CITY
                            + " (idCity, idRegion, name) VALUES "
                            + data;
                    String sqlDelete =
                        "DELETE FROM " + EduscoreOpenHelper.TABLE_DAT_CITY + " WHERE name = '0'";
                    dataBase.beginTransaction();
                    dataBase.execSQL(sql);
                    dataBase.execSQL(sqlDelete);
                    dataBase.setTransactionSuccessful();
                    dataBase.endTransaction();
                  } catch (Exception e) {
                    Log.e("Data Backup", "Error al Respaldar CIUDADES");
                  } finally {
                    dataBase.close();
                  }
                  return null;
                }
              }

              @Override
              public void continueProcessing() {
                int t = index;
                if ((index + 150) < count) {
                  t += 150;
                  backupCity(t);
                } else {
                  countElements(RPCHandlerString.OPERATION_COUNT_PERSONS);
                  backupPerson(maxElementPerson(EduscoreOpenHelper.TABLE_DAT_PERSON));
                }
              }

              @Override
              public void onResponse(String stringResponse) throws Exception {
                (new CityProcessor(this, stringResponse)).execute();
              }

              @Override
              public void onRequest() {
                // TODO:getDialog().setMessage("Respaldando Ciudades " + index + " / " + count);
                getDialog().setMessage(index + " / " + count);
              }

              @Override
              public void onException(Exception e) {
                cancelBackup();
              }
            });
    datadownlooader.execute(
        RPCHandler.OPERATION_GET_ALL_CITYS, new BasicNameValuePair("index", index + ""));
  }
Example #3
0
  private void backupOrigins(final int index) {
    getDialog().setTitle("Paso 7/13");
    datadownlooader =
        new RPCHandlerString(
            new IAsyncStringResponseHandler() {

              final class OriginsProcessor extends AsyncResponseProcessor {

                public OriginsProcessor(IAsyncStringResponseHandler handler, String data) {
                  super(handler, data);
                }

                @Override
                protected Void doInBackground(Object... params) {
                  super.doInBackground();
                  SQLiteOpenHelper helper = EduscoreOpenHelper.getInstance(mActivity.getMContext());
                  SQLiteDatabase dataBase = helper.getWritableDatabase();
                  try {
                    String sql =
                        "INSERT INTO "
                            + EduscoreOpenHelper.TABLE_DAT_ORIGIN
                            + " (idOrigin, name, type, status, idCampus) VALUES "
                            + data;
                    String sqlDelete =
                        "DELETE FROM " + EduscoreOpenHelper.TABLE_DAT_ORIGIN + " WHERE name = '0'";
                    dataBase.beginTransaction();
                    dataBase.execSQL(sql);
                    dataBase.execSQL(sqlDelete);
                    dataBase.setTransactionSuccessful();
                    dataBase.endTransaction();
                  } catch (Exception e) {
                    Log.e("Data Backup", "Error al Respaldar ORIGENES");
                  } finally {
                    dataBase.close();
                  }
                  return null;
                }
              }

              @Override
              public void continueProcessing() {
                int t = index;
                if ((index + 300) < count) {
                  t += 300;
                  backupOrigins(t);
                } else {
                  // NEXT BACKUP;
                  countElements(RPCHandlerString.OPERATION_COUNT_EMAILS);
                  backupEmail(maxElementEmail(EduscoreOpenHelper.TABLE_DAT_EMAIL));
                }
              }

              @Override
              public void onResponse(String stringResponse) throws Exception {
                (new OriginsProcessor(this, stringResponse)).execute();
              }

              @Override
              public void onRequest() {
                // TODO:getDialog().setMessage("Respaldando Origenes " + index + " / " + count);
                getDialog().setMessage(index + " / " + count);
              }

              @Override
              public void onException(Exception e) {
                cancelBackup();
              }
            });
    datadownlooader.execute(
        RPCHandler.OPERATION_GET_ALL_ORIGINS, new BasicNameValuePair("index", index + ""));
  }
Example #4
0
  private void backupUsuarios(final int index) {
    getDialog().setTitle("Paso 1/13");
    datadownlooader =
        new RPCHandlerString(
            new IAsyncStringResponseHandler() {

              final class UsuariosProcessor extends AsyncResponseProcessor {

                public UsuariosProcessor(IAsyncStringResponseHandler handler, String data) {
                  super(handler, data);
                }

                @Override
                protected Void doInBackground(Object... params) {
                  super.doInBackground();
                  SQLiteOpenHelper helper = EduscoreOpenHelper.getInstance(mActivity.getMContext());
                  SQLiteDatabase dataBase = helper.getWritableDatabase();
                  try {
                    String sql =
                        "INSERT INTO "
                            + EduscoreOpenHelper.TABLE_SIS_USER
                            + " (idUser, user, password, idPerson) VALUES "
                            + data;
                    String sqlDelete =
                        "DELETE FROM "
                            + EduscoreOpenHelper.TABLE_SIS_USER
                            + " WHERE password = '******'";
                    dataBase.beginTransaction();
                    dataBase.execSQL(sql);
                    dataBase.execSQL(sqlDelete);
                    dataBase.setTransactionSuccessful();
                    dataBase.endTransaction();
                  } catch (Exception e) {
                    Log.e("Data Backup", "Error al Respaldar USUARIOS");
                  } finally {
                    dataBase.close();
                  }
                  return null;
                }
              }

              @Override
              public void continueProcessing() {
                int t = index;
                if ((index + 300) < count) {
                  t += 300;
                  backupUsuarios(t);
                } else {
                  // NEXT BACKUP;
                  countElements(RPCHandlerString.OPERATION_COUNT_CAREERS);
                  backupCareers(maxElementCareers(EduscoreOpenHelper.TABLE_ESC_CAREER));
                }
              }

              @Override
              public void onResponse(String stringResponse) throws Exception {
                (new UsuariosProcessor(this, stringResponse)).execute();
              }

              @Override
              public void onRequest() {
                // TODO: ProgressBar
                getDialog().setMessage(index + " / " + count);
              }

              @Override
              public void onException(Exception e) {
                cancelBackup();
              }
            });
    datadownlooader.execute(
        RPCHandler.OPERATION_GET_ALL_USERS, new BasicNameValuePair("index", index + ""));
  }
Example #5
0
  private void backupPersonDescription(final int index) {
    getDialog().setTitle("Paso 13/13");
    datadownlooader =
        new RPCHandlerString(
            new IAsyncStringResponseHandler() {

              final class PersonDescriptionProcessor extends AsyncResponseProcessor {

                public PersonDescriptionProcessor(
                    IAsyncStringResponseHandler handler, String data) {
                  super(handler, data);
                }

                @Override
                protected Void doInBackground(Object... params) {
                  super.doInBackground();
                  SQLiteOpenHelper helper = EduscoreOpenHelper.getInstance(mActivity.getMContext());
                  SQLiteDatabase dataBase = helper.getWritableDatabase();
                  try {
                    String sql =
                        "INSERT INTO "
                            + EduscoreOpenHelper.TABLE_DAT_PERSONDESCRIPTION
                            + " (idPerson, name, lastName, idCountry, idRegion, idCity, gender, curp, "
                            + "rfc, street, numberExt, numberInt, zip) VALUES "
                            + data;
                    String sqlDelete =
                        "DELETE FROM "
                            + EduscoreOpenHelper.TABLE_DAT_PERSONDESCRIPTION
                            + " WHERE name = '0'";
                    dataBase.beginTransaction();
                    dataBase.execSQL(sql);
                    dataBase.execSQL(sqlDelete);
                    dataBase.setTransactionSuccessful();
                    dataBase.endTransaction();
                  } catch (Exception e) {
                    Log.e("Data Backup", "Error al Respaldar DES PERSONAS");
                  } finally {
                    dataBase.close();
                  }
                  return null;
                }
              }

              @Override
              public void continueProcessing() {
                int t = index;
                if ((index + 150) < count) {
                  t += 150;
                  backupPersonDescription(t);
                } else {
                  // NEXT BACKUP;
                  removeDialog();
                  Intent intent = new Intent(mActivity.getMContext(), MainActivity.class);
                  mActivity.finish();
                  mActivity.startActivity(intent);
                }
              }

              @Override
              public void onResponse(String stringResponse) throws Exception {
                (new PersonDescriptionProcessor(this, stringResponse)).execute();
              }

              @Override
              public void onRequest() {
                // TODO:getDialog().setMessage("Respaldando Personas " + index + " / " + count);
                getDialog().setMessage(index + " / " + count);
              }

              @Override
              public void onException(Exception e) {
                cancelBackup();
              }
            });
    datadownlooader.execute(
        RPCHandler.OPERATION_GET_ALL_PERSONDESCRIPTIONS,
        new BasicNameValuePair("index", index + ""));
  }