@Override public void delete(ExtensionLibraryDescriptor modulesDescriptor) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { delete(modulesDescriptor.getPath()); } }
@Override public void delete(ExtensionLibraryDescriptor modulesDescriptor) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { delete(modulesDescriptor.getPath()); } }
@Override public <T extends AbstractReadHandle> T read(ExtensionLibraryDescriptor modulesDescriptor, T readHandle) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { return read(modulesDescriptor.getPath(), readHandle); }
@Override public <T extends AbstractReadHandle> T read(ExtensionLibraryDescriptor modulesDescriptor, T readHandle) throws ResourceNotFoundException, ForbiddenUserException, FailedRequestException { return read(modulesDescriptor.getPath(), readHandle); }
@Override public void write(ExtensionLibraryDescriptor modulesDescriptor, AbstractWriteHandle contentHandle) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { RequestParameters requestParams = new RequestParameters(); for (Permission perm : modulesDescriptor.getPermissions()) { requestParams.add("perm:" + perm.getRoleName(), perm.getCapability()); } checkPath(modulesDescriptor.getPath()); services.putResource(requestLogger, modulesDescriptor.getPath(), null, requestParams, contentHandle, null); }
@Override public void write(ExtensionLibraryDescriptor modulesDescriptor, AbstractWriteHandle contentHandle) throws ResourceNotFoundException, ResourceNotResendableException, ForbiddenUserException, FailedRequestException { RequestParameters requestParams = new RequestParameters(); for (Permission perm : modulesDescriptor.getPermissions()) { requestParams.add("perm:" + perm.getRoleName(), perm.getCapability()); } services.putResource(requestLogger, modulesDescriptor.getPath(), requestParams, contentHandle, null); }
descriptor.setPath("/ext/my/path/to/my/new/module.xqy"); String xqueryModuleAsStringNew = libsMgr.read(Path, new StringHandle()).get(); System.out.println("Path returned by Descriptor " + descriptor.getPath() + "Document returned by Descriptor" + xqueryModuleAsStringNew); libsMgr.delete(descriptor.getPath());
@Test public void testXQueryModuleCRUDBinaryFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; // write XQuery file to the modules database libsMgr.write(Path, new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/binary.jpg")).withFormat(Format.BINARY)); // read it back File f = new File("src/test/java/com/marklogic/client/functionaltest/data/binary.jpg"); assertEquals(f.length(), libsMgr.read(Path, new StringHandle()).getByteLength()); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }
assertEquals(descriptor.getPath(), Path);
@Test public void testXQueryModuleCRUDTextFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; // write XQuery file to the modules database libsMgr.write(Path, new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/readme.txt")).withFormat(Format.TEXT)); // read it back String xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); assertTrue("module read and read back", xqueryModuleAsString.startsWith("Copyright 2017 MarkLogic Corporation")); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module xqueryModuleAsString = libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }
assertEquals(descriptor.getPath(), "/ext/my/path/to/my/module.xqy");
@Test public void testXQueryModuleCRUDXmlFile() throws KeyManagementException, NoSuchAlgorithmException, IOException { DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // get a manager ExtensionLibrariesManager libsMgr = client.newServerConfigManager().newExtensionLibrariesManager(); String Path = "/ext/my/path/to/my/module.xqy"; FileHandle f = new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/data/all_well.xml")).withFormat(Format.XML); // write XQuery file to the modules database libsMgr.write(Path, f); // read it back assertEquals(209745, libsMgr.read(Path, new StringHandle()).getByteLength()); // get the list of descriptors ExtensionLibraryDescriptor[] descriptors = libsMgr.list(); assertEquals("number of modules installed", descriptors.length, 1); for (ExtensionLibraryDescriptor descriptor : descriptors) { assertEquals(descriptor.getPath(), Path); } // delete it libsMgr.delete(Path); try { // read deleted module libsMgr.read(Path, new StringHandle()).get(); } catch (ResourceNotFoundException e) { // pass; } }