use of com.dropbox.core.v2.files.GetMetadataErrorException in project orgzly-android by orgzly.
the class DropboxClient method getBooks.
public List<VersionedRook> getBooks(Uri repoUri) throws IOException {
linkedOrThrow();
List<VersionedRook> list = new ArrayList<>();
String path = repoUri.getPath();
/* Fix root path. */
if (path == null || path.equals("/")) {
path = ROOT_PATH;
}
/* Strip trailing slashes. */
path = path.replaceAll("/+$", "");
try {
if (ROOT_PATH.equals(path) || dbxClient.files().getMetadata(path) instanceof FolderMetadata) {
/* Get folder content. */
ListFolderResult result = dbxClient.files().listFolder(path);
while (true) {
for (Metadata metadata : result.getEntries()) {
if (metadata instanceof FileMetadata) {
FileMetadata file = (FileMetadata) metadata;
if (BookName.isSupportedFormatFileName(file.getName())) {
Uri uri = repoUri.buildUpon().appendPath(file.getName()).build();
VersionedRook book = new VersionedRook(repoUri, uri, file.getRev(), file.getServerModified().getTime());
list.add(book);
}
}
}
if (!result.getHasMore()) {
break;
}
result = dbxClient.files().listFolderContinue(result.getCursor());
}
} else {
throw new IOException("Not a directory: " + repoUri);
}
} catch (DbxException e) {
e.printStackTrace();
/* If we get NOT_FOUND from Dropbox, just return the empty list. */
if (e instanceof GetMetadataErrorException) {
if (((GetMetadataErrorException) e).errorValue.getPathValue() == LookupError.NOT_FOUND) {
return list;
}
}
throw new IOException("Failed getting the list of files in " + repoUri + " listing " + path + ": " + (e.getMessage() != null ? e.getMessage() : e.toString()));
}
return list;
}
use of com.dropbox.core.v2.files.GetMetadataErrorException in project keepass2android by PhilippC.
the class DropboxV2Storage method convertException.
private Exception convertException(DbxException e) {
Log.d(TAG, "Exception of type " + e.getClass().getName() + ":" + e.getMessage());
if (InvalidAccessTokenException.class.isAssignableFrom(e.getClass())) {
Log.d(TAG, "LoggedIn=false (due to InvalidAccessTokenException)");
setLoggedIn(false);
clearKeys();
return new UserInteractionRequiredException("Unlinked from Dropbox! User must re-link.", e);
}
if (ListFolderErrorException.class.isAssignableFrom(e.getClass())) {
ListFolderErrorException listFolderErrorException = (ListFolderErrorException) e;
if (listFolderErrorException.errorValue.getPathValue().isNotFound())
return new FileNotFoundException(e.toString());
}
if (DownloadErrorException.class.isAssignableFrom(e.getClass())) {
DownloadErrorException downloadErrorException = (DownloadErrorException) e;
if (downloadErrorException.errorValue.getPathValue().isNotFound())
return new FileNotFoundException(e.toString());
}
if (GetMetadataErrorException.class.isAssignableFrom(e.getClass())) {
GetMetadataErrorException getMetadataErrorException = (GetMetadataErrorException) e;
if (getMetadataErrorException.errorValue.getPathValue().isNotFound())
return new FileNotFoundException(e.toString());
}
if (DeleteErrorException.class.isAssignableFrom(e.getClass())) {
DeleteErrorException deleteErrorException = (DeleteErrorException) e;
if (deleteErrorException.errorValue.getPathLookupValue().isNotFound())
return new FileNotFoundException(e.toString());
}
return e;
}
use of com.dropbox.core.v2.files.GetMetadataErrorException in project dropbox-sdk-java by dropbox.
the class DropboxBrowse method doBrowse.
// -------------------------------------------------------------------------------------------
// GET /browse?path=...
// -------------------------------------------------------------------------------------------
// The page that lets you browse your Dropbox account. Makes Dropbox API calls to figure out
// the contents of your files and folders and display them to you.
public void doBrowse(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!common.checkGet(request, response))
return;
User user = common.getLoggedInUser(request);
if (user == null) {
common.pageSoftError(response, "Can't do /browse. Nobody is logged in.");
return;
}
DbxClientV2 dbxClient = requireDbxClient(request, response, user);
if (dbxClient == null)
return;
String path = request.getParameter("path");
if (path == null || path.length() == 0) {
renderFolder(response, user, dbxClient, "");
} else {
String pathError = DbxPathV2.findError(path);
if (pathError != null) {
response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
return;
}
Metadata metadata;
try {
metadata = dbxClient.files().getMetadata(path);
} catch (GetMetadataErrorException ex) {
if (ex.errorValue.isPath()) {
LookupError le = ex.errorValue.getPathValue();
if (le.isNotFound()) {
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
return;
}
}
common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
return;
} catch (DbxException ex) {
common.handleDbxException(response, user, ex, "getMetadata(" + jq(path) + ")");
return;
}
path = DbxPathV2.getParent(path) + "/" + metadata.getName();
if (metadata instanceof FolderMetadata) {
renderFolder(response, user, dbxClient, path);
} else {
renderFile(response, path, (FileMetadata) metadata);
}
}
}
use of com.dropbox.core.v2.files.GetMetadataErrorException in project dropbox-sdk-java by dropbox.
the class DbxClientV2IT method testError409.
@Test(expectedExceptions = { GetMetadataErrorException.class })
public void testError409() throws Exception {
DbxClientV2 client = ITUtil.newClientV2();
String path = ITUtil.path(getClass(), "/testError409/" + ITUtil.format(new Date()));
try {
client.files().getMetadata(path);
} catch (GetMetadataErrorException ex) {
assertThat(ex.getRequestId()).isNotNull();
if (ex.getUserMessage() != null) {
assertThat(ex.getUserMessage().getLocale()).isNotNull();
assertThat(ex.getUserMessage().getText()).isNotNull();
assertThat(ex.getUserMessage().toString()).isNotNull();
}
GetMetadataError err = ex.errorValue;
assertThat(err).isNotNull();
assertThat(err.tag()).isEqualTo(GetMetadataError.Tag.PATH);
assertThat(err.isPath()).isTrue();
LookupError lookup = err.getPathValue();
assertThat(lookup).isNotNull();
assertThat(lookup.tag()).isEqualTo(LookupError.Tag.NOT_FOUND);
assertThat(lookup.isNotFound()).isTrue();
assertThat(lookup.isNotFile()).isFalse();
assertThat(lookup.isOther()).isFalse();
assertThat(lookup.isMalformedPath()).isFalse();
// raise so test can confirm an exception was thrown
throw ex;
}
}
Aggregations