}
private void initDatabaseDocuments(ServletContext servletContext) throws ServletException {
// Create update process for database
DocumentUpdateProcess updateProcess = null;
try {
updateProcess = new DocumentUpdateProcess(couchDb);
updateProcess.setListener(UpdateListener._singleton);
} catch (Exception e) {
throw new ServletException("Unable to create update process", e);
}
// Find root directory for initializing documents
{
File documentsDir = null;
{
documentsDir = new File(webInfDirectory, "initializeDocs");
if( false == documentsDir.exists() || false == documentsDir.isDirectory() ) {
documentsDir = null;
}
}
if( null == documentsDir ) {
logger.error("Unable to find document directory for initializing");
} else {
String[] fileNames = documentsDir.list();
for(String fileName : fileNames) {
File file = new File(documentsDir, fileName);
try {
FSEntry fileEntry = new FSEntryFile(file);
Document doc = DocumentFile.createDocument(fileEntry);
updateProcess.update(doc);
} catch(Exception e) {
throw new ServletException("Problem pushing document: "+file.getAbsolutePath(), e);
}
}
}
}
// Find root directory for updating documents
{
File documentsDir = null;
{
documentsDir = new File(webInfDirectory, "updateDocs");
if( false == documentsDir.exists() || false == documentsDir.isDirectory() ) {
documentsDir = null;
}
}
if( null == documentsDir ) {
logger.error("Unable to find document directory for updating");
} else {
String[] fileNames = documentsDir.list();
for(String fileName : fileNames) {
File file = new File(documentsDir, fileName);
try {
FSEntry fileEntry = new FSEntryFile(file);
Document doc = DocumentFile.createDocument(fileEntry);
updateProcess.update(
doc
,DocumentUpdateProcess.Schedule.UPDATE_EVEN_IF_MODIFIED
);
} catch(Exception e) {