Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for metadata: size (width/height) and geolocation #1178

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added library/src/androidTest/assets/gps.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -279,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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ package com.owncloud.android.lib.resources.files
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation
import com.owncloud.android.lib.resources.files.model.GeoLocation
import com.owncloud.android.lib.resources.files.model.ImageDimension
import com.owncloud.android.lib.resources.files.model.RemoteFile
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand Down Expand Up @@ -58,6 +60,27 @@ class ReadFileRemoteOperationIT : AbstractIT() {
assertEquals(remotePath, (result.data[0] as RemoteFile).remotePath)
}

@Test
fun testMetadata() {
val filePath = getFile("gps.jpg").absolutePath
val remotePath = "/gps.jpg"

assertTrue(
UploadFileRemoteOperation(filePath, remotePath, "image/jpg", RANDOM_MTIME)
.execute(client).isSuccess
)

val result = ReadFileRemoteOperation(remotePath).execute(client)

assertTrue(result.isSuccess)
val remoteFile = result.data[0] as RemoteFile

@Suppress("Detekt.MagicNumber")
assertEquals(ImageDimension(451f, 529f), remoteFile.imageDimension)
@Suppress("Detekt.MagicNumber")
assertEquals(GeoLocation(49.99679166666667, 8.67198611111111), remoteFile.geoLocation)
}

@Test
fun readEncryptedState() {
val remotePath = "/testEncryptedFolder/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
package com.owncloud.android.lib.common.network

import android.net.Uri
import com.google.gson.Gson
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.files.model.FileLockType
import com.owncloud.android.lib.resources.files.model.FileLockType.Companion.fromValue
import com.owncloud.android.lib.resources.files.model.GeoLocation
import com.owncloud.android.lib.resources.files.model.ImageDimension
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.ShareeUser
import org.apache.jackrabbit.webdav.MultiStatusResponse
Expand Down Expand Up @@ -96,6 +99,8 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
var lockToken: String? = null
private set
var tags = arrayOfNulls<String>(0)
var imageDimension: ImageDimension? = null
var geoLocation: GeoLocation? = null

enum class MountType {
INTERNAL, EXTERNAL, GROUP
Expand Down Expand Up @@ -395,6 +400,18 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
}
}

// NC metadata size property <nc:file-metadata-size>
prop = propSet[EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace]
if (prop != null && prop.value != null) {
imageDimension = Gson().fromJson(prop.value.toString(), ImageDimension::class.java)
}

// NC metadata gps property <nc:file-metadata-gps>
prop = propSet[EXTENDED_PROPERTY_METADATA_GPS, ncNamespace]
if (prop != null && prop.value != null) {
geoLocation = Gson().fromJson(prop.value.toString(), GeoLocation::class.java)
}

parseLockProperties(ncNamespace, propSet)
} else {
Log_OC.e("WebdavEntry", "General error, no status for webdav response")
Expand Down Expand Up @@ -542,6 +559,8 @@ class WebdavEntry constructor(ms: MultiStatusResponse, splitElement: String) {
const val EXTENDED_PROPERTY_LOCK_TIMEOUT = "lock-timeout"
const val EXTENDED_PROPERTY_LOCK_TOKEN = "lock-token"
const val EXTENDED_PROPERTY_SYSTEM_TAGS = "system-tags"
const val EXTENDED_PROPERTY_METADATA_SIZE = "file-metadata-size"
const val EXTENDED_PROPERTY_METADATA_GPS = "file-metadata-gps"
const val TRASHBIN_FILENAME = "trashbin-filename"
const val TRASHBIN_ORIGINAL_LOCATION = "trashbin-original-location"
const val TRASHBIN_DELETION_TIME = "trashbin-deletion-time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public static DavPropertyNameSet getAllPropSet() {
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace);

return propSet;
}
Expand Down Expand Up @@ -165,6 +167,8 @@ public static DavPropertyNameSet getFilePropSet() {
propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace);
propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace);

return propSet;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud GmbH
*
* 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:
*
* 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.
*
*/

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

data class GeoLocation(var latitude: Double = -1.0, var longitude: Double = -1.0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Nextcloud Android Library is available under MIT license
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud GmbH
*
* 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:
*
* 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.
*
*/

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

data class ImageDimension(var width: Float = -1f, var height: Float = -1f)
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class RemoteFile : Parcelable, Serializable {
var lockTimeout: Long = 0
var lockToken: String? = null
var tags: Array<String?>? = null
var imageDimension: ImageDimension? = null
var geoLocation: GeoLocation? = null

constructor() {
resetData()
Expand Down Expand Up @@ -119,6 +121,8 @@ class RemoteFile : Parcelable, Serializable {
lockTimeout = we.lockTimeout
lockToken = we.lockToken
tags = we.tags
imageDimension = we.imageDimension
geoLocation = we.geoLocation
}

/**
Expand Down
Loading