use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class Main method restoreWithGui.
private static void restoreWithGui(final String username, final String password, final Optional<String> dbaPassword, final Path f, final XmldbURI uri, boolean overwriteApps) {
final GuiRestoreServiceTaskListener listener = new GuiRestoreServiceTaskListener();
listener.info("Connecting ...");
final Callable<Void> callable = () -> {
try {
final Collection collection = DatabaseManager.getCollection(uri.toString(), username, password);
final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
service.restore(f.toAbsolutePath().toString(), dbaPassword.orElse(null), listener, overwriteApps);
listener.enableDismissDialogButton();
if (JOptionPane.showConfirmDialog(null, "Would you like to rebuild the application repository?\nThis is only necessary if application packages were restored.", "Rebuild App Repository?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
System.out.println("Rebuilding application repository ...");
try {
final Collection root = DatabaseManager.getCollection(uri.toString(), username, dbaPassword.orElse(password));
ClientFrame.repairRepository(root);
listener.info("Application repository rebuilt successfully.");
} catch (final XMLDBException e) {
reportError(e);
listener.info("Rebuilding application repository failed!");
}
}
} catch (final Exception e) {
// $NON-NLS-1$
ClientFrame.showErrorMessage(e.getMessage(), null);
} finally {
if (listener.hasProblems()) {
ClientFrame.showErrorMessage(listener.getAllProblems(), null);
}
}
return null;
};
final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory(null, null, "backup.restore-with-gui"));
final Future<Void> future = executor.submit(callable);
while (!future.isDone() && !future.isCancelled()) {
try {
future.get(100, TimeUnit.MILLISECONDS);
} catch (final InterruptedException | TimeoutException ie) {
} catch (final ExecutionException ee) {
break;
}
}
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class CreateBackupDialog method getAllCollections.
private void getAllCollections(final Collection collection, final Vector<String> collections) throws XMLDBException {
collections.add(collection.getName());
final String[] childCollections = collection.listChildCollections();
Collection child = null;
for (final String childCollection : childCollections) {
try {
child = collection.getChildCollection(childCollection);
} catch (final XMLDBException xmldbe) {
if (xmldbe.getCause() instanceof PermissionDeniedException) {
continue;
} else {
throw xmldbe;
}
} catch (final Exception npe) {
System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
continue;
}
try {
getAllCollections(child, collections);
} catch (final Exception ee) {
System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
continue;
}
}
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class IndexDialog method getCollections.
// THIS IS A COPY FROM ClientFrame
// TODO: share this code between the two classes
private ArrayList getCollections(Collection root, ArrayList collectionsList) throws XMLDBException {
collectionsList.add(new PrettyXmldbURI(XmldbURI.create(root.getName())));
final String[] childCollections = root.listChildCollections();
Collection child;
for (String childCollection : childCollections) {
child = root.getChildCollection(childCollection);
getCollections(child, collectionsList);
}
return collectionsList;
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class AbstractXMLDBTask method mkcol.
protected final Collection mkcol(final Collection rootCollection, final String baseURI, String path, final String relPath) throws XMLDBException {
CollectionManagementService mgtService;
Collection current = rootCollection;
Collection collection;
String token;
// /TODO : use dedicated function in XmldbURI
final StringTokenizer tokenizer = new StringTokenizer(relPath, "/");
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
if (path != null) {
path = path + "/" + token;
} else {
path = "/" + token;
}
log("Get collection " + baseURI + path, Project.MSG_DEBUG);
collection = DatabaseManager.getCollection(baseURI + path, user, password);
if (collection == null) {
log("Create collection management service for collection " + current.getName(), Project.MSG_DEBUG);
mgtService = (CollectionManagementService) current.getService("CollectionManagementService", "1.0");
log("Create child collection " + token, Project.MSG_DEBUG);
current = mgtService.createCollection(token);
log("Created collection " + current.getName() + '.', Project.MSG_DEBUG);
} else {
current = collection;
}
}
return (current);
}
use of org.xmldb.api.base.Collection in project exist by eXist-db.
the class RestoreTask method execute.
@Override
public void execute() throws BuildException {
if (uri == null) {
throw (new BuildException("You have to specify an XMLDB collection URI"));
}
if ((dir == null) && (dirSet == null) && (zipFile == null)) {
throw (new BuildException("Missing required argument: either dir, dirset or file required"));
}
if ((dir != null) && !Files.isReadable(dir)) {
final String msg = "Cannot read restore file: " + dir.toAbsolutePath().toString();
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
registerDatabase();
try {
if (dir != null) {
log("Restoring from " + dir.toAbsolutePath().toString(), Project.MSG_INFO);
final Path file = dir.resolve("__contents__.xml");
if (!Files.exists(file)) {
final String msg = "Could not find file " + file.toAbsolutePath().toString();
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
final RestoreServiceTaskListener listener = new ConsoleRestoreServiceTaskListener();
final Collection collection = DatabaseManager.getCollection(uri, user, password);
final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
service.restore(file.normalize().toAbsolutePath().toString(), restorePassword, listener, overwriteApps);
}
} else if (dirSet != null) {
final DirectoryScanner scanner = dirSet.getDirectoryScanner(getProject());
scanner.scan();
final String[] includedFiles = scanner.getIncludedFiles();
log("Found " + includedFiles.length + " files.\n");
for (final String included : includedFiles) {
dir = scanner.getBasedir().toPath().resolve(included);
final Path contentsFile = dir.resolve("__contents__.xml");
if (!Files.exists(contentsFile)) {
final String msg = "Did not found file " + contentsFile.toAbsolutePath().toString();
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
log("Restoring from " + contentsFile.toAbsolutePath().toString() + " ...\n");
// TODO subdirectories as sub-collections?
final RestoreServiceTaskListener listener = new ConsoleRestoreServiceTaskListener();
final Collection collection = DatabaseManager.getCollection(uri, user, password);
final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
service.restore(contentsFile.normalize().toAbsolutePath().toString(), restorePassword, listener, overwriteApps);
}
}
} else if (zipFile != null) {
log("Restoring from " + zipFile.toAbsolutePath().toString(), Project.MSG_INFO);
if (!Files.exists(zipFile)) {
final String msg = "File not found: " + zipFile.toAbsolutePath().toString();
if (failonerror) {
throw (new BuildException(msg));
} else {
log(msg, Project.MSG_ERR);
}
} else {
final RestoreServiceTaskListener listener = new ConsoleRestoreServiceTaskListener();
final Collection collection = DatabaseManager.getCollection(uri, user, password);
final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
service.restore(zipFile.normalize().toAbsolutePath().toString(), restorePassword, listener, overwriteApps);
}
}
} catch (final Exception e) {
e.printStackTrace();
final String msg = "Exception during restore: " + e.getMessage();
if (failonerror) {
throw new BuildException(msg, e);
} else {
log(msg, e, Project.MSG_ERR);
}
}
}
}
Aggregations