Merge tag 'oc-android-1.9' into sdcard-save
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / UpdateShareViaLinkOperation.java
index 64c25df..14b60e8 100644 (file)
@@ -31,6 +31,8 @@ import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 
+import java.util.Calendar;
+
 
 /**
  * Updates an existing public share for a given file
@@ -40,21 +42,46 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
 
     private String mPath;
     private String mPassword;
+    private long mExpirationDateInMillis;
 
     /**
      * Constructor
+     *
      * @param path          Full path of the file/folder being shared. Mandatory argument
-     * @param password      Password to protect a public link share.
      */
-    public UpdateShareViaLinkOperation(
-            String path,
-            String password
-    ) {
+    public UpdateShareViaLinkOperation(String path) {
 
         mPath = path;
+        mPassword = null;
+        mExpirationDateInMillis = 0;
+    }
+
+
+    /**
+     * Set password to update in public link.
+     *
+     * @param password      Password to set to the public link.
+     *                      Empty string clears the current password.
+     *                      Null results in no update applied to the password.
+     */
+    public void setPassword(String password) {
         mPassword = password;
     }
 
+
+    /**
+     * Set expiration date to update in Share resource.
+     *
+     * @param expirationDateInMillis    Expiration date to set to the public link.
+     *                                  A negative value clears the current expiration date.
+     *                                  Zero value (start-of-epoch) results in no update done on
+     *                                  the expiration date.
+     */
+    public void setExpirationDate(long expirationDateInMillis) {
+        mExpirationDateInMillis = expirationDateInMillis;
+    }
+
+
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
 
@@ -65,35 +92,24 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
         );
 
         if (publicShare == null) {
-            // TODO try to get remote?
-
+            // TODO try to get remote share before failing?
+            return new RemoteOperationResult(
+                    RemoteOperationResult.ResultCode.SHARE_NOT_FOUND
+            );
         }
 
         // Update remote share with password
-        RemoteOperation operation = new UpdateRemoteShareOperation(
+        UpdateRemoteShareOperation udpateOp = new UpdateRemoteShareOperation(
             publicShare.getRemoteId()
         );
-        ((UpdateRemoteShareOperation)operation).setPassword(mPassword);
-        RemoteOperationResult result = operation.execute(client);
-
-        /*
-        if (!result.isSuccess() || result.getData().size() <= 0) {
-            operation = new CreateRemoteShareOperation(
-                    mPath,
-                    ShareType.PUBLIC_LINK,
-                    "",
-                    false,
-                    mPassword,
-                    OCShare.DEFAULT_PERMISSION
-            );
-            result = operation.execute(client);
-        }
-        */
+        udpateOp.setPassword(mPassword);
+        udpateOp.setExpirationDate(mExpirationDateInMillis);
+        RemoteOperationResult result = udpateOp.execute(client);
 
         if (result.isSuccess()) {
             // Retrieve updated share / save directly with password? -> no; the password is not be saved
-            operation = new GetRemoteShareOperation(publicShare.getRemoteId());
-            result = operation.execute(client);
+            RemoteOperation getShareOp = new GetRemoteShareOperation(publicShare.getRemoteId());
+            result = getShareOp.execute(client);
             if (result.isSuccess()) {
                 OCShare share = (OCShare) result.getData().get(0);
                 updateData(share);