Loading src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ public class CreateRemoteShareOperation extends RemoteOperation { // retrieve more info - POST only returns the index of the new share OCShare emptyShare = (OCShare) result.getData().get(0); GetRemoteShareOperation getInfo = new GetRemoteShareOperation( emptyShare.getIdRemoteShared() emptyShare.getRemoteId() ); result = getInfo.execute(client); } Loading src/com/owncloud/android/lib/resources/shares/OCShare.java +12 −8 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class OCShare implements Parcelable, Serializable { private String mSharedWithDisplayName; private boolean mIsFolder; private long mUserId; private long mIdRemoteShared; private long mRemoteId; private String mShareLink; public OCShare() { Loading Loading @@ -95,7 +95,7 @@ public class OCShare implements Parcelable, Serializable { mSharedWithDisplayName = ""; mIsFolder = false; mUserId = -1; mIdRemoteShared = -1; mRemoteId = -1; mShareLink = ""; } Loading Loading @@ -205,12 +205,12 @@ public class OCShare implements Parcelable, Serializable { this.mUserId = userId; } public long getIdRemoteShared() { return mIdRemoteShared; public long getRemoteId() { return mRemoteId; } public void setIdRemoteShared(long idRemoteShared) { this.mIdRemoteShared = idRemoteShared; public void setIdRemoteShared(long remoteId) { this.mRemoteId = remoteId; } public String getShareLink() { Loading @@ -221,6 +221,10 @@ public class OCShare implements Parcelable, Serializable { this.mShareLink = (shareLink != null) ? shareLink : ""; } public boolean isPasswordProtected() { return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0; } /** * Parcelable Methods */ Loading Loading @@ -264,7 +268,7 @@ public class OCShare implements Parcelable, Serializable { mSharedWithDisplayName = source.readString(); mIsFolder = source.readInt() == 0; mUserId = source.readLong(); mIdRemoteShared = source.readLong(); mRemoteId = source.readLong(); mShareLink = source.readString(); } Loading @@ -290,7 +294,7 @@ public class OCShare implements Parcelable, Serializable { dest.writeString(mSharedWithDisplayName); dest.writeInt(mIsFolder ? 1 : 0); dest.writeLong(mUserId); dest.writeLong(mIdRemoteShared); dest.writeLong(mRemoteId); dest.writeString(mShareLink); } Loading src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java +2 −2 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ public class ShareXMLParser { private static final String TYPE_FOLDER = "folder"; private static final int SUCCESS = 100; private static final int ERROR_WRONG_PARAMETER = 403; private static final int ERROR_WRONG_PARAMETER = 400; private static final int ERROR_FORBIDDEN = 403; private static final int ERROR_NOT_FOUND = 404; Loading Loading @@ -368,7 +368,7 @@ public class ShareXMLParser { } private boolean isValidShare(OCShare share) { return (share.getIdRemoteShared() > -1); return (share.getRemoteId() > -1); } private void fixPathForFolder(OCShare share) { Loading src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java 0 → 100644 +153 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * @author David A. Velasco * Copyright (C) 2015 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.shares; import android.net.Uri; import android.util.Pair; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.http.HttpStatus; import java.util.ArrayList; import java.util.List; /** * Updates parameters of an existing Share resource, known its remote ID. * * Allow updating several parameters, triggering a request to the server per parameter. */ public class UpdateRemoteShareOperation extends RemoteOperation { private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); private long mRemoteId; private String mPassword; public UpdateRemoteShareOperation(long remoteId) { mRemoteId = remoteId; mPassword = null; } @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; /// prepare array of parameters to update List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>(); if (mPassword != null) { parametersToUpdate.add(new Pair<String, String>("password", mPassword)); } /* TODO complete rest of parameters if (mPermissions > 0) { parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions))); } if (mPublicUpload != null) { parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); } if (mExpireDate != null) { parametersToUpdate.add(new Pair("expireData", mExpireData.toString())); } */ /// perform required PUT requests PutMethod put = null; try{ Uri requestUri = client.getBaseUri(); Uri.Builder uriBuilder = requestUri.buildUpon(); uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1)); uriBuilder.appendEncodedPath(Long.toString(mRemoteId)); for (Pair<String, String> parameter : parametersToUpdate) { if (put != null) { put.releaseConnection(); } // TODO check if uriBuilder may be reused String uriString = uriBuilder.build().toString(); put = new PutMethod(uriString); put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); put.setRequestEntity(new StringRequestEntity( parameter.first + "=" + parameter.second, "application/x-www-form-urlencoded", "UTF-8" )); status = client.executeMethod(put); if (status == HttpStatus.SC_OK) { String response = put.getResponseBodyAsString(); // Parse xml response ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( new ShareXMLParser() ); parser.setOwnCloudVersion(client.getOwnCloudVersion()); parser.setServerBaseUri(client.getBaseUri()); result = parser.parse(response); } else { result = new RemoteOperationResult(false, status, put.getResponseHeaders()); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while updating remote share ", e); if (put != null) { put.releaseConnection(); } } finally { if (put != null) { put.releaseConnection(); } } return result; } /** * Set password to update in Share resource. * * @param password Password to set to the target share. The empty string clears the password. * Null results in no update applied to the password. */ public void setPassword(String password) { mPassword = password; } } test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class RemoveShareTest extends RemoteTest { Utils.logAndThrow(LOG_TAG, result); } else { OCShare created = (OCShare) result.getData().get(0); mShareId = created.getIdRemoteShared(); mShareId = created.getRemoteId(); } } Loading Loading
src/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.java +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ public class CreateRemoteShareOperation extends RemoteOperation { // retrieve more info - POST only returns the index of the new share OCShare emptyShare = (OCShare) result.getData().get(0); GetRemoteShareOperation getInfo = new GetRemoteShareOperation( emptyShare.getIdRemoteShared() emptyShare.getRemoteId() ); result = getInfo.execute(client); } Loading
src/com/owncloud/android/lib/resources/shares/OCShare.java +12 −8 Original line number Diff line number Diff line Loading @@ -61,7 +61,7 @@ public class OCShare implements Parcelable, Serializable { private String mSharedWithDisplayName; private boolean mIsFolder; private long mUserId; private long mIdRemoteShared; private long mRemoteId; private String mShareLink; public OCShare() { Loading Loading @@ -95,7 +95,7 @@ public class OCShare implements Parcelable, Serializable { mSharedWithDisplayName = ""; mIsFolder = false; mUserId = -1; mIdRemoteShared = -1; mRemoteId = -1; mShareLink = ""; } Loading Loading @@ -205,12 +205,12 @@ public class OCShare implements Parcelable, Serializable { this.mUserId = userId; } public long getIdRemoteShared() { return mIdRemoteShared; public long getRemoteId() { return mRemoteId; } public void setIdRemoteShared(long idRemoteShared) { this.mIdRemoteShared = idRemoteShared; public void setIdRemoteShared(long remoteId) { this.mRemoteId = remoteId; } public String getShareLink() { Loading @@ -221,6 +221,10 @@ public class OCShare implements Parcelable, Serializable { this.mShareLink = (shareLink != null) ? shareLink : ""; } public boolean isPasswordProtected() { return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0; } /** * Parcelable Methods */ Loading Loading @@ -264,7 +268,7 @@ public class OCShare implements Parcelable, Serializable { mSharedWithDisplayName = source.readString(); mIsFolder = source.readInt() == 0; mUserId = source.readLong(); mIdRemoteShared = source.readLong(); mRemoteId = source.readLong(); mShareLink = source.readString(); } Loading @@ -290,7 +294,7 @@ public class OCShare implements Parcelable, Serializable { dest.writeString(mSharedWithDisplayName); dest.writeInt(mIsFolder ? 1 : 0); dest.writeLong(mUserId); dest.writeLong(mIdRemoteShared); dest.writeLong(mRemoteId); dest.writeString(mShareLink); } Loading
src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java +2 −2 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ public class ShareXMLParser { private static final String TYPE_FOLDER = "folder"; private static final int SUCCESS = 100; private static final int ERROR_WRONG_PARAMETER = 403; private static final int ERROR_WRONG_PARAMETER = 400; private static final int ERROR_FORBIDDEN = 403; private static final int ERROR_NOT_FOUND = 404; Loading Loading @@ -368,7 +368,7 @@ public class ShareXMLParser { } private boolean isValidShare(OCShare share) { return (share.getIdRemoteShared() > -1); return (share.getRemoteId() > -1); } private void fixPathForFolder(OCShare share) { Loading
src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java 0 → 100644 +153 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * @author David A. Velasco * Copyright (C) 2015 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.shares; import android.net.Uri; import android.util.Pair; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.http.HttpStatus; import java.util.ArrayList; import java.util.List; /** * Updates parameters of an existing Share resource, known its remote ID. * * Allow updating several parameters, triggering a request to the server per parameter. */ public class UpdateRemoteShareOperation extends RemoteOperation { private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); private long mRemoteId; private String mPassword; public UpdateRemoteShareOperation(long remoteId) { mRemoteId = remoteId; mPassword = null; } @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; /// prepare array of parameters to update List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>(); if (mPassword != null) { parametersToUpdate.add(new Pair<String, String>("password", mPassword)); } /* TODO complete rest of parameters if (mPermissions > 0) { parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions))); } if (mPublicUpload != null) { parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); } if (mExpireDate != null) { parametersToUpdate.add(new Pair("expireData", mExpireData.toString())); } */ /// perform required PUT requests PutMethod put = null; try{ Uri requestUri = client.getBaseUri(); Uri.Builder uriBuilder = requestUri.buildUpon(); uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1)); uriBuilder.appendEncodedPath(Long.toString(mRemoteId)); for (Pair<String, String> parameter : parametersToUpdate) { if (put != null) { put.releaseConnection(); } // TODO check if uriBuilder may be reused String uriString = uriBuilder.build().toString(); put = new PutMethod(uriString); put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); put.setRequestEntity(new StringRequestEntity( parameter.first + "=" + parameter.second, "application/x-www-form-urlencoded", "UTF-8" )); status = client.executeMethod(put); if (status == HttpStatus.SC_OK) { String response = put.getResponseBodyAsString(); // Parse xml response ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( new ShareXMLParser() ); parser.setOwnCloudVersion(client.getOwnCloudVersion()); parser.setServerBaseUri(client.getBaseUri()); result = parser.parse(response); } else { result = new RemoteOperationResult(false, status, put.getResponseHeaders()); } } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while updating remote share ", e); if (put != null) { put.releaseConnection(); } } finally { if (put != null) { put.releaseConnection(); } } return result; } /** * Set password to update in Share resource. * * @param password Password to set to the target share. The empty string clears the password. * Null results in no update applied to the password. */ public void setPassword(String password) { mPassword = password; } }
test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class RemoveShareTest extends RemoteTest { Utils.logAndThrow(LOG_TAG, result); } else { OCShare created = (OCShare) result.getData().get(0); mShareId = created.getIdRemoteShared(); mShareId = created.getRemoteId(); } } Loading