1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Merge branch 'develop' into wide_scope_clean_up

This commit is contained in:
David A. Velasco 2014-02-17 12:48:05 +01:00
commit 7fe393b28e
8 changed files with 310 additions and 7 deletions

View File

@ -4,21 +4,21 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.owncloud.android</groupId>
<artifactId>oc_framework</artifactId>
<artifactId>owncloud-android-library</artifactId>
<version>${owncloud.version}</version>
<packaging>jar</packaging>
<name>oc_framework for Owncloud Android</name>
<name>owncloud-android-library for Owncloud Android</name>
<properties>
<owncloud.version>1.5.1-SNAPSHOT</owncloud.version>
<java-version>1.6</java-version>
<!-- Given by maven-android-sdk-deployer -->
<google.android-version>4.4_r1</google.android-version>
<google.android-version>4.4.2_r2</google.android-version>
<!-- Usually the latest Android API -->
<google.android-api>19</google.android-api>
</properties>
<description>oc_framwork for Owncloud for Android</description>
<description>owncloud-android-library for Owncloud for Android</description>
<dependencies>

View File

@ -97,7 +97,8 @@ public class RemoteOperationResult implements Serializable {
ACCOUNT_EXCEPTION,
ACCOUNT_NOT_NEW,
ACCOUNT_NOT_THE_SAME,
INVALID_CHARACTER_IN_NAME
INVALID_CHARACTER_IN_NAME,
SHARE_NOT_FOUND
}
private boolean mSuccess = false;

View File

@ -0,0 +1,118 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* 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.operations.remote;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
import android.util.Log;
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.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.ShareUtils;
import com.owncloud.android.lib.resources.shares.ShareXMLParser;
/**
* Remove a share
*
* @author masensio
*
*/
public class RemoveRemoteShareOperation extends RemoteOperation {
private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName();
private int mIdShare;
/**
* Constructor
*
* @param idShare Share ID
*/
public RemoveRemoteShareOperation(int idShare) {
mIdShare = idShare;
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status = -1;
DeleteMethod delete = null;
try {
String id = "/" + String.valueOf(mIdShare);
delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE + id);
Log.d(TAG, "URL ------> " + client.getBaseUri() + ShareUtils.SHAREAPI_ROUTE + id);
status = client.executeMethod(delete);
if(isSuccess(status)) {
String response = delete.getResponseBodyAsString();
Log.d(TAG, "Successful response: " + response);
result = new RemoteOperationResult(ResultCode.OK);
// Parse xml response
// convert String into InputStream
InputStream is = new ByteArrayInputStream(response.getBytes());
ShareXMLParser xmlParser = new ShareXMLParser();
xmlParser.parseXMLResponse(is);
if (xmlParser.isSuccess()) {
result = new RemoteOperationResult(ResultCode.OK);
} else if (xmlParser.isFileNotFound()){
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
} else {
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
}
Log.i(TAG, "Unshare " + id + ": " + result.getLogMessage());
} else {
result = new RemoteOperationResult(false, status, delete.getResponseHeaders());
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e);
} finally {
if (delete != null)
delete.releaseConnection();
}
return result;
}
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}
}

View File

@ -139,7 +139,7 @@ public class CreateRemoteShareOperation extends RemoteOperation {
result.setData(sharesObjects);
}
} else if (xmlParser.isFileNotFound()){
result = new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
} else {
result = new RemoteOperationResult(false, status, post.getResponseHeaders());

View File

@ -37,7 +37,10 @@ import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.R;
import android.net.Uri;
@ -190,6 +193,11 @@ public class TestActivity extends Activity {
return result;
}
/** Access to the library method to Get Shares
*
* @return
*/
public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
@ -197,4 +205,47 @@ public class TestActivity extends Activity {
return result;
}
/** Access to the library method to Create Share
* @param path Full path of the file/folder being shared. Mandatory argument
* @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument
* @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1
* @param publicUpload If false (default) public cannot upload to a public shared folder.
* If true public can upload to a shared folder. Only available for public link shares
* @param password Password to protect a public link share. Only available for public link shares
* @param permissions 1 - Read only Default for public shares
* 2 - Update
* 4 - Create
* 8 - Delete
* 16- Re-share
* 31- All above Default for private shares
* For user or group shares.
* To obtain combinations, add the desired values together.
* For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
*
* @return
*/
public RemoteOperationResult createShare(String path, ShareType shareType, String shareWith, boolean publicUpload,
String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Remove Share
*
* @param idShare Share ID
*/
public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;
}
}

View File

@ -0,0 +1,59 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* 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.test_project.test;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
/* File to share.*/
private final String mFileToShare = "/fileToShare.png";
private TestActivity mActivity;
public CreateShareTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Create Share: the server must support SHARE API
*/
public void testCreateShare() {
RemoteOperationResult result = mActivity.createShare(mFileToShare, ShareType.PUBLIC_LINK, "", false, "", 1);
assertTrue(result.isSuccess());
}
}

View File

@ -24,7 +24,7 @@
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;

View File

@ -0,0 +1,74 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
*
* 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.test_project.test;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
private static final String TAG = RemoveShareTest.class.getSimpleName();
private TestActivity mActivity;
public RemoveShareTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
}
/**
* Test Remove Share: the server must support SHARE API
*/
public void testRemoveShare() {
// Get the shares
RemoteOperationResult result = mActivity.getShares();
if (result.isSuccess()) {
int size = result.getData().size();
if (size > 0) {
OCShare share = ((OCShare) result.getData().get(size -1));
long id = share.getIdRemoteShared();
Log.d(TAG, "File to unshare: " + share.getPath() );
result = mActivity.removeShare((int) id); // Unshare
assertTrue(result.isSuccess());
} else {
assertTrue(true);
}
} else {
assertTrue(true);
}
}
}