Search in sources :

Example 11 with Journal

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

the class GetDateRangeOperation method execute.

@Override
public void execute() {
    // get all entries
    List<Journal> all = db().getAll();
    Set<JournalPointer> result = new TreeSet<>();
    // filter
    for (Journal i : all) {
        // truncate timestamp to year, month, and date
        Date theDate = TimeUtils.truncDate(i.getDate());
        // the filter is inclusive
        if (theDate.equals(lowerBound) || theDate.equals(upperBound)) {
            result.add(new JournalPointer(i));
            continue;
        }
        // check if out of range
        if (theDate.after(lowerBound) && theDate.before(upperBound)) {
            result.add(new JournalPointer(i));
        }
    }
    this.setResult(result);
}
Also used : JournalPointer(net.viperfish.journal.framework.JournalPointer) TreeSet(java.util.TreeSet) Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date)

Example 12 with Journal

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

the class OperationTest method testGetEntryOperation.

@Test
public void testGetEntryOperation() throws FailToSyncEntryException {
    cleanUp();
    Journal test = new Journal();
    test.setContent("test");
    test.setDate(new Date());
    test.setSubject("test");
    Journal result = db.addEntry(test);
    test.setId(result.getId());
    OperationWithResult<Journal> o = new GetEntryOperation(test.getId());
    executeAsyncOperation(o);
    result = o.getResult();
    Assert.assertEquals(true, o.isDone());
    Assert.assertEquals(test.getId(), result.getId());
    Assert.assertEquals(test.getContent(), result.getContent());
    Assert.assertEquals(test.getSubject(), result.getSubject());
    Assert.assertEquals(test.getDate().getTime(), result.getDate().getTime());
    cleanUp();
}
Also used : Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Journal

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

the class OperationTest method testSearchEntryOperation.

@Test
public void testSearchEntryOperation() throws FailToSyncEntryException {
    cleanUp();
    Journal t1 = new Journal();
    t1.setContent("test 1");
    t1.setDate(new Date());
    t1.setSubject("test 1");
    Journal t2 = new Journal();
    t2.setSubject("test 2");
    t2.setDate(new Date());
    t2.setContent("test 2");
    Journal t3 = new Journal();
    t3.setContent("random stuff");
    t3.setSubject("something");
    t3.setDate(new Date());
    t1 = db.addEntry(t1);
    t2 = db.addEntry(t2);
    t3 = db.addEntry(t3);
    indexer.add(t1);
    indexer.add(t2);
    indexer.add(t3);
    SearchEntryOperation ops = new SearchEntryOperation("test");
    executeAsyncOperation(ops);
    Set<JournalPointer> s = ops.getResult();
    Assert.assertEquals(true, s.contains(new JournalPointer(t1)));
    Assert.assertEquals(true, s.contains(new JournalPointer(t2)));
    Assert.assertEquals(false, s.contains(new JournalPointer(t3)));
    cleanUp();
}
Also used : JournalPointer(net.viperfish.journal.framework.JournalPointer) Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Journal

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

the class OperationTest method testEditSubjectOperation.

@Test
public void testEditSubjectOperation() throws FailToSyncEntryException {
    cleanUp();
    Journal test = new Journal();
    test.setSubject("unedited");
    test.setDate(new Date());
    test.setContent("mary has a little lamb");
    Journal result = db.addEntry(test);
    Long id = result.getId();
    new EditSubjectOperation(id, "edited").execute();
    result = db.getEntry(id);
    Assert.assertEquals("edited", result.getSubject());
    cleanUp();
}
Also used : Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Example 15 with Journal

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

the class OperationTest method testImportOperation.

@Test
public void testImportOperation() throws FailToSyncEntryException {
    cleanUp();
    addEntries(20, "testImport");
    exportJournals(db.getAll());
    cleanUp();
    new ImportEntriesOperation("test.txt").execute();
    List<Journal> imported = db.getAll();
    int count = 0;
    for (Journal i : imported) {
        Assert.assertEquals("testImport", i.getSubject());
        Assert.assertEquals("testImport", i.getContent());
        ++count;
    }
    Assert.assertEquals(20, count);
}
Also used : Journal(net.viperfish.journal.framework.Journal) Test(org.junit.Test)

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