use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class OperationsService method dispatchResultToOperationListeners.
/**
* Notifies the currently subscribed listeners about the end of an operation.
*
* @param operation Finished operation.
* @param result Result of the operation.
*/
protected void dispatchResultToOperationListeners(final RemoteOperation operation, final RemoteOperationResult result) {
int count = 0;
Iterator<OnRemoteOperationListener> listeners = mOperationsBinder.mBoundListeners.keySet().iterator();
while (listeners.hasNext()) {
final OnRemoteOperationListener listener = listeners.next();
final Handler handler = mOperationsBinder.mBoundListeners.get(listener);
if (handler != null) {
handler.post(new Runnable() {
@Override
public void run() {
listener.onRemoteOperationFinish(operation, result);
}
});
count += 1;
}
}
if (count == 0) {
Pair<RemoteOperation, RemoteOperationResult> undispatched = new Pair<RemoteOperation, RemoteOperationResult>(operation, result);
mUndispatchedFinishedOperations.put(((Runnable) operation).hashCode(), undispatched);
}
Log_OC.d(TAG, "Called " + count + " listeners");
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UploadFileOperation method existsFile.
private boolean existsFile(OwnCloudClient client, String remotePath) {
ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
RemoteOperationResult result = existsOperation.execute(client);
return result.isSuccess();
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class CreateShareWithShareeOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateRemoteShareOperation operation = new CreateRemoteShareOperation(mPath, mShareType, mShareeName, false, "", mPermissions);
operation.setGetShareDetails(true);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
if (result.getData().size() > 0) {
OCShare share = (OCShare) result.getData().get(0);
updateData(share);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
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 (redirectedLocation != null && redirectedLocation.length() > 0 && !result.isIdPRedirection()) {
client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();
}
// analyze response
if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
String authRequest = ((result.getAuthenticateHeader()).trim()).toLowerCase();
if (authRequest.startsWith("basic")) {
authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;
} else if (authRequest.startsWith("bearer")) {
authMethod = AuthenticationMethod.BEARER_TOKEN;
}
// 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.equals(AuthenticationMethod.UNKNOWN)) {
result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null);
}
ArrayList<Object> data = new ArrayList<Object>();
data.add(authMethod);
result.setData(data);
// same result instance, so that other errors
return result;
// can be handled by the caller transparently
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class GetCapabilitiesOperarion method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
RemoteOperationResult result = getCapabilities.execute(client);
if (result.isSuccess()) {
// Read data from the result
if (result.getData() != null && result.getData().size() > 0) {
OCCapability capability = (OCCapability) result.getData().get(0);
// Save the capabilities into database
getStorageManager().saveCapabilities(capability);
}
}
return result;
}
Aggregations