Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import fr.gouv.vitam.tools.resip.threads.CleanThread;
import fr.gouv.vitam.tools.resip.threads.ExportThread;
import fr.gouv.vitam.tools.resip.threads.ImportThread;
import fr.gouv.vitam.tools.resip.threads.RecalculateDigestsThread;
import fr.gouv.vitam.tools.resip.utils.ResipException;
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
Expand Down Expand Up @@ -128,7 +129,8 @@ public class ResipGraphicApp implements ActionListener, Runnable {
// GUI elements. */
public static MainWindow mainWindow;

// MainWindow menu elements dis/enabled depending on work state and used by controller. */
// MainWindow menu elements dis/enabled depending on work state and used by
// controller. */
private JMenuItem saveMenuItem, saveAsMenuItem, closeMenuItem;
private JMenuItem sedaValidationMenuItem, sedaProfileValidationMenuItem;
private JCheckBoxMenuItem structuredMenuItem, debugMenuItem, experimentalMenuItem;
Expand Down Expand Up @@ -227,7 +229,7 @@ public ResipGraphicApp(CreationContext creationContext) throws ResipException {

public void run() {
try {
mainWindow = new MainWindow(this); //NOSONAR
mainWindow = new MainWindow(this); // NOSONAR
mainWindow.setVisible(true);
mainWindow.setLocationRelativeTo(null);
this.searchDialog = new SearchDialog(mainWindow);
Expand Down Expand Up @@ -437,6 +439,11 @@ public JMenuBar createMenu() {
actionByMenuItem.put(menuItem, "RegenerateContinuousIds");
treatMenu.add(menuItem);

menuItem = new JMenuItem("Recalculer les empreintes");
menuItem.addActionListener(this);
actionByMenuItem.put(menuItem, "RecalculateDigests");
treatMenu.add(menuItem);

importMenu = new JMenu("Import");
menuBar.add(importMenu);

Expand Down Expand Up @@ -600,6 +607,9 @@ else switch (action) {
case "SortTreeViewer":
doSortTreeViewer();
break;
case "RecalculateDigests":
recalculateDigests();
break;
// Context Menu
case "SeeImportContext":
seeImportContext();
Expand Down Expand Up @@ -934,6 +944,7 @@ void editPrefs() {
preferencesDialog.ip.toPrefs(Preferences.getInstance());
Preferences.getInstance().save();
interfaceParameters = preferencesDialog.ip;
treatmentParameters = preferencesDialog.tp;
debugMenuItem.setState(interfaceParameters.isDebugFlag());
experimentalMenuItem.setState(interfaceParameters.isExperimentalFlag());
structuredMenuItem.setState(interfaceParameters.isStructuredMetadataEditionFlag());
Expand Down Expand Up @@ -1155,6 +1166,20 @@ void doRegenerateContinuousIds() {
if (currentWork != null) {
currentWork.getDataObjectPackage().regenerateContinuousIds();
mainWindow.treePane.allTreeChanged();
setModifiedContext(true);
}
}

/**
* Recalculate digests.
*/
void recalculateDigests() {
if (currentWork != null) {
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Recalcul des empreintes");
RecalculateDigestsThread recalculateDigestsThread = new RecalculateDigestsThread(inOutDialog);
recalculateDigestsThread.execute();
inOutDialog.setVisible(true);
setModifiedContext(true);
}
}

Expand Down Expand Up @@ -1609,7 +1634,7 @@ private void about() {
);
dialog.setVisible(true);
} catch (Exception ignored) {
//no real case
// no real case
}
}

Expand Down Expand Up @@ -1683,4 +1708,13 @@ private void toggleExperimentalMode() {
);
}
}

/**
* Gets treatment parameters.
*
* @return the treatment parameters
*/
public static TreatmentParameters getTreatmentParameters() {
return getTheApp().treatmentParameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2022)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* contact@programmevitam.fr
*
* This software is a computer program whose purpose is to provide
* tools for construction and manipulation of SIP (Submission
* Information Package) conform to the SEDA (Standard d’Échange
* de données pour l’Archivage) standard.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
package fr.gouv.vitam.tools.resip.event;

public class DigestAlgorithmChangedEvent implements Event {

private final String newDigestAlgorithm;

public DigestAlgorithmChangedEvent(String newDigestAlgorithm) {
this.newDigestAlgorithm = newDigestAlgorithm;
}

public String getNewDigestAlgorithm() {
return newDigestAlgorithm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
import fr.gouv.vitam.tools.sedalib.core.DataObjectPackage;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
import fr.gouv.vitam.tools.sedalib.utils.digest.DigestComputer;

import javax.swing.*;
import javax.swing.text.AbstractDocument;
Expand Down Expand Up @@ -130,6 +131,7 @@ public class PreferencesDialog extends JDialog {
private final JRadioButton structuredInterfaceRadioButton;
private final JCheckBox debugModeCheckBox;
private final JCheckBox experimentalModeCheckBox;
private final JComboBox<String> digestAlgorithmComboBox;

private final JFrame owner;

Expand Down Expand Up @@ -222,7 +224,8 @@ public class PreferencesDialog extends JDialog {
*
* @param args the input arguments
* @throws ClassNotFoundException the class not found exception
* @throws UnsupportedLookAndFeelException the unsupported look and feel exception
* @throws UnsupportedLookAndFeelException the unsupported look and feel
* exception
* @throws InstantiationException the instantiation exception
* @throws IllegalAccessException the illegal access exception
* @throws NoSuchMethodException the no such method exception
Expand All @@ -232,9 +235,9 @@ public class PreferencesDialog extends JDialog {
*/
public static void main(String[] args)
throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ResipException, InterruptedException {
ResipGraphicApp rga = new ResipGraphicApp(null); //NOSONAR used for debug run
ResipGraphicApp rga = new ResipGraphicApp(null); // NOSONAR used for debug run
Thread.sleep(1000);
TestDialogWindow window = new TestDialogWindow(PreferencesDialog.class); //NOSONAR used for debug run
TestDialogWindow window = new TestDialogWindow(PreferencesDialog.class); // NOSONAR used for debug run
}

/**
Expand Down Expand Up @@ -1411,6 +1414,26 @@ public PreferencesDialog(JFrame owner) {
gbc.gridy = 5;
treatmentParametersPanel.add(sedaVersionSelector, gbc);

gbc.gridy = 5;
treatmentParametersPanel.add(sedaVersionSelector, gbc);

JLabel digestAlgorithmLabel = new JLabel("Algorithme de hachage par défaut:");
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.EAST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 0;
gbc.gridy = 6;
treatmentParametersPanel.add(digestAlgorithmLabel, gbc);

digestAlgorithmComboBox = new JComboBox<>(DigestComputer.ALGORITHMS.toArray(new String[0]));
digestAlgorithmComboBox.setSelectedItem(tp.getDigestAlgorithm());
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 1;
gbc.gridy = 6;
treatmentParametersPanel.add(digestAlgorithmComboBox, gbc);

JLabel interfaceLabel = new JLabel("Interface");
interfaceLabel.setFont(MainWindow.BOLD_LABEL_FONT);
gbc = new GridBagConstraints();
Expand All @@ -1420,31 +1443,31 @@ public PreferencesDialog(JFrame owner) {
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0;
gbc.gridy = 6;
gbc.gridy = 7;
treatmentParametersPanel.add(interfaceLabel, gbc);

JLabel interfaceTypeLabel = new JLabel("Interface par défaut:");
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.EAST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 0;
gbc.gridy = 7;
gbc.gridy = 8;
treatmentParametersPanel.add(interfaceTypeLabel, gbc);

structuredInterfaceRadioButton = new JRadioButton("Structurée");
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 1;
gbc.gridy = 7;
gbc.gridy = 8;
treatmentParametersPanel.add(structuredInterfaceRadioButton, gbc);

JRadioButton classicInterfaceRadioButton = new JRadioButton("XML-expert");
gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 2;
gbc.gridy = 7;
gbc.gridy = 8;
treatmentParametersPanel.add(classicInterfaceRadioButton, gbc);

ButtonGroup interfaceTypeButtonGroup = new ButtonGroup();
Expand All @@ -1459,7 +1482,7 @@ public PreferencesDialog(JFrame owner) {
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 0;
gbc.gridy = 8;
gbc.gridy = 9;
treatmentParametersPanel.add(debugModeLabel, gbc);

debugModeCheckBox = new JCheckBox("debug");
Expand All @@ -1468,7 +1491,7 @@ public PreferencesDialog(JFrame owner) {
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 1;
gbc.gridy = 8;
gbc.gridy = 9;
treatmentParametersPanel.add(debugModeCheckBox, gbc);

experimentalModeCheckBox = new JCheckBox("experimental");
Expand All @@ -1477,7 +1500,7 @@ public PreferencesDialog(JFrame owner) {
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.insets = new Insets(0, 0, 5, 5);
gbc.gridx = 2;
gbc.gridy = 8;
gbc.gridy = 9;
treatmentParametersPanel.add(experimentalModeCheckBox, gbc);

// Buttons
Expand Down Expand Up @@ -1741,6 +1764,7 @@ private boolean extractFromDialog() {
return false;
}
tp.setDupMax(tmp);
tp.setDigestAlgorithm((String) digestAlgorithmComboBox.getSelectedItem());

SedaVersion selectedVersion = sedaVersionSelector.getSelectedVersion();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
package fr.gouv.vitam.tools.resip.parameters;

import fr.gouv.vitam.tools.resip.event.DigestAlgorithmChangedEvent;
import fr.gouv.vitam.tools.resip.event.EventBus;
import fr.gouv.vitam.tools.resip.event.SedaVersionChangedEvent;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
Expand Down Expand Up @@ -68,13 +69,21 @@ public class TreatmentParameters {
*/
SedaVersion sedaVersion;

/**
* The digest algorithm.
*/
String digestAlgorithm;

/**
* Instantiates a new creation context.
*/
public TreatmentParameters() {
EventBus.subscribe(SedaVersionChangedEvent.class, event -> {
this.sedaVersion = event.getNewVersion();
});
EventBus.subscribe(DigestAlgorithmChangedEvent.class, event -> {
this.digestAlgorithm = event.getNewDigestAlgorithm();
});
}

private String canonizeCategoryName(String category) {
Expand All @@ -90,6 +99,9 @@ public TreatmentParameters(Preferences preferences) {
EventBus.subscribe(SedaVersionChangedEvent.class, event -> {
this.sedaVersion = event.getNewVersion();
});
EventBus.subscribe(DigestAlgorithmChangedEvent.class, event -> {
this.digestAlgorithm = event.getNewDigestAlgorithm();
});

final String categoriesString = preferences
.getPrefProperties()
Expand Down Expand Up @@ -123,6 +135,8 @@ public TreatmentParameters(Preferences preferences) {
.getProperty("treatmentParameters.seda2Version", defaultConfiguredSedaVersion);

EventBus.publish(new SedaVersionChangedEvent(parseSedaVersion(configuredSedaVersion)));

digestAlgorithm = preferences.getPrefProperties().getProperty("treatmentParameters.digestAlgorithm", "SHA-512");
}

/**
Expand All @@ -144,6 +158,7 @@ public void toPrefs(Preferences preferences) {
}
preferences.getPrefProperties().setProperty("treatmentParameters.dupMax", Integer.toString(dupMax));
preferences.getPrefProperties().setProperty("treatmentParameters.seda2Version", sedaVersion.toString());
preferences.getPrefProperties().setProperty("treatmentParameters.digestAlgorithm", digestAlgorithm);
}

/**
Expand Down Expand Up @@ -379,6 +394,7 @@ public void setDefaultPrefs() {
formatByCategoryMap.put("Autres...", List.of("Other"));
dupMax = 1000;
sedaVersion = SedaVersion.V2_1;
digestAlgorithm = "SHA-512";
}

// Getters and setters
Expand Down Expand Up @@ -448,4 +464,23 @@ private SedaVersion parseSedaVersion(String version) {

return SedaVersion.from(finalVersion);
}

/**
* Gets digest algorithm.
*
* @return the digest algorithm
*/
public String getDigestAlgorithm() {
return digestAlgorithm;
}

/**
* Sets digest algorithm.
*
* @param digestAlgorithm the digest algorithm
*/
public void setDigestAlgorithm(String digestAlgorithm) {
this.digestAlgorithm = digestAlgorithm;
EventBus.publish(new DigestAlgorithmChangedEvent(digestAlgorithm));
}
}
Loading