Skip to content

Commit 074035e

Browse files
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent b001071 commit 074035e

File tree

20 files changed

+397
-138
lines changed

20 files changed

+397
-138
lines changed

Diff for: dav4jvm

-1
This file was deleted.

Diff for: library/src/androidTest/java/com/owncloud/android/AbstractIT.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public static void beforeAll() throws InterruptedException,
128128
String userId = loginName; // for test same as userId
129129
String credentials = Credentials.basic(loginName, password);
130130
nextcloudClient = new NextcloudClient(url, userId, credentials, context);
131-
nextcloudClient.setUserId(userId);
132131

133132
waitForServer(client, url);
134133
testConnection();
@@ -280,8 +279,8 @@ public static File extractAsset(String fileName, Context context) throws IOExcep
280279

281280
@After
282281
public void after() {
283-
// removeOnClient(client);
284-
// removeOnClient(client2);
282+
removeOnClient(client);
283+
removeOnClient(client2);
285284
}
286285

287286
private void removeOnClient(OwnCloudClient client) {

Diff for: library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt

+41-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ import at.bitfire.dav4jvm.DavResource
3131
import at.bitfire.dav4jvm.Response
3232
import com.nextcloud.common.NextcloudAuthenticator
3333
import com.nextcloud.operations.PropFindMethod
34+
import com.nextcloud.test.RandomStringGenerator
3435
import com.owncloud.android.lib.common.network.WebdavUtils
3536
import com.owncloud.android.lib.common.utils.WebDavFileUtils
3637
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
3738
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation
39+
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperationIT
3840
import com.owncloud.android.lib.resources.files.SearchRemoteOperation
3941
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation
4042
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
@@ -43,6 +45,9 @@ import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation
4345
import com.owncloud.android.lib.resources.shares.OCShare
4446
import com.owncloud.android.lib.resources.shares.ShareType
4547
import com.owncloud.android.lib.resources.status.OCCapability
48+
import com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation
49+
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation
50+
import com.owncloud.android.lib.resources.tags.PutTagRemoteOperation
4651
import okhttp3.HttpUrl.Companion.toHttpUrl
4752
import org.apache.jackrabbit.webdav.DavConstants
4853
import org.junit.Assert.assertEquals
@@ -97,14 +102,35 @@ class Dav4JVM : AbstractIT() {
97102
assertTrue(ReadFolderRemoteOperation(subFolder).execute(client).isSuccess)
98103

99104
// do old read folder operation to compare data against it
100-
val result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
105+
var result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
101106
assertEquals(2, result.size)
102-
val oldRemoteFile = result[0]
103-
val oldSubFolderFile = result[1]
107+
var oldRemoteFile = result[0]
108+
var oldSubFolderFile = result[1]
104109

105110
assertEquals(path, oldRemoteFile.remotePath)
106111
assertEquals(subFolder, oldSubFolderFile.remotePath)
107112

113+
// create tag
114+
val tag1 = "a" + RandomStringGenerator.make(ReadFolderRemoteOperationIT.TAG_LENGTH)
115+
assertTrue(CreateTagRemoteOperation(tag1).execute(nextcloudClient).isSuccess)
116+
117+
// list tags
118+
val tags = GetTagsRemoteOperation().execute(client).resultData
119+
120+
// add tag
121+
assertTrue(
122+
PutTagRemoteOperation(
123+
tags[0].id,
124+
oldRemoteFile.localId
125+
).execute(nextcloudClient).isSuccess
126+
)
127+
128+
// do old read folder operation to compare data against it
129+
result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
130+
assertEquals(2, result.size)
131+
oldRemoteFile = result[0]
132+
oldSubFolderFile = result[1]
133+
108134
// new
109135
val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl()
110136

@@ -117,10 +143,11 @@ class Dav4JVM : AbstractIT() {
117143
val client = nextcloudClient.client
118144
.newBuilder()
119145
.followRedirects(false)
120-
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials, "Authorization"))
146+
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials))
121147
.build()
122148

123149
// register custom property
150+
// TODO check how to do it in a central way
124151
WebdavUtils.registerCustomFactories()
125152

126153
// TODO use DavResource().propfind in ReadFileRemoteOperation/ReadFolderRemoteOperation
@@ -194,7 +221,11 @@ class Dav4JVM : AbstractIT() {
194221
"test",
195222
SearchRemoteOperation.SearchType.FILE_SEARCH,
196223
false,
197-
OCCapability(23, 0, 0)
224+
OCCapability().apply {
225+
versionMayor = 23
226+
versionMinor = 0
227+
versionMicro = 0
228+
}
198229
).execute(
199230
client
200231
)
@@ -213,7 +244,11 @@ class Dav4JVM : AbstractIT() {
213244
"test",
214245
SearchRemoteOperation.SearchType.FILE_SEARCH,
215246
false,
216-
OCCapability(23, 0, 0)
247+
OCCapability().apply {
248+
versionMayor = 23
249+
versionMinor = 0
250+
versionMicro = 0
251+
}
217252
).execute(
218253
nextcloudClient
219254
)

