use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class DocumentsStorageProvider method copyDocument.
@Override
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
Log.d(TAG, "copyDocument(), id=" + sourceDocumentId);
Document document = toDocument(sourceDocumentId);
FileDataStorageManager storageManager = document.getStorageManager();
Document targetFolder = toDocument(targetParentDocumentId);
RemoteOperationResult result = new CopyFileOperation(document.getRemotePath(), targetFolder.getRemotePath(), document.getStorageManager()).execute(document.getClient());
if (!result.isSuccess()) {
Log_OC.e(TAG, result.toString());
throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId + " to " + targetParentDocumentId);
}
Context context = getNonNullContext();
User user = document.getUser();
RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(), System.currentTimeMillis(), false, false, true, storageManager, user, context).execute(targetFolder.getClient());
if (!updateParent.isSuccess()) {
Log_OC.e(TAG, updateParent.toString());
throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId + " to " + targetParentDocumentId);
}
String newPath = targetFolder.getRemotePath() + document.getFile().getFileName();
if (document.getFile().isFolder()) {
newPath = newPath + PATH_SEPARATOR;
}
Document newFile = new Document(storageManager, newPath);
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
return newFile.getDocumentId();
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class CreateShareWithShareeOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateShareRemoteOperation operation = new CreateShareRemoteOperation(path, shareType, shareeName, false, sharePassword, permissions);
operation.setGetShareDetails(true);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess() && result.getData().size() > 0) {
OCShare share = (OCShare) result.getData().get(0);
// once creating share link update other information
UpdateShareInfoOperation updateShareInfoOperation = new UpdateShareInfoOperation(share, getStorageManager());
updateShareInfoOperation.setExpirationDateInMillis(expirationDateInMillis);
updateShareInfoOperation.setHideFileDownload(hideFileDownload);
updateShareInfoOperation.setNote(noteMessage);
updateShareInfoOperation.setLabel(label);
// execute and save the result in database
RemoteOperationResult updateShareInfoResult = updateShareInfoOperation.execute(client);
if (updateShareInfoResult.isSuccess() && updateShareInfoResult.getData().size() > 0) {
OCShare shareUpdated = (OCShare) updateShareInfoResult.getData().get(0);
updateData(shareUpdated);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult 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.RemoteOperationResult in project android by nextcloud.
the class CreateShareViaLinkOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateShareRemoteOperation createOp = new CreateShareRemoteOperation(path, ShareType.PUBLIC_LINK, "", false, password, OCShare.NO_PERMISSION);
createOp.setGetShareDetails(true);
RemoteOperationResult 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.common.operations.RemoteOperationResult 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