@Override public JSONObject getJSONObject() { return wrapped.getJSONObject(); }
@Override public String getId() { return wrapped.getId(); }
@Override public Collection<Attachment> getAttachments() { return wrapped.getAttachments(); }
@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); } }
if( 0 != objectComparator.compare(sourceDoc.getJSONObject(), targetDoc) ){ result.setDocumentModified(true); Collection<Attachment> attachments = sourceDoc.getAttachments(); if( null != attachments ) { for(Attachment attachment : attachments){
@Override public String getRevision() { return wrapped.getRevision(); }
@Override public void setId(String id) throws Exception { wrapped.setId(id); }
@Override public Attachment getAttachmentByName(String attachmentName) { return wrapped.getAttachmentByName(attachmentName); }
throw new Exception("A directory must be specified for storing: "+doc.getId()); removeUndesiredFiles(doc.getJSONObject(), dir); String id = doc.getId(); JSONObject jsonObj = doc.getJSONObject(); Iterator<?> it = jsonObj.keys(); while( it.hasNext() ){ Collection<Attachment> attachments = doc.getAttachments(); if( attachments.size() > 0 ) { throw new Exception("Error while storing document: "+doc.getId(), e);
JSONObject sourceJson = sourceDoc.getJSONObject(); if( null != jsonObjectConverter ){ sourceJson = jsonObjectConverter.convertObject(sourceJson); builder.value(sourceDoc.getId()); for(Attachment attachment : sourceDoc.getAttachments()){ if( attachmentNamesToUpload.contains(attachment.getName()) ) { InputStream is = attachment.getInputStream();
@Override public void documentSkippedBecauseUnchanged(Document doc) { ++count; os.println("Not restoring "+count+" of "+total+" ("+doc.getId()+") because it is unchanged"); }
@Override public SchemaExportInfo getExportInfo(String schemaName) throws Exception { if( exportInfoFromSchemaName.containsKey(schemaName) ){ return exportInfoFromSchemaName.get(schemaName); } SchemaExportInfo exportInfo = null; try { Document doc = getSchema(schemaName); if( null != doc ) { JSONArray jsonExport = doc.getJSONObject().optJSONArray("export"); if( null != jsonExport ) { exportInfo = SchemaExportInfo.parseJson(jsonExport); } } } catch(Exception e) { throw new Exception("Error parsing export field for schema: "+schemaName); } exportInfoFromSchemaName.put(schemaName,exportInfo); return exportInfo; }
@Override public void updatingDocument(Phase phase, Document doc) { if( phase == Phase.BEFORE ) { ++count; os.println("Restoring "+count+" of "+total+" ("+doc.getId()+")"); } }
@Override public SchemaExportInfo getCsvExportInfo(String schemaName) throws Exception { if( csvExportInfoFromSchemaName.containsKey(schemaName) ){ return csvExportInfoFromSchemaName.get(schemaName); } SchemaExportInfo exportInfo = null; try { Document doc = getSchema(schemaName); if( null != doc ) { JSONArray jsonExport = doc.getJSONObject().optJSONArray("csvExport"); if( null != jsonExport ) { exportInfo = SchemaExportInfo.parseJson(jsonExport); } } } catch(Exception e) { throw new Exception("Error parsing CSV export field for schema: "+schemaName,e); } csvExportInfoFromSchemaName.put(schemaName,exportInfo); return exportInfo; } }
@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 boolean accepts(Document doc) throws Exception { if( filterType == Filter.ALL ) { return true; } Geometry geometry = null; try { JSONObject jsonDoc = doc.getJSONObject(); if( JSONSupport.containsKey(jsonDoc, "nunaliit_geom") ) { JSONObject jsonGeom = jsonDoc.getJSONObject("nunaliit_geom"); String wkt = jsonGeom.optString("wkt", null); if( null != wkt ){ geometry = wktParser.parseWkt(wkt); } } } catch(Exception e) { throw new Exception("Error while filtering on geometry", e); } return acceptsGeometry(geometry); }
@Override public void documentSkippedBecauseModified(Document doc) { gs.getOutStream().println("Update skipped: "+doc.getId()); }
JSONObject jsonDoc = doc.getJSONObject(); String docId = jsonDoc.optString("_id",null); String nunaliitType = jsonDoc.optString("nunaliit_type",null); JSONObject jsonDoc = doc.getJSONObject(); String nunaliitType = jsonDoc.optString("nunaliit_type",null); String name = jsonDoc.optString("name",null); Document doc = documentsByDocId.get(docId); File schemaDir = dirByDocId.get(docId); JSONObject jsonDoc = doc.getJSONObject(); String name = jsonDoc.getString("name"); JSONObject jsonDef = jsonDoc.getJSONObject("definition");
static public Map<String,File> listDocumentsFromDir( GlobalSettings gs ,File docsDir ) throws Exception { Map<String,File> docIds = new HashMap<String,File>(); if( docsDir.exists() && docsDir.isDirectory() ){ // Iterate over each subdirectory, attempting to // load each document String[] subDirNames = docsDir.list( gs.getFilenameFilter() ); for(String subDirName : subDirNames){ File subDir = new File(docsDir, subDirName); if( subDir.exists() && subDir.isDirectory() ) { // OK, let's create a document based on this Document doc = null; try { FSEntryFile entry = new FSEntryFile(subDir); doc = DocumentFile.createDocument(entry); } catch(Exception e){ throw new Exception("Unable to read document at: "+subDir.getName(), e); } docIds.put(doc.getId(), subDir); } } } return docIds; }
JSONObject jsonDoc = doc.getJSONObject(); diskVersion = jsonDoc.optInt(PROP_NAME_VERSION, 0);