• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/backup/ExportGUI.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.backup;
50

51
import org.exist.EXistException;
52
import org.exist.security.PermissionDeniedException;
53
import org.exist.start.CompatibleJavaVersionCheck;
54
import org.exist.start.StartException;
55
import org.exist.storage.BrokerPool;
56
import org.exist.storage.DBBroker;
57
import org.exist.storage.txn.Txn;
58
import org.exist.util.Configuration;
59
import org.exist.util.MimeTable;
60
import org.exist.util.MimeType;
61
import org.exist.util.OSUtil;
62
import org.exist.util.SystemExitCodes;
63
import org.exist.xquery.TerminatedException;
64
import se.softhouse.jargo.Argument;
65
import se.softhouse.jargo.ArgumentException;
66
import se.softhouse.jargo.CommandLineParser;
67

68
import javax.swing.*;
69
import javax.swing.filechooser.FileFilter;
70
import java.io.File;
71
import java.io.IOException;
72
import java.io.PrintWriter;
73
import java.nio.file.Files;
74
import java.nio.file.Path;
75
import java.nio.file.Paths;
76
import java.util.List;
77
import java.util.Optional;
78

79
import static java.nio.charset.StandardCharsets.UTF_8;
80
import static org.exist.util.ThreadUtils.newGlobalThread;
81
import static org.exist.util.ThreadUtils.newInstanceThread;
82
import static se.softhouse.jargo.Arguments.helpArgument;
83

84

85
/**
86
 * DOCUMENT ME!
87
 *
88
 * @author wolf
89
 */
