diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperation.kt b/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperation.kt index 059788374f..8adb94b3c1 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperation.kt +++ b/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardGetWidgetItemsRemoteOperation.kt @@ -48,11 +48,16 @@ class DashboardGetWidgetItemsRemoteOperation(val id: String, private val limitSi get, object : TypeToken>>>() {} - ).ocs.data + )?.ocs?.data - result = - RemoteOperationResult>>(true, get) - result.resultData = list + if (list != null) { + result = + RemoteOperationResult>>(true, get) + result.resultData = list + } else { + result = + RemoteOperationResult>>(false, get) + } } else { result = RemoteOperationResult>>(false, get) diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardListWidgetsRemoteOperation.kt b/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardListWidgetsRemoteOperation.kt index b5f4fd8a1c..b8146024d8 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardListWidgetsRemoteOperation.kt +++ b/library/src/main/java/com/nextcloud/android/lib/resources/dashboard/DashboardListWidgetsRemoteOperation.kt @@ -45,10 +45,14 @@ class DashboardListWidgetsRemoteOperation : OCSRemoteOperation>>() {} - ).ocs.data + )?.ocs?.data - result = RemoteOperationResult>(true, get) - result.resultData = list + if (list != null) { + result = RemoteOperationResult>(true, get) + result.resultData = list + } else { + result = RemoteOperationResult>(false, get) + } } else { result = RemoteOperationResult>(false, get) } diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java index dfcb447077..ced695397b 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainListOfTemplatesRemoteOperation.java @@ -69,13 +69,15 @@ protected RemoteOperationResult run(OwnCloudClient client) { int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { - TemplateList templateList = getServerResponse(getMethod, - new TypeToken>() { - }) - .getOcs().getData(); + ServerResponse serverResponse = getServerResponse(getMethod, new TypeToken<>() {}); - result = new RemoteOperationResult<>(true, getMethod); - result.setResultData(templateList); + if (serverResponse != null) { + TemplateList templateList = serverResponse.getOcs().getData(); + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(templateList); + } else { + result = new RemoteOperationResult<>(false, getMethod); + } } else { result = new RemoteOperationResult<>(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); @@ -89,6 +91,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { getMethod.releaseConnection(); } } + return result; } } diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java index c49a748b30..87409a4702 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/directediting/DirectEditingObtainRemoteOperation.java @@ -57,13 +57,18 @@ protected RemoteOperationResult run(OwnCloudClient client) { int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); if (status == HttpStatus.SC_OK) { - DirectEditing directEditing = getServerResponse(getMethod, - new TypeToken>() { - }) - .getOcs().getData(); + ServerResponse serverResponse = getServerResponse(getMethod, + new TypeToken<>() { + }); + + if (serverResponse != null) { + DirectEditing directEditing = serverResponse.getOcs().getData(); + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(directEditing); + } else { + result = new RemoteOperationResult<>(false, getMethod); + } - result = new RemoteOperationResult<>(true, getMethod); - result.setResultData(directEditing); } else { result = new RemoteOperationResult<>(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); @@ -77,6 +82,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { getMethod.releaseConnection(); } } + return result; } } diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/groupfolders/GetGroupfoldersRemoteOperation.kt b/library/src/main/java/com/nextcloud/android/lib/resources/groupfolders/GetGroupfoldersRemoteOperation.kt index 698b4adc66..f917382753 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/groupfolders/GetGroupfoldersRemoteOperation.kt +++ b/library/src/main/java/com/nextcloud/android/lib/resources/groupfolders/GetGroupfoldersRemoteOperation.kt @@ -56,10 +56,14 @@ class GetGroupfoldersRemoteOperation : getServerResponse( getMethod, object : TypeToken>>() {} - ) - .ocs.data - result = RemoteOperationResult(true, getMethod) - result.setResultData(map) + )?.ocs?.data + + if (map != null) { + result = RemoteOperationResult(true, getMethod) + result.setResultData(map) + } else { + result = RemoteOperationResult(false, getMethod) + } } else { result = RemoteOperationResult(false, getMethod) } diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt b/library/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt index 61acd055ec..d23292c7b0 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt +++ b/library/src/main/java/com/nextcloud/android/lib/resources/profile/GetHoverCardRemoteOperation.kt @@ -48,14 +48,19 @@ class GetHoverCardRemoteOperation(private val userId: String) : OCSRemoteOperati GetMethod(client.baseUri.toString() + DIRECT_ENDPOINT + userId + JSON_FORMAT, true) val status = client.execute(getMethod) if (status == HttpStatus.SC_OK) { - val hoverCard: HoverCard = - getServerResponse>( - getMethod, - object : TypeToken?>() {} - ) - .ocs.data - result = RemoteOperationResult(true, getMethod) - result.setResultData(hoverCard) + val serverResponse: ServerResponse? = getServerResponse( + getMethod, + object : TypeToken>() {} + ) + + val hoverCard: HoverCard? = serverResponse?.ocs?.data + + if (hoverCard != null) { + result = RemoteOperationResult(true, getMethod) + result.setResultData(hoverCard) + } else { + result = RemoteOperationResult(false, getMethod) + } } else { result = RemoteOperationResult(false, getMethod) } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/OCSRemoteOperation.kt b/library/src/main/java/com/owncloud/android/lib/resources/OCSRemoteOperation.kt index 9b87aa3fc9..fbf34f7368 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/OCSRemoteOperation.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/OCSRemoteOperation.kt @@ -32,7 +32,6 @@ import com.google.gson.reflect.TypeToken import com.nextcloud.common.OkHttpMethodBase import com.owncloud.android.lib.common.operations.RemoteOperation import org.apache.commons.httpclient.HttpMethodBase -import java.io.IOException abstract class OCSRemoteOperation : RemoteOperation() { private val gson = Gson() diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/ConvertAppTokenRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/ConvertAppTokenRemoteOperation.java index 321dca243f..e022837004 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/ConvertAppTokenRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/ConvertAppTokenRemoteOperation.java @@ -61,13 +61,14 @@ public RemoteOperationResult run(NextcloudClient client) { int status = client.execute(method); if (status == HttpStatus.SC_OK) { - // Parse the response - ServerResponse serverResponse = getServerResponse(method, - new TypeToken>() { - }); + ServerResponse serverResponse = getServerResponse(method, new TypeToken<>() {}); - result = new RemoteOperationResult<>(true, method); - result.setResultData(serverResponse.getOcs().getData().getAppPassword()); + if (serverResponse != null) { + result = new RemoteOperationResult<>(true, method); + result.setResultData(serverResponse.getOcs().getData().getAppPassword()); + } else { + result = new RemoteOperationResult<>(false, method); + } } else if (status == HttpStatus.SC_FORBIDDEN) { result = new RemoteOperationResult<>(true, method); result.setResultData(""); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetPredefinedStatusesRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/GetPredefinedStatusesRemoteOperation.java index ae0370dd07..e74b3b8faf 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/GetPredefinedStatusesRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetPredefinedStatusesRemoteOperation.java @@ -61,14 +61,14 @@ public RemoteOperationResult> run(NextcloudClient cl int status = client.execute(getMethod); if (status == HttpStatus.SC_OK) { - // Parse the response - ServerResponse> serverResponse = - getServerResponse(getMethod, - new TypeToken>>() { - }); + ServerResponse> serverResponse = getServerResponse(getMethod, new TypeToken<>() {}); - result = new RemoteOperationResult<>(true, getMethod); - result.setResultData(serverResponse.getOcs().getData()); + if (serverResponse != null) { + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(serverResponse.getOcs().getData()); + } else { + result = new RemoteOperationResult<>(false, getMethod); + } } else { result = new RemoteOperationResult<>(false, getMethod); getMethod.releaseConnection(); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetPrivateKeyRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/GetPrivateKeyRemoteOperation.java index d49a992609..2d204e548c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/GetPrivateKeyRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetPrivateKeyRemoteOperation.java @@ -66,8 +66,12 @@ public RemoteOperationResult run(NextcloudClient client) { getServerResponse(getMethod, new TypeToken>() { }); - result = new RemoteOperationResult<>(true, getMethod); - result.setResultData(serverResponse.getOcs().data); + if (serverResponse != null) { + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(serverResponse.getOcs().data); + } else { + result = new RemoteOperationResult<>(false, getMethod); + } } else { result = new RemoteOperationResult<>(false, getMethod); } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetStatusRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/GetStatusRemoteOperation.java index e3b793dd5c..ed9c4dae04 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/GetStatusRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetStatusRemoteOperation.java @@ -60,13 +60,13 @@ public RemoteOperationResult run(NextcloudClient client) { int status = client.execute(getMethod); if (status == HttpStatus.SC_OK) { - // Parse the response - ServerResponse serverResponse = getServerResponse(getMethod, - new TypeToken>() { - }); - - result = new RemoteOperationResult<>(true, getMethod); - result.setResultData(serverResponse.getOcs().getData()); + ServerResponse serverResponse = getServerResponse(getMethod, new TypeToken<>() {}); + if (serverResponse != null) { + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(serverResponse.getOcs().getData()); + } else { + result = new RemoteOperationResult<>(false, getMethod); + } } else { // 404 if no status was set before if (HttpStatus.SC_NOT_FOUND == getMethod.getStatusCode()) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.java index e5e9bf36a3..ee0f3b20dc 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/users/GetUserInfoRemoteOperation.java @@ -94,18 +94,20 @@ public RemoteOperationResult run(NextcloudClient client) { status = client.execute(get); if (isSuccess(status)) { - ServerResponse ocsResponse = getServerResponse(get, - new TypeToken>() { - }); + ServerResponse ocsResponse = getServerResponse(get, new TypeToken<>() {}); - UserInfo userInfo = ocsResponse.ocs.data; + if (ocsResponse != null) { + UserInfo userInfo = ocsResponse.ocs.data; - if (userInfo.getQuota() == null || userInfo.getQuota().getQuota() == 0) { - userInfo.setQuota(new Quota(QUOTA_LIMIT_INFO_NOT_AVAILABLE)); - } + if (userInfo.getQuota() == null || userInfo.getQuota().getQuota() == 0) { + userInfo.setQuota(new Quota(QUOTA_LIMIT_INFO_NOT_AVAILABLE)); + } - result = new RemoteOperationResult<>(true, get); - result.setResultData(userInfo); + result = new RemoteOperationResult<>(true, get); + result.setResultData(userInfo); + } else { + result = new RemoteOperationResult<>(false, get); + } } else { result = new RemoteOperationResult<>(false, get); String response = get.getResponseBodyAsString();