Skip to content

Commit

Permalink
use localID everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Co-authored-by: Álvaro Brey <alvaro.brey@nextcloud.com>
  • Loading branch information
tobiasKaminsky and AlvaroBrey committed Dec 6, 2022
1 parent 0e50595 commit a01b07f
Show file tree
Hide file tree
Showing 25 changed files with 1,273 additions and 53 deletions.
1,130 changes: 1,130 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/67.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@

package com.owncloud.android.datamodel;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.db.ProviderMeta;

public class FileDataStorageManagerContentProviderClientIT extends FileDataStorageManagerIT {
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class FileDataStorageManagerContentProviderClientIT extends AbstractIT {
protected FileDataStorageManager sut;

@Override
public void before() {
sut = new FileDataStorageManager(user,
targetContext
Expand All @@ -36,4 +42,24 @@ public void before() {

super.before();
}

@Test
public void saveFile() {
before();

String path = "/1.txt";
OCFile file = new OCFile(path, "00000008ocjycgrudn78");

// TODO check via reflection that every parameter is set

file.setFileLength(1024000);
file.setModificationTimestamp(1582019340);
sut.saveNewFile(file);


OCFile read = sut.getFileByPath(path);
assertNotNull(read);

assertEquals(file.getRemotePath(), read.getRemotePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,5 @@ public void testOCCapability() {

assertEquals(capability.getUserStatus(), newCapability.getUserStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import com.owncloud.android.db.ProviderMeta
],
version = ProviderMeta.DB_VERSION,
autoMigrations = [
AutoMigration(from = 65, to = 66)
AutoMigration(from = 65, to = 66),
AutoMigration(from = 66, to = 67)
],
exportSchema = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ data class FileEntity(
val permissions: String?,
@ColumnInfo(name = ProviderTableMeta.FILE_REMOTE_ID)
val remoteId: String?,
@ColumnInfo(name = ProviderTableMeta.FILE_LOCAL_ID)
val localId: Long?,
@ColumnInfo(name = ProviderTableMeta.FILE_UPDATE_THUMBNAIL)
val updateThumbnail: Int?,
@ColumnInfo(name = ProviderTableMeta.FILE_IS_DOWNLOADING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.owncloud.android.lib.common.OwnCloudClient

internal class LoadUrlTask(
private val client: OwnCloudClient,
private val fileId: String,
private val fileId: Long,
private val onResult: (String?) -> Unit
) : AsyncTask<Void, Void, String>() {

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/client/media/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal class Player(
checkNotNull(user)
playedFile?.let {
val client = clientFactory.create(user)
val task = LoadUrlTask(client, it.remoteId, this@Player::onDownloaded)
val task = LoadUrlTask(client, it.localId, this@Player::onDownloaded)
task.execute()
loadUrlTask = task
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ private ContentValues createContentValuesBase(OCFile fileOrFolder) {
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, fileOrFolder.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, fileOrFolder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, fileOrFolder.getRemoteId());
cv.put(ProviderTableMeta.FILE_LOCAL_ID, fileOrFolder.getLocalId());
cv.put(ProviderTableMeta.FILE_FAVORITE, fileOrFolder.isFavorite());
cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, fileOrFolder.getUnreadCommentsCount());
cv.put(ProviderTableMeta.FILE_OWNER_ID, fileOrFolder.getOwnerId());
Expand Down Expand Up @@ -994,6 +995,7 @@ private OCFile createFileInstance(Cursor cursor) {
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
ocFile.setPermissions(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PERMISSIONS)));
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID)));
ocFile.setLocalId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCAL_ID)));
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
ocFile.setDownloading(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
Expand Down
29 changes: 17 additions & 12 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.FileProvider;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.daveKoeller.AlphanumComparator;

public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
Expand Down Expand Up @@ -83,6 +84,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private String etagOnServer;
private boolean sharedViaLink;
private String permissions;
private long localId; // unique fileId for the file within the instance
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
private boolean updateThumbnailNeeded;
private boolean downloading;
Expand Down Expand Up @@ -166,6 +168,7 @@ private OCFile(Parcel source) {
etagOnServer = source.readString();
sharedViaLink = source.readInt() == 1;
permissions = source.readString();
localId = source.readLong();
remoteId = source.readString();
updateThumbnailNeeded = source.readInt() == 1;
downloading = source.readInt() == 1;
Expand Down Expand Up @@ -208,6 +211,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(etagOnServer);
dest.writeInt(sharedViaLink ? 1 : 0);
dest.writeString(permissions);
dest.writeLong(localId);
dest.writeString(remoteId);
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
dest.writeInt(downloading ? 1 : 0);
Expand Down Expand Up @@ -284,8 +288,7 @@ public String getRemotePath() {
}

/**
* Can be used to check, whether or not this file exists in the database
* already
* Can be used to check, whether or not this file exists in the database already
*
* @return true, if the file exists in the database
*/
Expand Down Expand Up @@ -486,6 +489,7 @@ private void resetData() {
etagOnServer = null;
sharedViaLink = false;
permissions = null;
localId = -1;
remoteId = null;
updateThumbnailNeeded = false;
downloading = false;
Expand Down Expand Up @@ -594,17 +598,14 @@ public boolean isHidden() {
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}

/**
* The unique fileId for the file within the instance
*
* @return file fileId, unique within the instance
*/
@Nullable
public String getLocalId() {
if (getRemoteId() != null) {
return getRemoteId().substring(0, 8).replaceAll("^0*", "");
@SuppressFBWarnings("STT")
public long getLocalId() {
if (localId > 0) {
return localId;
} else if (remoteId != null) {
return Long.parseLong(remoteId.substring(0, 8).replaceAll("^0*", ""));
} else {
return null;
return -1;
}
}

Expand Down Expand Up @@ -772,6 +773,10 @@ public void setFileId(long fileId) {
this.fileId = fileId;
}

public void setLocalId(long localId) {
this.localId = localId;
}

public void setParentId(long parentId) {
this.parentId = parentId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {
Bitmap bitmap;
if (MimeTypeUtil.isVideo(ocFile)) {
bitmap = ThumbnailUtils.createVideoThumbnail(ocFile.getStoragePath(),
MediaStore.Images.Thumbnails.MINI_KIND);
MediaStore.Images.Thumbnails.MINI_KIND);
} else {
bitmap = BitmapUtils.decodeSampledBitmapFromFile(ocFile.getStoragePath(), pxW, pxH);
}
Expand Down Expand Up @@ -731,18 +731,18 @@ private Bitmap doThumbnailFromOCFileInBackground() {
if (file instanceof OCFile) {
uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/");
} else {
} else if (file instanceof TrashbinFile) {
uri = mClient.getBaseUri() + "/index.php/apps/files_trashbin/preview?fileId=" +
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
}

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie",
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");

getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
RemoteOperation.OCS_API_HEADER_VALUE);
RemoteOperation.OCS_API_HEADER_VALUE);

int status = mClient.executeMethod(getMethod, READ_TIMEOUT, CONNECTION_TIMEOUT);
if (status == HttpStatus.SC_OK) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 66;
public static final int DB_VERSION = 67;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -101,6 +101,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_SHARED_VIA_LINK = "share_by_link";
public static final String FILE_SHARED_WITH_SHAREE = "shared_via_users";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_LOCAL_ID = "local_id";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_IS_DOWNLOADING = "is_downloading";
Expand Down Expand Up @@ -148,6 +149,7 @@ static public class ProviderTableMeta implements BaseColumns {
FILE_SHARED_WITH_SHAREE,
FILE_PERMISSIONS,
FILE_REMOTE_ID,
FILE_LOCAL_ID,
FILE_UPDATE_THUMBNAIL,
FILE_IS_DOWNLOADING,
FILE_ETAG_IN_CONFLICT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class StreamMediaFileOperation extends RemoteOperation {
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
private static final String STREAM_MEDIA_URL = "/ocs/v2.php/apps/dav/api/v1/direct";

private String fileID;
private final long fileID;

// JSON node names
private static final String NODE_OCS = "ocs";
private static final String NODE_DATA = "data";
private static final String NODE_URL = "url";
private static final String JSON_FORMAT = "?format=json";

public StreamMediaFileOperation(String fileID) {
public StreamMediaFileOperation(long fileID) {
this.fileID = fileID;
}

Expand All @@ -55,7 +55,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

try {
postMethod = new Utf8PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT);
postMethod.setParameter("fileId", fileID);
postMethod.setParameter("fileId", String.valueOf(fileID));

// remote request
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
public class CommentFileOperation extends RemoteOperation {

private final String message;
private final String fileId;
private final long fileId;

/**
* Constructor
*
* @param message Comment to store
*/
public CommentFileOperation(String message, String fileId) {
public CommentFileOperation(String message, long fileId) {
this.message = message;
this.fileId = fileId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
private static final int REMOVE_READ_TIMEOUT = 30000;
private static final int REMOVE_CONNECTION_TIMEOUT = 5000;

private String remotePath;
private String parentId;
private final String remotePath;
private final long parentId;
private User user;

private ArbitraryDataProvider arbitraryDataProvider;
private String fileName;
private final ArbitraryDataProvider arbitraryDataProvider;
private final String fileName;

/**
* Constructor
Expand All @@ -76,7 +76,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
* @param parentId local id of parent folder
*/
RemoveRemoteEncryptedFileOperation(String remotePath,
String parentId,
long parentId,
User user,
Context context,
String fileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public class RichDocumentsUrlOperation extends RemoteOperation {
private static final String NODE_URL = "url";
private static final String JSON_FORMAT = "?format=json";

private String fileID;
private final long fileId;

public RichDocumentsUrlOperation(String fileID) {
this.fileID = fileID;
public RichDocumentsUrlOperation(long fileID) {
this.fileId = fileID;
}

@NextcloudServer(max = 18)
Expand All @@ -64,7 +64,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {

try {
postMethod = new Utf8PostMethod(client.getBaseUri() + DOCUMENT_URL + JSON_FORMAT);
postMethod.setParameter(FILE_ID, fileID);
postMethod.setParameter(FILE_ID, String.valueOf(fileId));

// remote request
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
Expand All @@ -86,7 +86,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Get rich document url for file with id " + fileID + " failed: " + result.getLogMessage(),
Log_OC.e(TAG, "Get rich document url for file with id " + fileId + " failed: " + result.getLogMessage(),
result.getException());
} finally {
if (postMethod != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {

case ACTION_RESTORE_VERSION:
FileVersion fileVersion = operationIntent.getParcelableExtra(EXTRA_FILE_VERSION);
operation = new RestoreFileVersionRemoteOperation(fileVersion.getRemoteId(),
operation = new RestoreFileVersionRemoteOperation(fileVersion.getLocalId(),
fileVersion.getFileName());
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* Event for set folder as encrypted/decrypted
*/
public class EncryptionEvent {
public final String localId;
public final long localId;
public final String remotePath;
public final String remoteId;
public final boolean shouldBeEncrypted;

public EncryptionEvent(String localId, String remoteId, String remotePath, boolean shouldBeEncrypted) {
public EncryptionEvent(long localId, String remoteId, String remotePath, boolean shouldBeEncrypted) {
this.localId = localId;
this.remoteId = remoteId;
this.remotePath = remotePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,14 @@ public boolean shouldCallGeneratedCallback(String tag, Object callContext) {

private static class SubmitCommentTask extends AsyncTask<Void, Void, Boolean> {

private String message;
private String fileId;
private VersionListInterface.CommentCallback callback;
private OwnCloudClient client;

private SubmitCommentTask(String message, String fileId, VersionListInterface.CommentCallback callback,
private final String message;
private final long fileId;
private final VersionListInterface.CommentCallback callback;
private final OwnCloudClient client;

private SubmitCommentTask(String message,
long fileId,
VersionListInterface.CommentCallback callback,
OwnCloudClient client) {
this.message = message;
this.fileId = fileId;
Expand Down
Loading

0 comments on commit a01b07f

Please sign in to comment.