public CouchDb getDatabase() { return dd.getDatabase(); }
@Override public boolean treeExists() throws Exception { CouchDb db = atlasDesign.getDatabase(); boolean exists = false; try { exists = db.documentExists(DATE_CLUSTER_DOC_ID); } catch (Exception e) { // Ignore for now throw new Exception("Unable to verify cluster document existence", e); } return exists; }
@Override public void createDocument(JSONObject doc) throws Exception { dd.getDatabase().createDocument(doc); }
public CouchClient getClient() { return dd.getDatabase().getClient(); }
public void downloadFile(String attachmentName, File outputFile) throws Exception { FileOutputStream fos = new FileOutputStream(outputFile); JSONObject doc = getDoc(); dd.getDatabase().downloadAttachment( doc ,attachmentName ,fos ); fos.flush(); fos.close(); }
private void initSimplifiedGeometry(ServletContext servletContext) throws ServletException { try { SimplifiedGeometryServletConfiguration config = new SimplifiedGeometryServletConfiguration(); CouchDb couchDb = couchDd.getDatabase(); config.setCouchDb(couchDb); servletContext.setAttribute(SimplifiedGeometryServletConfiguration.CONFIGURATION_KEY, config); } catch(Exception e) { logger.error("Error configuring simplified geometry service",e); throw new ServletException("Error configuring simplified geometry service",e); } }
public JSONObject getUuids(CouchAuthenticationContext authContext, int count) throws Exception { try { String[] uuids = submissionDesign.getDatabase().getClient().getUuids(count); JSONObject result = new JSONObject(); JSONArray jsonUuids = new JSONArray(); for(int loop=0; loop<uuids.length; ++loop){ jsonUuids.put(uuids[loop]); } result.put("uuids", jsonUuids); return result; } catch (Exception e) { throw new Exception("Error while obtaining uuids",e); } }
@Override public void saveDocument() throws Exception { if( 0 != JSONSupport.compare(doc, originalDoc) ){ logger.debug("Saving document "+docId); // Modified since loaded documentDbDesign.getDatabase().updateDocument(doc); doc = null; originalDoc = null; } }
@Override public JSONObject getDocument() throws Exception { if( null == doc ){ logger.debug("Loading document "+docId); doc = documentDbDesign.getDatabase().getDocument(docId); originalDoc = JSONSupport.copyObject(doc); } return doc; }
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 Collection<UserDocument> getAllUsers() throws Exception { CouchDb userDb = dd.getDatabase(); Collection<String> allDocIds = userDb.getAllDocIds(); List<String> userDocIds = new ArrayList<String>( allDocIds.size() ); for(String docId : allDocIds){ if( docId.startsWith("org.couchdb.user:") ){ userDocIds.add(docId); } } List<UserDocument> users = new ArrayList<UserDocument>( userDocIds.size() ); Collection<JSONObject> docs = userDb.getDocuments(userDocIds); for(JSONObject doc : docs){ UserDocument user = new UserDocument(doc); users.add(user); } return users; }
public DateRobotThread(CouchDesignDocument atlasDesign, Tree clusterTree) throws Exception { this.atlasDesign = atlasDesign; this.clusterTree = clusterTree; noWorkDelayInMs = DELAY_NO_WORK_POLLING; CouchDbChangeMonitor changeMonitor = atlasDesign.getDatabase().getChangeMonitor(); if( null != changeMonitor ){ changeMonitor.addChangeListener(this); noWorkDelayInMs = DELAY_NO_WORK_MONITOR; } }
@Override public void saveDocument() throws Exception { SubmissionUtils.DocAndReserved docAndReserved = SubmissionUtils.computeDocAndReservedFromDocument(submittedDoc); JSONObject submissionInfo = submissionDoc.getJSONObject("nunaliit_submission"); submissionInfo.put("submitted_doc",docAndReserved.doc); submissionInfo.put("submitted_reserved",docAndReserved.reserved); if( 0 != JSONSupport.compare(submissionDoc, originalSubmissionDoc) ){ logger.debug("Saving document "+docId); submissionDbDesign.getDatabase().updateDocument(submissionDoc); submissionDoc = null; submittedDoc = null; originalSubmissionDoc = null; } }
@Override public JSONObject getDocument() throws Exception { if( null == submittedDoc ){ logger.debug("Loading document "+docId); submissionDoc = submissionDbDesign.getDatabase().getDocument(docId); submittedDoc = SubmissionUtils.getSubmittedDocumentFromSubmission(submissionDoc); originalSubmissionDoc = JSONSupport.copyObject(submissionDoc); } return submittedDoc; }
private void initExport(ServletContext servletContext) throws ServletException { try { ExportConfiguration config = new ExportConfiguration(); CouchDb couchDb = couchDd.getDatabase(); config.setCouchDb(couchDb); CouchDesignDocument atlasDesign = couchDb.getDesignDocument("atlas"); config.setAtlasDesignDocument(atlasDesign); servletContext.setAttribute(ExportConfiguration.CONFIGURATION_KEY, config); } catch(Exception e) { logger.error("Error configuring export service",e); throw new ServletException("Error configuring export service",e); } }
private void initDate(ServletContext servletContext) throws ServletException { try { DateServletConfiguration config = new DateServletConfiguration(); CouchDb couchDb = couchDd.getDatabase(); config.setCouchDb(couchDb); CouchDesignDocument atlasDesign = couchDb.getDesignDocument("atlas"); config.setAtlasDesignDocument(atlasDesign); servletContext.setAttribute(DateServletConfiguration.CONFIGURATION_KEY, config); } catch(Exception e) { logger.error("Error configuring date service",e); throw new ServletException("Error configuring date service",e); } }
private CouchDb getUserCouchDbFromCookies(Cookie[] cookies) throws Exception { CouchContextCookie contextCookie = new CouchContextCookie(); for(Cookie cookie : cookies){ contextCookie.setCookie(cookie.getName(), cookie.getValue()); } CouchFactory factory = new CouchFactory(); return factory.getDb(contextCookie, dd.getDatabase()); }
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; }
public AgreementRobotThread(AgreementRobotSettings settings) throws Exception { this.atlasName = settings.getAtlasName(); this.documentDbDesignDocument = settings.getDocumentDesignDocument(); this.userDbDesignDocument = settings.getUserDb().getDesignDocument("nunaliit_user"); agreementRole = "nunaliit_agreement_atlas"; if( null != atlasName ){ agreementRole = "nunaliit_agreement_" + atlasName; } noWorkDelay = DELAY_NO_WORK_POLLING; CouchDbChangeMonitor changeMonitor = documentDbDesignDocument.getDatabase().getChangeMonitor(); if( null != changeMonitor ){ noWorkDelay = DELAY_NO_WORK_MONITOR; changeMonitor.addChangeListener(this); } }
public SubmissionRobotThread(SubmissionRobotSettings settings) throws Exception { this.submissionDbDesignDocument = settings.getSubmissionDesignDocument(); this.documentDbDesignDocument = settings.getDocumentDesignDocument(); this.userDb = settings.getUserDb(); this.mailNotifier = settings.getMailNotifier(); if( null != settings.getAtlasName() ){ adminRole = settings.getAtlasName() + "_administrator"; vetterRole = settings.getAtlasName() + "_vetter"; } noWorkDelay = DELAY_NO_WORK_POLLING; CouchDbChangeMonitor changeMonitor = submissionDbDesignDocument.getDatabase().getChangeMonitor(); if( null != changeMonitor ){ noWorkDelay = DELAY_NO_WORK_MONITOR; changeMonitor.addChangeListener(this); } }