use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class OCFileListAdapter method parseShares.
private void parseShares(ArrayList<Object> objects) {
List<OCShare> shares = new ArrayList<>();
for (int i = 0; i < objects.size(); i++) {
// check type before cast as of long running data fetch it is possible that old result is filled
if (objects.get(i) instanceof OCShare) {
OCShare ocShare = (OCShare) objects.get(i);
shares.add(ocShare);
// get ocFile from Server to have an up-to-date copy
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(ocShare.getPath());
RemoteOperationResult result = operation.execute(mAccount, mContext);
if (result.isSuccess()) {
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
searchForLocalFileInDefaultPath(file);
file = mStorageManager.saveFileWithParent(file, mContext);
ShareType newShareType = ocShare.getShareType();
if (newShareType == ShareType.PUBLIC_LINK) {
file.setShareViaLink(true);
} else if (newShareType == ShareType.USER || newShareType == ShareType.GROUP || newShareType == ShareType.EMAIL || newShareType == ShareType.FEDERATED) {
file.setShareWithSharee(true);
}
mStorageManager.saveFile(file);
if (!mFiles.contains(file)) {
mFiles.add(file);
}
} else {
Log_OC.e(TAG, "Error in getting prop for file: " + ocShare.getPath());
}
}
}
mStorageManager.saveShares(shares);
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
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) {
// get display name
GetRemoteUserInfoOperation getDisplayName = new GetRemoteUserInfoOperation();
RemoteOperationResult result = getDisplayName.execute(client);
if (result.isSuccess()) {
// store display name with account data
AccountManager accountManager = AccountManager.get(MainApp.getAppContext());
UserInfo userInfo = (UserInfo) result.getData().get(0);
Account storedAccount = getStorageManager().getAccount();
accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME, userInfo.getDisplayName());
accountManager.setUserData(storedAccount, AccountUtils.Constants.KEY_USER_ID, userInfo.getId());
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class OAuth2GetAccessToken method run.
/*
public Map<String, String> getResultTokenMap() {
return mResultTokenMap;
}
*/
@Override
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
PostMethod postMethod = null;
try {
parseAuthorizationResponse();
if (mOAuth2ParsedAuthorizationResponse.keySet().contains(OAuth2Constants.KEY_ERROR)) {
if (OAuth2Constants.VALUE_ERROR_ACCESS_DENIED.equals(mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_ERROR))) {
result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR_ACCESS_DENIED);
} else {
result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
}
}
if (result == null) {
NameValuePair[] nameValuePairs = new NameValuePair[4];
nameValuePairs[0] = new NameValuePair(OAuth2Constants.KEY_GRANT_TYPE, mGrantType);
nameValuePairs[1] = new NameValuePair(OAuth2Constants.KEY_CODE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_CODE));
nameValuePairs[2] = new NameValuePair(OAuth2Constants.KEY_REDIRECT_URI, mRedirectUri);
nameValuePairs[3] = new NameValuePair(OAuth2Constants.KEY_CLIENT_ID, mClientId);
// nameValuePairs[4] = new NameValuePair(OAuth2Constants.KEY_SCOPE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_SCOPE));
postMethod = new PostMethod(client.getWebdavUri().toString());
postMethod.setRequestBody(nameValuePairs);
client.executeMethod(postMethod);
String response = postMethod.getResponseBodyAsString();
if (response != null && response.length() > 0) {
JSONObject tokenJson = new JSONObject(response);
parseAccessTokenResult(tokenJson);
if (mResultTokenMap.get(OAuth2Constants.KEY_ERROR) != null || mResultTokenMap.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) {
result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
} else {
result = new RemoteOperationResult(true, postMethod);
ArrayList<Object> data = new ArrayList<>();
data.add(mResultTokenMap);
result.setData(data);
}
} else {
result = new RemoteOperationResult(false, postMethod);
client.exhaustResponse(postMethod.getResponseBodyAsStream());
}
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
} finally {
if (postMethod != null) {
// let the connection available for other methods
postMethod.releaseConnection();
}
final String code = "code";
final String oauth_token_request = "OAuth2 TOKEN REQUEST with auth code ";
if (result != null) {
if (result.isSuccess()) {
Log_OC.i(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
} else if (result.getException() != null) {
Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage(), result.getException());
} else if (result.getCode() == ResultCode.OAUTH2_ERROR) {
Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL"));
} else {
Log_OC.e(TAG, oauth_token_request + mOAuth2ParsedAuthorizationResponse.get(code) + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
}
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by nextcloud.
the class UnshareOperation 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 nextcloud.
the class ActivitiesListActivity method onActivityClicked.
@Override
public void onActivityClicked(RichObject richObject) {
String path = FileUtils.PATH_SEPARATOR + richObject.getPath();
runOnUiThread(new Runnable() {
@Override
public void run() {
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
swipeListRefreshLayout.setVisibility(View.GONE);
setLoadingMessage();
}
});
updateTask = new AsyncTask<String, Object, OCFile>() {
@Override
protected OCFile doInBackground(String... path) {
OCFile ocFile = null;
// always update file as it could be an old state saved in database
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(path[0]);
RemoteOperationResult resultRemoteFileOp = operation.execute(ownCloudClient);
if (resultRemoteFileOp.isSuccess()) {
OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) resultRemoteFileOp.getData().get(0));
ocFile = getStorageManager().saveFileWithParent(temp, getBaseContext());
if (ocFile.isFolder()) {
// perform folder synchronization
RemoteOperation synchFolderOp = new RefreshFolderOperation(ocFile, System.currentTimeMillis(), false, getFileOperationsHelper().isSharedSupported(), true, getStorageManager(), getAccount(), getApplicationContext());
synchFolderOp.execute(ownCloudClient);
}
}
return ocFile;
}
@Override
protected void onPostExecute(OCFile ocFile) {
if (!isCancelled()) {
if (ocFile == null) {
Toast.makeText(getBaseContext(), R.string.file_not_found, Toast.LENGTH_LONG).show();
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
swipeListRefreshLayout.setVisibility(View.VISIBLE);
dismissLoadingDialog();
} else {
Intent showDetailsIntent;
if (PreviewImageFragment.canBePreviewed(ocFile)) {
showDetailsIntent = new Intent(getBaseContext(), PreviewImageActivity.class);
} else {
showDetailsIntent = new Intent(getBaseContext(), FileDisplayActivity.class);
}
showDetailsIntent.putExtra(EXTRA_FILE, ocFile);
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
startActivity(showDetailsIntent);
}
}
}
};
updateTask.execute(path);
}
Aggregations