private CouchAuthenticationContext getUserFromClient(CouchClient client) throws Exception { CouchSession session = client.getSession(); return session.getAuthenticationContext(); } }
static public CouchDb createCouchDb( GlobalSettings gs ,AtlasProperties atlasProperties ) throws Exception { CouchClient couchClient = createCouchClient(gs, atlasProperties); // Get database from Couch Client CouchDb couchDb = null; { String dbName = atlasProperties.getCouchDbName(); if( false == couchClient.databaseExists(dbName) ) { couchClient.createDatabase(dbName); } couchDb = couchClient.getDatabase(dbName); } return couchDb; }
public CouchClient getClient(CouchContext context, CouchClient clonedClient) throws Exception { CouchClientImpl client = new CouchClientImpl(context, clonedClient.getUrl()); client.setVersion(clonedClient.getVersion()); return client; }
public CouchDb createCouchDb() throws Exception { CouchClient couchClient = createCouchClient(); // Get database from Couch Client CouchDb couchDb = null; { if( false == couchClient.databaseExists(dbName) ) { throw new Exception("Can not find a database with the name: "+dbName); } couchDb = couchClient.getDatabase(dbName); } return couchDb; }
documentDatabase = couchClient.getDatabase(documentDatabaseName); } catch(Exception e) { logger.error("Unable to connect to document database: "+documentDatabaseName,e); userDb = couchClient.getUserDatabase(); } catch(Exception e) { logger.error("Unable to connect to _users database",e); try { String submissionDbName = atlasProperties.getCouchDbSubmissionDbName(); submissionDb = couchClient.getDatabase(submissionDbName);
public AtlasInfo getAtlasInfo(String databaseName) throws Exception { CouchDb db = couchClient.getDatabase(databaseName); return getAtlasInfo(db, databaseName); }
synchronized public JSONObject getWelcome() throws Exception{ if( null == cached_welcome ){ cached_welcome = new JSONObject(); cached_welcome.put("SubmissionServlet", true); if( null != submissionDesign ){ cached_welcome.put("submissionDbAvailable", true); } else { cached_welcome.put("submissionDbAvailable", false); } CouchServerVersion version = submissionDesign.getDatabase().getClient().getVersion(); cached_welcome.put("version", version.getFullVersion()); } return cached_welcome; }
@Override public CouchAuthenticationContext getUserFromName(String userName) throws Exception { CouchUserDb userDb = getClient().getUserDatabase(); return userDb.getUserFromName(userName); } }
private void performReplication(ReplicationRequest replication) { try { // Check if active String source = CouchUtils.computeEffectiveDatabaseUrl( replication.getSourceServerUrl() ,replication.getSourceUserName() ,replication.getSourcePassword() ,replication.getSourceDbName() ); String target = CouchUtils.computeEffectiveDatabaseUrl( replication.getTargetServerUrl() ,replication.getTargetUserName() ,replication.getTargetPassword() ,replication.getTargetDbName() ); JSONArray activeTasks = couchClient.activeTasks(); ReplicationStatus status = ReplicationStatus.findReplicationTask(activeTasks, source, target); if( null == status ) { logger.info("Start replication: "+replication); // Replication not running, start it couchClient.replicate(replication); } } catch(Exception e) { logger.error("Problem performing replication: "+replication, e); } }
static public UserDesignDocumentImpl getUserDesignDocument(CouchClient couchClient) throws Exception { if( false == couchClient.databaseExists("_users") ) { throw new Exception("_users database not found"); } CouchDb userDb = couchClient.getDatabase("_users"); return getUserDesignDocument(userDb); }
CouchDb atlasDb = couchClient.getDatabase(atlasInfo.getDatabaseName()); CouchDesignDocument atlasDesign = atlasDb.getDesignDocument("atlas");
@Override public void computeUserPassword(JSONObject userDoc, String password) throws Exception { String version = this.getClient().getVersion().getFullVersion();
@Override public CouchAuthenticationContext getRolesFromAuthentication(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } CouchFactory factory = new CouchFactory(); CouchDb couchDb = factory.getDb(contextCookie, userDb); CouchSession session = couchDb.getClient().getSession(); CouchAuthenticationContext userContext = session.getAuthenticationContext(); return userContext; }
static public CouchDb createCouchDbSubmission( GlobalSettings gs ,AtlasProperties atlasProperties ) throws Exception { CouchClient couchClient = createCouchClient(gs, atlasProperties); // Get database from Couch Client CouchDb couchDb = null; { String dbName = atlasProperties.getCouchDbSubmissionDbName(); if( false == couchClient.databaseExists(dbName) ) { couchClient.createDatabase(dbName); } couchDb = couchClient.getDatabase(dbName); } return couchDb; } }
private CouchAuthenticationContext getAuthenticationContextFromCookies(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); if( null != cookies ) { for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } } CouchClient client = documentDesign.getDatabase().getClient(); CouchFactory factory = new CouchFactory(); CouchClient userClient = factory.getClient(contextCookie, client); CouchSession session = userClient.getSession(); CouchAuthenticationContext authContext = session.getAuthenticationContext(); return authContext; }
@Override public void saveTree(Tree tree) throws Exception { CouchDb db = atlasDesign.getDatabase(); boolean exists = db.documentExists(DATE_CLUSTER_DOC_ID); JSONObject jsonDoc = null; if( exists ) { jsonDoc = db.getDocument(DATE_CLUSTER_DOC_ID); } else { jsonDoc = new JSONObject(); jsonDoc.put("_id", "org.nunaliit.date_clusters"); } jsonDoc.put("nunaliit_date_clusters", tree.toJSON()); CouchAuthenticationContext authContext = db.getClient().getSession().getAuthenticationContext(); CouchNunaliitUtils.adjustDocumentForStorage(jsonDoc, authContext); if( exists ){ db.updateDocument(jsonDoc); } else { db.createDocument(jsonDoc); } }