90
public class ExportGUI extends javax.swing.JFrame {
91
    private static final long serialVersionUID = -8104424554660744639L;
92

93
    /* general arguments */
94
    private static final Argument<?> helpArg = helpArgument("-h", "--help");
×
95

96
    private BrokerPool pool = null;
×
97
    private int documentCount = 0;
×
98
    private PrintWriter logWriter = null;
×
99

100
    // Variables declaration - do not modify//GEN-BEGIN:variables
101
    private javax.swing.JButton btnChangeDir;
102
    private javax.swing.JButton btnConfSelect;
103
    private javax.swing.JLabel currentTask;
104
    private javax.swing.JTextField dbConfig;
105
    private javax.swing.JButton exportBtn;
106
    private javax.swing.JCheckBox zipBtn;
107
    private javax.swing.JCheckBox incrementalBtn;
108
    private JCheckBox directAccessBtn;
109
    private javax.swing.JCheckBox scanBtn;
110
    private javax.swing.JLabel jLabel1;
111
    private javax.swing.JLabel jLabel2;
112
    private javax.swing.JMenu jMenu1;
113
    private javax.swing.JMenuBar jMenuBar1;
114
    private javax.swing.JScrollPane jScrollPane2;
115
    private javax.swing.JToolBar jToolBar1;
116
    private javax.swing.JMenuItem menuQuit;
117
    private javax.swing.JTextArea messages;
118
    private javax.swing.JTextField outputDir;
119
    private javax.swing.JProgressBar progress;
120
    private javax.swing.JButton startBtn;
121
    // End of variables declaration//GEN-END:variables
122

123
    /**
124
     * Creates new form CheckerGUI.
125
     */
126
    public ExportGUI() {
127
        super("Consistency Check and Repair");
×
128
        initComponents();
×
129
        final String existHome = System.getProperty("exist.home", "./");
×
130
        final Path home = Paths.get(existHome).normalize();
×
131
        dbConfig.setText(
×
132
                Optional.ofNullable(System.getProperty("exist.configurationFile")).map(Paths::get)
×
133
                        .orElse(home.resolve("etc").resolve("conf.xml"))
×
134
                        .toAbsolutePath().toString());
×
135
        outputDir.setText(home.resolve("export").toAbsolutePath().toString());
×
136
    }
×
137

138
    protected boolean checkOutputDir() {
139
        final Path dir = Paths.get(outputDir.getText()).normalize();
×
140

141
        if (!Files.exists(dir)) {
×
142

143
            if (JOptionPane.showConfirmDialog(this, "The output directory " + dir.toAbsolutePath().toString() + " does not exist. Create it?", "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
×
144
                try {
145
                    Files.createDirectories(dir);
×
146
                } catch (final IOException e) {
×
147
                    JOptionPane.showMessageDialog(this, "Could not create output dir: " + dir.toAbsolutePath().toString(), "Configuration Error", JOptionPane.ERROR_MESSAGE);
×
148
                    e.printStackTrace();
×
149
                    System.err.println("ERROR: Failed to create output dir: " + e.getMessage());
×
150
                }
151
            } else {
×
152
                return false;
×
153
            }
154
        }
155
        return true;
×
156
    }
157

158

159
    protected boolean startDB() {
160
        if (pool != null) {
×
161
            return true;
×
162
        }
163
        final Path confFile = Paths.get(dbConfig.getText()).normalize();
×
164

165
        if (!(Files.exists(confFile) && Files.isReadable(confFile))) {
×
166
            JOptionPane.showMessageDialog(this, "The selected database configuration file " + confFile.toAbsolutePath().toString() + " does not exist or is not readable.", "Configuration Error", JOptionPane.ERROR_MESSAGE);
×
167
            return false;
×
168
        }
169

170
        try {
171
            final Configuration config = new Configuration(confFile.toAbsolutePath().toString(), Optional.empty());
×
172
            BrokerPool.configure(1, 5, config);
×
173
            pool = BrokerPool.getInstance();
×
174
            return true;
×
175
        } catch (final Exception e) {
×
176
            JOptionPane.showMessageDialog(this, "Could not start the database instance. Please remember\n" + "that this tool tries to launch an embedded db instance. No other db instance should\n" + "be running on the same data.", "DB Error", JOptionPane.ERROR_MESSAGE);
×
177
            e.printStackTrace();
×
178
            System.err.println("ERROR: Failed to open database: " + e.getMessage());
×
179
        }
180
        return false;
×
181
    }
182

183

184
    /**
185
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is
186
     * always regenerated by the Form Editor.
187
     */
188
    // <editor-fold defaultstate="collapsed" desc="Generated
189
    // Code">//GEN-BEGIN:initComponents
190
    private void initComponents() {
191
        java.awt.GridBagConstraints gridBagConstraints;
192

193
        currentTask = new javax.swing.JLabel();
×
194
        progress = new javax.swing.JProgressBar();
×
195
        jScrollPane2 = new javax.swing.JScrollPane();
×
196
        messages = new javax.swing.JTextArea();
×
197
        jToolBar1 = new javax.swing.JToolBar();
×
198
        startBtn = new javax.swing.JButton();
×
199
        exportBtn = new javax.swing.JButton();
×
200
        incrementalBtn = new JCheckBox("Incremental");
×
201
        scanBtn = new JCheckBox("Scan docs");
×
202
        directAccessBtn = new JCheckBox("Direct access");
×
203
        zipBtn = new JCheckBox("Create ZIP");
×
204
        zipBtn.setSelected(true);
×
205
        outputDir = new javax.swing.JTextField();
×
206
        jLabel1 = new javax.swing.JLabel();
×
207
        btnChangeDir = new javax.swing.JButton();
×
208
        dbConfig = new javax.swing.JTextField();
×
209
        jLabel2 = new javax.swing.JLabel();
×
210
        btnConfSelect = new javax.swing.JButton();
×
211
        jMenuBar1 = new javax.swing.JMenuBar();
×
212
        jMenu1 = new javax.swing.JMenu();
×
213
        menuQuit = new javax.swing.JMenuItem();
×
214

215
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
×
216
        addWindowListener(new java.awt.event.WindowAdapter() {
×
217
            public void windowClosed(final java.awt.event.WindowEvent evt) {
218
                formWindowClosed(evt);
×
219
            }
×
220
        });
221
        getContentPane().setLayout(new java.awt.GridBagLayout());
×
222

223
        currentTask.setText(" ");
×
224
        currentTask.setMinimumSize(new java.awt.Dimension(0, 25));
×
225
        gridBagConstraints = new java.awt.GridBagConstraints();
×
226
        gridBagConstraints.gridx = 0;
×
227
        gridBagConstraints.gridy = 3;
×
228
        gridBagConstraints.gridwidth = 3;
×
229
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
×
230
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
×
231
        gridBagConstraints.weightx = 1.0;
×
232
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
233
        getContentPane().add(currentTask, gridBagConstraints);
×
234
        gridBagConstraints = new java.awt.GridBagConstraints();
×
235
        gridBagConstraints.gridx = 0;
×
236
        gridBagConstraints.gridy = 4;
×
237
        gridBagConstraints.gridwidth = 3;
×
238
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
×
239
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
×
240
        gridBagConstraints.weightx = 1.0;
×
241
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
242
        getContentPane().add(progress, gridBagConstraints);
×
243

244
        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("Messages"));
×
245
        jScrollPane2.setPreferredSize(new java.awt.Dimension(400, 200));
×
246

247
        messages.setColumns(20);
×
248
        messages.setLineWrap(true);
×
249
        messages.setRows(5);
×
250
        messages.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
×
251
        jScrollPane2.setViewportView(messages);
×
252

253
        gridBagConstraints = new java.awt.GridBagConstraints();
×
254
        gridBagConstraints.gridx = 0;
×
255
        gridBagConstraints.gridy = 5;
×
256
        gridBagConstraints.gridwidth = 3;
×
257
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
×
258
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
×
259
        gridBagConstraints.weightx = 1.0;
×
260
        gridBagConstraints.weighty = 1.0;
×
261
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
262
        getContentPane().add(jScrollPane2, gridBagConstraints);
×
263

264
        jToolBar1.setRollover(true);
×
265

266
        startBtn.setText("Check");
×
267
        startBtn.setFocusable(false);
×
268
        startBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
×
269
        startBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
×
270
        startBtn.addActionListener(this::startBtncheck);
×
271
        jToolBar1.add(startBtn);
×
272

273
        exportBtn.setText("Check & Export");
×
274
        exportBtn.setFocusable(false);
×
275
        exportBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
×
276
        exportBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
×
277
        exportBtn.addActionListener(this::exportBtnActionPerformed);
×
278
        jToolBar1.add(exportBtn);
×
279

280
        jToolBar1.add(incrementalBtn);
×
281
        scanBtn.setSelected(true);
×
282
        scanBtn.setToolTipText("Perform additional checks; scans every XML document");
×
283
        jToolBar1.add(scanBtn);
×
284
        directAccessBtn.setToolTipText("Bypass collection index by scanning collection store");
×
285
        jToolBar1.add(directAccessBtn);
×
286
        jToolBar1.add(zipBtn);
×
287

288
        gridBagConstraints = new java.awt.GridBagConstraints();
×
289
        gridBagConstraints.gridwidth = 3;
×
290
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
×
291
        gridBagConstraints.weightx = 1.0;
×
292
        getContentPane().add(jToolBar1, gridBagConstraints);
×
293
        gridBagConstraints = new java.awt.GridBagConstraints();
×
294
        gridBagConstraints.gridx = 1;
×
295
        gridBagConstraints.gridy = 2;
×
296
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
×
297
        gridBagConstraints.weightx = 1.0;
×
298
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
299
        getContentPane().add(outputDir, gridBagConstraints);
×
300

301
        jLabel1.setText("Output Directory:");
×
302
        gridBagConstraints = new java.awt.GridBagConstraints();
×
303
        gridBagConstraints.gridx = 0;
×
304
        gridBagConstraints.gridy = 2;
×
305
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
×
306
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
307
        getContentPane().add(jLabel1, gridBagConstraints);
×
308

309
        btnChangeDir.setText("Change");
×
310
        btnChangeDir.addActionListener(this::btnChangeDirActionPerformed);
×
311
        gridBagConstraints = new java.awt.GridBagConstraints();
×
312
        gridBagConstraints.gridx = 2;
×
313
        gridBagConstraints.gridy = 2;
×
314
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
×
315
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
316
        getContentPane().add(btnChangeDir, gridBagConstraints);
×
317
        gridBagConstraints = new java.awt.GridBagConstraints();
×
318
        gridBagConstraints.gridx = 1;
×
319
        gridBagConstraints.gridy = 1;
×
320
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
×
321
        gridBagConstraints.weightx = 1.0;
×
322
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
323
        getContentPane().add(dbConfig, gridBagConstraints);
×
324

325
        jLabel2.setText("DB Configuration:");
×
326
        gridBagConstraints = new java.awt.GridBagConstraints();
×
327
        gridBagConstraints.gridx = 0;
×
328
        gridBagConstraints.gridy = 1;
×
329
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
×
330
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
331
        getContentPane().add(jLabel2, gridBagConstraints);
×
332

333
        btnConfSelect.setText("Select");
×
334
        btnConfSelect.setMaximumSize(new java.awt.Dimension(75, 24));
×
335
        btnConfSelect.setMinimumSize(new java.awt.Dimension(75, 24));
×
336
        btnConfSelect.setPreferredSize(new java.awt.Dimension(75, 24));
×
337
        btnConfSelect.addActionListener(this::btnConfSelectActionPerformed);
×
338
        gridBagConstraints = new java.awt.GridBagConstraints();
×
339
        gridBagConstraints.gridx = 2;
×
340
        gridBagConstraints.gridy = 1;
×
341
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
×
342
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
×
343
        getContentPane().add(btnConfSelect, gridBagConstraints);
×
344

345
        jMenu1.setText("File");
×
346

347
        menuQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
×
348
        menuQuit.setText("Quit");
×
349
        menuQuit.addActionListener(this::menuQuitActionPerformed);
×
350
        jMenu1.add(menuQuit);
×
351

352
        jMenuBar1.add(jMenu1);
×
353

354
        setJMenuBar(jMenuBar1);
×
355

356
        pack();
×
357
    } // </editor-fold>//GEN-END:initComponents
×
358

359

360
    private void formWindowClosed(final java.awt.event.WindowEvent evt) { // GEN-FIRST:event_formWindowClosed
361
        BrokerPool.stopAll(false);
×
362
    } // GEN-LAST:event_formWindowClosed
×
363

364

365
    private void startBtncheck(final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_startBtncheck
366

367
        if (!checkOutputDir()) {
×
368
            return;
×
369
        }
370
        final Runnable checkRun = () -> {
×
371
            openLog(outputDir.getText());
×
372

373
            try {
374
                checkDB();
×
375
            } finally {
×
376
                closeLog();
×
377
            }
378
        };
×
379
        if (pool != null) {
×
380
            newInstanceThread(pool, "export-gui.check-run", checkRun).start();
×
381
        } else {
×
382
            newGlobalThread("export-gui.check-run", checkRun).start();
×
383
        }
384
    } // GEN-LAST:event_startBtncheck
×
385

386

387
    private void exportBtnActionPerformed(final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_exportBtnActionPerformed
388

389
        if (!checkOutputDir()) {
×
390
            return;
×
391
        }
392
        final Runnable th = () -> {
×
393
            openLog(outputDir.getText());
×
394

395
            try {
396
                currentTask.setText("Checking database consistency ...");
×
397
                final List<ErrorReport> errors = checkDB();
×
398
                currentTask.setText("Exporting data ...");
×
399
                exportDB(outputDir.getText(), errors);
×
400
            } finally {
×
401
                closeLog();
×
402
            }
403
        };
×
404
        if (pool != null) {
×
405
            newInstanceThread(pool, "export-gui.export", th).start();
×
406
        } else {
×
407
            newGlobalThread("export-gui.export", th).start();
×
408
        }
409
    } // GEN-LAST:event_exportBtnActionPerformed
×
410

411

412
    private void btnChangeDirActionPerformed(final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnChangeDirActionPerformed
413
        final Path dir = Paths.get(outputDir.getText());
×
414
        final JFileChooser chooser = new JFileChooser();
×
415
        chooser.setMultiSelectionEnabled(false);
×
416
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
×
417
        chooser.setSelectedFile(dir.resolve("export").toFile());
×
418
        chooser.setCurrentDirectory(dir.toFile());
×
419

420
        if (chooser.showDialog(this, "Export") == JFileChooser.APPROVE_OPTION) {
×
421
            outputDir.setText(chooser.getSelectedFile().getAbsolutePath());
×
422
        }
423
    } // GEN-LAST:event_btnChangeDirActionPerformed
×
424

425

426
    private void menuQuitActionPerformed(final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_menuQuitActionPerformed
427
        BrokerPool.stopAll(false);
×
428
        System.exit(SystemExitCodes.OK_EXIT_CODE);
×
429
    } // GEN-LAST:event_menuQuitActionPerformed
×
430

431

432
    private void btnConfSelectActionPerformed(final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnConfSelectActionPerformed
433
        final Path dir = Paths.get(dbConfig.getText()).normalize().getParent();
×
434
        final JFileChooser chooser = new JFileChooser();
×
435
        chooser.setMultiSelectionEnabled(false);
×
436
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
×
437
        chooser.setSelectedFile(Optional.ofNullable(System.getProperty("exist.configurationFile"))
×
438
                .map(Paths::get)
×
439
                .orElse(dir.resolve("etc").resolve("conf.xml"))
×
440
                .toFile());
×
441
        chooser.setCurrentDirectory(dir.resolve("etc").toFile());
×
442
        chooser.setFileFilter(new FileFilter() {
×
443
            public boolean accept(final File f) {
444
                if (f.isDirectory()) {
×
445
                    return (true);
×
446
                }
447
                final MimeType mime = MimeTable.getInstance().getContentTypeFor(f.getName());
×
448

449
                if (mime == null) {
×
450
                    return false;
×
451
                }
452
                return mime.isXMLType();
×
453
            }
454

455

456
            public String getDescription() {
457
                return ("Database XML configuration file");
×
458
            }
459

460
        });
461

462
        if (chooser.showDialog(this, "Select") == JFileChooser.APPROVE_OPTION) {
×
463
            dbConfig.setText(chooser.getSelectedFile().getAbsolutePath());
×
464
        }
465
    } // GEN-LAST:event_btnConfSelectActionPerformed
×
466

467

468
    private void exportDB(final String exportTarget, final List<ErrorReport> errorList) {
469
        if (!startDB()) {
×
470
            return;
×
471
        }
472

473
        try {
474
            final SystemExport.StatusCallback callback = new SystemExport.StatusCallback() {
×
475
                public void startCollection(final String path) {
476
                    progress.setString(path);
×
477
                }
×
478

479

480
                public void startDocument(final String name, final int current, final int count) {
481
                    progress.setString(name);
×
482
                    progress.setValue(progress.getValue() + 1);
×
483
                }
×
484

485

486
                public void error(final String message, final Throwable exception) {
487
                    displayMessage(message);
×
488

489
                    if (exception != null) {
×
490
                        displayMessage(exception.toString());
×
491
                    }
492
                    displayMessage("---------------------------------------------------");
×
493
                }
×
494
            };
495
            progress.setIndeterminate(false);
×
496
            progress.setValue(0);
×
497
            progress.setStringPainted(true);
×
498
            progress.setMinimum(0);
×
499
            progress.setMaximum(documentCount);
×
500

501
            Object[] selected = directAccessBtn.getSelectedObjects();
×
502
            final boolean directAccess = (selected != null) && (selected[0] != null);
×
503

504
            selected = incrementalBtn.getSelectedObjects();
×
505
            final boolean incremental = (selected != null) && (selected[0] != null);
×
506

507
            selected = zipBtn.getSelectedObjects();
×
508
            final boolean zip = (selected != null) && (selected[0] != null);
×
509

510
            displayMessage("Starting export ...");
×
511
            final long start = System.currentTimeMillis();
×
512

513
            try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
×
514
                 final Txn transaction = pool.getTransactionManager().beginTransaction()) {
×
515

516
                final SystemExport sysexport = new SystemExport(broker, transaction, callback, null, directAccess);
×
517
                final Path file = sysexport.export(exportTarget, incremental, zip, errorList);
×
518

519
                transaction.commit();
×
520

521

522
                final long end = System.currentTimeMillis();
×
523

524
                displayMessage("Export to " + file.toAbsolutePath().toString() + " completed successfully.");
×
525
                displayMessage("Export took " + (end - start) + "ms.");
×
526

527
            } catch (final EXistException e) {
×
528
                System.err.println("ERROR: Failed to retrieve database broker: " + e.getMessage());
×
529
            }
530

531
        } finally {
×
532
            progress.setString("");
×
533
            progress.setValue(0);
×
534
            currentTask.setText(" ");
×
535
        }
536
    }
