use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class JournalEncryptionWrapper method updateEntry.
@Override
public Journal updateEntry(Long id, Journal j) throws FailToSyncEntryException {
Journal trueUpdate;
try {
trueUpdate = encryptor.encryptJournal(j);
Journal result = db.updateEntry(id, trueUpdate);
j.setId(result.getId());
return j;
} catch (CipherException e) {
throw new RuntimeException(e);
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class JournalEncryptionWrapper method addEntry.
@Override
public Journal addEntry(Journal j) throws FailToSyncEntryException {
Journal toAdd;
try {
toAdd = encryptor.encryptJournal(j);
} catch (CipherException e) {
throw new RuntimeException(e);
}
Journal result = db.addEntry(toAdd);
j.setId(result.getId());
return j;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class ChangeConfigurationOperation method revert.
private void revert(List<Journal> all, String password, Map<String, String> old) throws FailToStoreCredentialException, CannotClearPasswordException, FailToSyncEntryException {
// reverts configuration
for (Entry<String, String> i : old.entrySet()) {
Configuration.setProperty(i.getKey(), i.getValue());
}
// refresh all providers to reflect changes in configuration
EntryDatabases.INSTANCE.refreshAll();
Indexers.INSTANCE.refreshAll();
AuthManagers.INSTANCE.refreshAll();
JournalTransformers.INSTANCE.refreshAll();
// re-initialize components
this.refresh();
// clear new components
resetUnits();
// set the password on the new Auth manager
auth().setPassword(password);
// configuration, entry database, and indexer
for (Journal i : all) {
i.setId(null);
db().addEntry(i);
indexer().add(i);
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class ChangePasswordOperation method execute.
@Override
public void execute() {
List<Journal> buffer = db().getAll();
// set the new password
try {
auth().setPassword(pass);
// clear all
indexer().clear();
db().clear();
// re-encrypt all entries
for (Journal i : buffer) {
i.setId(null);
Journal added = db().addEntry(i);
indexer().add(added);
}
} catch (FailToStoreCredentialException e) {
File userHome = new File(System.getProperty("user.home"));
File export = new File(userHome, "export.txt");
OperationErrorException err = new OperationErrorException("Failed to save the new password:" + e.getMessage() + " Exporting all entries to " + export.getAbsolutePath());
new ExportJournalOperation(export.getAbsolutePath()).execute();
throw err;
} catch (FailToSyncEntryException e) {
File userHome = new File(System.getProperty("user.home"));
File export = new File(userHome, "export.txt");
OperationErrorException err = new OperationErrorException("Failed to re-add entries with the new password:" + e.getMessage() + " Exporting all entries to " + export.getAbsolutePath());
new ExportJournalOperation(export.getAbsolutePath()).execute();
throw err;
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class DatabaseStub method updateEntry.
@Override
public Journal updateEntry(Long id, Journal j) {
Journal reference = backend.get(id);
reference.setContent(j.getContent());
reference.setDate(j.getDate());
reference.setSubject(j.getSubject());
return reference;
}
Aggregations