protected File getOutputFile(DocumentRecord documentRecord) { return new File(baseDir, documentRecord.getUri()); }
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); }
@Override public void accept(DocumentRecord documentRecord) { String uri = documentRecord.getUri(); File outputFile = getOutputFile(documentRecord); if (logger.isDebugEnabled()) { logger.debug("Writing document with URI " + uri + " to file: " + outputFile); } try { writeDocumentToFile(documentRecord, outputFile); } catch (IOException e) { String message = "Unable to write document to file; URI: " + uri + "; file: " + outputFile; if (logErrors) { logger.warn(message, e); } else { throw new RuntimeException(message, e); } } }
@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); } } }
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()); } }
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()); } }
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()); }
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()); // System.out.println(record.getMimetype()); }
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()); } }
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()); // System.out.println(record.getMimetype()); }
@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(); }
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); } }
@Test public void testWriteMultipleJSONDocsWithDefaultMetadata() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/a.json", "/b.json", "/c.json" }; String json1 = new String("{\"animal\":\"dog\", \"says\":\"woof\"}"); String json2 = new String("{\"animal\":\"cat\", \"says\":\"meow\"}"); String json3 = new String("{\"animal\":\"rat\", \"says\":\"keek\"}"); Reader strReader = new StringReader(json1); JSONDocumentManager docMgr = client.newJSONDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new ReaderHandle(strReader).withFormat(Format.JSON)); writeset.add(docId[1], new ReaderHandle(new StringReader(json2))); writeset.add(docId[2], new ReaderHandle(new StringReader(json3))); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); System.out.println(rec.getUri()); validateMetadata(mh); } validateMetadata(mh); }
assertEquals("You should have one and only one doc with uri=[" + uri + "]", 1, docs.size()); DocumentRecord doc = docs.next(); assertEquals(uri, doc.getUri()); assertEquals(contents, doc.getContent(new StringHandle()).get()); docMgr.delete(new String[] {uri});
@Test public void testBulkSearchSQDwithResponseFormatandStringHandle() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadTxtDocuments(); loadJSONDocuments(); TextDocumentManager docMgr = client.newTextDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("bar"); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.METADATA); docMgr.setMetadataCategories(Metadata.PERMISSIONS); StringHandle results = new StringHandle().withFormat(Format.JSON); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); while (page.hasNext()) { DocumentRecord rec = page.next(); validateRecord(rec, Format.TEXT); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertTrue("Record has collections ?", mh.getCollections().isEmpty()); } assertFalse("Search handle contains", results.get().isEmpty()); }
@Test public void testBulkSearchSQDwithResponseFormatandStringHandle() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadJSONDocuments(); JSONDocumentManager docMgr = client.newJSONDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("dog1", "dog11")); queryMgr.search(qd, new SearchHandle()); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.METADATA); docMgr.setMetadataCategories(Metadata.PERMISSIONS); StringHandle results = new StringHandle().withFormat(Format.JSON); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); while (page.hasNext()) { DocumentRecord rec = page.next(); validateRecord(rec, Format.JSON); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertTrue("Record has collections ?", mh.getCollections().isEmpty()); } assertFalse("Search handle contains", results.get().isEmpty()); }
@Test public void testWriteMultipleTextDocWithDefaultMetadata() { String docId[] = { "/foo/test/myFoo1.txt", "/foo/test/myFoo2.txt", "/foo/test/myFoo3.txt" }; TextDocumentManager docMgr = client.newTextDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new StringHandle().with("This is so foo1")); writeset.add(docId[1], new StringHandle().with("This is so foo2")); writeset.add(docId[2], new StringHandle().with("This is so foo3")); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); validateMetadata(mh); } validateMetadata(mh); }
@Test public void testWriteMultipleXMLDocWithDefaultMetadata() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "/foo/test/Foo1.xml", "/foo/test/Foo2.xml", "/foo/test/Foo3.xml" }; XMLDocumentManager docMgr = client.newXMLDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); // put metadata DocumentMetadataHandle mh = setMetadata(); writeset.addDefault(mh); writeset.add(docId[0], new DOMHandle(getDocumentContent("This is so foo1"))); writeset.add(docId[1], new DOMHandle().with(getDocumentContent("This is so foo2"))); writeset.add(docId[2], new DOMHandle().with(getDocumentContent("This is so foo3"))); docMgr.write(writeset); DocumentPage page = docMgr.read(docId); assertTrue("DocumentPage Size did not return expected value:: returned== " + page.size(), page.size() == 3); while (page.hasNext()) { DocumentRecord rec = page.next(); docMgr.readMetadata(rec.getUri(), mh); validateMetadata(mh); } validateMetadata(mh); }
docMgr.readMetadata(rec.getUri(), metadataHandleRead); validateUpdatedMetadataCollections(metadataHandleRead);