List of usage examples for android.content OperationApplicationException getMessage
public String getMessage()
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
public void removeSharesForFile(String remotePath) { resetShareFlagInAFile(remotePath);/*from www. j a v a 2 s .com*/ ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); operations = prepareRemoveSharesInFile(remotePath, operations); // apply operations in batch if (operations.size() > 0) { Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); try { if (getContentResolver() != null) { getContentResolver().applyBatch(MainApp.getAuthority(), operations); } else { getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } catch (RemoteException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } } }
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
public void saveSharesInFolder(ArrayList<OCShare> shares, OCFile folder) { resetShareFlagsInFolder(folder);/*from w w w. j a v a 2s . co m*/ ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); operations = prepareRemoveSharesInFolder(folder, operations); if (shares != null) { // prepare operations to insert or update files to save in the given folder operations = prepareInsertShares(shares, operations); } // apply operations in batch if (operations.size() > 0) { Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); try { if (getContentResolver() != null) { getContentResolver().applyBatch(MainApp.getAuthority(), operations); } else { getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } catch (RemoteException e) { } } }
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
public void saveShares(ArrayList<OCShare> shares) { ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); // Reset flags & Remove shares for this files String filePath = ""; for (OCShare share : shares) { if (!filePath.equals(share.getPath())) { filePath = share.getPath();//w w w. ja v a2 s. c o m resetShareFlagInAFile(filePath); operations = prepareRemoveSharesInFile(filePath, operations); } } // Add operations to insert shares operations = prepareInsertShares(shares, operations); // apply operations in batch if (operations.size() > 0) { Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); try { if (getContentResolver() != null) { getContentResolver().applyBatch(MainApp.getAuthority(), operations); } else { getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } catch (RemoteException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } } }
From source file:com.owncloud.android.datamodel.FileDataStorageManager.java
/** * Inserts or updates the list of files contained in a given folder. * <p/>// ww w.java 2 s .com * CALLER IS THE RESPONSIBLE FOR GRANTING RIGHT UPDATE OF INFORMATION, NOT THIS METHOD. * HERE ONLY DATA CONSISTENCY SHOULD BE GRANTED * * @param folder * @param updatedFiles * @param filesToRemove */ public void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove) { Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size() + " children and " + filesToRemove.size() + " files to remove"); ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>( updatedFiles.size()); // prepare operations to insert or update files to save in the given folder for (OCFile file : updatedFiles) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp()); cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData()); cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp()); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength()); cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype()); cv.put(ProviderTableMeta.FILE_NAME, file.getFileName()); cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId()); cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath()); if (!file.isFolder()) { cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath()); } cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_TREE_ETAG, file.getTreeEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0); cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail()); cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading()); cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict()); cv.put(ProviderTableMeta.FILE_PRIVATE_LINK, file.getPrivateLink()); boolean existsByPath = fileExists(file.getRemotePath()); if (existsByPath || fileExists(file.getFileId())) { // updating an existing file operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).withValues(cv) .withSelection(ProviderTableMeta._ID + "=?", new String[] { String.valueOf(file.getFileId()) }) .build()); } else { // adding a new file setInitialAvailableOfflineStatus(file, cv); operations.add( ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build()); } } // prepare operations to remove files in the given folder String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?"; String[] whereArgs = null; for (OCFile file : filesToRemove) { if (file.getParentId() == folder.getFileId()) { whereArgs = new String[] { mAccount.name, file.getRemotePath() }; if (file.isFolder()) { operations.add(ContentProviderOperation .newDelete( ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, file.getFileId())) .withSelection(where, whereArgs).build()); File localFolder = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file)); if (localFolder.exists()) { removeLocalFolder(localFolder); } } else { operations.add(ContentProviderOperation.newDelete( ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId())) .withSelection(where, whereArgs).build()); if (file.isDown()) { String path = file.getStoragePath(); new File(path).delete(); triggerMediaScan(path); // notify MediaScanner about removed file } } } } // update metadata of folder ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp()); cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, folder.getModificationTimestampAtLastSyncForData()); cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp()); cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, folder.getFileLength()); cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype()); cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName()); cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId()); cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath()); cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties()); cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData()); cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag()); cv.put(ProviderTableMeta.FILE_TREE_ETAG, folder.getTreeEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0); cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId()); cv.put(ProviderTableMeta.FILE_PRIVATE_LINK, folder.getPrivateLink()); operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).withValues(cv) .withSelection(ProviderTableMeta._ID + "=?", new String[] { String.valueOf(folder.getFileId()) }) .build()); // apply operations in batch ContentProviderResult[] results = null; Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); try { if (getContentResolver() != null) { results = getContentResolver().applyBatch(MainApp.getAuthority(), operations); } else { results = getContentProviderClient().applyBatch(operations); } } catch (OperationApplicationException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } catch (RemoteException e) { Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); } // update new id in file objects for insertions if (results != null) { long newId; Iterator<OCFile> filesIt = updatedFiles.iterator(); OCFile file = null; for (int i = 0; i < results.length; i++) { if (filesIt.hasNext()) { file = filesIt.next(); } else { file = null; } if (results[i].uri != null) { newId = Long.parseLong(results[i].uri.getPathSegments().get(1)); //updatedFiles.get(i).setFileId(newId); if (file != null) { file.setFileId(newId); } } } } }