UpdateShareViaLinkOperation.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2015 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 com.owncloud.android.lib.common.OwnCloudClient;
  22. import com.owncloud.android.lib.common.operations.RemoteOperation;
  23. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  24. import com.owncloud.android.lib.resources.shares.GetShareRemoteOperation;
  25. import com.owncloud.android.lib.resources.shares.OCShare;
  26. import com.owncloud.android.lib.resources.shares.UpdateShareRemoteOperation;
  27. import com.owncloud.android.operations.common.SyncOperation;
  28. /**
  29. * Updates an existing public share for a given file
  30. */
  31. public class UpdateShareViaLinkOperation extends SyncOperation {
  32. private String password;
  33. /**
  34. * Enable upload permissions to update in Share resource.
  35. */
  36. private boolean publicUpload;
  37. private Boolean hideFileDownload;
  38. private long expirationDateInMillis;
  39. private long shareId;
  40. private String label;
  41. public UpdateShareViaLinkOperation(long shareId) {
  42. expirationDateInMillis = 0;
  43. this.shareId = shareId;
  44. }
  45. @Override
  46. protected RemoteOperationResult run(OwnCloudClient client) {
  47. OCShare publicShare = getStorageManager().getShareById(shareId);
  48. UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(publicShare.getRemoteId());
  49. updateOp.setPassword(password);
  50. updateOp.setExpirationDate(expirationDateInMillis);
  51. updateOp.setHideFileDownload(hideFileDownload);
  52. updateOp.setLabel(label);
  53. RemoteOperationResult result = updateOp.execute(client);
  54. if (result.isSuccess()) {
  55. // Retrieve updated share / save directly with password? -> no; the password is not to be saved
  56. RemoteOperation getShareOp = new GetShareRemoteOperation(publicShare.getRemoteId());
  57. result = getShareOp.execute(client);
  58. if (result.isSuccess()) {
  59. OCShare share = (OCShare) result.getData().get(0);
  60. getStorageManager().saveShare(share);
  61. }
  62. }
  63. return result;
  64. }
  65. public String getPassword() {
  66. return this.password;
  67. }
  68. public void setPassword(String password) {
  69. this.password = password;
  70. }
  71. public void setPublicUpload(boolean publicUpload) {
  72. this.publicUpload = publicUpload;
  73. }
  74. public void setHideFileDownload(Boolean hideFileDownload) {
  75. this.hideFileDownload = hideFileDownload;
  76. }
  77. public void setExpirationDateInMillis(long expirationDateInMillis) {
  78. this.expirationDateInMillis = expirationDateInMillis;
  79. }
  80. public void setLabel(String label) {
  81. this.label = label;
  82. }
  83. }