use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method saveSharesDB.
public void saveSharesDB(ArrayList<OCShare> shares) {
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
// Reset flags & Remove shares for this files
String filePath = "";
for (OCShare share : shares) {
if (filePath != share.getPath()) {
filePath = share.getPath();
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());
}
}
// // TODO: review if it is needed
// // Update shared files
// ArrayList<OCFile> sharedFiles = new ArrayList<OCFile>();
//
// for (OCShare share : shares) {
// // Get the path
// String path = share.getPath();
// if (share.isFolder()) {
// path = path + FileUtils.PATH_SEPARATOR;
// }
//
// // Update OCFile with data from share: ShareByLink, publicLink and
// OCFile file = getFileByPath(path);
// if (file != null) {
// if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
// file.setShareViaLink(true);
// sharedFiles.add(file);
// }
// }
// }
//
// // TODO: Review
// updateSharedFiles(sharedFiles);
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class UpdateShareViaLinkOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
OCShare publicShare = getStorageManager().getFirstShareByPathAndType(mPath, ShareType.PUBLIC_LINK, "");
if (publicShare == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
// Update remote share with password
UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(publicShare.getRemoteId());
updateOp.setPassword(mPassword);
updateOp.setExpirationDate(mExpirationDateInMillis);
updateOp.setPublicUpload(mPublicUpload);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
// Retrieve updated share / save directly with password? -> no; the password is not to be saved
RemoteOperation getShareOp = new GetRemoteShareOperation(publicShare.getRemoteId());
result = getShareOp.execute(client);
if (result.isSuccess()) {
OCShare share = (OCShare) result.getData().get(0);
updateData(share);
}
}
return result;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method getSharesWithForAFile.
public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName) {
// Condition
String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + "AND" + " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
String[] whereArgs = new String[] { filePath, accountName, Integer.toString(ShareType.USER.getValue()), Integer.toString(ShareType.GROUP.getValue()), Integer.toString(ShareType.FEDERATED.getValue()) };
Cursor c = null;
if (getContentResolver() != null) {
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where, whereArgs, null);
} else {
try {
c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_SHARE, null, where, whereArgs, null);
} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
c = null;
}
}
ArrayList<OCShare> shares = new ArrayList<OCShare>();
OCShare share = null;
if (c != null) {
if (c.moveToFirst()) {
do {
share = createShareInstance(c);
shares.add(share);
// }
} while (c.moveToNext());
}
c.close();
}
return shares;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class GetSharesForFileOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mPath, mReshares, mSubfiles);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
// Update DB with the response
Log_OC.d(TAG, "File = " + mPath + " Share list size " + result.getData().size());
ArrayList<OCShare> shares = new ArrayList<OCShare>();
for (Object obj : result.getData()) {
shares.add((OCShare) obj);
}
getStorageManager().saveSharesDB(shares);
} else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) {
// no share on the file - remove local shares
getStorageManager().removeSharesForFile(mPath);
}
return result;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class UnshareOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
// Get Share for a file
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, mShareType, mShareWith);
if (share != null) {
OCFile file = getStorageManager().getFileByPath(mRemotePath);
RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getRemoteId());
result = operation.execute(client);
if (result.isSuccess()) {
Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
if (ShareType.PUBLIC_LINK.equals(mShareType)) {
file.setShareViaLink(false);
file.setPublicLink("");
} else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType) || ShareType.FEDERATED.equals(mShareType)) {
// Check if it is the last share
ArrayList<OCShare> sharesWith = getStorageManager().getSharesWithForAFile(mRemotePath, getStorageManager().getAccount().name);
if (sharesWith.size() == 1) {
file.setShareWithSharee(false);
}
}
getStorageManager().saveFile(file);
getStorageManager().removeShare(share);
} else if (result.getCode() != ResultCode.SERVICE_UNAVAILABLE && !existsFile(client, file.getRemotePath())) {
// unshare failed because file was deleted before
getStorageManager().removeFile(file, true, true);
}
} else {
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
}
return result;
}
Aggregations