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

Read capabilities to show the Share Options

This commit is contained in:
masensio 2015-10-30 11:05:03 +01:00
parent 7bd4dc96db
commit 75581c18a4
9 changed files with 808 additions and 6 deletions

View File

@ -24,8 +24,6 @@
package com.owncloud.android.lib.common.operations;
import java.io.IOException;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountsException;
@ -42,6 +40,8 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import java.io.IOException;
/**
* Operation which execution involves one or several interactions with an ownCloud server.

View File

@ -33,7 +33,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
/**
* Get the data about a Share resource, known its remote ID.
*/

View File

@ -35,7 +35,6 @@ 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;
/**
* Provide a list shares for a specific file.
* The input is the full path of the desired file.

View File

@ -34,7 +34,6 @@ 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;
/**
* Get the data from the server about ALL the known shares owned by the requester.
*
@ -72,7 +71,6 @@ public class GetRemoteSharesOperation extends RemoteOperation {
parser.setOwnCloudVersion(client.getOwnCloudVersion());
parser.setServerBaseUri(client.getBaseUri());
result = parser.parse(response);
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
}

View File

@ -0,0 +1,83 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2015 ownCloud Inc.
* @author masensio
*
* 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.status;
/**
* Enum for Boolean Type in OCCapability parameters, with values:
* -1 - Unknown
* 0 - False
* 1 - True
*/
public enum CapabilityBooleanType {
UNKNOWN (-1),
FALSE (0),
TRUE (1);
private int value;
CapabilityBooleanType(int value)
{
this.value = value;
}
public int getValue() {
return value;
}
public static CapabilityBooleanType fromValue(int value)
{
switch (value)
{
case -1:
return UNKNOWN;
case 0:
return FALSE;
case 1:
return TRUE;
}
return null;
}
public static CapabilityBooleanType fromBooleanValue(boolean boolValue){
if (boolValue){
return TRUE;
} else {
return FALSE;
}
}
public boolean isUnknown(){
return getValue() == -1;
}
public boolean isFalse(){
return getValue() == 0;
}
public boolean isTrue(){
return getValue() == 1;
}
};

View File

