use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method saveShares.
public void saveShares(Collection<OCShare> shares) {
cleanShares();
if (shares != null) {
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(shares.size());
// prepare operations to insert or update files to save in the given folder
for (OCShare share : shares) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
if (shareExistsForRemoteId(share.getRemoteId())) {
// updating an existing file
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).withSelection(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", new String[] { String.valueOf(share.getRemoteId()) }).build());
} else {
// adding a new file
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
}
}
// apply operations in batch
if (operations.size() > 0) {
@SuppressWarnings("unused") 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());
}
}
}
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class FileDataStorageManager method getShareById.
/**
* Retrieves an stored {@link OCShare} given its id.
*
* @param id Identifier.
* @return Stored {@link OCShare} given its id.
*/
public OCShare getShareById(long id) {
OCShare share = null;
Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
if (c != null) {
if (c.moveToFirst()) {
share = createShareInstance(c);
}
c.close();
}
return share;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class UpdateSharePermissionsOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// ShareType.USER | ShareType.GROUP
OCShare share = getStorageManager().getShareById(mShareId);
if (share == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
mPath = share.getPath();
// Update remote share with password
UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId());
updateOp.setPermissions(mPermissions);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId());
result = getShareOp.execute(client);
if (result.isSuccess()) {
share = (OCShare) result.getData().get(0);
// TODO check permissions are being saved
updateData(share);
}
}
return result;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class CreateShareViaLinkOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// Check if the share link already exists
RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
RemoteOperationResult result = operation.execute(client);
// Create public link if doesn't exist yet
boolean publicShareExists = false;
if (result.isSuccess()) {
OCShare share = null;
for (int i = 0; i < result.getData().size(); i++) {
share = (OCShare) result.getData().get(i);
if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
publicShareExists = true;
break;
}
}
}
if (!publicShareExists) {
CreateRemoteShareOperation createOp = new CreateRemoteShareOperation(mPath, ShareType.PUBLIC_LINK, "", false, mPassword, OCShare.DEFAULT_PERMISSION);
createOp.setGetShareDetails(true);
result = createOp.execute(client);
}
if (result.isSuccess()) {
if (result.getData().size() > 0) {
Object item = result.getData().get(0);
if (item instanceof OCShare) {
updateData((OCShare) item);
} else {
ArrayList<Object> data = result.getData();
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
result.setData(data);
}
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
}
return result;
}
use of com.owncloud.android.lib.resources.shares.OCShare in project android by owncloud.
the class RefreshFolderOperation method refreshSharesForFolder.
/**
* Syncs the Share resources for the files contained in the folder refreshed (children, not deeper descendants).
*
* @param client Handler of a session with an OC server.
* @return The result of the remote operation retrieving the Share resources in the folder refreshed by
* the operation.
*/
private RemoteOperationResult refreshSharesForFolder(OwnCloudClient client) {
RemoteOperationResult result;
// remote request
GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), true, true);
result = operation.execute(client);
if (result.isSuccess()) {
// update local database
ArrayList<OCShare> shares = new ArrayList<>();
for (Object obj : result.getData()) {
shares.add((OCShare) obj);
}
getStorageManager().saveSharesInFolder(shares, mLocalFolder);
}
return result;
}
Aggregations