Skip to content

Commit

Permalink
Remote operation part2
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Sep 4, 2023
1 parent cb84895 commit 1f8bad5
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 55 deletions.
4 changes: 1 addition & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 29 additions & 44 deletions library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ package com.owncloud.android

import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Response
import at.bitfire.dav4jvm.property.CreationDate
import com.nextcloud.common.NextcloudAuthenticator
import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.utils.WebDavFileUtils
Expand All @@ -39,7 +38,6 @@ import com.owncloud.android.lib.resources.files.SearchRemoteOperation
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
Expand All @@ -59,6 +57,7 @@ class Dav4JVM : AbstractIT() {
@Throws(IOException::class)
fun singlePropfind() {
val path = "/testFolder/"
val subFolder = "$path subfolder/"

// create folder
CreateFolderRemoteOperation(
Expand Down Expand Up @@ -86,9 +85,24 @@ class Dav4JVM : AbstractIT() {
.isSuccess
)

// add one child
// create folder
CreateFolderRemoteOperation(
subFolder,
true
).execute(client).isSuccess

// verify folder
assertTrue(ReadFolderRemoteOperation(subFolder).execute(client).isSuccess)

// do old read folder operation to compare data against it
val result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
assertEquals(2, result.size)
val oldRemoteFile = result[0]
val oldSubFolderFile = result[1]

assertEquals(path, oldRemoteFile.remotePath)
assertEquals(subFolder, oldSubFolderFile.remotePath)

// new
val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl()
Expand All @@ -109,6 +123,8 @@ class Dav4JVM : AbstractIT() {
WebdavUtils.registerCustomFactories()

// TODO use DavResource().propfind in ReadFileRemoteOperation/ReadFolderRemoteOperation
// TODO extract in own class for convenient use
// TODO test all properties on server!
DavResource(client, httpUrl)
.propfind(
DavConstants.DEPTH_1,
Expand All @@ -125,49 +141,11 @@ class Dav4JVM : AbstractIT() {

assertTrue(davResponse?.isSuccess() == true)
assertTrue(rootElement != null)
assertEquals(0, memberElements.size)
assertEquals(1, memberElements.size)

val remoteFile = WebDavFileUtils().parseResponse(rootElement, nextcloudClient.filesDavUri)

val date = davResponse?.get(CreationDate::class.java)
assertEquals(
oldRemoteFile.creationTimestamp,
(WebdavUtils.parseResponseDate(date?.creationDate)?.time ?: 0) / 1000
)

assertTrue(oldRemoteFile.isFavorite)
val favorite = davResponse?.get(NCFavorite::class.java)
assertTrue(favorite?.isOcFavorite == true)

assertEquals(oldRemoteFile.remotePath, remoteFile.remotePath)
assertEquals(oldRemoteFile.mimeType, remoteFile.mimeType)
assertEquals(oldRemoteFile.length, remoteFile.length)
assertEquals(oldRemoteFile.creationTimestamp, remoteFile.creationTimestamp)
// assertEquals(oldRemoteFile.modifiedTimestamp, remoteFile.modifiedTimestamp)
assertEquals(oldRemoteFile.uploadTimestamp, remoteFile.uploadTimestamp)
assertEquals(oldRemoteFile.etag, remoteFile.etag)
assertEquals(oldRemoteFile.permissions, remoteFile.permissions)
assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId)
assertEquals(oldRemoteFile.size, remoteFile.size)
assertEquals(oldRemoteFile.isFavorite, remoteFile.isFavorite)
assertEquals(oldRemoteFile.isEncrypted, remoteFile.isEncrypted)
assertEquals(oldRemoteFile.mountType, remoteFile.mountType)
assertEquals(oldRemoteFile.ownerId, remoteFile.ownerId)
assertEquals(oldRemoteFile.ownerDisplayName, remoteFile.ownerDisplayName)
assertEquals(oldRemoteFile.unreadCommentsCount, remoteFile.unreadCommentsCount)
assertEquals(oldRemoteFile.isHasPreview, remoteFile.isHasPreview)
assertEquals(oldRemoteFile.note, remoteFile.note)
assertEquals(oldRemoteFile.sharees.size, remoteFile.sharees.size)
assertEquals(oldRemoteFile.richWorkspace, remoteFile.richWorkspace)
assertEquals(oldRemoteFile.isLocked, remoteFile.isLocked)
assertEquals(oldRemoteFile.lockType, remoteFile.lockType)
assertEquals(oldRemoteFile.lockOwner, remoteFile.lockOwner)
assertEquals(oldRemoteFile.lockOwnerDisplayName, remoteFile.lockOwnerDisplayName)
assertEquals(oldRemoteFile.lockTimestamp, remoteFile.lockTimestamp)
assertEquals(oldRemoteFile.lockOwnerEditor, remoteFile.lockOwnerEditor)
assertEquals(oldRemoteFile.lockTimeout, remoteFile.lockTimeout)
assertEquals(oldRemoteFile.lockToken, remoteFile.lockToken)
assertEquals(oldRemoteFile.localId, remoteFile.localId)
assertTrue(oldRemoteFile == remoteFile)
}

@Test
Expand Down Expand Up @@ -213,7 +191,11 @@ class Dav4JVM : AbstractIT() {
assertEquals(2, ror.resultData.size)

val oldRemoteFile = ror.resultData[0]
assertEquals(path, oldRemoteFile.remotePath)

assertTrue(
path == ror.resultData[0].remotePath ||
path == ror.resultData[1].remotePath
)

ror = SearchRemoteOperation(
"test",
Expand All @@ -228,7 +210,10 @@ class Dav4JVM : AbstractIT() {
assertEquals(2, ror.resultData.size)

val remoteFile = ror.resultData[0]
assertEquals(path, remoteFile.remotePath)
assertTrue(
path == ror.resultData[0].remotePath ||
path == ror.resultData[1].remotePath
)

assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.nextcloud.talk.components.filebrowser.models.properties.OCSize;
import com.owncloud.android.lib.resources.files.webdav.NCEtag;
import com.owncloud.android.lib.resources.files.webdav.NCFavorite;
import com.owncloud.android.lib.resources.files.webdav.NCGetLastModified;
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;
Expand All @@ -61,7 +62,6 @@
import at.bitfire.dav4jvm.property.GetContentLength;
import at.bitfire.dav4jvm.property.GetContentType;
import at.bitfire.dav4jvm.property.GetETag;
import at.bitfire.dav4jvm.property.GetLastModified;
import at.bitfire.dav4jvm.property.ResourceType;

public class WebdavUtils {
Expand Down Expand Up @@ -165,7 +165,7 @@ public static Property.Name[] getAllPropertiesList() {
list.add(GetContentType.NAME);
list.add(ResourceType.NAME);
list.add(GetContentLength.NAME);
list.add(GetLastModified.NAME);
list.add(NCGetLastModified.NAME);
list.add(CreationDate.NAME);
list.add(GetETag.NAME); // list.add(NCEtag.NAME);
list.add(NCPermissions.NAME);
Expand Down Expand Up @@ -330,6 +330,7 @@ public static String getEtagFromResponse(HttpMethod method) {
public static void registerCustomFactories() {
List<PropertyFactory> list = new ArrayList<>();
list.add(new NCFavorite.Factory());
list.add(new NCGetLastModified.Factory());
list.add(new NCEtag.Factory());
list.add(new NCPermissions.Factory());
list.add(new OCId.Factory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.files.webdav.NCEtag;
import com.owncloud.android.lib.resources.files.webdav.NCFavorite;
import com.owncloud.android.lib.resources.files.webdav.NCGetLastModified;
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;
Expand All @@ -51,7 +52,6 @@
import at.bitfire.dav4jvm.Property;
import at.bitfire.dav4jvm.Response;
import at.bitfire.dav4jvm.property.GetContentType;
import at.bitfire.dav4jvm.property.GetLastModified;
import at.bitfire.dav4jvm.property.ResourceType;
import okhttp3.MediaType;

Expand Down Expand Up @@ -121,8 +121,8 @@ public RemoteFile parseResponse(Response response, Uri filesDavUri) {
remoteFile.setFavorite(((NCFavorite) property).isOcFavorite());
}

if (property instanceof GetLastModified) {
remoteFile.setModifiedTimestamp(((GetLastModified) property).getLastModified());
if (property instanceof NCGetLastModified) {
remoteFile.setModifiedTimestamp(((NCGetLastModified) property).getLastModified());
}

if (property instanceof GetContentType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class NCFavorite internal constructor(var isOcFavorite: Boolean) : Property {
return NCFavorite(false)
}

override fun getName(): Property.Name {
return NAME
}
override fun getName() = NAME
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
*/

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

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlUtils
import com.owncloud.android.lib.common.network.WebdavUtils
import org.xmlpull.v1.XmlPullParser

class NCGetLastModified internal constructor(var lastModified: Long) : Property {

class Factory : PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): NCGetLastModified? {
// <!ELEMENT getlastmodified (#PCDATA) >
XmlUtils.readText(parser)?.let { rawDate ->
val date = WebdavUtils.parseResponseDate(rawDate)
if (date != null) {
return NCGetLastModified(date.time)
} else {
0
}
}
return null
}
}

companion object {
@JvmField
val NAME = Property.Name(XmlUtils.NS_WEBDAV, "getlastmodified")
}
}

0 comments on commit 1f8bad5

Please sign in to comment.