use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class Shelf method loadBookFromRepo.
public Book loadBookFromRepo(Uri repoUri, String fileName) throws IOException {
Book book;
Repo repo = RepoFactory.getFromUri(mContext, repoUri);
if (repo == null) {
throw new IOException("Unsupported repository URL \"" + repoUri + "\"");
}
File tmpFile = getTempBookFile();
try {
/* Download from repo. */
VersionedRook vrook = repo.retrieveBook(fileName, tmpFile);
BookName bookName = BookName.fromFileName(fileName);
/* Store from file to Shelf. */
book = loadBookFromFile(bookName.getName(), bookName.getFormat(), tmpFile, vrook);
} finally {
tmpFile.delete();
}
return book;
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class LocalDbRepoClient method getAll.
/**
* Select only those belonging to this repo's name.
*/
public static List<VersionedRook> getAll(Context context, Uri repoUri) {
Cursor cursor = context.getContentResolver().query(ProviderContract.LocalDbRepo.ContentUri.dbRepos(), null, ProviderContract.LocalDbRepo.Param.REPO_URL + "=?", new String[] { repoUri.toString() }, null);
List<VersionedRook> result = new ArrayList<>();
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.URL)));
String revision = cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.REVISION));
long mtime = cursor.getLong(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.MTIME));
result.add(new VersionedRook(repoUri, uri, revision, mtime));
}
} finally {
cursor.close();
}
return result;
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class Shelf method groupAllNotebooksByName.
/**
* Compares every local book with every remote one and calculates the status for each link.
*
* @return number of links (unique book names)
* @throws IOException
*/
public Map<String, BookNamesake> groupAllNotebooksByName() throws IOException {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Collecting all local and remote books ...");
Map<String, Repo> repos = ReposClient.getAll(mContext);
List<Book> localBooks = getBooks();
List<VersionedRook> versionedRooks = getBooksFromAllRepos(repos);
/* Group local and remote books by name. */
Map<String, BookNamesake> namesakes = BookNamesake.getAll(mContext, localBooks, versionedRooks);
/* If there is no local book, create empty "dummy" one. */
for (BookNamesake namesake : namesakes.values()) {
if (namesake.getBook() == null) {
Book book = createDummyBook(namesake.getName());
namesake.setBook(book);
}
namesake.updateStatus(repos.size());
}
return namesakes;
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class Shelf method renameBook.
public void renameBook(Book book, String name) throws IOException {
String oldName = book.getName();
/* Make sure there is no notebook with this name. */
if (getBook(name) != null) {
throw new IOException("Notebook with that name already exists");
}
/* Make sure link's repo is the same as sync book repo. */
if (book.hasLink() && book.getLastSyncedToRook() != null) {
if (!book.getLinkRepo().equals(book.getLastSyncedToRook().getRepoUri())) {
String s = BookSyncStatus.ROOK_AND_VROOK_HAVE_DIFFERENT_REPOS.toString();
setBookStatus(book, s, new BookAction(BookAction.Type.ERROR, s));
return;
}
}
/* Do not rename if there are local changes. */
if (book.getLastSyncedToRook() != null) {
if (book.isModifiedAfterLastSync()) {
throw new IOException("Notebook is not synced");
}
}
/* Prefer link. */
if (book.getLastSyncedToRook() != null) {
VersionedRook vrook = book.getLastSyncedToRook();
Repo repo = RepoFactory.getFromUri(mContext, vrook.getRepoUri());
VersionedRook movedVrook = repo.renameBook(vrook.getUri(), name);
book.setLastSyncedToRook(movedVrook);
BooksClient.saved(mContext, book.getId(), movedVrook);
}
if (BooksClient.updateName(mContext, book.getId(), name) != 1) {
String msg = mContext.getString(R.string.failed_renaming_book);
setBookStatus(book, null, new BookAction(BookAction.Type.ERROR, msg));
throw new IOException(msg);
}
setBookStatus(book, null, new BookAction(BookAction.Type.INFO, mContext.getString(R.string.renamed_book_from, oldName)));
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class ShelfTestUtils method setupRook.
/**
* Overwrites existing repoUrl / url combinations (due to table definition).
*/
public void setupRook(String repoUrl, String url, String content, String rev, long mtime) {
try {
VersionedRook vrook = new VersionedRook(Uri.parse(repoUrl), Uri.parse(url), rev, mtime);
LocalDbRepoClient.insert(context, vrook, content);
} catch (IOException e) {
e.printStackTrace();
fail(e.toString());
}
// RemoteBookRevision remoteBookRevision = new RemoteBookRevision(repoUrl, url, rev, mtime);
// RemoteBooksHelper.updateOrInsert(testContext, remoteBookRevision);
}
Aggregations