use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class CreateFolderOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
CreateRemoteFolderOperation operation = new CreateRemoteFolderOperation(mRemotePath, mCreateFullPath);
RemoteOperationResult result = operation.execute(client);
if (result.isSuccess()) {
OCFile newDir = saveFolderInDB();
String localPath = FileStorageUtils.getDefaultSavePathFor(getStorageManager().getAccount().name, newDir);
File localFile = new File(localPath);
boolean created = localFile.mkdirs();
if (!created) {
Log_OC.w(TAG, "Local folder " + localPath + " was not fully created");
}
} else {
Log_OC.e(TAG, mRemotePath + "hasn't been created");
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult 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.common.operations.RemoteOperationResult in project android by owncloud.
the class DownloadFileOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
File newFile;
boolean moved;
/// download will be performed to a temporal file, then moved to the final location
File tmpFile = new File(getTmpPath());
String tmpFolder = getTmpFolder();
/// perform the download
synchronized (mCancellationRequested) {
if (mCancellationRequested.get()) {
return new RemoteOperationResult(new OperationCancelledException());
}
}
mDownloadOperation = new DownloadRemoteFileOperation(mFile.getRemotePath(), tmpFolder);
Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
while (listener.hasNext()) {
mDownloadOperation.addDatatransferProgressListener(listener.next());
}
result = mDownloadOperation.execute(client);
if (result.isSuccess()) {
mModificationTimestamp = mDownloadOperation.getModificationTimestamp();
mEtag = mDownloadOperation.getEtag();
if (FileStorageUtils.getUsableSpace(mAccount.name) < tmpFile.length()) {
Log_OC.w(TAG, "Not enough space to copy " + tmpFile.getAbsolutePath());
}
newFile = new File(getSavePath());
Log_OC.d(TAG, "Save path: " + newFile.getAbsolutePath());
File parent = newFile.getParentFile();
boolean created = parent.mkdirs();
Log_OC.d(TAG, "Creation of parent folder " + parent.getAbsolutePath() + " succeeded: " + created);
Log_OC.d(TAG, "Parent folder " + parent.getAbsolutePath() + " exists: " + parent.exists());
Log_OC.d(TAG, "Parent folder " + parent.getAbsolutePath() + " is directory: " + parent.isDirectory());
moved = tmpFile.renameTo(newFile);
Log_OC.d(TAG, "New file " + newFile.getAbsolutePath() + " exists: " + newFile.exists());
Log_OC.d(TAG, "New file " + newFile.getAbsolutePath() + " is directory: " + newFile.isDirectory());
if (!moved) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED);
}
}
Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage());
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class GetServerInfoOperation method run.
/**
* Performs the operation
*
* @return Result of the operation. If successful, includes an instance of
* {@link ServerInfo} with the information retrieved from the server.
* Call {@link RemoteOperationResult#getData()}.get(0) to get it.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// first: check the status of the server (including its version)
GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mContext);
RemoteOperationResult result = getStatus.execute(client);
if (result.isSuccess()) {
// second: get authentication method required by the server
mResultData.mVersion = (OwnCloudVersion) (result.getData().get(0));
mResultData.mIsSslConn = (result.getCode() == ResultCode.OK_SSL);
mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn);
RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client);
// third: merge results
if (detectAuthResult.isSuccess()) {
mResultData.mAuthMethod = (AuthenticationMethod) detectAuthResult.getData().get(0);
ArrayList<Object> data = new ArrayList<Object>();
data.add(mResultData);
result.setData(data);
} else {
result = detectAuthResult;
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class GetUserProfileOperation method run.
/**
* Performs the operation.
*
* Target user account is implicit in 'client'.
*
* Stored account is implicit in {@link #getStorageManager()}.
*
* @return Result of the operation. If successful, includes an instance of
* {@link String} with the display name retrieved from the server.
* Call {@link RemoteOperationResult#getData()}.get(0) to get it.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
UserProfile userProfile = null;
RemoteOperationResult result = null;
try {
/// get display name
GetRemoteUserInfoOperation getDisplayName = new GetRemoteUserInfoOperation();
RemoteOperationResult remoteResult = getDisplayName.execute(client);
if (remoteResult.isSuccess()) {
// store display name with account data
AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
UserInfo userInfo = (UserInfo) remoteResult.getData().get(0);
Account storedAccount = getStorageManager().getAccount();
accountManager.setUserData(storedAccount, // keep also there, for the moment
AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.mDisplayName);
// map user info into UserProfile instance
userProfile = new UserProfile(storedAccount.name, userInfo.mId, userInfo.mDisplayName, userInfo.mEmail);
/// get avatar (optional for success)
int dimension = getAvatarDimension();
UserProfile.UserAvatar currentUserAvatar = getUserProfilesRepository().getAvatar(storedAccount.name);
GetRemoteUserAvatarOperation getAvatarOperation = new GetRemoteUserAvatarOperation(dimension, (currentUserAvatar == null) ? "" : currentUserAvatar.getEtag());
remoteResult = getAvatarOperation.execute(client);
if (remoteResult.isSuccess()) {
GetRemoteUserAvatarOperation.ResultData avatar = (GetRemoteUserAvatarOperation.ResultData) remoteResult.getData().get(0);
//
byte[] avatarData = avatar.getAvatarData();
String avatarKey = ThumbnailsCacheManager.addAvatarToCache(storedAccount.name, avatarData, dimension);
UserProfile.UserAvatar userAvatar = new UserProfile.UserAvatar(avatarKey, avatar.getMimeType(), avatar.getEtag());
userProfile.setAvatar(userAvatar);
} else if (remoteResult.getCode().equals(RemoteOperationResult.ResultCode.FILE_NOT_FOUND)) {
Log_OC.i(TAG, "No avatar available, removing cached copy");
getUserProfilesRepository().deleteAvatar(storedAccount.name);
ThumbnailsCacheManager.removeAvatarFromCache(storedAccount.name);
}
// others are ignored, including 304 (not modified), so the avatar is only stored
// if changed in the server :D
/// store userProfile
getUserProfilesRepository().update(userProfile);
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);
ArrayList<Object> data = new ArrayList<>();
data.add(userProfile);
result.setData(data);
} else {
result = remoteResult;
}
} catch (Exception e) {
Log_OC.e(TAG, "Exception while getting user profile: ", e);
result = new RemoteOperationResult(e);
}
return result;
}
Aggregations