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;
}
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;
}
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();
}
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;
}
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());
}
Aggregations