@Override public JSONObject getJSONObject() { return wrapped.getJSONObject(); }
@Override public Attachment getAttachmentByName(String attachmentName) { return wrapped.getAttachmentByName(attachmentName); }
@Override public DocumentDigest computeDocumentDigest(Document doc) throws Exception { try { JSONObject json = doc.getJSONObject(); // Initialize digest DocumentDigest dd = new DocumentDigest(); dd.setType(DIGEST_COMPUTER_TYPE); // Compute digest of main document String mainDigest = this.computeDigestFromJsonObject(json); dd.setDocDigest(mainDigest); // Process each attachment Collection<Attachment> attachments = doc.getAttachments(); if( null != attachments ) { for(Attachment attachment : attachments){ String digest = computeAttachmentDigest(attachment); dd.addAttachmentDigest(attachment.getName(), digest); } } return dd; } catch(Exception e) { throw new Exception("Error while computing document digest for "+doc.getId(), e); } }
DocumentUpdateProcess updateProcess = new DocumentUpdateProcess(couchDb); updateProcess.setListener(listener); Map<String,FSEntry> documentsToRestore = computeDocIds(); listener.reportDocumentIds(docIds); doc = DocumentFile.createDocument(entry); updateProcess.update(doc); listener.endRestore();
List<String> docIds = computeDocIds(); listener.reportDocumentIds(docIds); String name = computeNameFromId(docId); docDir = new File(dumpDir, name); listener.reportDownload(docId); Document doc = DocumentCouchDb.documentFromCouchDb(couchDb, docId); listener.reportStore(docId); storeProcess.store(doc, docDir); listener.reportEnd();
@Override public String getId() { return wrapped.getId(); }
static public DocumentUpdateProcess createDocumentUpdateProcess( GlobalSettings gs ,CouchDb couchDb ) throws Exception { DocumentUpdateProcess updateProcess = new DocumentUpdateProcess(couchDb); DocumentUpdateListener l = new UpdateProgress(gs); updateProcess.setListener(l); return updateProcess; }
static public DocumentDigest fromJSONObject(JSONObject jsonObj){ DocumentDigest dd = new DocumentDigest(); dd.setType(type); dd.setDocDigest(digest); String digest = attObj.optString("digest"); if( null != digest ){ dd.addAttachmentDigest(attachmentName, digest);
@Override public Collection<Attachment> getAttachments() { return wrapped.getAttachments(); }
@Override public String getRevision() { return wrapped.getRevision(); }
@Override public void setId(String id) throws Exception { wrapped.setId(id); }
public void addAttachment(Attachment attachment){ attachments.put(attachment.getName(), attachment); } }
private List<String> computeDocIds() throws Exception { if( allDocs ) { // Get all documents from database Collection<String> allDocIds = couchDb.getAllDocIds(); return new ArrayList<String>(allDocIds); } else { return getDocIds(); } }
@Override public void documentSkippedBecauseUnchanged(Document doc) { ++count; os.println("Not restoring "+count+" of "+total+" ("+doc.getId()+") because it is unchanged"); }
public void update(Document sourceDoc) throws Exception { update(sourceDoc, Schedule.UPDATE_UNLESS_MODIFIED); }
@Override public void updatingDocument(Phase phase, Document doc) { if( phase == Phase.BEFORE ) { ++count; os.println("Restoring "+count+" of "+total+" ("+doc.getId()+")"); } }
@Override public void documentSkippedBecauseModified(Document doc) { ++count; ++skipped; os.println("Can not restore "+doc.getId()+" because the document was modified in the database"); }
@Override public void documentSkippedBecauseModified(Document doc) { gs.getOutStream().println("Update skipped: "+doc.getId()); }
public void outputExport(Writer writer) throws Exception { while( retrieval.hasNext() ){ Document doc = retrieval.getNext(); if( null != doc ) { try{ outputDocument(writer, doc); } catch(Exception e) { throw new Exception("Error exporting document: "+doc.getId(), e); } } } }