Search in sources :

Example 1 with Journal

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);
    }
}
Also used : CipherException(net.viperfish.journal.framework.errors.CipherException) Journal(net.viperfish.journal.framework.Journal)

Example 2 with Journal

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;
}
Also used : CipherException(net.viperfish.journal.framework.errors.CipherException) Journal(net.viperfish.journal.framework.Journal)

Example 3 with Journal

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);
    }
}
Also used : Journal(net.viperfish.journal.framework.Journal)

Example 4 with Journal

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;
    }
}
Also used : FailToSyncEntryException(net.viperfish.journal.framework.errors.FailToSyncEntryException) FailToStoreCredentialException(net.viperfish.journal.framework.errors.FailToStoreCredentialException) Journal(net.viperfish.journal.framework.Journal) OperationErrorException(net.viperfish.journal.framework.errors.OperationErrorException) File(java.io.File)

Example 5 with Journal

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;
}
Also used : Journal(net.viperfish.journal.framework.Journal)

Aggregations

Journal (net.viperfish.journal.framework.Journal)35 Test (org.junit.Test)13 Date (java.util.Date)8 File (java.io.File)7 JournalPointer (net.viperfish.journal.framework.JournalPointer)6 IOException (java.io.IOException)4 FailToSyncEntryException (net.viperfish.journal.framework.errors.FailToSyncEntryException)4 CipherException (net.viperfish.journal.framework.errors.CipherException)3 OperationErrorException (net.viperfish.journal.framework.errors.OperationErrorException)3 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 IOFile (net.viperfish.framework.file.IOFile)2 TextIOStreamHandler (net.viperfish.framework.file.TextIOStreamHandler)2 DatabaseTest (net.viperfish.journal.framework.DatabaseTest)2 FailToStoreCredentialException (net.viperfish.journal.framework.errors.FailToStoreCredentialException)2 ByteBuffer (java.nio.ByteBuffer)1 DateFormat (java.text.DateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 JsonGenerator (net.viperfish.framework.serialization.JsonGenerator)1