}
if (auth==null) {
getLogger().warning("Cannot configure db entry for "+dbName+" as auth service "+authName+" does not exist.");
return;
}
DBInfo dbinfo = autodbList.get(dbName);
Storage storage = null;
if (dbinfo==null) {
getLogger().info("Creating DB "+dbName);
DB db = new DB(getLogger(),new File(dbDir,dbName));
dbinfo = new DBInfo(dbName,db,auth,groupT!=null ? groupT.getFirstValue() : null, aliasT!=null ? aliasT.getFirstValue() : null);
storage = storageFactory.getStorage(db);
try {
getLogger().info("Connecting to DB "+dbName);
db.connect();
getLogger().info("Connected to DB "+dbName);
autodbList.put(dbName,dbinfo);
storage.start();
} catch (SQLException ex) {
getLogger().log(Level.SEVERE,"Cannot connect to database "+dbName,ex);
}
} else {
storage = storageFactory.getStorage(dbinfo.getDB());
}
currentDBList.put(dbName,Boolean.TRUE);
UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",auth);
adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);
adminGuard.setNext(new AdminApplication(childContext,dbinfo.getDB(),storage,AtomApplication.RESOURCE_BASE));
admins.put(dbName,adminGuard);
for (Router router : adminRouters) {
router.attach("/admin/database/"+dbName,adminGuard).getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
}
}
// Remove databases that have been removed from feed
for (String name : autodbList.keySet()) {
if (currentDBList.get(name)==null) {
// the database was removed
DBInfo dbinfo = autodbList.remove(name);
dbinfo.getDB().stop();
Storage storage = storageFactory.getStorage(dbinfo.getDB());
storage.stop();
Restlet admin = admins.remove(name);
if (admin!=null) {
for (Router router : adminRouters) {
router.detach(admin);