Diff for: library/src/main/java/com/nextcloud/common/NextcloudAuthenticator.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
import okhttp3.Route;
3737

3838
public class NextcloudAuthenticator implements Authenticator {
39-
private String credentials;
40-
private String authenticatorType;
39+
private final String credentials;
4140

42-
public NextcloudAuthenticator(@NonNull String credentials, @NonNull String authenticatorType) {
41+
public NextcloudAuthenticator(@NonNull String credentials) {
4342
this.credentials = credentials;
44-
this.authenticatorType = authenticatorType;
4543
}
4644

4745
@Nullable
4846
@Override
4947
public Request authenticate(@Nullable Route route, @NonNull Response response) {
48+
String authenticatorType = "Authorization";
49+
5050
if (response.request().header(authenticatorType) != null) {
5151
return null;
5252
}

Diff for: library/src/main/java/com/nextcloud/common/NextcloudClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class NextcloudClient private constructor(
122122
return client
123123
.newBuilder()
124124
.followRedirects(false)
125-
.authenticator(NextcloudAuthenticator(credentials, "Authorization"))
125+
.authenticator(NextcloudAuthenticator(credentials))
126126
.build()
127127
}
128128

Diff for: library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
511511
}
512512

513513
val isDirectory: Boolean
514-
get() = "DIR" == contentType
514+
get() = DIR_TYPE == contentType
515515

516516
private fun resetData() {
517517
permissions = null
@@ -532,6 +532,8 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
532532

533533
companion object {
534534
private val TAG = WebdavEntry::class.java.simpleName
535+
private const val IS_ENCRYPTED = "1"
536+
private const val CODE_PROP_NOT_FOUND = 404
535537
const val NAMESPACE_OC = "http://owncloud.org/ns"
536538
const val NAMESPACE_NC = "http://nextcloud.org/ns"
537539
const val EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"
@@ -569,7 +571,6 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
569571
const val SHAREES_SHARE_TYPE = "type"
570572
const val PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"
571573
const val PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"
572-
private const val IS_ENCRYPTED = "1"
573-
private const val CODE_PROP_NOT_FOUND = 404
574+
const val DIR_TYPE = "DIR"
574575
}
575576
}

Diff for: library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929

3030
import androidx.annotation.Nullable;
3131

32-
import com.nextcloud.talk.components.filebrowser.models.properties.OCId;
33-
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerDisplayName;
34-
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerId;
35-
import com.nextcloud.talk.components.filebrowser.models.properties.OCSize;
3632
import com.owncloud.android.lib.resources.files.webdav.NCEtag;
3733
import com.owncloud.android.lib.resources.files.webdav.NCFavorite;
3834
import com.owncloud.android.lib.resources.files.webdav.NCGetLastModified;
3935
import com.owncloud.android.lib.resources.files.webdav.NCMountType;
4036
import com.owncloud.android.lib.resources.files.webdav.NCPermissions;
4137
import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace;
4238
import com.owncloud.android.lib.resources.files.webdav.NCSharee;
39+
import com.owncloud.android.lib.resources.files.webdav.NCTags;
40+
import com.owncloud.android.lib.resources.files.webdav.OCId;
41+
import com.owncloud.android.lib.resources.files.webdav.OCLocalId;
42+
import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName;
43+
import com.owncloud.android.lib.resources.files.webdav.OCOwnerId;
44+
import com.owncloud.android.lib.resources.files.webdav.OCSize;
4345

4446
import org.apache.commons.httpclient.Header;
4547
import org.apache.commons.httpclient.HttpMethod;
@@ -159,6 +161,7 @@ public static DavPropertyNameSet getAllPropSet() {
159161
}
160162

161163
public static Property.Name[] getAllPropertiesList() {
164+
// TODO re-enable all
162165
List<Property.Name> list = new ArrayList<>();
163166

164167
list.add(DisplayName.NAME);
@@ -169,6 +172,7 @@ public static Property.Name[] getAllPropertiesList() {
169172
list.add(CreationDate.NAME);
170173
list.add(GetETag.NAME); // list.add(NCEtag.NAME);
171174
list.add(NCPermissions.NAME);
175+
list.add(OCLocalId.NAME);
172176
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace);
173177
list.add(OCSize.NAME);
174178
list.add(NCFavorite.NAME);
@@ -191,6 +195,9 @@ public static Property.Name[] getAllPropertiesList() {
191195
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIME, ncNamespace);
192196
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace);
193197
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
198+
list.add(NCTags.NAME);
199+
// metadata size
200+
// metadata gps
194201
list.add(OCId.NAME); // what about this?
195202

196203
return list.toArray(new Property.Name[0]);
@@ -340,6 +347,8 @@ public static void registerCustomFactories() {
340347
list.add(new OCOwnerDisplayName.Factory());
341348
list.add(new NCRichWorkspace.Factory());
342349
list.add(new NCSharee.Factory());
350+
list.add(new NCTags.Factory());
351+
list.add(new OCLocalId.Factory());
343352

344353
PropertyRegistry.INSTANCE.register(list);
345354
}

Diff for: library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperation.java

-14
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,4 @@ public void run() {
444444
});
445445
}
446446
}
447-
448-
449-
/**
450-
* Returns the current client instance to access the remote server.
451-
*
452-
* @return Current client instance to access the remote server.
453-
*/
454-
public final OwnCloudClient getClient() {
455-
return mClient;
456-
}
457-
458-
public final NextcloudClient getClientNew() {
459-
return clientNew;
460-
}
461447
}

