Skip to content

Commit 642aa62

Browse files
committed
oC10 now uses meta endpoint to retrieve remote path, just like oCIS
1 parent 5e9fefe commit 642aa62

File tree

11 files changed

+38
-158
lines changed

11 files changed

+38
-158
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/nonwebdav/HeadMethod.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/GetRemoteMetaFileOperation.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class GetRemoteMetaFileOperation(val fileId: String) : RemoteOperation<RemoteMet
4949
return try {
5050

5151
val propFindMethod =
52-
PropfindMethod(URL(stringUrl), DavConstants.DEPTH_0, arrayOf(OCMetaPathForUser.NAME)).apply {
52+
PropfindMethod(URL(stringUrl), DavConstants.DEPTH_0,
53+
arrayOf(OCMetaPathForUser.NAME, OCId.NAME, OCFileId.NAME, OCSpaceId.NAME)
54+
).apply {
5355
setReadTimeout(TIMEOUT, TimeUnit.SECONDS)
5456
setConnectionTimeout(TIMEOUT, TimeUnit.SECONDS)
5557
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/GetRemotePathForFileIdOperation.kt

Lines changed: 0 additions & 69 deletions
This file was deleted.

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ interface FileService : Service {
8787

8888
fun getMetaFileInfo(
8989
fileId: String,
90-
isOcis: Boolean
9190
): RemoteOperationResult<RemoteMetaFile>
9291

9392
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation
3030
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation
3131
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation
3232
import com.owncloud.android.lib.resources.files.GetRemoteMetaFileOperation
33-
import com.owncloud.android.lib.resources.files.GetRemotePathForFileIdOperation
3433
import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation
3534
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation
3635
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation
@@ -144,10 +143,8 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
144143
spaceWebDavUrl = spaceWebDavUrl,
145144
).execute(client)
146145

147-
override fun getMetaFileInfo(fileId: String, isOcis: Boolean): RemoteOperationResult<RemoteMetaFile> =
148-
if (isOcis) {
149-
GetRemoteMetaFileOperation(fileId)
150-
} else {
151-
GetRemotePathForFileIdOperation(fileId)
152-
}.execute(client)
146+
override fun getMetaFileInfo(
147+
fileId: String,
148+
): RemoteOperationResult<RemoteMetaFile> =
149+
GetRemoteMetaFileOperation(fileId).execute(client)
153150
}

owncloudData/src/main/java/com/owncloud/android/data/files/datasources/RemoteFileDataSource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ interface RemoteFileDataSource {
9494
fun getMetaFile(
9595
fileId: String,
9696
accountName: String,
97-
isOcis: Boolean
9897
): OCMetaFile
9998

10099
}

owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCRemoteFileDataSource.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ class OCRemoteFileDataSource(
208208
override fun getMetaFile(
209209
fileId: String,
210210
accountName: String,
211-
isOcis: Boolean
212211
): OCMetaFile = executeRemoteOperation {
213-
clientManager.getFileService(accountName).getMetaFileInfo(fileId, isOcis)
212+
clientManager.getFileService(accountName).getMetaFileInfo(fileId)
214213
}.toModel()
215214

216215
companion object {

owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,33 @@ class OCFileRepository(
165165
override fun getFileByRemotePath(remotePath: String, owner: String, spaceId: String?): OCFile? =
166166
localFileDataSource.getFileByRemotePath(remotePath, owner, spaceId)
167167

168+
override fun getFileFromRemoteId(fileId: String, accountName: String): OCFile? {
169+
val metaFile = remoteFileDataSource.getMetaFile(fileId, accountName)
170+
val remotePath = metaFile.path!!
171+
172+
val splitPath = remotePath.split(PATH_SEPARATOR)
173+
var containerFolder = listOf<OCFile>()
174+
for (i in 0..splitPath.size - 2) {
175+
var path = splitPath[0]
176+
for (j in 1..i) {
177+
path += "$PATH_SEPARATOR${splitPath[j]}"
178+
}
179+
containerFolder = refreshFolder(path, accountName, metaFile.spaceId)
180+
}
181+
refreshFolder(remotePath, accountName, metaFile.spaceId)
182+
return if (remotePath == ROOT_PATH) {
183+
getFileByRemotePath(remotePath, accountName, metaFile.spaceId)
184+
} else {
185+
containerFolder.find { file ->
186+
if (file.isFolder) {
187+
file.remotePath.dropLast(1)
188+
} else {
189+
file.remotePath
190+
} == remotePath
191+
}
192+
}
193+
}
194+
168195
override fun getPersonalRootFolderForAccount(owner: String): OCFile {
169196
val personalSpace = localSpacesDataSource.getPersonalSpaceForAccount(owner)
170197
if (personalSpace == null) {
@@ -530,33 +557,6 @@ class OCFileRepository(
530557
localFileDataSource.updateFileWithLastUsage(fileId, lastUsage)
531558
}
532559

533-
override fun getFileFromRemoteId(fileId: String, accountName: String, isOcis: Boolean): OCFile? {
534-
val metaFile = remoteFileDataSource.getMetaFile(fileId, accountName, isOcis)
535-
val remotePath = metaFile.path!!
536-
537-
val splitPath = remotePath.split(PATH_SEPARATOR)
538-
var containerFolder = listOf<OCFile>()
539-
for (i in 0..splitPath.size - 2) {
540-
var path = splitPath[0]
541-
for (j in 1..i) {
542-
path += "$PATH_SEPARATOR${splitPath[j]}"
543-
}
544-
containerFolder = refreshFolder(path, accountName, metaFile.spaceId)
545-
}
546-
refreshFolder(remotePath, accountName, metaFile.spaceId)
547-
return if (remotePath == ROOT_PATH) {
548-
getFileByRemotePath(remotePath, accountName, metaFile.spaceId)
549-
} else {
550-
containerFolder.find { file ->
551-
if (file.isFolder) {
552-
file.remotePath.dropLast(1)
553-
} else {
554-
file.remotePath
555-
} == remotePath
556-
}
557-
}
558-
}
559-
560560
override fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) {
561561
localFileDataSource.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory)
562562
}

owncloudData/src/test/java/com/owncloud/android/data/files/datasources/implementation/OCRemoteFileDataSourceTest.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,24 +387,19 @@ class OCRemoteFileDataSourceTest {
387387
every {
388388
ocFileService.getMetaFileInfo(
389389
fileId = OC_FILE.remoteId!!,
390-
isOcis = any()
391390
)
392391
} returns remoteResult
393392

394393
val result = ocRemoteFileDataSource.getMetaFile(
395394
OC_FILE.remoteId!!,
396395
OC_ACCOUNT_NAME,
397-
false,
398396
)
399397

400398
assertEquals(REMOTE_META_FILE.toModel(), result)
401399

402400
verify(exactly = 1) {
403401
clientManager.getFileService(OC_ACCOUNT_NAME)
404-
ocFileService.getMetaFileInfo(
405-
OC_FILE.remoteId!!,
406-
false,
407-
)
402+
ocFileService.getMetaFileInfo(OC_FILE.remoteId!!)
408403
}
409404
}
410405
}

owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface FileRepository {
3939
fun getFileByIdAsFlow(fileId: Long): Flow<OCFile?>
4040
fun getFileWithSyncInfoByIdAsFlow(fileId: Long): Flow<OCFileWithSyncInfo?>
4141
fun getFileByRemotePath(remotePath: String, owner: String, spaceId: String? = null): OCFile?
42+
fun getFileFromRemoteId(fileId: String, accountName: String): OCFile?
4243
fun getPersonalRootFolderForAccount(owner: String): OCFile
4344
fun getSharesRootFolderForAccount(owner: String): OCFile?
4445
fun getSearchFolderContent(fileListOption: FileListOption, folderId: Long, search: String): List<OCFile>
@@ -68,6 +69,4 @@ interface FileRepository {
6869
fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String)
6970
fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?)
7071

71-
fun getFileFromRemoteId(fileId: String, accountName: String, isOcis: Boolean): OCFile?
72-
7372
}

0 commit comments

Comments
 (0)