CheckCurrentCredentialsOperation.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package com.owncloud.android.operations;
  21. import android.accounts.Account;
  22. import com.nextcloud.client.account.User;
  23. import com.owncloud.android.datamodel.OCFile;
  24. import com.owncloud.android.lib.common.OwnCloudClient;
  25. import com.owncloud.android.lib.common.operations.RemoteOperation;
  26. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  27. import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
  28. import com.owncloud.android.operations.common.SyncOperation;
  29. import java.util.ArrayList;
  30. /**
  31. * Checks validity of currently stored credentials for a given OC account
  32. */
  33. public class CheckCurrentCredentialsOperation extends SyncOperation {
  34. private final User user;
  35. public CheckCurrentCredentialsOperation(User user) {
  36. this.user = user;
  37. }
  38. @Override
  39. protected RemoteOperationResult run(OwnCloudClient client) {
  40. RemoteOperationResult result = null;
  41. boolean validAccount = user.nameEquals(getStorageManager().getAccount().name);
  42. if (!validAccount) {
  43. result = new RemoteOperationResult(new IllegalStateException(
  44. "Account to validate is not the account connected to!")
  45. );
  46. } else {
  47. RemoteOperation check = new ExistenceCheckRemoteOperation(OCFile.ROOT_PATH, false);
  48. result = check.execute(client);
  49. ArrayList<Object> data = new ArrayList<>();
  50. data.add(user.toPlatformAccount());
  51. result.setData(data);
  52. }
  53. return result;
  54. }
  55. }