UpdateShareViaLinkOperation.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.datamodel.FileDataStorageManager;
  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.GetShareRemoteOperation;
  26. import com.owncloud.android.lib.resources.shares.OCShare;
  27. import com.owncloud.android.lib.resources.shares.UpdateShareRemoteOperation;
  28. import com.owncloud.android.operations.common.SyncOperation;
  29. /**
  30. * Updates an existing public share for a given file
  31. */
  32. public class UpdateShareViaLinkOperation extends SyncOperation {
  33. private String password;
  34. private Boolean hideFileDownload;
  35. private long expirationDateInMillis;
  36. private final long shareId;
  37. private String label;
  38. public UpdateShareViaLinkOperation(long shareId, FileDataStorageManager storageManager) {
  39. super(storageManager);
  40. expirationDateInMillis = 0;
  41. this.shareId = shareId;
  42. }
  43. @Override
  44. protected RemoteOperationResult run(OwnCloudClient client) {
  45. OCShare publicShare = getStorageManager().getShareById(shareId);
  46. UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(publicShare.getRemoteId());
  47. updateOp.setPassword(password);
  48. updateOp.setExpirationDate(expirationDateInMillis);
  49. updateOp.setHideFileDownload(hideFileDownload);
  50. updateOp.setLabel(label);
  51. RemoteOperationResult result = updateOp.execute(client);
  52. if (result.isSuccess()) {
  53. // Retrieve updated share / save directly with password? -> no; the password is not to be saved
  54. RemoteOperation getShareOp = new GetShareRemoteOperation(publicShare.getRemoteId());
  55. result = getShareOp.execute(client);
  56. if (result.isSuccess()) {
  57. OCShare share = (OCShare) result.getData().get(0);
  58. getStorageManager().saveShare(share);
  59. }
  60. }
  61. return result;
  62. }
  63. public String getPassword() {
  64. return this.password;
  65. }
  66. public void setPassword(String password) {
  67. this.password = password;
  68. }
  69. public void setHideFileDownload(Boolean hideFileDownload) {
  70. this.hideFileDownload = hideFileDownload;
  71. }
  72. public void setExpirationDateInMillis(long expirationDateInMillis) {
  73. this.expirationDateInMillis = expirationDateInMillis;
  74. }
  75. public void setLabel(String label) {
  76. this.label = label;
  77. }
  78. }