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);
}
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();
}
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();
}
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();
}
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);
}
Aggregations