diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperationIT.kt b/library/src/androidTest/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperationIT.kt index ebd6bf325..df05b15e1 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/nextcloud/android/lib/resources/search/UnifiedSearchRemoteOperationIT.kt @@ -75,7 +75,7 @@ class UnifiedSearchRemoteOperationIT : AbstractIT() { assertNotNull(firstResult) assertEquals(remotePath, firstResult?.remotePath()) - assertEquals(fileId, firstResult?.fileId()) + assertEquals(fileId.toString(), firstResult?.fileId()) } @Test diff --git a/library/src/androidTest/java/com/owncloud/android/FileIT.java b/library/src/androidTest/java/com/owncloud/android/FileIT.java index c3e069536..045872494 100644 --- a/library/src/androidTest/java/com/owncloud/android/FileIT.java +++ b/library/src/androidTest/java/com/owncloud/android/FileIT.java @@ -328,4 +328,21 @@ public void testTwoSharees() { assertTrue(sharees.contains(user)); } } + + @Test + public void testLocalID() { + // create & verify folder + String path = "/testFolder/"; + assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess()); + + RemoteOperationResult result = new ReadFolderRemoteOperation(path).execute(client); + assertTrue(result.isSuccess()); + + RemoteFile folder = (RemoteFile) result.getData().get(0); + + // we do this only here for testing, this might not work on large installations + int localId = Integer.parseInt(folder.getRemoteId().substring(0, 8).replaceAll("^0*", "")); + + assertEquals(folder.getLocalId(), localId); + } } diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java index 8b7180022..fcf2bf308 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/SearchRemoteOperationIT.java @@ -81,7 +81,7 @@ public void testSearchByFileIdSuccess() { assertTrue(readFile.isSuccess()); RemoteFile remoteFile = ((RemoteFile) readFile.getSingleData()); - SearchRemoteOperation sut = new SearchRemoteOperation(remoteFile.getLocalId(), + SearchRemoteOperation sut = new SearchRemoteOperation(String.valueOf(remoteFile.getLocalId()), SearchRemoteOperation.SearchType.FILE_ID_SEARCH, false, capability); diff --git a/library/src/main/java/com/nextcloud/common/NextcloudUriDelegate.kt b/library/src/main/java/com/nextcloud/common/NextcloudUriDelegate.kt index 9e8719ee5..c378b2f85 100644 --- a/library/src/main/java/com/nextcloud/common/NextcloudUriDelegate.kt +++ b/library/src/main/java/com/nextcloud/common/NextcloudUriDelegate.kt @@ -65,7 +65,7 @@ class NextcloudUriDelegate(baseUri: Uri, var userId: String?) : NextcloudUriProv return "$filesDavUri${WebdavUtils.encodePath(path)}" } - override fun getCommentsUri(fileId: String): String { + override fun getCommentsUri(fileId: Long): String { return "$davUri/comments/files/$fileId" } } diff --git a/library/src/main/java/com/nextcloud/common/NextcloudUriProvider.kt b/library/src/main/java/com/nextcloud/common/NextcloudUriProvider.kt index 25e0581b6..12dc68211 100644 --- a/library/src/main/java/com/nextcloud/common/NextcloudUriProvider.kt +++ b/library/src/main/java/com/nextcloud/common/NextcloudUriProvider.kt @@ -39,5 +39,5 @@ interface NextcloudUriProvider { val davUri: Uri fun getFilesDavUri(path: String): String - fun getCommentsUri(fileId: String): String + fun getCommentsUri(fileId: Long): String } diff --git a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java index 963c9e86e..c0e425829 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/library/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java @@ -328,7 +328,7 @@ public Uri getDavUri() { return nextcloudUriDelegate.getDavUri(); } - public String getCommentsUri(String fileId) { + public String getCommentsUri(long fileId) { return nextcloudUriDelegate.getCommentsUri(fileId); } diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java index 57c830c95..db7a86b74 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java +++ b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java @@ -54,10 +54,11 @@ public class WebdavEntry { private static final String TAG = WebdavEntry.class.getSimpleName(); - public static final String NAMESPACE_OC = "http://owncloud.org/ns"; - public static final String NAMESPACE_NC = "http://nextcloud.org/ns"; - public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; - public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; + public static final String NAMESPACE_OC = "http://owncloud.org/ns"; + public static final String NAMESPACE_NC = "http://nextcloud.org/ns"; + public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; + public static final String EXTENDED_PROPERTY_NAME_LOCAL_ID = "fileid"; + public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; public static final String EXTENDED_PROPERTY_IS_ENCRYPTED = "is-encrypted"; @@ -100,8 +101,12 @@ public class WebdavEntry { @Getter private String contentType; @Getter private String eTag; @Getter private String permissions; - @Getter private String remoteId; - @Getter private String trashbinOriginalLocation; + @Getter + private String remoteId; + @Getter + private long localId; + @Getter + private String trashbinOriginalLocation; @Getter private String trashbinFilename; @Getter private long trashbinDeletionTimestamp; @Getter @Setter private boolean favorite; @@ -282,6 +287,12 @@ public WebdavEntry(MultiStatusResponse ms, String splitElement) { remoteId = prop.getValue().toString(); } + // OC remote id property + prop = propSet.get(EXTENDED_PROPERTY_NAME_LOCAL_ID, ocNamespace); + if (prop != null) { + localId = Long.parseLong((String) prop.getValue()); + } + // OC size property prop = propSet.get(EXTENDED_PROPERTY_NAME_SIZE, ocNamespace); if (prop != null) { @@ -531,6 +542,7 @@ public boolean isDirectory() { private void resetData() { name = uri = contentType = permissions = null; remoteId = null; + localId = -1; contentLength = createTimestamp = modifiedTimestamp = 0; size = 0; quotaUsedBytes = null; 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 95860b49a..5b84b63c7 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 @@ -102,6 +102,7 @@ public static DavPropertyNameSet getAllPropSet() { propSet.add(DavPropertyName.CREATIONDATE); propSet.add(DavPropertyName.GETETAG); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace); + propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_LOCAL_ID, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace); @@ -145,6 +146,7 @@ public static DavPropertyNameSet getFilePropSet() { propSet.add(DavPropertyName.CREATIONDATE); propSet.add(DavPropertyName.GETETAG); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace); + propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_LOCAL_ID, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java index 642ca5c09..01c0e9f9d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/activities/GetActivitiesRemoteOperation.java @@ -75,16 +75,16 @@ public class GetActivitiesRemoteOperation extends RemoteOperation { private int lastGiven = -1; - private String fileId = ""; + private long fileId = -1; public GetActivitiesRemoteOperation() { } - public GetActivitiesRemoteOperation(String fileId) { + public GetActivitiesRemoteOperation(long fileId) { this.fileId = fileId; } - - public GetActivitiesRemoteOperation(String fileId, int lastGiven) { + + public GetActivitiesRemoteOperation(long fileId, int lastGiven) { this.fileId = fileId; this.lastGiven = lastGiven; } @@ -102,7 +102,7 @@ public RemoteOperationResult run(NextcloudClient client) { String url = client.getBaseUri() + OCS_ROUTE_V12_AND_UP; // add filter for fileId, if available - if (!fileId.isEmpty()) { + if (fileId > 0) { url = url + "/filter"; } @@ -119,10 +119,10 @@ public RemoteOperationResult run(NextcloudClient client) { parameters.put("since", String.valueOf(lastGiven)); } - if (!fileId.isEmpty()) { + if (fileId > 0) { parameters.put("sort", "desc"); parameters.put("object_type", "files"); - parameters.put("object_id", fileId); + parameters.put("object_id", String.valueOf(fileId)); } get.setQueryString(parameters); @@ -173,7 +173,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { String url = client.getBaseUri() + OCS_ROUTE_V12_AND_UP; // add filter for fileId, if available - if (!fileId.isEmpty()) { + if (fileId > 0) { url = url + "/filter"; } @@ -191,10 +191,10 @@ protected RemoteOperationResult run(OwnCloudClient client) { parameters.add(new NameValuePair("since", String.valueOf(lastGiven))); } - if (!fileId.isEmpty()) { + if (fileId > 0) { parameters.add(new NameValuePair("sort", "desc")); parameters.add(new NameValuePair("object_type", "files")); - parameters.add(new NameValuePair("object_id", fileId)); + parameters.add(new NameValuePair("object_id", String.valueOf(fileId))); } get.setQueryString(parameters.toArray(new NameValuePair[]{})); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/comments/CommentFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/comments/CommentFileRemoteOperation.java index 063cadfc3..99d72d377 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/comments/CommentFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/comments/CommentFileRemoteOperation.java @@ -58,15 +58,15 @@ public class CommentFileRemoteOperation extends RemoteOperation { private static final String VERB_VALUE = "comment"; private static final String MESSAGE = "message"; - private String message; - private String fileId; + private final String message; + private final long fileId; /** * Constructor * * @param message Comment to store */ - public CommentFileRemoteOperation(String message, String fileId) { + public CommentFileRemoteOperation(String message, long fileId) { this.message = message; this.fileId = fileId; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/comments/MarkCommentsAsReadRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/comments/MarkCommentsAsReadRemoteOperation.java index 5d701701b..d6db35f76 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/comments/MarkCommentsAsReadRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/comments/MarkCommentsAsReadRemoteOperation.java @@ -47,9 +47,9 @@ public class MarkCommentsAsReadRemoteOperation extends RemoteOperation { private static final String COMMENTS_URL = "/comments/files/"; - private String fileId; + private final long fileId; - public MarkCommentsAsReadRemoteOperation(String fileId) { + public MarkCommentsAsReadRemoteOperation(long fileId) { this.fileId = fileId; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java index 38c832d1e..bd838cc17 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/GetMetadataRemoteOperation.java @@ -55,12 +55,12 @@ public class GetMetadataRemoteOperation extends RemoteOperation { private static final String NODE_DATA = "data"; private static final String NODE_META_DATA = "meta-data"; - private String fileId; + private final long fileId; /** * Constructor */ - public GetMetadataRemoteOperation(String fileId) { + public GetMetadataRemoteOperation(long fileId) { this.fileId = fileId; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java index 054626aa8..42b8d5cdc 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/LockFileRemoteOperation.java @@ -49,8 +49,8 @@ public class LockFileRemoteOperation extends RemoteOperation { private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; - private String localId; - private String token; + private final long localId; + private final String token; // JSON node names private static final String NODE_OCS = "ocs"; @@ -59,12 +59,12 @@ public class LockFileRemoteOperation extends RemoteOperation { /** * Constructor */ - public LockFileRemoteOperation(String localId, String token) { + public LockFileRemoteOperation(long localId, String token) { this.localId = localId; this.token = token; } - public LockFileRemoteOperation(String localId) { + public LockFileRemoteOperation(long localId) { this.localId = localId; this.token = ""; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java index 07c3637d0..c03bddef4 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/StoreMetadataRemoteOperation.java @@ -56,13 +56,13 @@ public class StoreMetadataRemoteOperation extends RemoteOperation { private static final String NODE_DATA = "data"; private static final String NODE_META_DATA = "meta-data"; - private String fileId; - private String encryptedMetadataJson; + private final long fileId; + private final String encryptedMetadataJson; /** * Constructor */ - public StoreMetadataRemoteOperation(String fileId, String encryptedMetadataJson) { + public StoreMetadataRemoteOperation(long fileId, String encryptedMetadataJson) { this.fileId = fileId; this.encryptedMetadataJson = encryptedMetadataJson; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java index b19ce658b..4947a5dc3 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/ToggleEncryptionRemoteOperation.java @@ -49,14 +49,14 @@ public class ToggleEncryptionRemoteOperation extends RemoteOperation { private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String ENCRYPTED_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted/"; - private String localId; - private String remotePath; - private boolean encryption; + private final long localId; + private final String remotePath; + private final boolean encryption; /** * Constructor */ - public ToggleEncryptionRemoteOperation(String localId, String remotePath, boolean encryption) { + public ToggleEncryptionRemoteOperation(long localId, String remotePath, boolean encryption) { this.localId = localId; this.remotePath = remotePath; this.encryption = encryption; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java index c8fd89a49..11adca4e1 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UnlockFileRemoteOperation.java @@ -45,13 +45,13 @@ public class UnlockFileRemoteOperation extends RemoteOperation { private static final int SYNC_CONNECTION_TIMEOUT = 5000; private static final String LOCK_FILE_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/lock/"; - private String localId; - private String token; + private final long localId; + private final String token; /** * Constructor */ - public UnlockFileRemoteOperation(String localId, String token) { + public UnlockFileRemoteOperation(long localId, String token) { this.localId = localId; this.token = token; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java index e42b2f3cb..ee9f0e114 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/e2ee/UpdateMetadataRemoteOperation.java @@ -59,14 +59,14 @@ public class UpdateMetadataRemoteOperation extends RemoteOperation { private static final String NODE_DATA = "data"; private static final String NODE_META_DATA = "meta-data"; - private String fileId; - private String encryptedMetadataJson; - private String token; + private final long fileId; + private final String encryptedMetadataJson; + private final String token; /** * Constructor */ - public UpdateMetadataRemoteOperation(String fileId, String encryptedMetadataJson, String token) { + public UpdateMetadataRemoteOperation(long fileId, String encryptedMetadataJson, String token) { this.fileId = fileId; this.encryptedMetadataJson = URLEncoder.encode(encryptedMetadataJson); this.token = token; diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java index 3defe5144..a93790809 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/ReadFileVersionsRemoteOperation.java @@ -27,8 +27,6 @@ package com.owncloud.android.lib.resources.files; -import androidx.annotation.NonNull; - import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavUtils; @@ -53,7 +51,7 @@ public class ReadFileVersionsRemoteOperation extends RemoteOperation { private static final String TAG = ReadFileVersionsRemoteOperation.class.getSimpleName(); - private String fileId; + private final long localId; private ArrayList versions; /** @@ -61,8 +59,8 @@ public class ReadFileVersionsRemoteOperation extends RemoteOperation { * * @param fileId FileId of the file. */ - public ReadFileVersionsRemoteOperation(@NonNull String fileId) { - this.fileId = fileId; + public ReadFileVersionsRemoteOperation(long fileId) { + this.localId = fileId; } /** @@ -76,7 +74,7 @@ protected RemoteOperationResult run(OwnCloudClient client) { PropFindMethod query = null; try { - String uri = client.getDavUri() + "/versions/" + client.getUserId() + "/versions/" + fileId; + String uri = client.getDavUri() + "/versions/" + client.getUserId() + "/versions/" + localId; DavPropertyNameSet propSet = WebdavUtils.getFileVersionPropSet(); query = new PropFindMethod(uri, propSet, DavConstants.DEPTH_1); @@ -109,16 +107,16 @@ protected RemoteOperationResult run(OwnCloudClient client) { if (result == null) { result = new RemoteOperationResult(new Exception("unknown error")); - Log_OC.e(TAG, "Synchronized file with id " + fileId + ": failed"); + Log_OC.e(TAG, "Synchronized file with id " + localId + ": failed"); } else { if (result.isSuccess()) { - Log_OC.i(TAG, "Synchronized file with id " + fileId + ": " + result.getLogMessage()); + Log_OC.i(TAG, "Synchronized file with id " + localId + ": " + result.getLogMessage()); } else { if (result.isException()) { - Log_OC.e(TAG, "Synchronized with id " + fileId + ": " + result.getLogMessage(), - result.getException()); + Log_OC.e(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage(), + result.getException()); } else { - Log_OC.w(TAG, "Synchronized with id " + fileId + ": " + result.getLogMessage()); + Log_OC.w(TAG, "Synchronized with id " + localId + ": " + result.getLogMessage()); } } } @@ -141,7 +139,7 @@ private void readData(MultiStatus remoteData, OwnCloudClient client) { // loop to update every child for (int i = 1; i < remoteData.getResponses().length; ++i) { - versions.add(new FileVersion(fileId, new WebdavEntry(remoteData.getResponses()[i], splitElement))); + versions.add(new FileVersion(localId, new WebdavEntry(remoteData.getResponses()[i], splitElement))); } } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java index 159758ab1..21789d769 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/RestoreFileVersionRemoteOperation.java @@ -50,8 +50,8 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { private static final int RESTORE_READ_TIMEOUT = 30000; private static final int RESTORE_CONNECTION_TIMEOUT = 5000; - private String fileId; - private String fileName; + private final long fileId; + private final String fileName; /** * Constructor @@ -59,7 +59,7 @@ public class RestoreFileVersionRemoteOperation extends RemoteOperation { * @param fileId fileId * @param fileName version date in unixtime */ - public RestoreFileVersionRemoteOperation(String fileId, String fileName) { + public RestoreFileVersionRemoteOperation(long fileId, String fileName) { this.fileId = fileId; this.fileName = fileName; } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileVersion.java b/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileVersion.java index 005d5f46f..8030b73b6 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileVersion.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileVersion.java @@ -51,7 +51,7 @@ public class FileVersion implements Parcelable, ServerFileInterface { @Getter @Setter private String mimeType; @Getter @Setter private long fileLength; @Getter @Setter private long modifiedTimestamp; - @Getter private String remoteId; + @Getter private long localId; @Override public boolean isFavorite() { @@ -63,6 +63,11 @@ public String getFileName() { return String.valueOf(modifiedTimestamp / 1000); } + @Override + public String getMimeType() { + return mimeType; + } + @Override public String getRemotePath() { return ""; @@ -72,20 +77,33 @@ public String getRemotePath() { * For file version this is the same as remoteId */ @Override - public String getLocalId() { - return getRemoteId(); + public long getLocalId() { + return localId; + } + + /** + * For file version this is the same as remoteId + */ + @Override + public String getRemoteId() { + return String.valueOf(localId); } public boolean isFolder() { return DIRECTORY.equals(mimeType); } + @Override + public long getFileLength() { + return 0; + } + public boolean isHidden() { return getFileName().startsWith("."); } - public FileVersion(String fileId, WebdavEntry we) { - remoteId = fileId; + public FileVersion(long fileId, WebdavEntry we) { + localId = fileId; setMimeType(we.getContentType()); if (isFolder()) { diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/model/RemoteFile.java b/library/src/main/java/com/owncloud/android/lib/resources/files/model/RemoteFile.java index 8254c71bf..20abdc508 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/model/RemoteFile.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/model/RemoteFile.java @@ -33,7 +33,6 @@ import java.io.Serializable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import lombok.Getter; import lombok.Setter; @@ -58,6 +57,7 @@ public class RemoteFile implements Parcelable, Serializable { private long uploadTimestamp; private String etag; private String permissions; + private long localId; private String remoteId; private long size; private boolean favorite; @@ -107,6 +107,7 @@ public RemoteFile(WebdavEntry we) { setUploadTimestamp(we.getUploadTimestamp()); setEtag(we.getETag()); setPermissions(we.getPermissions()); + setLocalId(we.getLocalId()); setRemoteId(we.getRemoteId()); setSize(we.getSize()); setFavorite(we.isFavorite()); @@ -140,6 +141,7 @@ private void resetData() { modifiedTimestamp = 0; etag = null; permissions = null; + localId = -1; remoteId = null; size = 0; favorite = false; @@ -191,6 +193,7 @@ public void readFromParcel(Parcel source) { modifiedTimestamp = source.readLong(); etag = source.readString(); permissions = source.readString(); + localId = source.readLong(); remoteId = source.readString(); size = source.readLong(); favorite = Boolean.parseBoolean(source.readString()); @@ -225,6 +228,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeLong(modifiedTimestamp); dest.writeString(etag); dest.writeString(permissions); + dest.writeLong(localId); dest.writeString(remoteId); dest.writeLong(size); dest.writeString(Boolean.toString(favorite)); @@ -244,10 +248,4 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeLong(lockTimeout); dest.writeString(lockToken); } - - @SuppressFBWarnings(value = "STT_STRING_PARSING_A_FIELD", justification = "remoteId contains cloud id and local id") - public String getLocalId() { - return remoteId.substring(0, 8).replaceAll("^0*", ""); - } - } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/model/ServerFileInterface.java b/library/src/main/java/com/owncloud/android/lib/resources/files/model/ServerFileInterface.java index 667faa559..80c4af97b 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/model/ServerFileInterface.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/model/ServerFileInterface.java @@ -1,20 +1,20 @@ package com.owncloud.android.lib.resources.files.model; public interface ServerFileInterface { - + String getFileName(); - + String getMimeType(); String getRemotePath(); - - String getLocalId(); - + + long getLocalId(); + String getRemoteId(); - + boolean isFavorite(); - + boolean isFolder(); - + long getFileLength(); } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/model/TrashbinFile.java b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/model/TrashbinFile.java index 128e4da97..70959962d 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/trashbin/model/TrashbinFile.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/trashbin/model/TrashbinFile.java @@ -27,13 +27,14 @@ import android.os.Parcel; import android.os.Parcelable; +import androidx.annotation.VisibleForTesting; + import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.files.model.ServerFileInterface; import java.io.Serializable; -import androidx.annotation.VisibleForTesting; import lombok.Getter; import lombok.Setter; @@ -65,8 +66,8 @@ public class TrashbinFile implements Parcelable, Serializable, ServerFileInterfa * For trashbin this is the same as remoteId */ @Override - public String getLocalId() { - return getRemoteId(); + public long getLocalId() { + return Long.parseLong(getRemoteId()); } @Override @@ -78,6 +79,31 @@ public boolean isHidden() { return getFileName().startsWith("."); } + @Override + public long getFileLength() { + return fileLength; + } + + @Override + public String getFileName() { + return fileName; + } + + @Override + public String getMimeType() { + return mimeType; + } + + @Override + public String getRemotePath() { + return remotePath; + } + + @Override + public String getRemoteId() { + return String.valueOf(remoteId); + } + @Override public boolean isFavorite() { return false; @@ -85,7 +111,7 @@ public boolean isFavorite() { public TrashbinFile(WebdavEntry we, String userId) { String path = we.decodedPath(); - + if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) { throw new IllegalArgumentException("Trying to create a TrashbinFile with a non valid remote path: " + path); }