use of com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation 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.GetRemoteSharesForFileOperation 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;
}
use of com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation 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;
}
Aggregations