@ -0,0 +1,281 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* 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.status;
import android.net.Uri;
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.GetMethod;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import java.util.ArrayList;
/**
* Get the Capabilities from the server
*
* Save in Result.getData in a OCCapability object
*/
public class GetRemoteCapabilitiesOperation extends RemoteOperation {
private static final String TAG = GetRemoteCapabilitiesOperation.class.getSimpleName();
// OCS Routes
private static final String OCS_ROUTE = "ocs/v1.php/cloud/capabilities";
// Arguments - names
private static final String PARAM_FORMAT = "format";
// Arguments - constant values
private static final String VALUE_FORMAT = "json";
// JSON Node names
private static final String NODE_OCS = "ocs";
private static final String NODE_META = "meta";
private static final String NODE_DATA = "data";
private static final String NODE_VERSION = "version";
private static final String NODE_CAPABILITIES = "capabilities";
private static final String NODE_CORE = "core";
private static final String NODE_FILES_SHARING = "files_sharing";
private static final String NODE_PUBLIC = "public";
private static final String NODE_PASSWORD = "password";
private static final String NODE_EXPIRE_DATE = "expire_date";
private static final String NODE_USER = "user";
private static final String NODE_FEDERATION = "federation";
private static final String NODE_FILES = "files";
private static final String PROPERTY_STATUS = "status";
private static final String PROPERTY_STATUSCODE = "statuscode";
private static final String PROPERTY_MESSAGE = "message";
private static final String PROPERTY_POLLINTERVAL = "pollinterval";
private static final String PROPERTY_MAJOR = "major";
private static final String PROPERTY_MINOR = "minor";
private static final String PROPERTY_MICRO = "micro";
private static final String PROPERTY_STRING = "string";
private static final String PROPERTY_EDITION = "edition";
private static final String PROPERTY_API_ENABLED = "api_enabled";
private static final String PROPERTY_ENABLED = "enabled";
private static final String PROPERTY_ENFORCED = "enforced";
private static final String PROPERTY_DAYS = "days";
private static final String PROPERTY_SEND_MAIL = "send_mail";
private static final String PROPERTY_UPLOAD = "upload";
private static final String PROPERTY_RESHARING = "resharing";
private static final String PROPERTY_OUTGOING = "outgoing";
private static final String PROPERTY_INCOMING = "incoming";
private static final String PROPERTY_BIGFILECHUNKING = "bigfilechunking";
private static final String PROPERTY_UNDELETE = "undelete";
private static final String PROPERTY_VERSIONING = "versioning";
/**
* Constructor
*
*/
public GetRemoteCapabilitiesOperation() {
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status;
GetMethod get = null;
try {
Uri requestUri = client.getBaseUri();
Uri.Builder uriBuilder = requestUri.buildUpon();
uriBuilder.appendEncodedPath(OCS_ROUTE); // avoid starting "/" in this method
uriBuilder.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT);
// Get Method
get = new GetMethod(uriBuilder.build().toString());
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if(isSuccess(status)) {
String response = get.getResponseBodyAsString();
Log_OC.d(TAG, "Successful response: " + response);
// Parse the response
JSONObject respJSON = new JSONObject(response);
JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
JSONObject respMeta = respOCS.getJSONObject(NODE_META);
JSONObject respData = respOCS.getJSONObject(NODE_DATA);
// Read meta
boolean statusProp = respMeta.getString(PROPERTY_STATUS).equalsIgnoreCase("ok");
int statuscode = respMeta.getInt(PROPERTY_STATUSCODE);
String message = respMeta.getString(PROPERTY_MESSAGE);
if (statusProp) {
ArrayList<Object> data = new ArrayList<Object>(); // For result data
OCCapability capability = new OCCapability();
// Add Version
if (respData.has(NODE_VERSION)) {
JSONObject respVersion = respData.getJSONObject(NODE_VERSION);
capability.setVersionMayor(respVersion.getInt(PROPERTY_MAJOR));
capability.setVersionMinor(respVersion.getInt(PROPERTY_MINOR));
capability.setVersionMicro(respVersion.getInt(PROPERTY_MICRO));
capability.setVersionString(respVersion.getString(PROPERTY_STRING));
capability.setVersionEdition(respVersion.getString(PROPERTY_EDITION));
Log_OC.d(TAG, "*** Added " + NODE_VERSION);
}
// Capabilities Object
if (respData.has(NODE_CAPABILITIES)) {
JSONObject respCapabilities = respData.getJSONObject(NODE_CAPABILITIES);
// Add Core: pollinterval
if (respCapabilities.has(NODE_CORE)) {
JSONObject respCore = respCapabilities.getJSONObject(NODE_CORE);
capability.setCorePollinterval(respCore.getInt(PROPERTY_POLLINTERVAL));
Log_OC.d(TAG, "*** Added " + NODE_CORE);
}
// Add files_sharing: public, user, resharing
if (respCapabilities.has(NODE_FILES_SHARING)) {
JSONObject respFilesSharing = respCapabilities.getJSONObject(NODE_FILES_SHARING);
if (respFilesSharing.has(PROPERTY_API_ENABLED)) {
capability.setFilesSharingApiEnabled(CapabilityBooleanType.fromBooleanValue(
respFilesSharing.getBoolean(PROPERTY_API_ENABLED)));
}
if (respFilesSharing.has(NODE_PUBLIC)) {
JSONObject respPublic = respFilesSharing.getJSONObject(NODE_PUBLIC);
capability.setFilesSharingPublicEnabled(CapabilityBooleanType.fromBooleanValue(
respPublic.getBoolean(PROPERTY_ENABLED)));
if(respPublic.has(NODE_PASSWORD)) {
capability.setFilesSharingPublicPasswordEnforced(
CapabilityBooleanType.fromBooleanValue(
respPublic.getJSONObject(NODE_PASSWORD).getBoolean(PROPERTY_ENFORCED)));
}
if(respPublic.has(NODE_EXPIRE_DATE)){
JSONObject respExpireDate = respPublic.getJSONObject(NODE_EXPIRE_DATE);
capability.setFilesSharingPublicExpireDateEnabled(
CapabilityBooleanType.fromBooleanValue(
respExpireDate.getBoolean(PROPERTY_ENABLED)));
if (respExpireDate.has(PROPERTY_DAYS)) {
capability.setFilesSharingPublicExpireDateDays(
respExpireDate.getInt(PROPERTY_DAYS));
}
if (respExpireDate.has(PROPERTY_ENFORCED)) {
capability.setFilesSharingPublicExpireDateEnforced(
CapabilityBooleanType.fromBooleanValue(
respExpireDate.getBoolean(PROPERTY_ENFORCED)));
}
}
if (respPublic.has(PROPERTY_UPLOAD)){
capability.setFilesSharingPublicUpload(CapabilityBooleanType.fromBooleanValue(
respPublic.getBoolean(PROPERTY_UPLOAD)));
}
}
if (respFilesSharing.has(NODE_USER)) {
JSONObject respUser = respFilesSharing.getJSONObject(NODE_USER);
capability.setFilesSharingUserSendMail(CapabilityBooleanType.fromBooleanValue(
respUser.getBoolean(PROPERTY_SEND_MAIL)));
}
capability.setFilesSharingResharing(CapabilityBooleanType.fromBooleanValue(
respFilesSharing.getBoolean(PROPERTY_RESHARING)));
if (respFilesSharing.has(NODE_FEDERATION)) {
JSONObject respFederation = respFilesSharing.getJSONObject(NODE_FEDERATION);
capability.setFilesSharingFederationOutgoing(
CapabilityBooleanType.fromBooleanValue(respFederation.getBoolean(PROPERTY_OUTGOING)));
capability.setFilesSharingFederationIncoming(CapabilityBooleanType.fromBooleanValue(
respFederation.getBoolean(PROPERTY_INCOMING)));
}
Log_OC.d(TAG, "*** Added " + NODE_FILES_SHARING);
}
if (respCapabilities.has(NODE_FILES)) {
JSONObject respFiles = respCapabilities.getJSONObject(NODE_FILES);
// Add files
capability.setFilesBigFileChuncking(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_BIGFILECHUNKING)));
if (respFiles.has(PROPERTY_UNDELETE)) {
capability.setFilesUndelete(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_UNDELETE)));
}
capability.setFilesVersioning(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_VERSIONING)));
Log_OC.d(TAG, "*** Added " + NODE_FILES);
}
}
// Result
data.add(capability);
result = new RemoteOperationResult(true, status, get.getResponseHeaders());
result.setData(data);
Log_OC.d(TAG, "*** Get Capabilities completed ");
} else {
result = new RemoteOperationResult(statusProp, statuscode, null);
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message);
}
} else {
result = new RemoteOperationResult(false, status, get.getResponseHeaders());
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting capabilities from the server ");
if (response != null) {
Log_OC.e(TAG, "*** status code: " + status + "; response message: " + response);
} else {
Log_OC.e(TAG, "*** status code: " + status);
}
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Exception while getting capabilities", e);
} finally {
if (get != null) {
get.releaseConnection();
}
}
return result;
}
private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK);
}
}

