static public FileHandle FileToHandle(File value) { return (value == null) ? null : new FileHandle(value); } static public Stream<FileHandle> FileToHandle(Stream<? extends File> values) {
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new FileHandle() : null; return handle; } };
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new FileHandle() : null; return handle; } };
private static void uploadData() throws Exception { DocumentMetadataHandle meta = new DocumentMetadataHandle() .withCollections(collection); JSONDocumentManager docMgr = evalClient.newJSONDocumentManager(); File folder = new File("src/test/resources/legal_holds/data"); for ( Path path: Files.newDirectoryStream(folder.toPath(), "*.json") ) { File file = path.toFile(); docMgr.write(directory + file.getName(), meta, new FileHandle(file)); } }
protected void installStagingDoc(String uri, DocumentMetadataHandle meta, String resource) { FileHandle handle = new FileHandle(getResourceFile(resource)); stagingDocMgr.write(uri, meta, handle); }
private static void installModule() throws Exception { // get a modules manager ExtensionLibrariesManager libsMgr = adminClient.newServerConfigManager().newExtensionLibrariesManager(); // write server-side javascript module file to the modules database libsMgr.write("/ext" + directory + "filterUrisReferencedByHolds.sjs", new FileHandle(new File("src/test/resources/legal_holds/filterUrisReferencedByHolds.sjs")) .withFormat(Format.TEXT)); }
public static void installModule() { Common.newAdminClient().newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform( transformName1, new FileHandle(new File("src/test/resources/" + transformName1))); Common.newAdminClient().newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform( transformName2, new FileHandle(new File("src/test/resources/" + transformName2))); }
public static void writeNTriplesFromFile(String filename, String graphName) throws KeyManagementException, NoSuchAlgorithmException, Exception { File file = new File(datasource + filename); FileHandle filehandle = new FileHandle(); GraphManager sparqlGmgr = writeclient.newGraphManager(); filehandle.set(file); sparqlGmgr.write(graphName, filehandle.withMimetype(RDFMimeTypes.TURTLE)); }
@Test public void testThings_Differentmimetypes() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.TRIPLEXML); String tripleGraphUri = "http://test.things.com/multiple"; File file = new File(datasource + "relative5.xml"); gmWriter.write(tripleGraphUri, new FileHandle(file)); file = new File(datasource + "semantics.ttl"); gmWriter.merge(tripleGraphUri, new FileHandle(file).withMimetype(RDFMimeTypes.TURTLE)); StringHandle things = gmWriter.things(new StringHandle(), "http://dbpedia.org/resource/Hadoop"); assertTrue("Things did not return expected Uri's", things.get().contains("Apache Hadoop")); gmWriter.delete(tripleGraphUri); }
@Test public void testWrite_rdfjson_TripleReadHandle() throws Exception { File file = new File(datasource + "relative6.json"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/rdfjson", filehandle.withMimetype("application/rdf+json")); TriplesReadHandle handle1 = gmWriter.read("htp://test.sem.graph/rdfjson", new JacksonHandle()); assertTrue("Did not insert document or inserted empty doc", handle1.toString().contains("http://purl.org/dc/elements/1.1/title")); }
@Test public void testThings_file() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.TRIPLEXML); String tripleGraphUri = "http://test.things.com/file"; File file = new File(datasource + "relative5.xml"); gmWriter.write(tripleGraphUri, new FileHandle(file)); TriplesReadHandle things = gmWriter.things(new StringHandle(), "about"); assertTrue("Things did not return expected Uri's", things.toString().contains("<about> <http://purl.org/dc/elements/1.1/title> \"Anna's Homepage\" .")); gmWriter.delete(tripleGraphUri); }
@Test public void testThingsAs() throws Exception { gmWriter.setDefaultMimetype(RDFMimeTypes.NTRIPLES); File file = new File(datasource + "relative1.nt"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("http://test.things.com/", filehandle); String things = gmWriter.thingsAs(String.class, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); assertTrue( "Did not return Expected graph Uri's", things.equals("<#electricVehicle2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://people.aifb.kit.edu/awa/2011/smartgrid/schema/smartgrid#ElectricVehicle> .")); }
@Test public void testWrite_rdfjson_JacksonHandle() throws Exception { File file = new File(datasource + "relative6.json"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/rdfjson", filehandle.withMimetype("application/rdf+json")); JacksonHandle handle1 = gmWriter.read("htp://test.sem.graph/rdfjson", new JacksonHandle()); JsonNode readFile = handle1.get(); assertTrue("Did not insert document or inserted empty doc", readFile.toString().contains("http://purl.org/dc/elements/1.1/title")); }
@Test public void testWrite_trig_FileHandle() throws Exception { File file = new File(datasource + "semantics.trig"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/trig", filehandle.withMimetype("application/trig")); gmWriter.write("htp://test.sem.graph/trig", filehandle.withMimetype("application/trig")); FileHandle handle = gmWriter.read("htp://test.sem.graph/trig", new FileHandle()); File readFile = handle.get(); String expectedContent = convertFileToString(readFile); assertTrue("Did not insert document or inserted empty doc", expectedContent.contains("http://www.example.org/exampleDocument#Monica")); }
@BeforeClass public static void beforeClass() { Common.connectAdmin(); // get a manager libsMgr = Common.adminClient .newServerConfigManager().newExtensionLibrariesManager(); // write XQuery file to the modules database libsMgr.write("/ext/my-lib.xqy", new FileHandle( new File("src/test/resources/my-lib.xqy")).withFormat(Format.TEXT)); Common.connect(); }
@BeforeClass public static void beforeClass() { Common.connectAdmin(); // get a manager libsMgr = Common.adminClient .newServerConfigManager().newExtensionLibrariesManager(); // write XQuery file to the modules database libsMgr.write("/ext/my-lib.xqy", new FileHandle( new File("src/test/resources/my-lib.xqy")).withFormat(Format.TEXT)); Common.connect(); } @AfterClass
@Test public void testReadAs_WriteAs() throws Exception { File file = new File(datasource + "semantics.nt"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.writeAs("htp://test.sem.graph/ntAs", filehandle.withMimetype(RDFMimeTypes.NTRIPLES)); File read = gmWriter.readAs("htp://test.sem.graph/ntAs", File.class); String expectedContent = convertFileToString(read); assertTrue("writeAs & readAs test did not return expected content", expectedContent.contains("http://www.w3.org/2001/sw/RDFCore/ntriples/")); }
@Test public void testWrite_nTriples_FileHandle() throws Exception { File file = new File(datasource + "5triples.nt"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/n", filehandle.withMimetype("application/n-triples")); StringHandle handle = gmWriter.read("htp://test.sem.graph/n", new StringHandle().withMimetype(RDFMimeTypes.NTRIPLES)); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("<http://jibbering.com/foaf/santa.rdf#bod>")); }
@Test public void testWrite_nquads_FileHandle() throws Exception { File file = new File(datasource + "relative2.nq"); FileHandle filehandle = new FileHandle(); filehandle.set(file); gmWriter.write("htp://test.sem.graph/nquads", filehandle.withMimetype("application/n-quads")); StringHandle handle = gmWriter.read("htp://test.sem.graph/nquads", new StringHandle().withMimetype(RDFMimeTypes.NQUADS)); assertTrue("Did not insert document or inserted empty doc", handle.toString().contains("<#electricVehicle2>")); }
@Test(expected = FailedRequestException.class) public void testWriteMultipleSameBinaryDoc() throws KeyManagementException, NoSuchAlgorithmException, Exception { String docId[] = { "Pandakarlino.jpg", "mlfavicon.png" }; BinaryDocumentManager docMgr = client.newBinaryDocumentManager(); DocumentWriteSet writeset = docMgr.newWriteSet(); File file1 = null; file1 = new File("src/test/java/com/marklogic/client/functionaltest/data/" + docId[0]); FileHandle handle1 = new FileHandle(file1); writeset.add("/1/" + docId[0], handle1.withFormat(Format.BINARY)); writeset.add("/1/" + docId[0], handle1.withFormat(Format.BINARY)); docMgr.write(writeset); }