Diff for: library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
import android.net.Uri;
3131

32-
import com.nextcloud.talk.components.filebrowser.models.properties.OCId;
33-
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerDisplayName;
34-
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerId;
35-
import com.nextcloud.talk.components.filebrowser.models.properties.OCSize;
3632
import com.owncloud.android.lib.common.network.WebdavEntry;
3733
import com.owncloud.android.lib.resources.files.model.RemoteFile;
3834
import com.owncloud.android.lib.resources.files.webdav.NCEtag;
@@ -42,6 +38,12 @@
4238
import com.owncloud.android.lib.resources.files.webdav.NCPermissions;
4339
import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace;
4440
import com.owncloud.android.lib.resources.files.webdav.NCSharee;
41+
import com.owncloud.android.lib.resources.files.webdav.NCTags;
42+
import com.owncloud.android.lib.resources.files.webdav.OCId;
43+
import com.owncloud.android.lib.resources.files.webdav.OCLocalId;
44+
import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName;
45+
import com.owncloud.android.lib.resources.files.webdav.OCOwnerId;
46+
import com.owncloud.android.lib.resources.files.webdav.OCSize;
4547

4648
import org.apache.jackrabbit.webdav.MultiStatus;
4749
import org.apache.jackrabbit.webdav.MultiStatusResponse;
@@ -153,6 +155,10 @@ public RemoteFile parseResponse(Response response, Uri filesDavUri) {
153155
remoteFile.setSize(((OCSize) property).getOcSize());
154156
}
155157

158+
if (property instanceof OCLocalId) {
159+
remoteFile.setLocalId(((OCLocalId) property).getLocalId());
160+
}
161+
156162
if (property instanceof NCMountType) {
157163
remoteFile.setMountType(((NCMountType) property).getType());
158164
}
@@ -172,6 +178,10 @@ public RemoteFile parseResponse(Response response, Uri filesDavUri) {
172178
if (property instanceof NCSharee) {
173179
remoteFile.setSharees(((NCSharee) property).getSharees());
174180
}
181+
182+
if (property instanceof NCTags) {
183+
remoteFile.setTags(((NCTags) property).getTags());
184+
}
175185
}
176186

177187
remoteFile.setRemotePath(path);

Diff for: library/src/main/java/com/owncloud/android/lib/resources/files/SearchRemoteOperation.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected RemoteOperationResult<List<RemoteFile>> run(OwnCloudClient client) {
129129
Namespace.XMLNS_NAMESPACE,
130130
searchQuery),
131131
searchType,
132-
getClient().getUserIdPlain(),
132+
client.getUserIdPlain(),
133133
timestamp,
134134
limit,
135135
filterOutFiles,
@@ -189,7 +189,7 @@ public RemoteOperationResult run(NextcloudClient client) {
189189
searchMethod = new NcSearchMethod(webDavUrl,
190190
searchInfo,
191191
searchType,
192-
getClientNew().getUserIdPlain(),
192+
client.getUserIdPlain(),
193193
timestamp,
194194
limit,
195195
filterOutFiles,

Diff for: library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPreview.kt

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
/*
2-
* Nextcloud Talk application
1+
/* Nextcloud Android Library is available under MIT license
32
*
4-
* @author Mario Danic
5-
* @author Andy Scherzinger
6-
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
7-
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2022 Tobias Kaminsky
5+
* Copyright (C) 2022 Nextcloud GmbH
86
*
9-
* This program is free software: you can redistribute it and/or modify
10-
* it under the terms of the GNU General Public License as published by
11-
* the Free Software Foundation, either version 3 of the License, or
12-
* at your option) any later version.
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
1313
*
14-
* This program is distributed in the hope that it will be useful,
15-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17-
* GNU General Public License for more details.
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
1825
*
19-
* You should have received a copy of the GNU General Public License
20-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2126
*/
2227

2328
package com.owncloud.android.lib.resources.files.webdav

0 commit comments

Comments
 (0)