com.dropbox.core.v2.files.Metadata Java Examples
The following examples show how to use
com.dropbox.core.v2.files.Metadata.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityBackup.java From fingen with Apache License 2.0 | 6 votes |
@NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) void restoreDBFromDropbox() { Thread t = new Thread(new Runnable() { @Override public void run() { SharedPreferences dropboxPrefs = getApplicationContext().getSharedPreferences("com.yoshione.fingen.dropbox", Context.MODE_PRIVATE); String token = dropboxPrefs.getString("dropbox-token", null); List<Metadata> metadataList; List<MetadataItem> items = new ArrayList<>(); try { metadataList = DropboxClient.getListFiles(DropboxClient.getClient(token)); for (int i = metadataList.size() - 1; i >= 0; i--) { if (metadataList.get(i).getName().toLowerCase().contains(".zip")) { items.add(new MetadataItem((FileMetadata) metadataList.get(i))); } } } catch (Exception e) { Log.d(TAG, "Error read list of files from Dropbox"); } mHandler.sendMessage(mHandler.obtainMessage(MSG_SHOW_DIALOG, items)); } }); t.start(); }
Example #2
Source File: DropboxFilePickerActivity.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 6 votes |
@Override protected AbstractFilePickerFragment<Metadata> getFragment(@Nullable final String startPath, final int mode, final boolean allowMultiple, final boolean allowCreateDir, final boolean allowExistingFile, final boolean singleClick) { DropboxFilePickerFragment fragment = null; if (!dropboxHelper.authenticationFailed(this)) { DbxClientV2 dropboxClient = dropboxHelper.getClient(this); if (dropboxClient != null) { fragment = new DropboxFilePickerFragment(dropboxClient); fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick); } } return fragment; }
Example #3
Source File: Dropbox.java From financisto with GNU General Public License v2.0 | 6 votes |
List<String> listFiles() throws Exception { if (authSession()) { try { List<String> files = new ArrayList<String>(); ListFolderResult listFolderResult = dropboxClient.files().listFolder(""); for (Metadata metadata : listFolderResult.getEntries()) { String name = metadata.getName(); if (name.endsWith(".backup")) { files.add(name); } } Collections.sort(files, new Comparator<String>() { @Override public int compare(String s1, String s2) { return s2.compareTo(s1); } }); return files; } catch (Exception e) { Log.e("Financisto", "Dropbox: Something wrong", e); throw new ImportExportException(R.string.dropbox_error, e); } } else { throw new ImportExportException(R.string.dropbox_auth_error); } }
Example #4
Source File: DropboxSearchFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
protected boolean parse(final Path workdir, final ListProgressListener listener, final AttributedList<Path> list, final SearchV2Result result) throws ConnectionCanceledException { final List<SearchMatchV2> matches = result.getMatches(); for(SearchMatchV2 match : matches) { final Metadata metadata = match.getMetadata().getMetadataValue(); final EnumSet<Path.Type> type; if(metadata instanceof FileMetadata) { type = EnumSet.of(Path.Type.file); } else if(metadata instanceof FolderMetadata) { type = EnumSet.of(Path.Type.directory); } else { log.warn(String.format("Skip file %s", metadata)); return true; } list.add(new Path(metadata.getPathDisplay(), type, attributes.toAttributes(metadata))); listener.chunk(workdir, list); } return false; }
Example #5
Source File: DropboxListService.java From cyberduck with GNU General Public License v3.0 | 6 votes |
protected Path parse(final Path directory, final Metadata metadata) { final EnumSet<Path.Type> type; if(metadata instanceof FileMetadata) { type = EnumSet.of(Path.Type.file); } else if(metadata instanceof FolderMetadata) { type = EnumSet.of(Path.Type.directory); if(StringUtils.isNotBlank(((FolderMetadata) metadata).getSharedFolderId())) { type.add(Path.Type.volume); type.add(Path.Type.shared); } else if(directory.isRoot()) { // Home folder type.add(Path.Type.volume); } } else { log.warn(String.format("Skip file %s", metadata)); return null; } return new Path(directory, PathNormalizer.name(metadata.getName()), type, attributes.toAttributes(metadata)); }
Example #6
Source File: Main.java From dropbox-sdk-java with MIT License | 6 votes |
/** * Prints changes made to a folder in Dropbox since the given * cursor was retrieved. * * @param dbxClient Dropbox client to use for fetching folder changes * @param cursor lastest cursor received since last set of changes * * @return latest cursor after changes */ private static String printChanges(DbxClientV2 client, String cursor) throws DbxApiException, DbxException { while (true) { ListFolderResult result = client.files() .listFolderContinue(cursor); for (Metadata metadata : result.getEntries()) { String type; String details; if (metadata instanceof FileMetadata) { FileMetadata fileMetadata = (FileMetadata) metadata; type = "file"; details = "(rev=" + fileMetadata.getRev() + ")"; } else if (metadata instanceof FolderMetadata) { FolderMetadata folderMetadata = (FolderMetadata) metadata; type = "folder"; details = folderMetadata.getSharingInfo() != null ? "(shared)" : ""; } else if (metadata instanceof DeletedMetadata) { type = "deleted"; details = ""; } else { throw new IllegalStateException("Unrecognized metadata type: " + metadata.getClass()); } System.out.printf("\t%10s %24s \"%s\"\n", type, details, metadata.getPathLower()); } // update cursor to fetch remaining results cursor = result.getCursor(); if (!result.getHasMore()) { break; } } return cursor; }
Example #7
Source File: DropboxAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
protected PathAttributes toAttributes(final Metadata metadata) { final PathAttributes attributes = new PathAttributes(); if(metadata instanceof FileMetadata) { final FileMetadata file = (FileMetadata) metadata; attributes.setSize(file.getSize()); attributes.setModificationDate(file.getClientModified().getTime()); if(file.getFileLockInfo() != null) { attributes.setLockId(String.valueOf(file.getFileLockInfo().getIsLockholder())); } } if(metadata instanceof FolderMetadata) { final FolderMetadata folder = (FolderMetadata) metadata; // All shared folders have a shared_folder_id. This value is identical to the namespace ID for that shared folder attributes.setVersionId(folder.getSharedFolderId()); } return attributes; }
Example #8
Source File: DropboxDirectory.java From sling-whiteboard with Apache License 2.0 | 6 votes |
@Override public @NotNull List<RemoteResourceReference> getChildren() { ArrayList<RemoteResourceReference> children = new ArrayList<>(); ListFolderResult result; try { result = client.files().listFolder(metadata.getPathLower()); boolean hasMoreResults = true; while (hasMoreResults) { for (Metadata entry : result.getEntries()) { if (!(entry instanceof DeletedMetadata)) { children.add(new DropboxResourceReference(dropboxStorageProvider, entry)); } } result = client.files().listFolderContinue(result.getCursor()); hasMoreResults = result.getHasMore(); } } catch (ListFolderContinueErrorException e) { LOGGER.error(String.format("Cannot read all children of folder %s.", metadata.getPathLower()), e); } catch ( DbxException ex) { LOGGER.error(String.format("Cannot access path %s on Dropbox.", metadata.getPathLower()), ex); } return children; }
Example #9
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testRetrySuccess() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withAutoRetryEnabled(3) .withHttpRequestor(mockRequestor) .build(); DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken"); FileMetadata expected = constructFileMetadate(); // 503 twice, then return result HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()) .thenReturn(createEmptyResponse(503)) .thenReturn(createEmptyResponse(503)) .thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); Metadata actual = client.files().getMetadata(expected.getId()); // should have only been called 3 times: initial call + 2 retries verify(mockRequestor, times(3)).startPost(anyString(), anyHeaders()); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); assertEquals(((FileMetadata) actual).getId(), expected.getId()); }
Example #10
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
@NonNull @Override public Metadata getPath(@NonNull String path) { return FolderMetadata.newBuilder(path, "id") .withPathLower(path) .build(); }
Example #11
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
@Override protected Metadata doInBackground(final String... paths) { if (paths.length == 0) { return null; } String path = paths[0]; try { CreateFolderResult createFolderResult = dropboxClient.files().createFolderV2(path); return createFolderResult.getMetadata(); } catch (DbxException e) { Log.d(TAG, getString(R.string.nnf_create_folder_error), e); return null; } }
Example #12
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
@Override protected void onPostExecute(@Nullable Metadata path) { if (path != null) { goToDir(path); } else { progressBar.setVisibility(View.INVISIBLE); recyclerView.setVisibility(View.VISIBLE); Toast.makeText(getActivity(), R.string.nnf_create_folder_error, Toast.LENGTH_SHORT).show(); } }
Example #13
Source File: FilesAdapter.java From dropbox-sdk-java with MIT License | 5 votes |
public void bind(Metadata item) { mItem = item; mTextView.setText(mItem.getName()); // Load based on file path // Prepending a magic scheme to get it to // be picked up by DropboxPicassoRequestHandler if (item instanceof FileMetadata) { MimeTypeMap mime = MimeTypeMap.getSingleton(); String ext = item.getName().substring(item.getName().indexOf(".") + 1); String type = mime.getMimeTypeFromExtension(ext); if (type != null && type.startsWith("image/")) { mPicasso.load(FileThumbnailRequestHandler.buildPicassoUri((FileMetadata)item)) .placeholder(R.drawable.ic_photo_grey_600_36dp) .error(R.drawable.ic_photo_grey_600_36dp) .into(mImageView); } else { mPicasso.load(R.drawable.ic_insert_drive_file_blue_36dp) .noFade() .into(mImageView); } } else if (item instanceof FolderMetadata) { mPicasso.load(R.drawable.ic_folder_blue_36dp) .noFade() .into(mImageView); } }
Example #14
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
@NonNull @Override public Metadata getParent(@NonNull final Metadata from) { String fromPath = from.getPathLower(); int lastSeparatorIndex = from.getPathLower().lastIndexOf('/'); String parentPath = ""; if (lastSeparatorIndex > 0) { parentPath = fromPath.substring(0, lastSeparatorIndex); } return getPath(parentPath); }
Example #15
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testRetrySuccessWithBackoff() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withAutoRetryEnabled(3) .withHttpRequestor(mockRequestor) .build(); DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken"); FileMetadata expected = constructFileMetadate(); // 503 twice, then return result HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()) .thenReturn(createEmptyResponse(503)) // no backoff .thenReturn(createRateLimitResponse(1)) // backoff 1 sec .thenReturn(createRateLimitResponse(2)) // backoff 2 sec .thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); long start = System.currentTimeMillis(); Metadata actual = client.files().getMetadata(expected.getId()); long end = System.currentTimeMillis(); // no way easy way to properly test this, but request should // have taken AT LEAST 3 seconds due to backoff. assertTrue((end - start) >= 3000L, "duration: " + (end - start) + " millis"); // should have been called 4 times: initial call + 3 retries verify(mockRequestor, times(4)).startPost(anyString(), anyHeaders()); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); }
Example #16
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testRefreshBeforeCall() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withHttpRequestor(mockRequestor) .build(); DbxCredential credential = new DbxCredential("accesstoken", 10L, "refresh_token", "appkey", "app_secret"); DbxClientV2 client = new DbxClientV2(config, credential); FileMetadata expected = constructFileMetadate(); HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()) .thenReturn(createSuccessRefreshResponse("newToken", 10L)) .thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); long now = System.currentTimeMillis(); Metadata actual = client.files().getMetadata(expected.getId()); verify(mockRequestor, times(2)).startPost(anyString(), anyHeaders()); assertEquals(credential.getAccessToken(), "newToken"); assertTrue(credential.getExpiresAt() > now); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); assertEquals(((FileMetadata) actual).getId(), expected.getId()); }
Example #17
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testDontRefreshBeforeCallIfNotExpired() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withHttpRequestor(mockRequestor) .build(); long now = System.currentTimeMillis(); DbxCredential credential = new DbxCredential("accesstoken", now + 2*DbxCredential .EXPIRE_MARGIN, "refresh_token", "appkey", "app_secret"); DbxClientV2 client = new DbxClientV2(config, credential); FileMetadata expected = constructFileMetadate(); HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()).thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); Metadata actual = client.files().getMetadata(expected.getId()); verify(mockRequestor, times(1)).startPost(anyString(), anyHeaders()); assertEquals(credential.getAccessToken(), "accesstoken"); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); assertEquals(((FileMetadata) actual).getId(), expected.getId()); }
Example #18
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testRefreshAndRetryAfterTokenExpired() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withHttpRequestor(mockRequestor) .build(); long now = System.currentTimeMillis(); DbxCredential credential = new DbxCredential("accesstoken", now + 2*DbxCredential .EXPIRE_MARGIN, "refresh_token", "appkey", "app_secret"); DbxClientV2 client = new DbxClientV2(config, credential); FileMetadata expected = constructFileMetadate(); HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()) .thenReturn(createTokenExpiredResponse()) .thenReturn(createSuccessRefreshResponse("new_token", 14400L)) .thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); Metadata actual = client.files().getMetadata(expected.getId()); verify(mockRequestor, times(3)).startPost(anyString(), anyHeaders()); assertEquals(credential.getAccessToken(), "new_token"); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); assertEquals(((FileMetadata) actual).getId(), expected.getId()); }
Example #19
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
@Test public void testRefreshAndRetryWith503Retry() throws Exception { HttpRequestor mockRequestor = mock(HttpRequestor.class); DbxRequestConfig config = createRequestConfig() .withAutoRetryEnabled() .withHttpRequestor(mockRequestor) .build(); long now = System.currentTimeMillis(); DbxCredential credential = new DbxCredential("accesstoken", now + 2*DbxCredential .EXPIRE_MARGIN, "refresh_token", "appkey", "app_secret"); DbxClientV2 client = new DbxClientV2(config, credential); FileMetadata expected = constructFileMetadate(); HttpRequestor.Uploader mockUploader = mockUploader(); when(mockUploader.finish()) .thenReturn(createTokenExpiredResponse()) .thenReturn(createSuccessRefreshResponse("new_token", 14400L)) .thenReturn(createEmptyResponse(503)) .thenReturn(createSuccessResponse(serialize(expected))); when(mockRequestor.startPost(anyString(), anyHeaders())) .thenReturn(mockUploader); Metadata actual = client.files().getMetadata(expected.getId()); verify(mockRequestor, times(4)).startPost(anyString(), anyHeaders()); assertEquals(credential.getAccessToken(), "new_token"); assertEquals(actual.getName(), expected.getName()); assertTrue(actual instanceof FileMetadata, actual.getClass().toString()); assertEquals(((FileMetadata) actual).getId(), expected.getId()); }
Example #20
Source File: DbxClientV2Test.java From dropbox-sdk-java with MIT License | 5 votes |
private static byte [] serialize(Metadata metadata) { assertNotNull(metadata); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { serializer(Metadata.class).serialize(metadata, out); } catch (Exception ex) { fail("unserializable type: " + metadata.getClass(), ex); return null; } return out.toByteArray(); }
Example #21
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
/** * Once loading has finished, show the list and hide the progress bar. */ @Override public void onLoaderReset(Loader<SortedList<Metadata>> loader) { progressBar.setVisibility(View.INVISIBLE); recyclerView.setVisibility(View.VISIBLE); super.onLoaderReset(loader); }
Example #22
Source File: Dropbox.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
private void treeList(String parentPath, List<FileMetadata> files) throws DbxException { List<Metadata> list = list(parentPath); for (Metadata entry : list) { if (entry instanceof FolderMetadata) treeList(entry.getPathDisplay(), files); else files.add((FileMetadata) entry); } }
Example #23
Source File: Dropbox.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
public List<FileMetadata> find(String basePath, String query) throws DbxException { List<FileMetadata> list = new ArrayList<FileMetadata>(); SearchResult result = client.files().search(basePath, query); List<SearchMatch> matches = result.getMatches(); for (SearchMatch searchMatch : matches) { Metadata metadata = searchMatch.getMetadata(); if (metadata instanceof FileMetadata) list.add((FileMetadata) metadata); } return list; }
Example #24
Source File: DropboxListService.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private void parse(final Path directory, final ListProgressListener listener, final AttributedList<Path> children, final ListFolderResult result) throws ConnectionCanceledException { for(Metadata md : result.getEntries()) { final Path child = this.parse(directory, md); if(child == null) { continue; } children.add(child); listener.chunk(directory, children); } }
Example #25
Source File: DropboxAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public PathAttributes find(final Path file) throws BackgroundException { try { final Metadata metadata = new DbxUserFilesRequests(session.getClient(file)).getMetadata(containerService.getKey(file)); return this.toAttributes(metadata); } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
Example #26
Source File: DropboxResourceReference.java From sling-whiteboard with Apache License 2.0 | 5 votes |
DropboxResourceReference(DropboxStorageProvider remoteStorageProvider, Metadata metadata) { this.remoteStorageProvider = remoteStorageProvider; this.metadata = metadata; if (metadata instanceof FileMetadata) { type = Type.FILE; } else { type = Type.DIRECTORY; } }
Example #27
Source File: DbxFileActions.java From Open-LaTeX-Studio with MIT License | 5 votes |
/** * @return List with user's files or empty List if error occurs */ public List<DbxEntryDto> getDbxTexEntries(DbxClientV2 client) { List<DbxEntryDto> dbxEntries = new ArrayList<>(); if (client == null) { return dbxEntries; } try { ListFolderResult result = client.files().listFolderBuilder("").withRecursive(true).start(); while (true) { for (Metadata metadata : result.getEntries()) { if (metadata instanceof FileMetadata) { String name = metadata.getName(); if (name.endsWith(TEX_EXTENSION)) { dbxEntries.add(new DbxEntryDto((FileMetadata) metadata)); } } } if (!result.getHasMore()) { break; } result = client.files().listFolderContinue(result.getCursor()); } } catch (DbxException ex) { DbxUtil.showDbxAccessDeniedPrompt(); dbxEntries = new ArrayList<>(); //Empty list } finally { return dbxEntries; } }
Example #28
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
/** * If we are loading, then hide the list and show the progress bar instead. * * @param nextPath path to list files for */ @Override protected void refresh(@NonNull Metadata nextPath) { super.refresh(nextPath); if (isLoading) { progressBar.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.INVISIBLE); } }
Example #29
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 5 votes |
/** * Once loading has finished, show the list and hide the progress bar. */ @Override public void onLoadFinished(Loader<SortedList<Metadata>> loader, SortedList<Metadata> data) { progressBar.setVisibility(View.INVISIBLE); recyclerView.setVisibility(View.VISIBLE); super.onLoadFinished(loader, data); }
Example #30
Source File: DropboxFilePickerFragment.java From NoNonsense-FilePicker with Mozilla Public License 2.0 | 4 votes |
@NonNull @Override public Uri toUri(@NonNull final Metadata file) { return new Uri.Builder().scheme("dropbox").authority("").path(file.getPathDisplay()).build(); }