×
537

538

539
    private List<ErrorReport> checkDB() {
540
        if (!startDB()) {
×
541
            return (null);
×
542
        }
543

544
        try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
×
545
                final Txn transaction = pool.getTransactionManager().beginTransaction()) {
×
546

547
            Object[] selected = directAccessBtn.getSelectedObjects();
×
548
            final boolean directAccess = (selected != null) && (selected[0] != null);
×
549
            selected = scanBtn.getSelectedObjects();
×
550
            final boolean scan = (selected != null) && (selected[0] != null);
×
551

552
            final ConsistencyCheck checker = new ConsistencyCheck(broker, transaction, directAccess, scan);
×
553
            final org.exist.backup.ConsistencyCheck.ProgressCallback cb = new ConsistencyCheck.ProgressCallback() {
×
554
                public void startDocument(final String path, final int current, final int count) {
555
                    progress.setString(path);
×
556
                    progress.setValue(progress.getValue() + 1);
×
557
                }
×
558

559

560
                public void error(final ErrorReport error) {
561
                    displayMessage(error.toString());
×
562
                    displayMessage("---------------------------------------------------");
×
563
                }
×
564

565

566
                public void startCollection(final String path) {
567
                    progress.setString(path);
×
568
                }
×
569
            };
570

571
            progress.setIndeterminate(true);
×
572
            messages.setText("");
×
573
            displayMessage("Checking collections ...");
×
574
            final List<ErrorReport> errors = checker.checkCollectionTree(cb);
×
575

576
            if (errors.isEmpty()) {
×
577
                displayMessage("No errors found.");
×
578
            } else {
×
579
                displayMessage("Errors found.");
×
580
            }
581

582
            progress.setStringPainted(true);
×
583
            progress.setString("Counting documents ...");
×
584
            documentCount = checker.getDocumentCount();
×
585
            progress.setIndeterminate(false);
×
586

587
            progress.setValue(0);
×
588
            progress.setMinimum(0);
×
589
            progress.setMaximum(documentCount);
×
590

591
            displayMessage("Checking documents ...");
×
592
            checker.checkDocuments(cb, errors);
×
593

594
            if (errors.isEmpty()) {
×
595
                displayMessage("No errors found.");
×
596
            } else {
×
597
                displayMessage("Errors found.");
×
598
            }
599
            progress.setString("");
×
600

601
            transaction.commit();
×
602

603
            return errors;
×
604
        } catch (final EXistException | PermissionDeniedException e) {
×
605
            System.err.println("ERROR: Failed to retrieve database broker: " + e.getMessage());
×
606
        } catch (final TerminatedException e) {
×
607
            System.err.println("WARN: Check terminated by db.");
×
608
        } finally {
609
            progress.setValue(0);
×
610
            currentTask.setText(" ");
×
611
        }
