diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperationIT.kt b/library/src/androidTest/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperationIT.kt index a1a4495b2..a2e9aed38 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperationIT.kt @@ -23,7 +23,7 @@ class DashboardGetWidgetItemsRemoteOperationIT : AbstractIT() { testOnlyOnServer(NextcloudVersion.nextcloud_25) // create folder to have some content - assertTrue(CreateFolderRemoteOperation("/testFolder", false).execute(nextcloudClient2).isSuccess) + assertTrue(CreateFolderRemoteOperation("/testFolder", false).execute(client2).isSuccess) assertTrue( CreateShareRemoteOperation( "/testFolder", @@ -32,7 +32,7 @@ class DashboardGetWidgetItemsRemoteOperationIT : AbstractIT() { false, "", OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER - ).execute(nextcloudClient2) + ).execute(client2) .isSuccess ) diff --git a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java index a8210ea45..72a1c2dd3 100644 --- a/library/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/library/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -149,7 +149,7 @@ private static void testConnection() throws KeyStoreException, InterruptedException { GetStatusRemoteOperation getStatus = new GetStatusRemoteOperation(context); - RemoteOperationResult result = getStatus.execute(nextcloudClient); + RemoteOperationResult result = getStatus.execute(client); if (result.isSuccess()) { Log_OC.d("AbstractIT", "Connection to server successful"); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java index 13f6dd0cd..2d666baa3 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java @@ -7,13 +7,14 @@ */ package com.owncloud.android.lib.resources.e2ee; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.GetMethod; +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.Header; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; import org.json.JSONObject; @@ -24,6 +25,8 @@ public class GetMetadataRemoteOperation extends RemoteOperation { private static final String TAG = GetMetadataRemoteOperation.class.getSimpleName(); + private static final int SYNC_READ_TIMEOUT = 40000; + private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String METADATA_V1_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/meta-data/"; private static final String METADATA_V2_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/meta-data/"; @@ -46,29 +49,32 @@ public GetMetadataRemoteOperation(long fileId) { * @param client Client object */ @Override - public RemoteOperationResult run(NextcloudClient client) { - com.nextcloud.operations.GetMethod getMethod = null; + protected RemoteOperationResult run(OwnCloudClient client) { + GetMethod getMethod = null; RemoteOperationResult result; try { // remote request - getMethod = new com.nextcloud.operations.GetMethod(client.getBaseUri() + METADATA_V2_URL + fileId + JSON_FORMAT, true); + getMethod = new GetMethod(client.getBaseUri() + METADATA_V2_URL + fileId + JSON_FORMAT); + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - int status = client.execute(getMethod); + int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_NOT_FOUND || status == HttpStatus.SC_INTERNAL_SERVER_ERROR) { // retry with v1 - getMethod = new GetMethod(client.getBaseUri() + METADATA_V1_URL + fileId + JSON_FORMAT, true); + getMethod = new GetMethod(client.getBaseUri() + METADATA_V1_URL + fileId + JSON_FORMAT); + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); - status = client.execute(getMethod); + status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); } if (status == HttpStatus.SC_OK) { String response = getMethod.getResponseBodyAsString(); - String signature = getMethod.getResponseHeader(HEADER_SIGNATURE); + Header signatureHeader = getMethod.getResponseHeader(HEADER_SIGNATURE); - if (signature == null) { - signature = ""; + String signature = ""; + if (signatureHeader != null) { + signature = signatureHeader.getValue(); } // Parse the response @@ -84,6 +90,7 @@ public RemoteOperationResult run(NextcloudClient client) { result.setResultData(metadataResponse); } else { result = new RemoteOperationResult<>(false, getMethod); + client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult<>(e); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java index bb4e299b7..27a265f7e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java @@ -7,17 +7,15 @@ */ package com.owncloud.android.lib.resources.e2ee; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.PostMethod; +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.HttpStatus; +import org.apache.commons.httpclient.methods.Utf8PostMethod; import org.json.JSONObject; -import okhttp3.RequestBody; - /** * Lock a file @@ -25,6 +23,8 @@ public class LockFileRemoteOperation extends RemoteOperation { private static final String TAG = LockFileRemoteOperation.class.getSimpleName(); + private static final int SYNC_READ_TIMEOUT = 40000; + private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; private static final String COUNTER_HEADER = "X-NC-E2EE-COUNTER"; @@ -52,22 +52,22 @@ public LockFileRemoteOperation(long localId) { * @param client Client object */ @Override - public RemoteOperationResult run(NextcloudClient client) { + protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; - PostMethod postMethod = null; + Utf8PostMethod postMethod = null; try { - RequestBody requestBody = RequestBody.create(new byte[] {}); - - postMethod = new PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT, true, requestBody); + postMethod = new Utf8PostMethod(client.getBaseUri() + LOCK_FILE_URL + localId + JSON_FORMAT); + // remote request + postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); postMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); if (counter > 0) { postMethod.addRequestHeader(COUNTER_HEADER, String.valueOf(counter)); } - int status = client.execute(postMethod); + int status = client.executeMethod(postMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { String response = postMethod.getResponseBodyAsString(); @@ -83,6 +83,7 @@ public RemoteOperationResult run(NextcloudClient client) { result.setResultData(token); } else { result = new RemoteOperationResult<>(false, postMethod); + client.exhaustResponse(postMethod.getResponseBodyAsStream()); } } catch (Exception e) { result = new RemoteOperationResult<>(e); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java index 9f83c4402..b3036c9bd 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java @@ -7,13 +7,13 @@ */ package com.owncloud.android.lib.resources.e2ee; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.DeleteMethod; +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.HttpStatus; +import org.apache.commons.httpclient.methods.DeleteMethod; /** @@ -22,6 +22,8 @@ public class UnlockFileRemoteOperation extends RemoteOperation { private static final String TAG = UnlockFileRemoteOperation.class.getSimpleName(); + private static final int SYNC_READ_TIMEOUT = 40000; + private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v2/lock/"; private final long localId; @@ -39,19 +41,22 @@ public UnlockFileRemoteOperation(long localId, String token) { * @param client Client object */ @Override - public RemoteOperationResult run(NextcloudClient client) { + protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; - com.nextcloud.operations.DeleteMethod deleteMethod = null; + DeleteMethod deleteMethod = null; try { // remote request - deleteMethod = new DeleteMethod(client.getBaseUri() + LOCK_FILE_URL + localId, true); + deleteMethod = new DeleteMethod(client.getBaseUri() + LOCK_FILE_URL + localId); + deleteMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); deleteMethod.addRequestHeader(CONTENT_TYPE, FORM_URLENCODED); deleteMethod.addRequestHeader(E2E_TOKEN, token); - int status = client.execute(deleteMethod); + int status = client.executeMethod(deleteMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); result = new RemoteOperationResult<>(status == HttpStatus.SC_OK, deleteMethod); + + client.exhaustResponse(deleteMethod.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Unlock file with id " + localId + " failed: " + result.getLogMessage(), diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java index 4a84591c1..dac141ca5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ExistenceCheckRemoteOperation.java @@ -8,25 +8,32 @@ import android.content.Context; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.HeadMethod; +import com.owncloud.android.lib.common.OwnCloudAnonymousCredentials; +import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.RedirectionPath; 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.HttpStatus; +import org.apache.commons.httpclient.methods.HeadMethod; /** * Operation to check the existence or absence of a path in a remote server. * * @author David A. Velasco */ -public class ExistenceCheckRemoteOperation extends RemoteOperation { - private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName(); +public class ExistenceCheckRemoteOperation extends RemoteOperation { + + /** + * Maximum time to wait for a response from the server in MILLISECONDs. + */ + public static final int TIMEOUT = 50000; - private final String mPath; - private final boolean mSuccessIfAbsent; + private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName(); + + private String mPath; + private boolean mSuccessIfAbsent; /** Sequence of redirections followed. Available only after executing the operation */ private RedirectionPath mRedirectionPath = null; @@ -58,21 +65,26 @@ public ExistenceCheckRemoteOperation(String remotePath, Context context, boolean } @Override - public RemoteOperationResult run(NextcloudClient client) { - RemoteOperationResult result; - com.nextcloud.operations.HeadMethod head = null; - boolean previousFollowRedirects = client.getFollowRedirects(); + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + HeadMethod head = null; + boolean previousFollowRedirects = client.isFollowRedirects(); try { - head = new HeadMethod(client.getFilesDavUri(mPath), false); + if (client.getCredentials() instanceof OwnCloudAnonymousCredentials) { + head = new HeadMethod(client.getDavUri().toString()); + } else { + head = new HeadMethod(client.getFilesDavUri(mPath)); + } client.setFollowRedirects(false); - int status = client.execute(head); + int status = client.executeMethod(head, TIMEOUT, TIMEOUT); if (previousFollowRedirects) { mRedirectionPath = client.followRedirection(head); status = mRedirectionPath.getLastStatus(); } + client.exhaustResponse(head.getResponseBodyAsStream()); boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); - result = new RemoteOperationResult<>( + result = new RemoteOperationResult( success, status, head.getStatusText(), @@ -83,7 +95,7 @@ public RemoteOperationResult run(NextcloudClient client) { "finished with HTTP status " + status + (!success ? "(FAIL)" : "")); } catch (Exception e) { - result = new RemoteOperationResult<>(e); + result = new RemoteOperationResult(e); Log_OC.e(TAG, "Existence check for " + client.getFilesDavUri(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException()); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java index fb449b760..79d92543b 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RenameFileRemoteOperation.java @@ -6,7 +6,6 @@ */ package com.owncloud.android.lib.resources.files; -import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -76,10 +75,8 @@ protected RemoteOperationResult run(OwnCloudClient client) { } // check if a file with the new name already exists - NextcloudClient nextcloudClient = client.toNextcloudClient(); - RemoteOperationResult existenceResult = new ExistenceCheckRemoteOperation(mNewRemotePath, false) - .execute(nextcloudClient); + .execute(client); if (existenceResult.isSuccess()) { return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/CreateShareRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/CreateShareRemoteOperation.java index 128f9db6f..0e3200d7b 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/CreateShareRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/CreateShareRemoteOperation.java @@ -15,11 +15,13 @@ import com.nextcloud.common.JSONRequestBody; import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.PostMethod; +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.HttpStatus; +import org.apache.commons.httpclient.methods.Utf8PostMethod; import java.io.IOException; import java.util.List; @@ -129,6 +131,73 @@ public void setGetShareDetails(boolean set) { getShareDetails = set; } + @Override + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result; + int status; + + Utf8PostMethod post = null; + + try { + // Post Method + post = new Utf8PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + + post.setRequestHeader(CONTENT_TYPE, FORM_URLENCODED); + + post.addParameter(PARAM_PATH, remoteFilePath); + post.addParameter(PARAM_SHARE_TYPE, Integer.toString(shareType.getValue())); + post.addParameter(PARAM_SHARE_WITH, shareWith); + if (publicUpload) { + post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); + } + if (password != null && password.length() > 0) { + post.addParameter(PARAM_PASSWORD, password); + } + if (OCShare.NO_PERMISSION != permissions) { + post.addParameter(PARAM_PERMISSIONS, Integer.toString(permissions)); + } + + if (!TextUtils.isEmpty(note)) { + post.addParameter(PARAM_NOTE, note); + } + + post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + status = client.executeMethod(post); + + if (isSuccess(status)) { + String response = post.getResponseBodyAsString(); + + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOneOrMoreSharesRequired(true); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + + if (result.isSuccess() && getShareDetails) { + // retrieve more info - POST only returns the index of the new share + OCShare emptyShare = result.getResultData().get(0); + GetShareRemoteOperation getInfo = new GetShareRemoteOperation(emptyShare.getRemoteId()); + result = getInfo.execute(client); + } + + } else { + result = new RemoteOperationResult<>(false, post); + } + + } catch (IOException e) { + result = new RemoteOperationResult<>(e); + Log_OC.e(TAG, "Exception while Creating New Share", e); + + } finally { + if (post != null) { + post.releaseConnection(); + } + } + return result; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareRemoteOperation.java index 76822138c..7fa2c8ec8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareRemoteOperation.java @@ -9,8 +9,13 @@ */ package com.owncloud.android.lib.resources.shares; +import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS; +import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS_OC; +import static com.owncloud.android.lib.resources.shares.ShareUtils.SHARING_API_PATH; + import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.GetMethod; +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; @@ -19,9 +24,6 @@ import java.util.List; -import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS; -import static com.owncloud.android.lib.resources.shares.ShareUtils.SHARING_API_PATH; - /** * Get the data about a Share resource, known its remote ID. */ @@ -36,6 +38,48 @@ public GetShareRemoteOperation(long remoteId) { this.remoteId = remoteId; } + @Override + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result; + int status; + + // Get Method + org.apache.commons.httpclient.methods.GetMethod get = null; + + // Get the response + try { + get = new org.apache.commons.httpclient.methods.GetMethod(client.getBaseUri() + SHARING_API_PATH + "/" + remoteId); + get.setQueryString(INCLUDE_TAGS_OC); + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + status = client.executeMethod(get); + + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); + + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setOneOrMoreSharesRequired(true); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + + } else { + result = new RemoteOperationResult<>(false, get); + } + + } catch (Exception e) { + result = new RemoteOperationResult<>(e); + Log_OC.e(TAG, "Exception while getting remote shares ", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } @Override public RemoteOperationResult> run(NextcloudClient client) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareesRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareesRemoteOperation.java index 2d7fc1d01..1959d057a 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareesRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetShareesRemoteOperation.java @@ -14,6 +14,7 @@ import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.GetMethod; +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; @@ -102,6 +103,129 @@ public GetShareesRemoteOperation(String searchString, int page, int perPage) { this.perPage = perPage; } + @Override + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result; + int status; + org.apache.commons.httpclient.methods.GetMethod get = null; + + try { + Uri requestUri = client.getBaseUri(); + Uri.Builder uriBuilder = requestUri.buildUpon(); + uriBuilder.appendEncodedPath(OCS_ROUTE); + uriBuilder.appendQueryParameter(PARAM_FORMAT, VALUE_FORMAT); + uriBuilder.appendQueryParameter(PARAM_ITEM_TYPE, VALUE_ITEM_TYPE); + uriBuilder.appendQueryParameter(PARAM_SEARCH, searchString); + uriBuilder.appendQueryParameter(PARAM_PAGE, String.valueOf(page)); + uriBuilder.appendQueryParameter(PARAM_PER_PAGE, String.valueOf(perPage)); + uriBuilder.appendQueryParameter(PARAM_LOOKUP, VALUE_FALSE); + + // Get Method + get = new org.apache.commons.httpclient.methods.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 respData = respOCS.getJSONObject(NODE_DATA); + JSONObject respExact = respData.getJSONObject(NODE_EXACT); + + JSONArray respExactUsers = respExact.getJSONArray(NODE_USERS); + JSONArray respExactGroups = respExact.getJSONArray(NODE_GROUPS); + JSONArray respExactRemotes = respExact.getJSONArray(NODE_REMOTES); + JSONArray respExactCircles; + if (respExact.has(NODE_CIRCLES)) { + respExactCircles = respExact.getJSONArray(NODE_CIRCLES); + } else { + respExactCircles = new JSONArray(); + } + + JSONArray respExactRooms; + if (respExact.has(NODE_ROOMS)) { + respExactRooms = respExact.getJSONArray(NODE_ROOMS); + } else { + respExactRooms = new JSONArray(); + } + + JSONArray respExactEmails = respExact.getJSONArray(NODE_EMAILS); + JSONArray respPartialUsers = respData.getJSONArray(NODE_USERS); + JSONArray respPartialGroups = respData.getJSONArray(NODE_GROUPS); + JSONArray respPartialRemotes = respData.getJSONArray(NODE_REMOTES); + JSONArray respPartialCircles; + + if (respData.has(NODE_CIRCLES)) { + respPartialCircles = respData.getJSONArray(NODE_CIRCLES); + } else { + respPartialCircles = new JSONArray(); + } + + JSONArray respPartialRooms; + + if (respData.has(NODE_ROOMS)) { + respPartialRooms = respData.getJSONArray(NODE_ROOMS); + } else { + respPartialRooms = new JSONArray(); + } + + JSONArray[] jsonResults = { + respExactUsers, + respExactGroups, + respExactRemotes, + respExactRooms, + respExactEmails, + respExactCircles, + respPartialUsers, + respPartialGroups, + respPartialRemotes, + respPartialRooms, + respPartialCircles + }; + + ArrayList data = new ArrayList<>(); + for (JSONArray jsonResult : jsonResults) { + for (int j = 0; j < jsonResult.length(); j++) { + JSONObject jsonObject = jsonResult.getJSONObject(j); + data.add(jsonObject); + Log_OC.d(TAG, "*** Added item: " + jsonObject.getString(PROPERTY_LABEL)); + } + } + + // Result + result = new RemoteOperationResult<>(true, get); + result.setResultData(data); + + Log_OC.d(TAG, "*** Get Users or groups completed"); + + } else { + result = new RemoteOperationResult<>(false, get); + String response = get.getResponseBodyAsString(); + Log_OC.e(TAG, "Failed response while getting users/groups 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 users/groups", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesForFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesForFileRemoteOperation.java index 6faa01937..e1cbbaab8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesForFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesForFileRemoteOperation.java @@ -12,11 +12,13 @@ import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.GetMethod; +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.HttpStatus; +import org.apache.commons.httpclient.NameValuePair; import java.util.List; import java.util.Map; @@ -54,6 +56,59 @@ public GetSharesForFileRemoteOperation(String remoteFilePath, boolean reshares, mSubfiles = subfiles; } + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result = null; + int status = -1; + + org.apache.commons.httpclient.methods.GetMethod get = null; + + try { + // Get Method + get = new org.apache.commons.httpclient.methods.GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + + // Add Parameters to Get Method + get.setQueryString(new NameValuePair[]{ + new NameValuePair(PARAM_PATH, mRemoteFilePath), + new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), + new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) //, + //new NameValuePair("shared_with_me", "true") + }); + + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + status = client.executeMethod(get); + + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); + + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + + if (result.isSuccess()) { + Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); + } + + } else { + result = new RemoteOperationResult(false, get); + } + + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Exception while getting shares", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesRemoteOperation.java index a9993827f..acbf2b01e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/GetSharesRemoteOperation.java @@ -10,8 +10,12 @@ */ package com.owncloud.android.lib.resources.shares; +import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS; +import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS_OC; + import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.GetMethod; +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; @@ -21,8 +25,6 @@ import java.util.List; import java.util.Map; -import static com.owncloud.android.lib.resources.shares.ShareUtils.INCLUDE_TAGS; - /** * Get the data from the server about ALL the known shares owned by the requester. */ @@ -39,6 +41,51 @@ public GetSharesRemoteOperation(boolean sharedWithMe) { this.sharedWithMe = sharedWithMe; } + @Override + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result; + int status; + + // Get Method + org.apache.commons.httpclient.methods.GetMethod get = null; + + // Get the response + try { + get = new org.apache.commons.httpclient.methods.GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); + get.setQueryString(INCLUDE_TAGS_OC); + get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + if (sharedWithMe) { + get.setQueryString("shared_with_me=true"); + } + + status = client.executeMethod(get); + + if (isSuccess(status)) { + String response = get.getResponseBodyAsString(); + + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + } else { + result = new RemoteOperationResult<>(false, get); + } + + } catch (Exception e) { + result = new RemoteOperationResult<>(e); + Log_OC.e(TAG, "Exception while getting remote shares ", e); + + } finally { + if (get != null) { + get.releaseConnection(); + } + } + return result; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/RemoveShareRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/RemoveShareRemoteOperation.java index e1866e644..e562e7884 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/RemoveShareRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/RemoveShareRemoteOperation.java @@ -12,6 +12,7 @@ import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.DeleteMethod; +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; @@ -41,6 +42,43 @@ public RemoveShareRemoteOperation(long remoteShareId) { } + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; + org.apache.jackrabbit.webdav.client.methods.DeleteMethod delete = null; + + try { + delete = new org.apache.jackrabbit.webdav.client.methods.DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + remoteShareId); + + delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + + int status = client.executeMethod(delete); + + if (isSuccess(status)) { + String response = delete.getResponseBodyAsString(); + + // Parse xml response and obtain the list of shares + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + result = parser.parse(response); + + Log_OC.d(TAG, "Unshare " + remoteShareId + ": " + result.getLogMessage()); + + } else { + result = new RemoteOperationResult(false, delete); + } + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); + + } finally { + if (delete != null) + delete.releaseConnection(); + } + return result; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java index 0cead8dba..a23fc2269 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareUtils.java @@ -23,6 +23,7 @@ public class ShareUtils { // OCS Route public static final String SHARING_API_PATH = "/ocs/v2.php/apps/files_sharing/api/v1/shares"; + public static final String INCLUDE_TAGS_OC = "include_tags=true"; public static final Map INCLUDE_TAGS = Map.of("include_tags", "true"); // String to build the link with the token of a share: diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/UpdateShareRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/shares/UpdateShareRemoteOperation.java index 402504bd4..a13a20112 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/UpdateShareRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/UpdateShareRemoteOperation.java @@ -16,11 +16,13 @@ import com.nextcloud.common.JSONRequestBody; import com.nextcloud.common.NextcloudClient; import com.nextcloud.operations.PutMethod; +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.HttpStatus; +import org.apache.commons.httpclient.methods.StringRequestEntity; import java.net.URLEncoder; import java.text.DateFormat; @@ -47,6 +49,8 @@ public class UpdateShareRemoteOperation extends RemoteOperation> { private static final String PARAM_HIDE_DOWNLOAD = "hideDownload"; private static final String PARAM_LABEL = "label"; private static final String FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"; + private static final String ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded"; + private static final String ENTITY_CHARSET = "UTF-8"; /** @@ -139,6 +143,104 @@ public void setNote(String note) { this.note = note; } + @Override + protected RemoteOperationResult> run(OwnCloudClient client) { + RemoteOperationResult> result = null; + int status; + + /// prepare array of parameters to update + List> parametersToUpdate = new ArrayList<>(); + if (password != null) { + parametersToUpdate.add(new Pair<>(PARAM_PASSWORD, password)); + } + + if (expirationDateInMillis < 0) { + // clear expiration date + parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, "")); + } else if (expirationDateInMillis > 0) { + // set expiration date + DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.US); + Calendar expirationDate = Calendar.getInstance(); + expirationDate.setTimeInMillis(expirationDateInMillis); + String formattedExpirationDate = dateFormat.format(expirationDate.getTime()); + parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, formattedExpirationDate)); + } + + if (permissions > 0) { + // set permissions + parametersToUpdate.add(new Pair<>(PARAM_PERMISSIONS, Integer.toString(permissions))); + } + + if (hideFileDownload != null) { + parametersToUpdate.add(new Pair<>(PARAM_HIDE_DOWNLOAD, Boolean.toString(hideFileDownload))); + } + + if (note != null) { + parametersToUpdate.add(new Pair<>(PARAM_NOTE, URLEncoder.encode(note))); + } + + if (label != null) { + parametersToUpdate.add(new Pair<>(PARAM_LABEL, URLEncoder.encode(label))); + } + + /// perform required PUT requests + org.apache.commons.httpclient.methods.PutMethod put = null; + String uriString; + + try { + Uri requestUri = client.getBaseUri(); + Uri.Builder uriBuilder = requestUri.buildUpon(); + uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH.substring(1)); + uriBuilder.appendEncodedPath(Long.toString(remoteId)); + uriString = uriBuilder.build().toString(); + + for (Pair parameter : parametersToUpdate) { + if (put != null) { + put.releaseConnection(); + } + put = new org.apache.commons.httpclient.methods.PutMethod(uriString); + put.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); + put.setRequestEntity(new StringRequestEntity( + parameter.first + "=" + parameter.second, + ENTITY_CONTENT_TYPE, + ENTITY_CHARSET + )); + + status = client.executeMethod(put); + + if (status == HttpStatus.SC_OK || status == HttpStatus.SC_BAD_REQUEST) { + String response = put.getResponseBodyAsString(); + + // Parse xml response + ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( + new ShareXMLParser() + ); + parser.setServerBaseUri(client.getBaseUri()); + result = parser.parse(response); + + } else { + result = new RemoteOperationResult<>(false, put); + } + if (!result.isSuccess()) { + break; + } + } + + } 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; + } + @Override public RemoteOperationResult> run(NextcloudClient client) { RemoteOperationResult> result = null; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/status/GetStatusRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/status/GetStatusRemoteOperation.java index c204dc62e..dbc828378 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/status/GetStatusRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/status/GetStatusRemoteOperation.java @@ -15,18 +15,21 @@ import android.net.ConnectivityManager; import android.net.Uri; -import com.nextcloud.common.NextcloudClient; -import com.nextcloud.operations.GetMethod; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.accounts.AccountUtils; 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.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.params.HttpMethodParams; +import org.apache.commons.httpclient.params.HttpParams; import org.json.JSONException; import org.json.JSONObject; -import kotlin.Pair; +import java.util.ArrayList; /** * Checks if the server is valid and if the server supports the Share API @@ -34,7 +37,13 @@ * @author David A. Velasco * @author masensio */ -public class GetStatusRemoteOperation extends RemoteOperation> { +public class GetStatusRemoteOperation extends RemoteOperation { + + /** + * Maximum time to wait for a response from the server when the connection is being tested, in MILLISECONDs. + */ + private static final int TRY_CONNECTION_TIMEOUT = 50000; + private static final String TAG = GetStatusRemoteOperation.class.getSimpleName(); private static final String NODE_INSTALLED = "installed"; @@ -44,24 +53,28 @@ public class GetStatusRemoteOperation extends RemoteOperation> mLatestResult; - private final Context mContext; + private RemoteOperationResult mLatestResult; + private Context mContext; public GetStatusRemoteOperation(Context context) { mContext = context; } - private boolean tryConnection(NextcloudClient client) { + private boolean tryConnection(OwnCloudClient client) { boolean retval = false; - com.nextcloud.operations.GetMethod get = null; - String baseUrlSt = String.valueOf(client.getBaseUri()); + GetMethod get = null; + String baseUrlSt = client.getBaseUri().toString(); try { - get = new com.nextcloud.operations.GetMethod(baseUrlSt + AccountUtils.STATUS_PATH, false); + get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH); + + HttpParams params = HttpMethodParams.getDefaultParams(); + params.setParameter(HttpMethodParams.USER_AGENT, OwnCloudClientManagerFactory.getUserAgent()); + get.getParams().setDefaults(params); client.setFollowRedirects(false); boolean isRedirectToNonSecureConnection = false; - int status = client.execute(get); - mLatestResult = new RemoteOperationResult<>((status == HttpStatus.SC_OK), get); + int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); + mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get); String redirectedLocation = mLatestResult.getRedirectedLocation(); while (redirectedLocation != null && redirectedLocation.length() > 0 @@ -72,9 +85,9 @@ private boolean tryConnection(NextcloudClient client) { redirectedLocation.startsWith(PROTOCOL_HTTP) ); get.releaseConnection(); - get = new GetMethod(redirectedLocation, false); - status = client.execute(get); - mLatestResult = new RemoteOperationResult<>((status == HttpStatus.SC_OK), get); + get = new GetMethod(redirectedLocation); + status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); + mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get); redirectedLocation = mLatestResult.getRedirectedLocation(); } @@ -83,7 +96,7 @@ private boolean tryConnection(NextcloudClient client) { if (status == HttpStatus.SC_OK) { JSONObject json = new JSONObject(response); if (!json.getBoolean(NODE_INSTALLED)) { - mLatestResult = new RemoteOperationResult<>( + mLatestResult = new RemoteOperationResult( RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } else { boolean extendedSupport = false; @@ -95,22 +108,24 @@ private boolean tryConnection(NextcloudClient client) { OwnCloudVersion ocVersion = new OwnCloudVersion(version); if (!ocVersion.isVersionValid()) { - mLatestResult = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.BAD_OC_VERSION); + mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION); } else { // success if (isRedirectToNonSecureConnection) { - mLatestResult = new RemoteOperationResult<>( + mLatestResult = new RemoteOperationResult( RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION); } else { - mLatestResult = new RemoteOperationResult<>( + mLatestResult = new RemoteOperationResult( baseUrlSt.startsWith(PROTOCOL_HTTPS) ? RemoteOperationResult.ResultCode.OK_SSL : RemoteOperationResult.ResultCode.OK_NO_SSL ); } - Pair data = new Pair<>(ocVersion, extendedSupport); - mLatestResult.setResultData(data); + ArrayList data = new ArrayList<>(); + data.add(ocVersion); + data.add(extendedSupport); + mLatestResult.setData(data); retval = true; } } @@ -119,22 +134,22 @@ private boolean tryConnection(NextcloudClient client) { JSONObject json = new JSONObject(response); if (json.getInt("code") == UNTRUSTED_DOMAIN_ERROR_CODE) { - mLatestResult = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.UNTRUSTED_DOMAIN); + mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNTRUSTED_DOMAIN); } else { - mLatestResult = new RemoteOperationResult<>(false, get); + mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (JSONException e) { - mLatestResult = new RemoteOperationResult<>(false, get); + mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } else { - mLatestResult = new RemoteOperationResult<>(false, get); + mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (JSONException e) { - mLatestResult = new RemoteOperationResult<>(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); + mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); } catch (Exception e) { - mLatestResult = new RemoteOperationResult<>(e); + mLatestResult = new RemoteOperationResult(e); } finally { if (get != null) @@ -156,16 +171,18 @@ private boolean tryConnection(NextcloudClient client) { } private boolean isOnline() { - ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - return cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnectedOrConnecting(); + ConnectivityManager cm = (ConnectivityManager) mContext + .getSystemService(Context.CONNECTIVITY_SERVICE); + return cm != null && cm.getActiveNetworkInfo() != null + && cm.getActiveNetworkInfo().isConnectedOrConnecting(); } @Override - public RemoteOperationResult> run(NextcloudClient client) { + protected RemoteOperationResult run(OwnCloudClient client) { if (!isOnline()) { - return new RemoteOperationResult<>(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); + return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); } - String baseUriStr = String.valueOf(client.getBaseUri()); + String baseUriStr = client.getBaseUri().toString(); if (baseUriStr.startsWith(PROTOCOL_HTTP) || baseUriStr.startsWith(PROTOCOL_HTTPS)) { tryConnection(client);