Migrate RemoteOperation.execute calls to User

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
Chris Narkiewicz 2022-05-08 23:51:57 +01:00
parent bd5a99a10e
commit 35e164fa2d
No known key found for this signature in database
GPG key ID: 30D28CA4CCC665C6
28 changed files with 51 additions and 57 deletions

View file

@ -468,7 +468,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
assertTrue(new RemoveFileOperation(fileToDelete,
false,
account,
user,
false,
targetContext,
getStorageManager())
@ -621,7 +621,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
Log_OC.d(this, "Remove file: " + child.getDecryptedRemotePath());
}
assertTrue(new RemoveFileOperation(child, false, account, false, targetContext, getStorageManager())
assertTrue(new RemoveFileOperation(child, false, user, false, targetContext, getStorageManager())
.execute(client)
.isSuccess()
);

View file

@ -63,7 +63,7 @@ public class DownloadIT extends AbstractOnServerIT {
if (result.isSuccess() && getStorageManager().getFileByDecryptedRemotePath(FOLDER) != null) {
new RemoveFileOperation(getStorageManager().getFileByDecryptedRemotePath(FOLDER),
false,
account,
user,
false,
targetContext,
getStorageManager())

View file

@ -38,7 +38,7 @@ public class FileIT extends AbstractOnServerIT {
assertTrue(file.isFolder());
// cleanup
new RemoveFileOperation(file, false, account, false, targetContext, getStorageManager()).execute(client);
new RemoveFileOperation(file, false, user, false, targetContext, getStorageManager()).execute(client);
}
@Test
@ -58,7 +58,7 @@ public class FileIT extends AbstractOnServerIT {
// cleanup
new RemoveFileOperation(file,
false,
account,
user,
false,
targetContext,
getStorageManager())

View file

@ -116,7 +116,7 @@ public class UploadIT extends AbstractOnServerIT {
if (result.isSuccess() && getStorageManager().getFileByDecryptedRemotePath(FOLDER) != null) {
new RemoveFileOperation(getStorageManager().getFileByDecryptedRemotePath(FOLDER),
false,
account,
user,
false,
targetContext,
getStorageManager())
@ -371,7 +371,7 @@ public class UploadIT extends AbstractOnServerIT {
// cleanup
new RemoveFileOperation(getStorageManager().getFileByDecryptedRemotePath(FOLDER),
false,
account,
user,
false,
targetContext,
getStorageManager())

View file

@ -47,7 +47,7 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
assertTrue(new RemoveFileOperation(folder,
false,
account,
user,
false,
targetContext,
getStorageManager())
@ -59,7 +59,7 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
assertNotNull(parentFolder);
assertTrue(new RemoveFileOperation(parentFolder,
false,
account,
user,
false,
targetContext,
getStorageManager())
@ -81,7 +81,7 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
assertTrue(new RemoveFileOperation(file,
false,
account,
user,
false,
targetContext,
getStorageManager())
@ -93,7 +93,7 @@ public class RemoveFileOperationIT extends AbstractOnServerIT {
assertNotNull(parentFolder);
assertTrue(new RemoveFileOperation(parentFolder,
false,
account,
user,
false,
targetContext,
getStorageManager())

View file

@ -58,7 +58,7 @@ public class ErrorMessageAdapterIT {
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
new RemoveFileOperation(new OCFile(PATH_TO_DELETE),
false,
user.toPlatformAccount(),
user,
false,
context,
new FileDataStorageManager(user, context.getContentResolver())),

View file

@ -24,8 +24,8 @@ import android.accounts.Account
import android.os.Parcelable
import com.owncloud.android.lib.common.OwnCloudAccount
interface User : Parcelable {
val accountName: String
interface User : Parcelable, com.nextcloud.common.User {
override val accountName: String
val server: Server
val isAnonymous: Boolean
@ -39,7 +39,7 @@ interface User : Parcelable {
* @return Account instance that is associated with this User object.
*/
@Deprecated("Temporary workaround")
fun toPlatformAccount(): Account
override fun toPlatformAccount(): Account
/**
* This is temporary helper method created to facilitate incremental refactoring.

View file

@ -88,7 +88,7 @@ class OfflineSyncWork constructor(
ocFolder.remotePath,
ocFolder.etagOnServer
)
val result = checkEtagOperation.execute(user.toPlatformAccount(), context)
val result = checkEtagOperation.execute(user, context)
when (result.code) {
ResultCode.ETAG_UNCHANGED -> {
Log_OC.d(TAG, "$folderName: eTag unchanged")

View file

@ -278,7 +278,7 @@ public class FileDataStorageManager {
// remote request
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(parentPath);
// TODO Deprecated
RemoteOperationResult result = operation.execute(getUser().toPlatformAccount(), context);
RemoteOperationResult result = operation.execute(getUser(), context);
if (result.isSuccess()) {
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));

View file

@ -202,7 +202,7 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
if (encryptedRemotePath != null) {
RemoteOperationResult removeResult = new RemoveRemoteEncryptedFileOperation(encryptedRemotePath,
parent.getLocalId(),
user.toPlatformAccount(),
user,
context,
filename).execute(client);

View file

@ -22,9 +22,9 @@
package com.owncloud.android.operations;
import android.accounts.Account;
import android.content.Context;
import com.nextcloud.client.account.User;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
@ -44,7 +44,7 @@ public class RemoveFileOperation extends SyncOperation {
private final OCFile fileToRemove;
private final boolean onlyLocalCopy;
private final Account account;
private final User user;
private final boolean inBackground;
private final Context context;
@ -57,7 +57,7 @@ public class RemoveFileOperation extends SyncOperation {
*/
public RemoveFileOperation(OCFile fileToRemove,
boolean onlyLocalCopy,
Account account,
User user,
boolean inBackground,
Context context,
FileDataStorageManager storageManager) {
@ -65,7 +65,7 @@ public class RemoveFileOperation extends SyncOperation {
this.fileToRemove = fileToRemove;
this.onlyLocalCopy = onlyLocalCopy;
this.account = account;
this.user = user;
this.inBackground = inBackground;
this.context = context;
}
@ -105,7 +105,7 @@ public class RemoveFileOperation extends SyncOperation {
OCFile parent = getStorageManager().getFileByPath(fileToRemove.getParentRemotePath());
operation = new RemoveRemoteEncryptedFileOperation(fileToRemove.getRemotePath(),
parent.getLocalId(),
account,
user,
context,
fileToRemove.getEncryptedFileName());
} else {

View file

@ -21,10 +21,10 @@
package com.owncloud.android.operations;
import android.accounts.Account;
import android.content.Context;
import com.google.gson.reflect.TypeToken;
import com.nextcloud.client.account.User;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.DecryptedFolderMetadata;
import com.owncloud.android.datamodel.EncryptedFolderMetadata;
@ -63,7 +63,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
private String remotePath;
private String parentId;
private Account account;
private User user;
private ArbitraryDataProvider arbitraryDataProvider;
private String fileName;
@ -76,12 +76,12 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
*/
RemoveRemoteEncryptedFileOperation(String remotePath,
String parentId,
Account account,
User user,
Context context,
String fileName) {
this.remotePath = remotePath;
this.parentId = parentId;
this.account = account;
this.user = user;
this.fileName = fileName;
arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
@ -97,7 +97,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
String token = null;
DecryptedFolderMetadata metadata;
String privateKey = arbitraryDataProvider.getValue(account.name, EncryptionUtils.PRIVATE_KEY);
String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY);
try {
// Lock folder

View file

@ -284,7 +284,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
Context context = getNonNullContext();
OCFile ocFile = document.getFile();
RemoteOperationResult result = new CheckEtagRemoteOperation(ocFile.getRemotePath(), ocFile.getEtag())
.execute(document.getUser().toPlatformAccount(), context);
.execute(document.getUser(), context);
switch (result.getCode()) {
case ETAG_CHANGED:
return true;
@ -611,7 +611,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
OCFile file = document.getStorageManager().getFileByPath(document.getRemotePath());
RemoteOperationResult result = new RemoveFileOperation(file,
false,
document.getUser().toPlatformAccount(),
document.getUser(),
true,
context,
document.getStorageManager())

View file

@ -668,7 +668,7 @@ public class OperationsService extends Service {
boolean inBackground = operationIntent.getBooleanExtra(EXTRA_IN_BACKGROUND, false);
operation = new RemoveFileOperation(file,
onlyLocalCopy,
account,
user,
inBackground,
getApplicationContext(),
fileDataStorageManager);

View file

@ -1165,7 +1165,7 @@ public abstract class DrawerActivity extends ToolbarActivity
Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();

View file

@ -176,7 +176,7 @@ public class RichDocumentsEditorWebView extends EditorWebView {
new Thread(() -> {
User user = currentAccountProvider.getUser();
RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath());
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), this);
RemoteOperationResult result = operation.execute(user, this);
if (result.isSuccess()) {
String asset = (String) result.getSingleData();

View file

@ -108,7 +108,7 @@ public class ShareActivity extends FileActivity {
Activity activity = this;
new Thread(() -> {
RemoteOperationResult result = new ReadFileRemoteOperation(getFile().getRemotePath())
.execute(optionalUser.get().toPlatformAccount(),
.execute(optionalUser.get(),
activity);
if (result.isSuccess()) {

View file

@ -770,7 +770,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
mStorageManager,
user,
activity);
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
refreshFolderOperation.execute(user, activity);
}
}

View file

@ -578,7 +578,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
storageManager,
user,
context)
.execute(user.toPlatformAccount(), context, (caller, result) -> {
.execute(user, context, (caller, result) -> {
view.binding.uploadListItemLayout.setClickable(true);
listener.onRemoteOperationFinish(caller, result);
}, parentActivity.getHandler());

View file

@ -60,8 +60,7 @@ public class FetchRemoteFileTask extends AsyncTask<Void, Void, String> {
FILE_ID_SEARCH,
false,
fileDisplayActivity.getCapabilities());
RemoteOperationResult remoteOperationResult = searchRemoteOperation.execute(user.toPlatformAccount(),
fileDisplayActivity);
RemoteOperationResult remoteOperationResult = searchRemoteOperation.execute(user, fileDisplayActivity);
if (remoteOperationResult.isSuccess() && remoteOperationResult.getData() != null) {
if (remoteOperationResult.getData().isEmpty()) {
@ -70,7 +69,7 @@ public class FetchRemoteFileTask extends AsyncTask<Void, Void, String> {
String remotePath = ((RemoteFile) remoteOperationResult.getData().get(0)).getRemotePath();
ReadFileRemoteOperation operation = new ReadFileRemoteOperation(remotePath);
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), fileDisplayActivity);
RemoteOperationResult result = operation.execute(user, fileDisplayActivity);
if (!result.isSuccess()) {
Exception exception = result.getException();
@ -105,7 +104,7 @@ public class FetchRemoteFileTask extends AsyncTask<Void, Void, String> {
storageManager,
user,
fileDisplayActivity);
refreshFolderOperation.execute(user.toPlatformAccount(), fileDisplayActivity);
refreshFolderOperation.execute(user, fileDisplayActivity);
fileDisplayActivity.setFile(ocFile);
} else {

View file

@ -96,8 +96,7 @@ public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.R
" - " + new Date(endDate * 1000L) +
" with limit: " + limit);
RemoteOperationResult result = searchRemoteOperation.execute(user.toPlatformAccount(),
photoFragment.getContext());
RemoteOperationResult result = searchRemoteOperation.execute(user, photoFragment.getContext());
if (result.isSuccess()) {
boolean emptySearch = parseMedia(startDate, endDate, result.getData());

View file

@ -297,7 +297,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
}
RemoteOperationResult<com.owncloud.android.lib.ocs.responses.PrivateKey> privateKeyResult =
new GetPrivateKeyOperation().execute(user.toPlatformAccount(), getContext());
new GetPrivateKeyOperation().execute(user, getContext());
if (privateKeyResult.isSuccess()) {
Log_OC.d(TAG, "private key successful downloaded for " + user.getAccountName());
@ -356,7 +356,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
String urlEncoded = CsrHelper.generateCsrPemEncodedString(keyPair, userId);
SendCSROperation operation = new SendCSROperation(urlEncoded);
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), getContext());
RemoteOperationResult result = operation.execute(user, getContext());
if (result.isSuccess()) {
Log_OC.d(TAG, "public key success");
@ -374,8 +374,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
// upload encryptedPrivateKey
StorePrivateKeyOperation storePrivateKeyOperation = new StorePrivateKeyOperation(encryptedPrivateKey);
RemoteOperationResult storePrivateKeyResult = storePrivateKeyOperation.execute(user.toPlatformAccount(),
getContext());
RemoteOperationResult storePrivateKeyResult = storePrivateKeyOperation.execute(user, getContext());
if (storePrivateKeyResult.isSuccess()) {
Log_OC.d(TAG, "private key success");
@ -390,7 +389,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj
return (String) storePrivateKeyResult.getData().get(0);
} else {
DeletePublicKeyOperation deletePublicKeyOperation = new DeletePublicKeyOperation();
deletePublicKeyOperation.execute(user.toPlatformAccount(), getContext());
deletePublicKeyOperation.execute(user, getContext());
}
} catch (Exception e) {
Log_OC.e(TAG, e.getMessage());

View file

@ -542,7 +542,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
public void createRichWorkspace() {
new Thread(() -> {
RemoteOperationResult result = new RichWorkspaceDirectEditingRemoteOperation(mFile.getRemotePath())
.execute(accountManager.getUser().toPlatformAccount(), requireContext());
.execute(accountManager.getUser(), requireContext());
if (result.isSuccess()) {
String url = (String) result.getSingleData();

View file

@ -61,9 +61,7 @@ class OCFileListSearchAsyncTask(
}
fragment.setTitle()
val remoteOperationResult = remoteOperation.execute(
currentUser.toPlatformAccount(), fragment.context
)
val remoteOperationResult = remoteOperation.execute(currentUser, fragment.context)
if (remoteOperationResult.hasSuccessfulResult() && !isCancelled && fragment.searchFragment) {
fragment.searchEvent = event
if (remoteOperationResult.resultData.isNullOrEmpty()) {

View file

@ -84,8 +84,7 @@ class SharedListFragment : OCFileListFragment(), Injectable {
private suspend fun fetchFileData(partialFile: OCFile): OCFile? {
return withContext(Dispatchers.IO) {
val user = accountManager.user
val fetchResult = ReadFileRemoteOperation(partialFile.remotePath)
.execute(user.toPlatformAccount(), context)
val fetchResult = ReadFileRemoteOperation(partialFile.remotePath).execute(user, context)
if (!fetchResult.isSuccess) {
logger.e(SHARED_TAG, "Error fetching file")
if (fetchResult.isException) {

View file

@ -260,7 +260,7 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(),
false, false, storageManager, user, context);
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), context);
RemoteOperationResult result = operation.execute(user, context);
return result.isSuccess();
} else {
return Boolean.FALSE;

View file

@ -235,7 +235,7 @@ public class FileOperationsHelper {
// check for changed eTag
CheckEtagRemoteOperation checkEtagOperation = new CheckEtagRemoteOperation(file.getRemotePath(),
file.getEtag());
RemoteOperationResult result = checkEtagOperation.execute(user.toPlatformAccount(), fileActivity);
RemoteOperationResult result = checkEtagOperation.execute(user, fileActivity);
// eTag changed, sync file
if (result.getCode() == RemoteOperationResult.ResultCode.ETAG_CHANGED) {
@ -454,7 +454,7 @@ public class FileOperationsHelper {
final User user = currentAccount.getUser();
new Thread(() -> {
StreamMediaFileOperation sfo = new StreamMediaFileOperation(file.getRemoteId());
RemoteOperationResult result = sfo.execute(user.toPlatformAccount(), fileActivity);
RemoteOperationResult result = sfo.execute(user, fileActivity);
fileActivity.dismissLoadingDialog();

View file

@ -136,7 +136,7 @@ public class PreviewTextStringFragment extends PreviewTextFragment {
private void edit() {
new Thread(() -> {
RemoteOperationResult result = new RichWorkspaceDirectEditingRemoteOperation(getFile().getRemotePath())
.execute(accountManager.getUser().toPlatformAccount(), getContext());
.execute(accountManager.getUser(), getContext());
if (result.isSuccess()) {
String url = (String) result.getSingleData();