Search in sources :

Example 6 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class FileEntryDatabase method removeEntry.

@Override
public Journal removeEntry(Long id) {
    Journal j = new Journal(struct.getData().get(id));
    struct.getData().remove(id);
    return j;
}
Also used : Journal(net.viperfish.journal.framework.Journal)

Example 7 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class JavaSerializationEntryDatabase method removeEntry.

@Override
public Journal removeEntry(Long id) {
    Journal j = new Journal(data.get(id));
    data.remove(id);
    return j;
}
Also used : Journal(net.viperfish.journal.framework.Journal)

Example 8 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class HibernateEntryDatabase method removeEntry.

@Override
public Journal removeEntry(Long id) throws FailToSyncEntryException {
    Transaction tr = this.getSession().beginTransaction();
    try {
        Journal deleted = getEntry(id);
        this.getSession().delete(getEntry(id));
        return deleted;
    } catch (RuntimeException e) {
        tr.rollback();
        FailToSyncEntryException f = new FailToSyncEntryException("Cannot delete entry from database:" + e.getMessage() + " id:" + id);
        throw f;
    } finally {
        tr.commit();
    }
}
Also used : Transaction(org.hibernate.Transaction) FailToSyncEntryException(net.viperfish.journal.framework.errors.FailToSyncEntryException) Journal(net.viperfish.journal.framework.Journal)

Example 9 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class ExportJournalOperation method execute.

@Override
public void execute() {
    // get all entries
    List<Journal> allJournals = db().getAll();
    Journal[] toExport = allJournals.toArray(new Journal[0]);
    // set the id to null to reassign id when importing
    for (Journal i : toExport) {
        i.setId(null);
    }
    // serialize to JSON and write
    try {
        String result = generator.toJson(toExport);
        outputTarget.write(result, StandardCharsets.UTF_16);
    } catch (IOException e) {
        FailToExportEntriesException f = new FailToExportEntriesException("Cannot export entries to:" + outputTarget + " message:" + e.getMessage());
        f.initCause(e);
        throw new RuntimeException(f);
    }
}
Also used : FailToExportEntriesException(net.viperfish.journal.framework.errors.FailToExportEntriesException) Journal(net.viperfish.journal.framework.Journal) IOException(java.io.IOException)

Example 10 with Journal

use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.

the class GetAllOperation method execute.

@Override
public void execute() {
    List<Journal> all = new LinkedList<>();
    List<JournalPointer> results = new LinkedList<>();
    try {
        all = db().getAll();
        for (Journal i : all) {
            results.add(new JournalPointer(i));
        }
        Collections.sort(results);
    } finally {
        setResult(results);
    }
}
Also used : JournalPointer(net.viperfish.journal.framework.JournalPointer) Journal(net.viperfish.journal.framework.Journal) LinkedList(java.util.LinkedList)

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