Java Code Examples for com.dropbox.client2.DropboxAPI#Entry
The following examples show how to use
com.dropbox.client2.DropboxAPI#Entry .
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: DropboxFileDownloaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 6 votes |
public void testBothFilesMissing() { DropboxAPI<?> dropboxapi = new DropboxAPIStub() { public DropboxAPI.Entry metadata(String arg0, int arg1, String arg2, boolean arg3, String arg4) throws DropboxException { throw notFoundException(); } }; DropboxFileDownloader downloader = new DropboxFileDownloader( dropboxapi, dropboxFiles2); downloader.pullFiles(); assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS, downloader.getStatus()); assertEquals("Should have 2 files", 2, downloader.getFiles().size()); assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND, dbFile1.getStatus()); assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND, dbFile2.getStatus()); }
Example 2
Source File: DropboxFileDownloaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 6 votes |
public void testRemoteFileDeleted() { DropboxAPI<?> dropboxapi = new DropboxAPIStub() { public DropboxAPI.Entry metadata(String arg0, int arg1, String arg2, boolean arg3, String arg4) throws DropboxException { return create_metadata(remoterev1, true); } }; DropboxFileDownloader downloader = new DropboxFileDownloader( dropboxapi, dropboxFiles1); downloader.pullFiles(); assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS, downloader.getStatus()); assertEquals("Should have 1 file", 1, downloader.getFiles().size()); assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND, dbFile1.getStatus()); }
Example 3
Source File: DropboxFileDownloaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 6 votes |
public void testRemoteFileMissing() { DropboxAPI<?> dropboxapi = new DropboxAPIStub() { public DropboxAPI.Entry metadata(String arg0, int arg1, String arg2, boolean arg3, String arg4) throws DropboxException { throw notFoundException(); } }; DropboxFileDownloader downloader = new DropboxFileDownloader( dropboxapi, dropboxFiles1); downloader.pullFiles(); assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS, downloader.getStatus()); assertEquals("Should have 1 file", 1, downloader.getFiles().size()); assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND, dbFile1.getStatus()); }
Example 4
Source File: DropboxFileUploaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 5 votes |
private DropboxAPI.Entry create_metadata(String path, String rev, boolean isDeleted) { DropboxAPI.Entry metadata = new DropboxAPI.Entry(); metadata.path = path; metadata.rev = rev; metadata.isDeleted = isDeleted; return metadata; }
Example 5
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 5 votes |
@Override public List<RemoteDataInfo> getRemoteEntries() throws SyncFailedException { StringBuilder sb = new StringBuilder(); sb.append(getBaseFilePath()); sb.append(ENTRIES); List<RemoteDataInfo> dataInfoObjects = new ArrayList<>(); try { List<DropboxAPI.Entry> dropboxEntries = getFileInfo(sb.toString()).contents; for (DropboxAPI.Entry entry : dropboxEntries) { if ( !entry.isDir ) { RemoteDataInfo infoObject = new RemoteDataInfo(); infoObject.isDirectory = entry.isDir; infoObject.isDeleted = entry.isDeleted; infoObject.name = entry.fileName().toUpperCase(); infoObject.modifiedDate = RESTUtility.parseDate(entry.modified).getTime(); infoObject.revision = entry.rev; dataInfoObjects.add(infoObject); } } } catch (Exception e) { if (!BuildConfig.DEBUG) Crashlytics.logException(e); e.printStackTrace(); throw new SyncFailedException(e.getMessage()); } return dataInfoObjects; }
Example 6
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 5 votes |
@Override public List<RemoteDataInfo> getRemotePhotos() throws SyncFailedException { StringBuilder sb = new StringBuilder(); sb.append(getBaseFilePath()); sb.append(PHOTOS); List<RemoteDataInfo> dataInfoObjects = new ArrayList<>(); try { List<DropboxAPI.Entry> dropboxEntries = getFileInfo(sb.toString()).contents; for (DropboxAPI.Entry file : dropboxEntries) { if ( !file.isDir ) { RemoteDataInfo infoObject = new RemoteDataInfo(); infoObject.isDirectory = file.isDir; infoObject.isDeleted = file.isDeleted; infoObject.name = file.fileName().toLowerCase(); infoObject.modifiedDate = RESTUtility.parseDate(file.modified).getTime(); infoObject.revision = file.rev; dataInfoObjects.add(infoObject); } } } catch (Exception e) { if (!BuildConfig.DEBUG) Crashlytics.logException(e); e.printStackTrace(); throw new SyncFailedException(e.getMessage()); } return dataInfoObjects; }
Example 7
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 5 votes |
private boolean doesFolderExist(String path) { try { DropboxAPI.Entry metadata = getFileInfo(path); return metadata.isDir; } catch (DropboxException e) { e.printStackTrace(); return false; } }
Example 8
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 5 votes |
/** * Returns 1 if it does exist * Returns 0 if it does not exist * Returns -1 if there is any other error * * @param path * @return */ private int doesFileExist(String path) { try { DropboxAPI.Entry metadata = getFileInfo(path); return 1; } catch (DropboxException e) { e.printStackTrace(); if (e.toString().contains("404")) return 0; else return -1; } }
Example 9
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
public DropboxAPI.Entry overwriteFile(String dbPath, File localFile) throws DropboxException, FileNotFoundException { checkNotNull(); FileInputStream inputStream = new FileInputStream(localFile); return mDBApi.putFileOverwrite(dbPath, inputStream, localFile.length(), null); }
Example 10
Source File: DropboxFileUploaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 4 votes |
private DropboxAPI.Entry create_metadata(String path, String rev) { return create_metadata(path, rev, false); }
Example 11
Source File: DropboxFileDownloaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 4 votes |
private DropboxAPI.Entry create_metadata(String rev, boolean isDeleted) { DropboxAPI.Entry metadata = new DropboxAPI.Entry(); metadata.rev = rev; metadata.isDeleted = isDeleted; return metadata; }
Example 12
Source File: DropboxFileDownloaderTest.java From endpoints-codelab-android with GNU General Public License v3.0 | 4 votes |
private DropboxAPI.Entry create_metadata(String rev) { return create_metadata(rev, false); }
Example 13
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
private DropboxAPI.Entry moveFile(String from, String to) throws DropboxException { checkNotNull(); return mDBApi.move(from, to); }
Example 14
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
@Override public void save(Entry entry) { LogUtil.log(getClass().getSimpleName(), "save()"); // update sync status SyncInfo info = new SyncInfo(); info.setTitle(entry.uuid); info.setSyncService(SyncService.Dropbox.ordinal()); info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis()); info.setSyncStatus(SyncStatus.UPLOAD); SyncInfoDao.saveData(info); // save to user's dropbox String path = getPathForEntry(entry); File tmpFile = new File(GlobalApplication.getAppContext().getFilesDir() + File.separator + entry.uuid); DropboxAPI.Entry response = null; try { if (!tmpFile.exists()) tmpFile.createNewFile(); NSDictionary entryData = EntryHelper.toDictionary(entry); PropertyListParser.saveAsXML(entryData, tmpFile); // overwrite the entry if it already exists if (doesContain(entry)) response = overwriteFile(path, tmpFile); else response = uploadFile(path, tmpFile); info.setModifiedDate(RESTUtility.parseDate(response.modified).getTime()); info.setSyncStatus(SyncStatus.OK); info.setRevision(response.rev); SyncInfoDao.saveData(info); } catch (Exception e) { LogUtil.e(getClass().getSimpleName(), "Error Saving Entry: ", e); } finally { tmpFile.delete(); } }
Example 15
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
public DropboxAPI.Entry uploadFile(String dbPath, File localFile) throws FileNotFoundException, DropboxException { checkNotNull(); FileInputStream inputStream = new FileInputStream(localFile); return mDBApi.putFile(dbPath, inputStream, localFile.length(), null, null); }
Example 16
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
private DropboxAPI.Entry getFileInfo(String path) throws DropboxException { checkNotNull(); return mDBApi.metadata(path, 5000, null, true, null); }
Example 17
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
@Override public boolean delete(Photo photo) { LogUtil.log(getClass().getSimpleName(), "delete(Photo)"); // update sync status SyncInfo info = new SyncInfo(photo.name.toUpperCase()); info.setSyncService(SyncService.Dropbox.ordinal()); info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis()); info.setSyncStatus(SyncStatus.DELETE); SyncInfoDao.saveData(info); String from = getPathForPhoto(photo.name); StringBuilder to = new StringBuilder(); to.append(getBaseFilePath()); to.append(DELETED_PHOTOS); to.append(File.separator); to.append(photo.name); // attempt to delete from Dropbox try { DropboxAPI.Entry response = moveFile(from, to.toString()); info.setModifiedDate(RESTUtility.parseDate(response.modified).getTime()); info.setSyncStatus(SyncStatus.OK); SyncInfoDao.saveData(info); return true; } catch (DropboxException e) { e.printStackTrace(); if (e.toString().contains("404")) { // this may get thrown if the entry's photo has been deleted/removed/changed before // and there exists a file in the /Narrate/photos/deleted/ with the same name as // the one we are trying to save. try { mDBApi.delete(to.toString()); moveFile(from, to.toString()); } catch (DropboxException e1) { e1.printStackTrace(); } info.setSyncStatus(SyncStatus.OK); SyncInfoDao.saveData(info); return true; } else { info.setSyncStatus(SyncStatus.DELETE); SyncInfoDao.saveData(info); } } return false; }
Example 18
Source File: DropboxSyncService.java From narrate-android with Apache License 2.0 | 4 votes |
@Override public void delete(Entry entry) { LogUtil.log(getClass().getSimpleName(), "delete()"); // update sync status SyncInfo info = new SyncInfo(entry.uuid); info.setSyncService(SyncService.Dropbox.ordinal()); info.setModifiedDate(Calendar.getInstance(Locale.getDefault()).getTimeInMillis()); info.setSyncStatus(SyncStatus.DELETE); SyncInfoDao.saveData(info); // determine the path to the entry, if it exists StringBuilder from = new StringBuilder(); StringBuilder to = new StringBuilder(); boolean dayOneEntry; from.append(getBaseFilePath()); to.append(from.toString()); from.append(ENTRIES); from.append(File.separator); from.append(entry.uuid.toUpperCase()); to.append(DELETED_ENTRIES); to.append(File.separator); to.append(entry.uuid.toUpperCase()); dayOneEntry = !(doesFileExist(from.toString()) == 1); if (dayOneEntry) { from.append(".doentry"); to.append(".doentry"); } // attempt to delete from Dropbox try { DropboxAPI.Entry response = moveFile(from.toString(), to.toString()); info.setModifiedDate(RESTUtility.parseDate(response.modified).getTime()); info.setSyncStatus(SyncStatus.OK); SyncInfoDao.saveData(info); } catch (DropboxException e) { e.printStackTrace(); if (e.toString().contains("404")) { info.setSyncStatus(SyncStatus.OK); SyncInfoDao.saveData(info); } else { info.setSyncStatus(SyncStatus.DELETE); SyncInfoDao.saveData(info); } } }