use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class SearchEntryOperation method execute.
@Override
public void execute() {
Set<JournalPointer> searched = new TreeSet<>();
try {
if (firstTime) {
if (indexer().isMemoryBased()) {
for (Journal j : db().getAll()) {
indexer().add(j);
}
}
firstTime = false;
}
Iterable<Long> indexResult = indexer().search(query);
for (Long id : indexResult) {
Journal j = db().getEntry(id);
if (j == null) {
indexer().delete(id);
continue;
}
searched.add(new JournalPointer(j));
}
} finally {
setResult(searched);
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class DatabaseStub method removeEntry.
@Override
public Journal removeEntry(Long id) {
Journal deleted = getEntry(id);
backend.remove(id);
return deleted;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class ChangeConfigurationOperation method execute.
@Override
public void execute() {
Map<String, String> old = backUpConfig(config);
// actually load all units
this.refresh();
// save all entries in memory
List<Journal> result = db().getAll();
// save the password in memory
String password = auth().getPassword();
try {
// clear all entries
resetUnits();
// updates configuration
for (Entry<String, String> i : config.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 : result) {
i.setId(null);
db().addEntry(i);
indexer().add(i);
}
} catch (Exception e1) {
ChangeConfigurationFailException cf = new ChangeConfigurationFailException("Failed to change components from:" + old + " to:" + config + "message:" + e1.getMessage(), e1);
try {
revert(result, password, old);
} catch (Exception e) {
File userHome = new File(System.getProperty("user.home"));
File export = new File(userHome, "export.txt");
OperationErrorException fr = new OperationErrorException("Failed to revert changes, application not in usable status, please clear all data files. Exporting all entries to " + export.getAbsolutePath());
fr.initCause(cf);
ExportJournalOperation dump = new ExportJournalOperation(export.getAbsolutePath());
dump.execute();
throw fr;
}
throw new RuntimeException(cf);
} finally {
// save the configuration
try {
Configuration.save();
} catch (ConfigurationException e) {
ChangeConfigurationFailException cf = new ChangeConfigurationFailException("Failed to save configuration, change not persistent.", e);
throw new RuntimeException(cf);
}
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class FileEntryDatabaseTest method testPersistence.
@Test
public void testPersistence() {
File dir = new File("test");
FileEntryDatabase database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
for (int i = 0; i < 10; ++i) {
Journal j = new Journal();
j.setSubject("testPersist");
j.setContent("testPersist");
database.addEntry(j);
}
database.flush();
database = new FileEntryDatabase(new IOFile(new File(dir, "testPersist"), new TextIOStreamHandler()));
database.load();
int count = 0;
for (Journal i : database.getAll()) {
Assert.assertEquals("testPersist", i.getContent());
Assert.assertEquals("testPersist", i.getSubject());
count++;
}
Assert.assertEquals(10, count);
CommonFunctions.delete(new File("testPersist"));
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class EditEntryOperation method execute.
@Override
public void execute() {
Journal e = db().getEntry(id);
edit(e);
try {
db().updateEntry(id, e);
} catch (FailToSyncEntryException e1) {
OperationErrorException fail = new OperationErrorException("Cannot update journal " + id + " in the database:" + e1.getMessage());
fail.initCause(e1);
throw fail;
}
indexer().delete(id);
indexer().add(e);
}
Aggregations