From c67481289e10c9b195782d07d89b0a64a96df5ba Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 14 Oct 2022 07:00:57 +0200 Subject: [PATCH] Add remaining dav4jvm methods: SEARCH and PROPPATCH Add first tests for PROPFIND Signed-off-by: tobiasKaminsky --- library/build.gradle | 2 +- .../android/{Dav4JVMtest.kt => Dav4JVM.kt} | 63 ++++++--- .../com/nextcloud/operations/SearchMethod.kt | 11 +- .../lib/common/network/WebdavUtils.java | 3 + .../lib/common/utils/WebDavFileUtils.java | 5 + .../lib/resources/files/webdav/NCEtag.kt | 8 +- .../lib/resources/files/webdav/NCFavorite.kt | 8 +- .../lib/resources/files/webdav/NCMountType.kt | 8 +- .../resources/files/webdav/NCPermissions.kt | 8 +- .../resources/files/webdav/NCRichWorkspace.kt | 8 +- .../lib/resources/files/webdav/NCSharee.kt | 121 ++++++++++++++++++ .../lib/resources/shares/ShareeUser.kt | 3 +- settings.gradle | 6 - 13 files changed, 204 insertions(+), 50 deletions(-) rename library/src/androidTest/java/com/owncloud/android/{Dav4JVMtest.kt => Dav4JVM.kt} (84%) create mode 100644 library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt diff --git a/library/build.gradle b/library/build.gradle index 4c1e02af4b..a03e7c0d58 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -50,7 +50,7 @@ configurations { dependencies { implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' api 'com.squareup.okhttp3:okhttp:5.0.0-alpha.10' - implementation 'com.github.bitfireAT:dav4jvm:2.1.4' + implementation 'com.github.tobiasKaminsky:dav4jvm:addSearch-SNAPSHOT' // in transition phase, we use old and new libs implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.1' implementation 'androidx.annotation:annotation:1.5.0' diff --git a/library/src/androidTest/java/com/owncloud/android/Dav4JVMtest.kt b/library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt similarity index 84% rename from library/src/androidTest/java/com/owncloud/android/Dav4JVMtest.kt rename to library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt index ac0a52dec6..cb2c73b622 100644 --- a/library/src/androidTest/java/com/owncloud/android/Dav4JVMtest.kt +++ b/library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android @@ -35,6 +35,9 @@ import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation import com.owncloud.android.lib.resources.files.model.RemoteFile import com.owncloud.android.lib.resources.files.webdav.NCFavorite +import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation +import com.owncloud.android.lib.resources.shares.OCShare +import com.owncloud.android.lib.resources.shares.ShareType import com.owncloud.android.lib.resources.status.OCCapability import okhttp3.HttpUrl.Companion.toHttpUrl import org.apache.jackrabbit.webdav.DavConstants @@ -43,7 +46,10 @@ import org.junit.Assert.assertTrue import org.junit.Test import java.io.IOException -class Dav4JVMtest : AbstractIT() { +/* +can be removed after fully switching to dav4jvm as other tests should cover it + */ +class Dav4JVM : AbstractIT() { @Test @Throws(IOException::class) fun singlePropfind() { @@ -61,6 +67,20 @@ class Dav4JVMtest : AbstractIT() { // add favorite assertTrue(ToggleFavoriteRemoteOperation(true, path).execute(client).isSuccess) + // share it + assertTrue( + CreateShareRemoteOperation( + path, + ShareType.USER, + "admin", + false, + "", + OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER, + true + ).execute(client) + .isSuccess + ) + // do old read folder operation to compare data against it val result = ReadFolderRemoteOperation(path).execute(client).data as List val oldRemoteFile = result[0] @@ -131,7 +151,7 @@ class Dav4JVMtest : AbstractIT() { assertEquals(oldRemoteFile.unreadCommentsCount, remoteFile.unreadCommentsCount) assertEquals(oldRemoteFile.isHasPreview, remoteFile.isHasPreview) assertEquals(oldRemoteFile.note, remoteFile.note) - //assertEquals(oldRemoteFile.sharees, remoteFile.sharees) + assertEquals(oldRemoteFile.sharees.size, remoteFile.sharees.size) assertEquals(oldRemoteFile.richWorkspace, remoteFile.richWorkspace) assertEquals(oldRemoteFile.isLocked, remoteFile.isLocked) assertEquals(oldRemoteFile.lockType, remoteFile.lockType) @@ -142,8 +162,6 @@ class Dav4JVMtest : AbstractIT() { assertEquals(oldRemoteFile.lockTimeout, remoteFile.lockTimeout) assertEquals(oldRemoteFile.lockToken, remoteFile.lockToken) assertEquals(oldRemoteFile.localId, remoteFile.localId) - - // assertEquals(oldRemoteFile, remoteFile) } @Test @@ -151,12 +169,12 @@ class Dav4JVMtest : AbstractIT() { val path = "/testFolder/" // create folder - // assertTrue( - CreateFolderRemoteOperation( - path, - true - ).execute(client).isSuccess - // ) + assertTrue( + CreateFolderRemoteOperation( + path, + true + ).execute(client).isSuccess + ) // create file val filePath = createFile("text") @@ -210,7 +228,20 @@ class Dav4JVMtest : AbstractIT() { } @Test - fun proppatch() { - assertTrue(false) + fun propPatch() { + val path = "/testFolder/" + + // create folder + assertTrue(CreateFolderRemoteOperation(path, true).execute(client).isSuccess) + + // make it favorite + assertTrue( + ToggleFavoriteRemoteOperation(true, path).execute(nextcloudClient).isSuccess + ) + + val result = ReadFolderRemoteOperation(path).execute(client) + assertTrue(result.isSuccess) + val list = result.data as List + assertTrue(list[0].isFavorite) } } diff --git a/library/src/main/java/com/nextcloud/operations/SearchMethod.kt b/library/src/main/java/com/nextcloud/operations/SearchMethod.kt index 82f3513a77..6a3dec59be 100644 --- a/library/src/main/java/com/nextcloud/operations/SearchMethod.kt +++ b/library/src/main/java/com/nextcloud/operations/SearchMethod.kt @@ -4,23 +4,22 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.nextcloud.operations -class SearchMethod { -} +class SearchMethod diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java index 72563328dd..e09147dcd4 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java @@ -38,6 +38,7 @@ import com.owncloud.android.lib.resources.files.webdav.NCMountType; import com.owncloud.android.lib.resources.files.webdav.NCPermissions; import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace; +import com.owncloud.android.lib.resources.files.webdav.NCSharee; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethod; @@ -178,6 +179,7 @@ public static Property.Name[] getAllPropertiesList() { list.add(CreationDate.NAME); list.add(GetETag.NAME); list.add(ResourceType.NAME); + list.add(NCSharee.NAME); // list.add(NCPermission.NAME); // list.add(OCId.NAME); @@ -332,6 +334,7 @@ public static void registerCustomFactories() { list.add(new OCOwnerId.Factory()); list.add(new OCOwnerDisplayName.Factory()); list.add(new NCRichWorkspace.Factory()); + list.add(new NCSharee.Factory()); PropertyRegistry.INSTANCE.register(list); } diff --git a/library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java b/library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java index c5b42f2a6f..b6c3f90b0e 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java +++ b/library/src/main/java/com/owncloud/android/lib/common/utils/WebDavFileUtils.java @@ -40,6 +40,7 @@ import com.owncloud.android.lib.resources.files.webdav.NCMountType; import com.owncloud.android.lib.resources.files.webdav.NCPermissions; import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace; +import com.owncloud.android.lib.resources.files.webdav.NCSharee; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; @@ -160,6 +161,10 @@ public RemoteFile parseResponse(Response response, Uri filesDavUri) { if (property instanceof NCRichWorkspace) { remoteFile.setRichWorkspace(((NCRichWorkspace) property).getRichWorkspace()); } + + if (property instanceof NCSharee) { + remoteFile.setSharees(((NCSharee) property).getSharees()); + } } remoteFile.setRemotePath(path); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt index e6e3b72950..ba81292cd8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android.lib.resources.files.webdav diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt index f5062aa961..cb58625a8c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android.lib.resources.files.webdav diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt index 50c78bbf10..b075431774 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android.lib.resources.files.webdav diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt index be6b5763d6..c6a0493a5f 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android.lib.resources.files.webdav diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt index 1aedfc876a..c335a4220c 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt @@ -4,20 +4,20 @@ * @author Tobias Kaminsky * Copyright (C) 2022 Tobias Kaminsky * Copyright (C) 2022 Nextcloud GmbH - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * + * */ package com.owncloud.android.lib.resources.files.webdav diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt new file mode 100644 index 0000000000..56c5961ccb --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt @@ -0,0 +1,121 @@ +/* + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 Nextcloud GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.lib.resources.files.webdav + +import androidx.annotation.VisibleForTesting +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.propertyName +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.resources.shares.ShareType +import com.owncloud.android.lib.resources.shares.ShareeUser +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCSharee internal constructor(var sharees: Array) : Property { + + companion object { + @JvmField + val NAME = + Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_SHAREES) + } + + class Factory : PropertyFactory { + + override fun getName() = NAME + + override fun create(parser: XmlPullParser): NCSharee { + // NC sharees property + readArrayNode(parser).let { sharees -> + return NCSharee(sharees.toTypedArray()) + } + } + + @Throws(IOException::class, XmlPullParserException::class) + @VisibleForTesting + fun readArrayNode(parser: XmlPullParser): List { + var list: List = emptyList() + + val depth = parser.depth + var eventType = parser.eventType + while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + if (eventType != XmlPullParser.TEXT) { + list = readNCSharees(parser) + } + if (parser.eventType == XmlPullParser.END_TAG && parser.depth == depth) { + return list + } + + eventType = parser.next() + } + + return list + } + + private fun readNCSharees(parser: XmlPullParser): List { + val list: ArrayList = ArrayList() + + val depth = parser.depth + var eventType = parser.eventType + while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) { + list.add(readNCSharee(parser)) + } + + eventType = parser.next() + } + + return list + } + + private fun readNCSharee(parser: XmlPullParser): ShareeUser { + val depth = parser.depth + var eventType = parser.eventType + + val shareeUser = ShareeUser(null, null, null) + + while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + if (eventType != XmlPullParser.TEXT) { + when (parser.propertyName().toString()) { + "http://nextcloud.org/ns:id" -> { + shareeUser.userId = readText(parser) + } + "http://nextcloud.org/ns:display-name" -> { + shareeUser.displayName = readText(parser) + } + "http://nextcloud.org/ns:type" -> { + shareeUser.shareType = + ShareType.fromValue(readText(parser)?.toInt() ?: 0) + } + } + } + + eventType = parser.next() + } + + return shareeUser + } + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareeUser.kt b/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareeUser.kt index 3283751016..3302c156e8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareeUser.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/shares/ShareeUser.kt @@ -30,4 +30,5 @@ import android.os.Parcelable import kotlinx.parcelize.Parcelize @Parcelize -data class ShareeUser(val userId: String?, val displayName: String?, val shareType: ShareType?) : Parcelable +data class ShareeUser(var userId: String?, var displayName: String?, var shareType: ShareType?) : + Parcelable diff --git a/settings.gradle b/settings.gradle index a0ca01735c..eaae9a3945 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,2 @@ include ':library' include ':sample_client' - -includeBuild('/home/tobi/projekt/github/bitfireAT/dav4jvm/') { - dependencySubstitution { - substitute module('com.github.bitfireAT:dav4jvm') using project(':') - } -}