Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit f14abb0

Browse files
committed
Code revision suggestions have been implemented.
1 parent 0895732 commit f14abb0

File tree

7 files changed

+44
-48
lines changed

7 files changed

+44
-48
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public class HttpConstants {
6666
public static final String CONTENT_TYPE_JSON = "application/json";
6767
public static final String CONTENT_TYPE_WWW_FORM = "application/x-www-form-urlencoded";
6868

69+
/***********************************************************************************************************
70+
************************************************ ARGUMENTS NAMES ********************************************
71+
***********************************************************************************************************/
72+
73+
public static final String PARAM_FORMAT = "format";
74+
75+
/***********************************************************************************************************
76+
************************************************ ARGUMENTS VALUES ********************************************
77+
***********************************************************************************************************/
78+
79+
public static final String VALUE_FORMAT = "json";
80+
6981
/***********************************************************************************************************
7082
************************************************ STATUS CODES *********************************************
7183
***********************************************************************************************************/
@@ -205,4 +217,4 @@ public class HttpConstants {
205217
* Default timeout for establishing a connection
206218
*/
207219
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
208-
}
220+
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ package com.owncloud.android.lib.resources.shares
3131
import android.net.Uri
3232
import com.owncloud.android.lib.common.OwnCloudClient
3333
import com.owncloud.android.lib.common.http.HttpConstants
34+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
35+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3436
import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod
3537
import com.owncloud.android.lib.common.operations.RemoteOperation
3638
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -127,7 +129,7 @@ class CreateRemoteShareOperation(
127129
return result
128130
}
129131

130-
private fun createFormBodyBuilder(): FormBody.Builder {
132+
private fun createFormBodyBuilder(): FormBody {
131133

132134
val formBodyBuilder = FormBody.Builder()
133135
.add(PARAM_PATH, remoteFilePath)
@@ -156,15 +158,13 @@ class CreateRemoteShareOperation(
156158
formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString())
157159
}
158160

159-
return formBodyBuilder
161+
return formBodyBuilder.build()
160162
}
161163

162164
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> {
163165
val requestUri = buildRequestUri(client.baseUri)
164166

165-
val formBodyBuilder = createFormBodyBuilder()
166-
167-
val postMethod = PostMethod(URL(requestUri.toString()), formBodyBuilder.build()).apply {
167+
val postMethod = PostMethod(URL(requestUri.toString()), createFormBodyBuilder()).apply {
168168
setRequestHeader(HttpConstants.CONTENT_TYPE_HEADER, HttpConstants.CONTENT_TYPE_URLENCODED_UTF8)
169169
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
170170
}
@@ -173,10 +173,10 @@ class CreateRemoteShareOperation(
173173
val status = client.executeHttpMethod(postMethod)
174174
val response = postMethod.getResponseBodyAsString()
175175

176-
if (!isSuccess(status)) {
177-
onResultUnsuccessful(postMethod, response, status)
178-
} else {
176+
if (isSuccess(status)) {
179177
onRequestSuccessful(response)
178+
} else {
179+
onResultUnsuccessful(postMethod, response, status)
180180
}
181181

182182
} catch (e: Exception) {
@@ -193,7 +193,7 @@ class CreateRemoteShareOperation(
193193
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares"
194194

195195
//Arguments - names
196-
private const val PARAM_FORMAT = "format"
196+
197197
private const val PARAM_NAME = "name"
198198
private const val PARAM_EXPIRATION_DATE = "expireDate"
199199
private const val PARAM_PATH = "path"
@@ -204,7 +204,6 @@ class CreateRemoteShareOperation(
204204
private const val PARAM_PERMISSIONS = "permissions"
205205

206206
//Arguments - constant values
207-
private const val VALUE_FORMAT = "json"
208207
private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"
209208
}
210209
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareOperation.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ package com.owncloud.android.lib.resources.shares
2828
import android.net.Uri
2929
import com.owncloud.android.lib.common.OwnCloudClient
3030
import com.owncloud.android.lib.common.http.HttpConstants
31+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
32+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3133
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3234
import com.owncloud.android.lib.common.operations.RemoteOperation
3335
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -108,15 +110,7 @@ class GetRemoteShareOperation(private val remoteId: String) : RemoteOperation<Sh
108110
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK
109111

110112
companion object {
111-
112113
//OCS Route
113114
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares"
114-
115-
//Arguments - names
116-
private const val PARAM_FORMAT = "format"
117-
118-
//Arguments - constant values
119-
private const val VALUE_FORMAT = "json"
120-
121115
}
122116
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ package com.owncloud.android.lib.resources.shares
3232
import android.net.Uri
3333
import com.owncloud.android.lib.common.OwnCloudClient
3434
import com.owncloud.android.lib.common.http.HttpConstants
35+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
36+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3537
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3638
import com.owncloud.android.lib.common.operations.RemoteOperation
3739
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -136,10 +138,10 @@ class GetRemoteShareesOperation
136138
val status = client.executeHttpMethod(getMethod)
137139
val response = getMethod.getResponseBodyAsString()
138140

139-
if (!isSuccess(status)) {
140-
onResultUnsuccessful(getMethod, response, status)
141-
} else {
141+
if (isSuccess(status)) {
142142
onRequestSuccessful(response)
143+
} else {
144+
onResultUnsuccessful(getMethod, response, status)
143145
}
144146
} catch (e: Exception) {
145147
Timber.e(e, "Exception while getting users/groups")
@@ -155,14 +157,12 @@ class GetRemoteShareesOperation
155157
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/sharees" // from OC 8.2
156158

157159
// Arguments - names
158-
private const val PARAM_FORMAT = "format"
159160
private const val PARAM_ITEM_TYPE = "itemType"
160161
private const val PARAM_SEARCH = "search"
161162
private const val PARAM_PAGE = "page" // default = 1
162163
private const val PARAM_PER_PAGE = "perPage" // default = 200
163164

164165
// Arguments - constant values
165-
private const val VALUE_FORMAT = "json"
166166
private const val VALUE_ITEM_TYPE = "file" // to get the server search for users / groups
167167
}
168168
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ package com.owncloud.android.lib.resources.shares
3131
import android.net.Uri
3232
import com.owncloud.android.lib.common.OwnCloudClient
3333
import com.owncloud.android.lib.common.http.HttpConstants
34+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
35+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3436
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
3537
import com.owncloud.android.lib.common.operations.RemoteOperation
3638
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -125,10 +127,10 @@ class GetRemoteSharesForFileOperation(
125127
val status = client.executeHttpMethod(getMethod)
126128
val response = getMethod.getResponseBodyAsString()
127129

128-
if (!isSuccess(status)) {
129-
onResultUnsuccessful(getMethod, response, status)
130-
} else {
130+
if (isSuccess(status)) {
131131
onRequestSuccessful(response)
132+
} else {
133+
onResultUnsuccessful(getMethod, response, status)
132134
}
133135
} catch (e: Exception) {
134136
Timber.e(e, "Exception while getting remote shares for file operation")
@@ -144,13 +146,8 @@ class GetRemoteSharesForFileOperation(
144146
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares"
145147

146148
//Arguments - names
147-
private const val PARAM_FORMAT = "format"
148149
private const val PARAM_PATH = "path"
149150
private const val PARAM_RESHARES = "reshares"
150151
private const val PARAM_SUBFILES = "subfiles"
151-
152-
//Arguments - constant values
153-
private const val VALUE_FORMAT = "json"
154-
155152
}
156153
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoveRemoteShareOperation.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ package com.owncloud.android.lib.resources.shares
3131
import android.net.Uri
3232
import com.owncloud.android.lib.common.OwnCloudClient
3333
import com.owncloud.android.lib.common.http.HttpConstants
34+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
35+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3436
import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod
3537
import com.owncloud.android.lib.common.operations.RemoteOperation
3638
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -112,10 +114,10 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
112114
val status = client.executeHttpMethod(deleteMethod)
113115
val response = deleteMethod.getResponseBodyAsString()
114116

115-
if (!isSuccess(status)) {
116-
onResultUnsuccessful(deleteMethod, response, status)
117-
} else {
117+
if (isSuccess(status)) {
118118
onRequestSuccessful(response)
119+
} else {
120+
onResultUnsuccessful(deleteMethod, response, status)
119121
}
120122
} catch (e: Exception) {
121123
Timber.e(e, "Exception while unshare link")
@@ -126,15 +128,7 @@ class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOper
126128
private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK
127129

128130
companion object {
129-
130131
//OCS Route
131132
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares"
132-
133-
//Arguments - names
134-
private const val PARAM_FORMAT = "format"
135-
136-
//Arguments - constant values
137-
private const val VALUE_FORMAT = "json"
138-
139133
}
140134
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ package com.owncloud.android.lib.resources.shares
3131
import android.net.Uri
3232
import com.owncloud.android.lib.common.OwnCloudClient
3333
import com.owncloud.android.lib.common.http.HttpConstants
34+
import com.owncloud.android.lib.common.http.HttpConstants.PARAM_FORMAT
35+
import com.owncloud.android.lib.common.http.HttpConstants.VALUE_FORMAT
3436
import com.owncloud.android.lib.common.http.methods.nonwebdav.PutMethod
3537
import com.owncloud.android.lib.common.operations.RemoteOperation
3638
import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -208,10 +210,10 @@ class UpdateRemoteShareOperation
208210
val status = client.executeHttpMethod(putMethod)
209211
val response = putMethod.getResponseBodyAsString()
210212

211-
if (!isSuccess(status)) {
212-
onResultUnsuccessful(putMethod, response, status)
213-
} else {
213+
if (isSuccess(status)) {
214214
onRequestSuccessful(response)
215+
} else {
216+
onResultUnsuccessful(putMethod, response, status)
215217
}
216218
} catch (e: Exception) {
217219
Timber.e(e, "Exception while updating remote share")
@@ -227,15 +229,13 @@ class UpdateRemoteShareOperation
227229
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/shares"
228230

229231
//Arguments - names
230-
private const val PARAM_FORMAT = "format"
231232
private const val PARAM_NAME = "name"
232233
private const val PARAM_PASSWORD = "password"
233234
private const val PARAM_EXPIRATION_DATE = "expireDate"
234235
private const val PARAM_PERMISSIONS = "permissions"
235236
private const val PARAM_PUBLIC_UPLOAD = "publicUpload"
236237

237238
//Arguments - constant values
238-
private const val VALUE_FORMAT = "json"
239239
private const val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"
240240
private const val INITIAL_EXPIRATION_DATE_IN_MILLIS: Long = 0
241241
}

0 commit comments

Comments
 (0)