use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.
the class UploadFileOperation method grantFolderExistence.
/**
* Checks the existence of the folder where the current file will be uploaded both
* in the remote server and in the local database.
* <p/>
* If the upload is set to enforce the creation of the folder, the method tries to
* create it both remote and locally.
*
* @param pathToGrant Full remote path whose existence will be granted.
* @return An {@link OCFile} instance corresponding to the folder where the file
* will be uploaded.
*/
private RemoteOperationResult grantFolderExistence(String pathToGrant, OwnCloudClient client) {
RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, false);
RemoteOperationResult result = operation.execute(client);
if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mRemoteFolderToBeCreated) {
SyncOperation syncOp = new CreateFolderOperation(pathToGrant, user, getContext(), getStorageManager());
result = syncOp.execute(client);
}
if (result.isSuccess()) {
OCFile parentDir = getStorageManager().getFileByPath(pathToGrant);
if (parentDir == null) {
parentDir = createLocalFolder(pathToGrant);
}
if (parentDir != null) {
result = new RemoteOperationResult(ResultCode.OK);
} else {
result = new RemoteOperationResult(ResultCode.CANNOT_CREATE_FILE);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.
the class OperationsService method onStartCommand.
/**
* Entry point to add a new operation to the queue of operations.
* <p/>
* New operations are added calling to startService(), resulting in a call to this method. This ensures the service
* will keep on working although the caller activity goes away.
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log_OC.d(TAG, "Starting command with id " + startId);
// the rest of the operations are requested through the Binder
if (intent != null && ACTION_SYNC_FOLDER.equals(intent.getAction())) {
if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_REMOTE_PATH)) {
Log_OC.e(TAG, "Not enough information provided in intent");
return START_NOT_STICKY;
}
Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
Pair<Account, String> itemSyncKey = new Pair<>(account, remotePath);
Pair<Target, RemoteOperation> itemToQueue = newOperation(intent);
if (itemToQueue != null) {
mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation) itemToQueue.second);
Message msg = mSyncFolderHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = itemSyncKey;
mSyncFolderHandler.sendMessage(msg);
}
} else {
Message msg = mOperationsHandler.obtainMessage();
msg.arg1 = startId;
mOperationsHandler.sendMessage(msg);
}
return START_NOT_STICKY;
}
use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.
the class UpdateSharePermissionsOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// ShareType.USER | ShareType.GROUP
OCShare share = getStorageManager().getShareById(shareId);
if (share == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
path = share.getPath();
// Update remote share with password
UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(share.getRemoteId());
updateOp.setPassword(password);
updateOp.setPermissions(permissions);
updateOp.setExpirationDate(expirationDateInMillis);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
RemoteOperation getShareOp = new GetShareRemoteOperation(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.common.operations.RemoteOperation in project android by nextcloud.
the class UpdateShareInfoOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
OCShare share;
if (shareId > 0) {
share = getStorageManager().getShareById(shareId);
} else {
share = this.share;
}
if (share == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
// Update remote share
UpdateShareRemoteOperation updateOp = new UpdateShareRemoteOperation(share.getRemoteId());
updateOp.setExpirationDate(expirationDateInMillis);
updateOp.setHideFileDownload(hideFileDownload);
if (!TextUtils.isEmpty(note)) {
updateOp.setNote(note);
}
if (permissions > -1) {
updateOp.setPermissions(permissions);
}
updateOp.setPassword(password);
updateOp.setLabel(label);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
RemoteOperation getShareOp = new GetShareRemoteOperation(share.getRemoteId());
result = getShareOp.execute(client);
// this will be triggered by editing existing share
if (result.isSuccess() && shareId > 0) {
OCShare ocShare = (OCShare) result.getData().get(0);
ocShare.setPasswordProtected(!TextUtils.isEmpty(password));
getStorageManager().saveShare(ocShare);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.
the class DetectAuthenticationMethodOperation method run.
/**
* Performs the operation.
*
* Triggers a check of existence on the root folder of the server, granting
* that the request is not authenticated.
*
* Analyzes the result of check to find out what authentication method, if
* any, is requested by the server.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
client.clearCredentials();
client.setFollowRedirects(false);
// try to access the root folder, following redirections but not SAML SSO redirections
result = operation.execute(client);
String redirectedLocation = result.getRedirectedLocation();
while (!TextUtils.isEmpty(redirectedLocation) && !result.isIdPRedirection()) {
client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();
}
// analyze response
if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED || result.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
ArrayList<String> authHeaders = result.getAuthenticateHeaders();
for (String header : authHeaders) {
// currently we only support basic auth
if (header.toLowerCase(Locale.ROOT).contains("basic")) {
authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;
break;
}
}
// else - fall back to UNKNOWN
} else if (result.isSuccess()) {
authMethod = AuthenticationMethod.NONE;
} else if (result.isIdPRedirection()) {
authMethod = AuthenticationMethod.SAML_WEB_SSO;
}
// else - fall back to UNKNOWN
Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));
if (authMethod != AuthenticationMethod.UNKNOWN) {
result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), new Header[0]);
}
ArrayList<Object> data = new ArrayList<>();
data.add(authMethod);
result.setData(data);
// same result instance, so that other errors
return result;
// can be handled by the caller transparently
}
Aggregations