Skip to content

Commit

Permalink
wip
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 b001071 commit 074035e
Show file tree
Hide file tree
Showing 20 changed files with 397 additions and 138 deletions.
1 change: 0 additions & 1 deletion dav4jvm
Submodule dav4jvm deleted from c61e4b
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public static void beforeAll() throws InterruptedException,
String userId = loginName; // for test same as userId
String credentials = Credentials.basic(loginName, password);
nextcloudClient = new NextcloudClient(url, userId, credentials, context);
nextcloudClient.setUserId(userId);

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

@After
public void after() {
// removeOnClient(client);
// removeOnClient(client2);
removeOnClient(client);
removeOnClient(client2);
}

private void removeOnClient(OwnCloudClient client) {
Expand Down
47 changes: 41 additions & 6 deletions library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import at.bitfire.dav4jvm.DavResource
import at.bitfire.dav4jvm.Response
import com.nextcloud.common.NextcloudAuthenticator
import com.nextcloud.operations.PropFindMethod
import com.nextcloud.test.RandomStringGenerator
import com.owncloud.android.lib.common.network.WebdavUtils
import com.owncloud.android.lib.common.utils.WebDavFileUtils
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperationIT
import com.owncloud.android.lib.resources.files.SearchRemoteOperation
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
Expand All @@ -43,6 +45,9 @@ 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 com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation
import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation
import com.owncloud.android.lib.resources.tags.PutTagRemoteOperation
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.apache.jackrabbit.webdav.DavConstants
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -97,14 +102,35 @@ class Dav4JVM : AbstractIT() {
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>
var result = ReadFolderRemoteOperation(path).execute(client).data as List<RemoteFile>
assertEquals(2, result.size)
val oldRemoteFile = result[0]
val oldSubFolderFile = result[1]
var oldRemoteFile = result[0]
var oldSubFolderFile = result[1]

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

// create tag
val tag1 = "a" + RandomStringGenerator.make(ReadFolderRemoteOperationIT.TAG_LENGTH)
assertTrue(CreateTagRemoteOperation(tag1).execute(nextcloudClient).isSuccess)

// list tags
val tags = GetTagsRemoteOperation().execute(client).resultData

// add tag
assertTrue(
PutTagRemoteOperation(
tags[0].id,
oldRemoteFile.localId
).execute(nextcloudClient).isSuccess
)

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

// new
val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl()

Expand All @@ -117,10 +143,11 @@ class Dav4JVM : AbstractIT() {
val client = nextcloudClient.client
.newBuilder()
.followRedirects(false)
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials, "Authorization"))
.authenticator(NextcloudAuthenticator(nextcloudClient.credentials))
.build()

// register custom property
// TODO check how to do it in a central way
WebdavUtils.registerCustomFactories()

// TODO use DavResource().propfind in ReadFileRemoteOperation/ReadFolderRemoteOperation
Expand Down Expand Up @@ -194,7 +221,11 @@ class Dav4JVM : AbstractIT() {
"test",
SearchRemoteOperation.SearchType.FILE_SEARCH,
false,
OCCapability(23, 0, 0)
OCCapability().apply {
versionMayor = 23
versionMinor = 0
versionMicro = 0
}
).execute(
client
)
Expand All @@ -213,7 +244,11 @@ class Dav4JVM : AbstractIT() {
"test",
SearchRemoteOperation.SearchType.FILE_SEARCH,
false,
OCCapability(23, 0, 0)
OCCapability().apply {
versionMayor = 23
versionMinor = 0
versionMicro = 0
}
).execute(
nextcloudClient
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
import okhttp3.Route;

public class NextcloudAuthenticator implements Authenticator {
private String credentials;
private String authenticatorType;
private final String credentials;

public NextcloudAuthenticator(@NonNull String credentials, @NonNull String authenticatorType) {
public NextcloudAuthenticator(@NonNull String credentials) {
this.credentials = credentials;
this.authenticatorType = authenticatorType;
}

@Nullable
@Override
public Request authenticate(@Nullable Route route, @NonNull Response response) {
String authenticatorType = "Authorization";

if (response.request().header(authenticatorType) != null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class NextcloudClient private constructor(
return client
.newBuilder()
.followRedirects(false)
.authenticator(NextcloudAuthenticator(credentials, "Authorization"))
.authenticator(NextcloudAuthenticator(credentials))
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
}

val isDirectory: Boolean
get() = "DIR" == contentType
get() = DIR_TYPE == contentType

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

companion object {
private val TAG = WebdavEntry::class.java.simpleName
private const val IS_ENCRYPTED = "1"
private const val CODE_PROP_NOT_FOUND = 404
const val NAMESPACE_OC = "http://owncloud.org/ns"
const val NAMESPACE_NC = "http://nextcloud.org/ns"
const val EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"
Expand Down Expand Up @@ -569,7 +571,6 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
const val SHAREES_SHARE_TYPE = "type"
const val PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"
const val PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"
private const val IS_ENCRYPTED = "1"
private const val CODE_PROP_NOT_FOUND = 404
const val DIR_TYPE = "DIR"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@

import androidx.annotation.Nullable;

import com.nextcloud.talk.components.filebrowser.models.properties.OCId;
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerDisplayName;
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerId;
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;
import com.owncloud.android.lib.resources.files.webdav.NCSharee;
import com.owncloud.android.lib.resources.files.webdav.NCTags;
import com.owncloud.android.lib.resources.files.webdav.OCId;
import com.owncloud.android.lib.resources.files.webdav.OCLocalId;
import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName;
import com.owncloud.android.lib.resources.files.webdav.OCOwnerId;
import com.owncloud.android.lib.resources.files.webdav.OCSize;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod;
Expand Down Expand Up @@ -159,6 +161,7 @@ public static DavPropertyNameSet getAllPropSet() {
}

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

list.add(DisplayName.NAME);
Expand All @@ -169,6 +172,7 @@ public static Property.Name[] getAllPropertiesList() {
list.add(CreationDate.NAME);
list.add(GetETag.NAME); // list.add(NCEtag.NAME);
list.add(NCPermissions.NAME);
list.add(OCLocalId.NAME);
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace);
list.add(OCSize.NAME);
list.add(NCFavorite.NAME);
Expand All @@ -191,6 +195,9 @@ public static Property.Name[] getAllPropertiesList() {
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIME, ncNamespace);
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace);
// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
list.add(NCTags.NAME);
// metadata size
// metadata gps
list.add(OCId.NAME); // what about this?

return list.toArray(new Property.Name[0]);
Expand Down Expand Up @@ -340,6 +347,8 @@ public static void registerCustomFactories() {
list.add(new OCOwnerDisplayName.Factory());
list.add(new NCRichWorkspace.Factory());
list.add(new NCSharee.Factory());
list.add(new NCTags.Factory());
list.add(new OCLocalId.Factory());

PropertyRegistry.INSTANCE.register(list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,4 @@ public void run() {
});
}
}


/**
* Returns the current client instance to access the remote server.
*
* @return Current client instance to access the remote server.
*/
public final OwnCloudClient getClient() {
return mClient;
}

public final NextcloudClient getClientNew() {
return clientNew;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@

import android.net.Uri;

import com.nextcloud.talk.components.filebrowser.models.properties.OCId;
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerDisplayName;
import com.nextcloud.talk.components.filebrowser.models.properties.OCOwnerId;
import com.nextcloud.talk.components.filebrowser.models.properties.OCSize;
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.files.webdav.NCEtag;
Expand All @@ -42,6 +38,12 @@
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 com.owncloud.android.lib.resources.files.webdav.NCTags;
import com.owncloud.android.lib.resources.files.webdav.OCId;
import com.owncloud.android.lib.resources.files.webdav.OCLocalId;
import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName;
import com.owncloud.android.lib.resources.files.webdav.OCOwnerId;
import com.owncloud.android.lib.resources.files.webdav.OCSize;

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

if (property instanceof OCLocalId) {
remoteFile.setLocalId(((OCLocalId) property).getLocalId());
}

if (property instanceof NCMountType) {
remoteFile.setMountType(((NCMountType) property).getType());
}
Expand All @@ -172,6 +178,10 @@ public RemoteFile parseResponse(Response response, Uri filesDavUri) {
if (property instanceof NCSharee) {
remoteFile.setSharees(((NCSharee) property).getSharees());
}

if (property instanceof NCTags) {
remoteFile.setTags(((NCTags) property).getTags());
}
}

remoteFile.setRemotePath(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected RemoteOperationResult<List<RemoteFile>> run(OwnCloudClient client) {
Namespace.XMLNS_NAMESPACE,
searchQuery),
searchType,
getClient().getUserIdPlain(),
client.getUserIdPlain(),
timestamp,
limit,
filterOutFiles,
Expand Down Expand Up @@ -189,7 +189,7 @@ public RemoteOperationResult run(NextcloudClient client) {
searchMethod = new NcSearchMethod(webDavUrl,
searchInfo,
searchType,
getClientNew().getUserIdPlain(),
client.getUserIdPlain(),
timestamp,
limit,
filterOutFiles,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
/*
* Nextcloud Talk application
/* Nextcloud Android Library is available under MIT license
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <[email protected]>
* Copyright (C) 2017-2019 Mario Danic <[email protected]>
* @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 General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 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 General Public License for more details.
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.lib.resources.files.webdav
Expand Down
Loading

0 comments on commit 074035e

Please sign in to comment.