612
        return (null);
×
613
    }
614

615

616
    public void displayMessage(final String message) {
617
        messages.append(message + '\n');
×
618
        messages.setCaretPosition(messages.getDocument().getLength());
×
619

620
        if (logWriter != null) {
×
621
            logWriter.println(message);
×
622
        }
623
    }
×
624

625

626
    private void openLog(final String dir) {
627
        final Path file = SystemExport.getUniqueFile("report", ".log", dir);
×
628
        try {
629
            logWriter = new PrintWriter(Files.newBufferedWriter(file, UTF_8));
×
630
        } catch(final IOException e) {
×
631
            System.err.println("ERROR: failed to create log file");
×
632
        }
633
    }
×
634

635

636
    private void closeLog() {
637
        if (logWriter != null) {
×
638
            logWriter.close();
×
639
        }
640
    }
×
641

642

643
    /**
644
     * Main entry point.
645
     *
646
     * @param args the command line arguments
647
     */
648
    public static void main(final String[] args) {
649
        try {
650
            CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
×
651

652
            // parse command-line options
653
            CommandLineParser
×
654
                    .withArguments(helpArg)
×
655
                    .programName("export-gui" + (OSUtil.IS_WINDOWS ? ".bat" : ".sh"))
×
656
                    .parse(args);
×
657

658
        } catch (final StartException e) {
×
659
            if (e.getMessage() != null && !e.getMessage().isEmpty()) {
×
660
                System.err.println(e.getMessage());
×
661
            }
662
            System.exit(e.getErrorCode());
×
663
        } catch (final ArgumentException e) {
×
664
            consoleOut(e.getMessageAndUsage().toString());
×
665
            System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
×
666
        }
667

668
        java.awt.EventQueue.invokeLater(() -> new ExportGUI().setVisible(true));
×
669
    }
×
670

671
    private static void consoleOut(final String msg) {
672
        System.out.println(msg); //NOSONAR this has to go to the console
×
673
    }
×
674
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc