Search in sources :

Example 21 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadsStorageManager method getUploadById.

@Nullable
public OCUpload getUploadById(long id) {
    OCUpload result = null;
    Cursor cursor = getDB().query(ProviderTableMeta.CONTENT_URI_UPLOADS, null, ProviderTableMeta._ID + "=?", new String[] { Long.toString(id) }, "_id ASC");
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            result = createOCUploadFromCursor(cursor);
        }
    }
    Log_OC.d(TAG, "Retrieve job " + result + " for id " + id);
    return result;
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) Cursor(android.database.Cursor) Nullable(androidx.annotation.Nullable)

Example 22 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadsStorageManager method createOCUploadFromCursor.

private OCUpload createOCUploadFromCursor(Cursor c) {
    OCUpload upload = null;
    if (c != null) {
        String localPath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH));
        String remotePath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_REMOTE_PATH));
        String accountName = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_ACCOUNT_NAME));
        upload = new OCUpload(localPath, remotePath, accountName);
        upload.setFileSize(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FILE_SIZE)));
        upload.setUploadId(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta._ID)));
        upload.setUploadStatus(UploadStatus.fromValue(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_STATUS))));
        upload.setLocalAction(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)));
        upload.setNameCollisionPolicy(NameCollisionPolicy.deserialize(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
        upload.setCreateRemoteFolder(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
        upload.setUploadEndTimestamp(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)));
        upload.setLastResult(UploadResult.fromValue(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LAST_RESULT))));
        upload.setCreatedBy(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_CREATED_BY)));
        upload.setUseWifiOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) == 1);
        upload.setWhileChargingOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY)) == 1);
        upload.setFolderUnlockToken(c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN)));
    }
    return upload;
}
Also used : OCUpload(com.owncloud.android.db.OCUpload)

Example 23 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class FilesSyncHelper method restartJobsIfNeeded.

public static void restartJobsIfNeeded() {
    final Context context = MainApp.getAppContext();
    FileUploader.UploadRequester uploadRequester = new FileUploader.UploadRequester();
    boolean accountExists;
    UploadsStorageManager uploadsStorageManager = new UploadsStorageManager(context.getContentResolver(), context);
    OCUpload[] failedUploads = uploadsStorageManager.getFailedUploads();
    for (OCUpload failedUpload : failedUploads) {
        accountExists = false;
        // check if accounts still exists
        for (Account account : AccountUtils.getAccounts(context)) {
            if (account.name.equals(failedUpload.getAccountName())) {
                accountExists = true;
                break;
            }
        }
        if (!accountExists) {
            uploadsStorageManager.removeUpload(failedUpload);
        }
    }
    new Thread(() -> {
        if (!Device.getNetworkType(context).equals(JobRequest.NetworkType.ANY) && !ConnectivityUtils.isInternetWalled(context)) {
            uploadRequester.retryFailedUploads(context, null, null);
        }
    }).start();
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OCUpload(com.owncloud.android.db.OCUpload) FileUploader(com.owncloud.android.files.services.FileUploader) UploadsStorageManager(com.owncloud.android.datamodel.UploadsStorageManager)

Example 24 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class UploadsStorageManager method getUploads.

private OCUpload[] getUploads(@Nullable String selection, @Nullable String[] selectionArgs) {
    OCUpload[] list;
    Cursor c = getDB().query(ProviderTableMeta.CONTENT_URI_UPLOADS, null, selection, selectionArgs, null);
    if (c != null) {
        list = new OCUpload[c.getCount()];
        if (c.moveToFirst()) {
            do {
                OCUpload upload = createOCUploadFromCursor(c);
                if (upload == null) {
                    Log_OC.e(TAG, "OCUpload could not be created from cursor");
                } else {
                    list[c.getPosition()] = upload;
                }
            } while (c.moveToNext());
        }
        c.close();
    } else {
        list = new OCUpload[0];
    }
    return list;
}
Also used : OCUpload(com.owncloud.android.db.OCUpload) Cursor(android.database.Cursor)

Example 25 with OCUpload

use of com.owncloud.android.db.OCUpload in project android by nextcloud.

the class EndToEndRandomIT method testUploadWithMove.

@Test
public void testUploadWithMove() throws Exception {
    init();
    OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt", currentFolder.getRemotePath() + "nonEmpty.txt", account.name);
    uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
    File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
    OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() + "nonEmpty.txt");
    assertFalse(originalFile.exists());
    assertTrue(new File(uploadedFile.getStoragePath()).exists());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) OCUpload(com.owncloud.android.db.OCUpload) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) Test(org.junit.Test)

Aggregations

OCUpload (com.owncloud.android.db.OCUpload)49 Test (org.junit.Test)29 OCFile (com.owncloud.android.datamodel.OCFile)22 File (java.io.File)15 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)8 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)8 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)7 Intent (android.content.Intent)6 SmallTest (androidx.test.filters.SmallTest)5 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)4 Account (android.accounts.Account)3 Context (android.content.Context)3 Cursor (android.database.Cursor)3 DialogFragment (androidx.fragment.app.DialogFragment)3 BatteryStatus (com.nextcloud.client.device.BatteryStatus)3 Connectivity (com.nextcloud.client.network.Connectivity)3 ConnectivityService (com.nextcloud.client.network.ConnectivityService)3 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)3 RandomAccessFile (java.io.RandomAccessFile)3 SuppressLint (android.annotation.SuppressLint)2