UpdateNoteForShareOperation.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2018 Tobias Kaminsky
  6. * Copyright (C) 2018 Nextcloud GmbH.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.operations;
  22. import com.owncloud.android.lib.common.OwnCloudClient;
  23. import com.owncloud.android.lib.common.operations.RemoteOperation;
  24. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  25. import com.owncloud.android.lib.resources.shares.GetRemoteShareOperation;
  26. import com.owncloud.android.lib.resources.shares.OCShare;
  27. import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
  28. import com.owncloud.android.operations.common.SyncOperation;
  29. /**
  30. * Updates a note of a private share.
  31. */
  32. public class UpdateNoteForShareOperation extends SyncOperation {
  33. private long shareId;
  34. private String note;
  35. public UpdateNoteForShareOperation(long shareId, String note) {
  36. this.shareId = shareId;
  37. this.note = note;
  38. }
  39. @Override
  40. protected RemoteOperationResult run(OwnCloudClient client) {
  41. OCShare share = getStorageManager().getShareById(shareId);
  42. if (share == null) {
  43. return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
  44. }
  45. UpdateRemoteShareOperation updateOperation = new UpdateRemoteShareOperation(share.getRemoteId());
  46. updateOperation.setNote(note);
  47. RemoteOperationResult result = updateOperation.execute(client);
  48. if (result.isSuccess()) {
  49. RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId());
  50. result = getShareOp.execute(client);
  51. if (result.isSuccess()) {
  52. getStorageManager().saveShare((OCShare) result.getData().get(0));
  53. }
  54. }
  55. return result;
  56. }
  57. }