View File

@ -0,0 +1,291 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* 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.status;
/**
* Contains data of the Capabilities for an account, from the Capabilities API
*/
public class OCCapability {
private static final String TAG = OCCapability.class.getSimpleName();
private long mId;
private String mAccountName;
// Server version
private int mVersionMayor;
private int mVersionMinor;
private int mVersionMicro;
private String mVersionString;
private String mVersionEdition;
// Core PollInterval
private int mCorePollinterval;
// Files Sharing
private CapabilityBooleanType mFilesSharingApiEnabled;
private CapabilityBooleanType mFilesSharingPublicEnabled;
private CapabilityBooleanType mFilesSharingPublicPasswordEnforced;
private CapabilityBooleanType mFilesSharingPublicExpireDateEnabled;
private int mFilesSharingPublicExpireDateDays;
private CapabilityBooleanType mFilesSharingPublicExpireDateEnforced;
private CapabilityBooleanType mFilesSharingPublicSendMail;
private CapabilityBooleanType mFilesSharingPublicUpload;
private CapabilityBooleanType mFilesSharingUserSendMail;
private CapabilityBooleanType mFilesSharingResharing;
private CapabilityBooleanType mFilesSharingFederationOutgoing;
private CapabilityBooleanType mFilesSharingFederationIncoming;
// Files
private CapabilityBooleanType mFilesBigFileChuncking;
private CapabilityBooleanType mFilesUndelete;
private CapabilityBooleanType mFilesVersioning;
public OCCapability(){
mId = 0;
mAccountName = "";
mVersionMayor = 0;
mVersionMinor = 0;
mVersionMicro = 0;
mVersionString = "";
mVersionString = "";
mCorePollinterval = 0;
mFilesSharingApiEnabled = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicExpireDateEnabled = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicExpireDateDays = 0;
mFilesSharingPublicExpireDateEnforced = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicSendMail = CapabilityBooleanType.UNKNOWN;
mFilesSharingPublicUpload = CapabilityBooleanType.UNKNOWN;
mFilesSharingUserSendMail = CapabilityBooleanType.UNKNOWN;
mFilesSharingResharing = CapabilityBooleanType.UNKNOWN;
mFilesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN;
mFilesSharingFederationIncoming = CapabilityBooleanType.UNKNOWN;
mFilesBigFileChuncking = CapabilityBooleanType.UNKNOWN;
mFilesUndelete = CapabilityBooleanType.UNKNOWN;
mFilesVersioning = CapabilityBooleanType.UNKNOWN;
}
// Getters and Setters
public String getAccountName() {
return mAccountName;
}
public void setAccountName(String accountName) {
this.mAccountName = accountName;
}
public long getId() {
return mId;
}
public void setId(long id) {
this.mId = id;
}
public int getVersionMayor() {
return mVersionMayor;
}
public void setVersionMayor(int versionMayor) {
this.mVersionMayor = versionMayor;
}
public int getVersionMinor() {
return mVersionMinor;
}
public void setVersionMinor(int versionMinor) {
this.mVersionMinor = versionMinor;
}
public int getVersionMicro() {
return mVersionMicro;
}
public void setVersionMicro(int versionMicro) {
this.mVersionMicro = versionMicro;
}
public String getVersionString() {
return mVersionString;
}
public void setVersionString(String versionString) {
this.mVersionString = versionString;
}
public String getVersionEdition() {
return mVersionEdition;
}
public void setVersionEdition(String versionEdition) {
this.mVersionEdition = versionEdition;
}
public int getCorePollinterval() {
return mCorePollinterval;
}
public void setCorePollinterval(int corePollinterval) {
this.mCorePollinterval = corePollinterval;
}
public CapabilityBooleanType getFilesSharingApiEnabled() {
return mFilesSharingApiEnabled;
}
public void setFilesSharingApiEnabled(CapabilityBooleanType filesSharingApiEnabled) {
this.mFilesSharingApiEnabled = filesSharingApiEnabled;
}
public CapabilityBooleanType getFilesSharingPublicEnabled() {
return mFilesSharingPublicEnabled;
}
public void setFilesSharingPublicEnabled(CapabilityBooleanType filesSharingPublicEnabled) {
this.mFilesSharingPublicEnabled = filesSharingPublicEnabled;
}
public CapabilityBooleanType getFilesSharingPublicPasswordEnforced() {
return mFilesSharingPublicPasswordEnforced;
}
public void setFilesSharingPublicPasswordEnforced(CapabilityBooleanType filesSharingPublicPasswordEnforced) {
this.mFilesSharingPublicPasswordEnforced = filesSharingPublicPasswordEnforced;
}
public CapabilityBooleanType getFilesSharingPublicExpireDateEnabled() {
return mFilesSharingPublicExpireDateEnabled;
}
public void setFilesSharingPublicExpireDateEnabled(CapabilityBooleanType filesSharingPublicExpireDateEnabled) {
this.mFilesSharingPublicExpireDateEnabled = filesSharingPublicExpireDateEnabled;
}
public int getFilesSharingPublicExpireDateDays() {
return mFilesSharingPublicExpireDateDays;
}
public void setFilesSharingPublicExpireDateDays(int filesSharingPublicExpireDateDays) {
this.mFilesSharingPublicExpireDateDays = filesSharingPublicExpireDateDays;
}
public CapabilityBooleanType getFilesSharingPublicExpireDateEnforced() {
return mFilesSharingPublicExpireDateEnforced;
}
public void setFilesSharingPublicExpireDateEnforced(CapabilityBooleanType filesSharingPublicExpireDateEnforced) {
this.mFilesSharingPublicExpireDateEnforced = filesSharingPublicExpireDateEnforced;
}
public CapabilityBooleanType getFilesSharingPublicSendMail() {
return mFilesSharingPublicSendMail;
}
public void setFilesSharingPublicSendMail(CapabilityBooleanType filesSharingPublicSendMail) {
this.mFilesSharingPublicSendMail = filesSharingPublicSendMail;
}
public CapabilityBooleanType getFilesSharingPublicUpload() {
return mFilesSharingPublicUpload;
}
public void setFilesSharingPublicUpload(CapabilityBooleanType filesSharingPublicUpload) {
this.mFilesSharingPublicUpload = filesSharingPublicUpload;
}
public CapabilityBooleanType getFilesSharingUserSendMail() {
return mFilesSharingUserSendMail;
}
public void setFilesSharingUserSendMail(CapabilityBooleanType filesSharingUserSendMail) {
this.mFilesSharingUserSendMail = filesSharingUserSendMail;
}
public CapabilityBooleanType getFilesSharingResharing() {
return mFilesSharingResharing;
}
public void setFilesSharingResharing(CapabilityBooleanType filesSharingResharing) {
this.mFilesSharingResharing = filesSharingResharing;
}
public CapabilityBooleanType getFilesSharingFederationOutgoing() {
return mFilesSharingFederationOutgoing;
}
public void setFilesSharingFederationOutgoing(CapabilityBooleanType filesSharingFederationOutgoing) {
this.mFilesSharingFederationOutgoing = filesSharingFederationOutgoing;
}
public CapabilityBooleanType getFilesSharingFederationIncoming() {
return mFilesSharingFederationIncoming;
}
public void setFilesSharingFederationIncoming(CapabilityBooleanType filesSharingFederationIncoming) {
this.mFilesSharingFederationIncoming = filesSharingFederationIncoming;
}
public CapabilityBooleanType getFilesBigFileChuncking() {
return mFilesBigFileChuncking;
}
public void setFilesBigFileChuncking(CapabilityBooleanType filesBigFileChuncking) {
this.mFilesBigFileChuncking = filesBigFileChuncking;
}
public CapabilityBooleanType getFilesUndelete() {
return mFilesUndelete;
}
public void setFilesUndelete(CapabilityBooleanType filesUndelete) {
this.mFilesUndelete = filesUndelete;
}
public CapabilityBooleanType getFilesVersioning() {
return mFilesVersioning;
}
public void setFilesVersioning(CapabilityBooleanType filesVersioning) {
this.mFilesVersioning = filesVersioning;
}
}

