@@ -5,6 +5,7 @@ import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory
5
5
import com.owncloud.android.lib.common.http.HttpConstants
6
6
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod
7
7
import com.owncloud.android.lib.common.operations.RemoteOperationResult
8
+ import com.owncloud.android.lib.resources.files.CheckPathExistenceRemoteOperation
8
9
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
9
10
import com.owncloud.android.lib.resources.status.RemoteServerInfo
10
11
import org.apache.commons.lang3.exception.ExceptionUtils
@@ -15,7 +16,7 @@ class ConnectionValidator (
15
16
val clearCookiesOnValidation : Boolean
16
17
){
17
18
18
- fun validate (method : HttpBaseMethod , baseClient : OwnCloudClient ): Boolean {
19
+ fun validate (baseClient : OwnCloudClient ): Boolean {
19
20
try {
20
21
var validationRetryCount = 0
21
22
val client = OwnCloudClient (baseClient.baseUri, null , false )
@@ -26,27 +27,28 @@ class ConnectionValidator (
26
27
}
27
28
28
29
client.credentials = baseClient.credentials
29
- client.setFollowRedirects(true )
30
30
while (validationRetryCount < 5 ) {
31
31
var successCounter = 0
32
32
var failCounter = 0
33
33
34
+ client.setFollowRedirects(true )
34
35
if (isOnwCloudStatusOk(client)) {
35
36
successCounter++
36
37
} else {
37
38
failCounter++
38
39
}
39
40
40
- val contentReply = accessRootFolder()
41
- if (contentReply == HttpConstants .HTTP_OK ) {
42
- if (isRootFolderOk(contentReply)) {
41
+ client.setFollowRedirects(false )
42
+ val contentReply = canAccessRootFolder(client)
43
+ if (contentReply.httpCode == HttpConstants .HTTP_OK ) {
44
+ if (contentReply.data == true ) { // if data is true it means that the content reply was ok
43
45
successCounter++
44
46
} else {
45
47
failCounter++
46
48
}
47
49
} else {
48
50
failCounter++
49
- if (contentReply == HttpConstants .HTTP_UNAUTHORIZED ) {
51
+ if (contentReply.hashCode() == HttpConstants .HTTP_UNAUTHORIZED ) {
50
52
triggerAuthRefresh()
51
53
}
52
54
}
@@ -64,39 +66,24 @@ class ConnectionValidator (
64
66
}
65
67
66
68
private fun isOnwCloudStatusOk (client : OwnCloudClient ): Boolean {
67
- // TODO: Implement me
68
69
val reply = getOwnCloudStatus(client)
69
- return if (reply.httpCode == HttpConstants .HTTP_OK ) {
70
- isOCStatusReplyValid(reply.data)
71
- } else {
72
- false
73
- }
70
+ return reply.httpCode == HttpConstants .HTTP_OK &&
71
+ ! reply.isException &&
72
+ reply.data != null
74
73
}
75
74
76
75
private fun getOwnCloudStatus (client : OwnCloudClient ): RemoteOperationResult <RemoteServerInfo > {
77
76
val remoteStatusOperation = GetRemoteStatusOperation ()
78
- // TODO: follow redirects only 5 times
79
77
return remoteStatusOperation.execute(client)
80
78
}
81
79
82
- private fun isOCStatusReplyValid (info : RemoteServerInfo ): Boolean {
83
- // TODO: Implement me
84
- Timber .d(" owncloud version %s" , info.ownCloudVersion.version)
85
- return true
86
- }
87
-
88
80
private fun triggerAuthRefresh (): OwnCloudCredentials {
89
81
// TODO: Implement me
90
82
return OwnCloudCredentialsFactory .getAnonymousCredentials()
91
83
}
92
84
93
- private fun accessRootFolder (): Int {
94
- // TODO: Implement me
95
- return 55
96
- }
97
-
98
- private fun isRootFolderOk (content : Int ): Boolean {
99
- // TODO: Implement me
100
- return true
85
+ private fun canAccessRootFolder (client : OwnCloudClient ): RemoteOperationResult <Boolean > {
86
+ val checkPathExistenceRemoteOperation = CheckPathExistenceRemoteOperation (" /" , true )
87
+ return checkPathExistenceRemoteOperation.execute(client)
101
88
}
102
89
}
0 commit comments