@Override public <T extends AbstractReadHandle> T nextContent(T contentHandle) { return next().getContent(contentHandle); }
public void validateRecord(DocumentRecord record, Format type) { assertNotNull("DocumentRecord should never be null", record); assertNotNull("Document uri should never be null", record.getUri()); assertTrue("Document uri should start with " + DIRECTORY, record.getUri().startsWith(DIRECTORY)); assertEquals("All records are expected to be in same format", type, record.getFormat()); }
private void validateRecord(DocumentRecord record) { assertNotNull("DocumentRecord should never be null", record); assertNotNull("Document uri should never be null", record.getUri()); assertTrue("Document uri should start with " + DIRECTORY, record.getUri().startsWith(DIRECTORY)); assertEquals("All records are expected to be XML format", Format.XML, record.getFormat()); /* assertEquals("All records are expected to be mimetype application/xml", "application/xml", record.getMimetype()); */ if ( record.getUri().equals(DIRECTORY + "1205733.xml") ) { City chittagong = record.getContentAs(City.class); validateChittagong(chittagong); } }
@Override public void accept(DocumentRecord documentRecord) { String uri = documentRecord.getUri(); ZipEntry zipEntry = buildZipEntry(documentRecord); synchronized (this.zipOutputStream) { try { zipOutputStream.putNextEntry(zipEntry); if (logger.isDebugEnabled()) { logger.debug("Writing zip entry, name: " + zipEntry.getName()); } zipOutputStream.write(documentRecord.getContent(new BytesHandle()).get()); zipOutputStream.closeEntry(); } catch (IOException e) { throw new RuntimeException("Unable to write zip entry for URI: " + uri + "; cause: " + e.getMessage(), e); } } }
@Override public String generateOutput(DocumentRecord documentRecord) { if (Format.XML.equals(documentRecord.getFormat())) { DOMHandle handle = documentRecord.getContent(new DOMHandle()); Document document = handle.get(); OutputFormat format = new OutputFormat(handle.get()); format.setOmitXMLDeclaration(omitXmlDeclaration); StringWriter writer = new StringWriter(); try { new XMLSerializer(writer, format).serialize(document); return writer.toString(); } catch (IOException e) { throw new RuntimeException("Unable to serialize XML document to string: " + e.getMessage(), e); } } else if (logger.isDebugEnabled()) { logger.debug(String.format("Document '%s' has a format of '%s', so will not attempt to remove the XML declaration from it", documentRecord.getUri(), documentRecord.getFormat().name())); } return documentRecord.getContent(new StringHandle()).get(); }
protected File getOutputFile(DocumentRecord documentRecord) { return new File(baseDir, documentRecord.getUri()); }
rec.getFormat(); validateRecord(rec, Format.JSON); System.out.println(rec.getContent(new StringHandle()).get().toString()); count++;
try { for ( DocumentRecord record : documents ) { JacksonHandle content = record.getContent(new JacksonHandle()); JacksonHandle metadata = record.getMetadata(new JacksonHandle()); if ( "doc1.json".equals(record.getUri()) ) { assertEquals("Failed to read document 1", "dog", content.get().get("animal").textValue()); } else if ( "doc2.json".equals(record.getUri()) ) { assertEquals("Failed to read document 2", "cat", content.get().get("animal").textValue()); assertEquals("Failed to read expected quality", 2, metadata.get().get("quality").intValue());
@Test public void test_issue_758() throws Exception { BinaryDocumentManager docMgr = Common.client.newBinaryDocumentManager(); DocumentWriteSet writeset =docMgr.newWriteSet(); FileHandle h1 = new FileHandle(new File( "../marklogic-client-api-functionaltests/src/test/java/com/marklogic" + "/client" + "/functionaltest/data" + "/Sega-4MB.jpg")); String uri = "BinaryDocumentTest_" + new Random().nextInt(10000) + "/" + "Sega-4MB.jpg"; writeset.add(uri, h1); docMgr.write(writeset); DocumentPage page = docMgr.read(uri); DocumentRecord rec = page.next(); assertNotNull("DocumentRecord should never be null", rec); assertEquals(rec.getFormat(),Format.BINARY); } }
.onGenerateOutput( record -> { String uri = record.getUri(); String collection = record.getMetadata(new DocumentMetadataHandle()).getCollections().iterator().next(); String contents = record.getContentAs(String.class); return uri + "," + collection + "," + contents;
if ( uri1.equals(record.getUri()) ) { assertEquals( "the transform should have changed testProperty to 'test1a'", "test1a", record.getContentAs(JsonNode.class).get("testProperty").textValue() );
if (rec.getMimetype().contains("xml")) { validateRecord(rec, Format.XML); validateRecord(rec, Format.JSON); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertFalse("Record has collections ?", mh.getCollections().isEmpty());
mhRead = rec.getMetadata(mhRead); validateMetadata(mhRead);
.onDocumentReady(doc -> { String contents = doc.getContentAs(String.class); if ( ! "test contents".equals(contents) ) { badDocs.incrementAndGet();
.onUrisReady(new ExportListener() .onDocumentReady(doc -> { String contents = doc.getContent(new StringHandle()).get(); if (doc.getUri().equals(contents)) { errors.append("uri=[" + doc.getUri() + "] doesn't match contents=[" + contents + "]");
protected ZipEntry buildZipEntry(DocumentRecord documentRecord) { String uri = documentRecord.getUri(); if (flattenUri) { int pos = uri.lastIndexOf("/"); uri = pos > -1 ? uri.substring(pos + 1) : uri; } if (uriPrefix != null) { uri = uriPrefix + uri; } return new ZipEntry(uri); }
synchronized(writer) { for ( DocumentRecord doc : docs ) { Format format = doc.getFormat(); if ( Format.BINARY.equals(format) ) { throw new IllegalStateException("Document " + doc.getUri() + " is binary and cannot be written. Change your query to not select any binary documents."); } else { writer.write( doc.getContent(new StringHandle()).get() ); throw new DataMovementException("Failed to write document \"" + doc.getUri() + "\"", e);
rec.getFormat(); validateRecord(rec, Format.JSON); System.out.println(rec.getContent(new StringHandle()).get().toString()); count++;
try { for ( DocumentRecord doc: documents ) { DocumentMetadataHandle metadata = doc.getMetadata(new DocumentMetadataHandle()); StringHandle content = doc.getContent(new StringHandle()); if ( "doc4.json".equals(doc.getUri()) ) { assertEquals("Doc4 should also use the 1st batch default metadata, with quality 1", 1, metadata.getQuality()); assertTrue("Doc 4 contents are wrong", content.get().matches("\\{\"number\": ?4\\}")); } else if ( "doc5.json".equals(doc.getUri()) ) { assertEquals("Doc5 should use the 2nd batch default metadata, with quality 2", 2, metadata.getQuality()); try { for ( DocumentRecord doc: documents ) { DocumentMetadataHandle metadata = doc.getMetadata(new DocumentMetadataHandle()); if ( "doc6.json".equals(doc.getUri()) ) { assertEquals("Doc 6 should have the system default quality of 0", 0, metadata.getQuality()); } else if ( "doc7.json".equals(doc.getUri()) ) { assertEquals("Doc7 should also use the 1st batch default metadata, with quality 1", 1, metadata.getQuality()); } else if ( "doc8.json".equals(doc.getUri()) ) { assertEquals("Doc 8 should have the system default quality of 0", 0, metadata.getQuality());