View File

@ -46,6 +46,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public static final int MINIMUM_VERSION_FOR_SEARCHING_USERS = 0x08020000; //8.2
public static final int VERSION_8 = 0x08000000; // 8.0
public static final int MINIMUM_VERSION_CAPABILITIES_API = 0x08010000; // 8.1
private static final int MAX_DOTS = 3;
@ -144,6 +146,10 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public boolean isSearchUsersSupported() {
return (mVersion >= MINIMUM_VERSION_FOR_SEARCHING_USERS);
}
public boolean isVersionWithCapabilitiesAPI(){
return (mVersion>= MINIMUM_VERSION_CAPABILITIES_API);
}
}

View File

@ -0,0 +1,145 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* 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.test_project.test;
import java.security.GeneralSecurityException;
import junit.framework.AssertionFailedError;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory;
/**
* Class to test GetRemoteCapabilitiesOperation
*
*/
public class GetCapabilitiesTest extends RemoteTest {
private static final String LOG_TAG = GetCapabilitiesTest.class.getCanonicalName();
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public GetCapabilitiesTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
Log.v(LOG_TAG, "Remote fixture created.");
}
// Tests
/**
* Test get capabilities
*
* Requires OC server 8.1 or later
*/
public void testGetRemoteCapabilitiesOperation() {
// get capabilities
GetRemoteCapabilitiesOperation getCapabilitiesOperation = new GetRemoteCapabilitiesOperation();
RemoteOperationResult result = getCapabilitiesOperation.execute(mClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}