@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); } }
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; } }
public SchemaCacheCouchDb(CouchDb couchDb) throws Exception { // this.couchDb = couchDb; this.dd = couchDb.getDesignDocument("atlas"); }
static public UserDesignDocumentImpl getUserDesignDocument(CouchDb couchDb) throws Exception { if( false == couchDb.documentExists(DD_ID) ) { throw new Exception("Design document "+DD_ID+" was not found"); } CouchDesignDocument dd = couchDb.getDesignDocument(DD_NAME); return new UserDesignDocumentImpl(dd); }
public AtlasInfo getAtlasInfo(CouchDb db, String databaseName) throws Exception { JSONObject atlasDesign = db.getDocument("_design/atlas"); JSONObject nunaliit = atlasDesign.optJSONObject("nunaliit"); String atlasName = nunaliit.getString("name"); boolean restricted = nunaliit.optBoolean("restricted",false); String submissionDbName = nunaliit.optString("submissionDbName",null); boolean submissionDbEnabled = nunaliit.optBoolean("submissionDbEnabled",false); AtlasInfo info = new AtlasInfo(databaseName, atlasName, restricted); info.setSubmissionDbName(submissionDbName); info.setSubmissionDbEnabled(submissionDbEnabled); return info; }
int uploadedVersion = 0; boolean exists = couchDb.documentExists(DD_ID); if( exists ) { JSONObject uploaded = couchDb.getDocument(DD_ID); if( null != uploaded ){ uploadedVersion = uploaded.optInt(PROP_NAME_VERSION, 0);
JSONObject userDoc = userDbDesignDocument.getDatabase().getDocument(docId); userDbDesignDocument.getDatabase().updateDocument(userDoc);
targetDb.createDocument(originalDoc); submissionDb.updateDocument(submissionDoc); JSONObject toDeleteDoc = targetDb.getDocument(docId); targetDb.deleteDocument(toDeleteDoc); submissionDb.updateDocument(submissionDoc); targetDb.updateDocument(approvedDoc); submissionDb.updateDocument(submissionDoc); } else { targetDb.updateDocument(doc1); submissionDb.updateDocument(submissionDoc); } else { submissionDoc.getJSONObject("nunaliit_submission") .put("state", "collision"); submissionDb.updateDocument(submissionDoc);
public ConfigServletActions(CouchDb couchDb, String couchDbName){ this.couchDb = couchDb; this.couchClient = couchDb.getClient(); this.couchDbName = couchDbName; }
public JSONObject deleteDocument( CouchAuthenticationContext authContext ,String dbIdentifier ,String docId ,String rev ) throws Exception { if( "submissionDb".equals(dbIdentifier) ) { if( null == docId || null == rev ){ throw new Exception("Document identifier and revision must be specified"); } JSONObject originalDoc = null; { CouchDocumentOptions options = new CouchDocumentOptions(); options.setRevision( rev ); originalDoc = documentCouchDb.getDocument(docId, options); } JSONObject submissionRequest = buildSubmissionRequest(authContext, null, originalDoc); JSONObject result = submissionDesign.getDatabase().createDocument(submissionRequest); return result; } else { throw new Exception("Only operations against 'submissionDb' are accepted"); } }
CouchAuthenticationContext userContext = getUserFromClient(userCouchDb.getClient()); userCouchDb.createDocument(doc);
JSONObject uploadRequestDoc = documentDbDesign.getDatabase().getDocument(uploadRequestDocId); documentDbDesign.getDatabase().deleteDocument(uploadRequestDoc);
@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 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); }
@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; }
try { CouchDb db = documentDbDesignDocument.getDatabase(); boolean exist = db.documentExists(DOC_ID_NUNALIIT_USER_AGREEMENT); if( exist ) { agreementDoc = db.getDocument(DOC_ID_NUNALIIT_USER_AGREEMENT); } else { logger.error("User agreement document not found in database");
public void performWork(String submissionDocId) throws Exception { JSONObject submissionDoc = submissionDb.getDocument(submissionDocId); JSONObject currentDoc = null; try { currentDoc = documentDb.getDocument(docId); } catch(Exception e) { submissionDb.updateDocument(submissionDoc); } else { String stateStr = submissionInfo.optString("state",null);
public SubmissionMailNotifierImpl( String atlasName ,MailDelivery mailDelivery ,CouchDb couchDb ) throws Exception { this.atlasName = atlasName; this.mailDelivery = mailDelivery; // Set up user database access CouchClient couchClient = couchDb.getClient(); userDesignDocument = UserDesignDocumentImpl.getUserDesignDocument(couchClient); }