Skip to content

Commit 74a4766

Browse files
committed
story #15307 feat: set digest algorithm configurable
resolve #90
1 parent 313196c commit 74a4766

18 files changed

Lines changed: 777 additions & 168 deletions

resip/src/main/java/fr/gouv/vitam/tools/resip/app/ResipGraphicApp.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import fr.gouv.vitam.tools.resip.threads.CleanThread;
5454
import fr.gouv.vitam.tools.resip.threads.ExportThread;
5555
import fr.gouv.vitam.tools.resip.threads.ImportThread;
56+
import fr.gouv.vitam.tools.resip.threads.RecalculateDigestsThread;
5657
import fr.gouv.vitam.tools.resip.utils.ResipException;
5758
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
5859
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
@@ -128,7 +129,8 @@ public class ResipGraphicApp implements ActionListener, Runnable {
128129
// GUI elements. */
129130
public static MainWindow mainWindow;
130131

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

228230
public void run() {
229231
try {
230-
mainWindow = new MainWindow(this); //NOSONAR
232+
mainWindow = new MainWindow(this); // NOSONAR
231233
mainWindow.setVisible(true);
232234
mainWindow.setLocationRelativeTo(null);
233235
this.searchDialog = new SearchDialog(mainWindow);
@@ -437,6 +439,11 @@ public JMenuBar createMenu() {
437439
actionByMenuItem.put(menuItem, "RegenerateContinuousIds");
438440
treatMenu.add(menuItem);
439441

442+
menuItem = new JMenuItem("Recalculer les empreintes");
443+
menuItem.addActionListener(this);
444+
actionByMenuItem.put(menuItem, "RecalculateDigests");
445+
treatMenu.add(menuItem);
446+
440447
importMenu = new JMenu("Import");
441448
menuBar.add(importMenu);
442449

@@ -600,6 +607,9 @@ else switch (action) {
600607
case "SortTreeViewer":
601608
doSortTreeViewer();
602609
break;
610+
case "RecalculateDigests":
611+
recalculateDigests();
612+
break;
603613
// Context Menu
604614
case "SeeImportContext":
605615
seeImportContext();
@@ -934,6 +944,7 @@ void editPrefs() {
934944
preferencesDialog.ip.toPrefs(Preferences.getInstance());
935945
Preferences.getInstance().save();
936946
interfaceParameters = preferencesDialog.ip;
947+
treatmentParameters = preferencesDialog.tp;
937948
debugMenuItem.setState(interfaceParameters.isDebugFlag());
938949
experimentalMenuItem.setState(interfaceParameters.isExperimentalFlag());
939950
structuredMenuItem.setState(interfaceParameters.isStructuredMetadataEditionFlag());
@@ -1155,6 +1166,20 @@ void doRegenerateContinuousIds() {
11551166
if (currentWork != null) {
11561167
currentWork.getDataObjectPackage().regenerateContinuousIds();
11571168
mainWindow.treePane.allTreeChanged();
1169+
setModifiedContext(true);
1170+
}
1171+
}
1172+
1173+
/**
1174+
* Recalculate digests.
1175+
*/
1176+
void recalculateDigests() {
1177+
if (currentWork != null) {
1178+
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Recalcul des empreintes");
1179+
RecalculateDigestsThread recalculateDigestsThread = new RecalculateDigestsThread(inOutDialog);
1180+
recalculateDigestsThread.execute();
1181+
inOutDialog.setVisible(true);
1182+
setModifiedContext(true);
11581183
}
11591184
}
11601185

@@ -1609,7 +1634,7 @@ private void about() {
16091634
);
16101635
dialog.setVisible(true);
16111636
} catch (Exception ignored) {
1612-
//no real case
1637+
// no real case
16131638
}
16141639
}
16151640

@@ -1683,4 +1708,13 @@ private void toggleExperimentalMode() {
16831708
);
16841709
}
16851710
}
1711+
1712+
/**
1713+
* Gets treatment parameters.
1714+
*
1715+
* @return the treatment parameters
1716+
*/
1717+
public static TreatmentParameters getTreatmentParameters() {
1718+
return getTheApp().treatmentParameters;
1719+
}
16861720
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2022)
3+
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
4+
*
5+
* contact@programmevitam.fr
6+
*
7+
* This software is a computer program whose purpose is to provide
8+
* tools for construction and manipulation of SIP (Submission
9+
* Information Package) conform to the SEDA (Standard d’Échange
10+
* de données pour l’Archivage) standard.
11+
*
12+
* This software is governed by the CeCILL-C license under French law and
13+
* abiding by the rules of distribution of free software. You can use,
14+
* modify and/ or redistribute the software under the terms of the CeCILL-C
15+
* license as circulated by CEA, CNRS and INRIA at the following URL
16+
* "http://www.cecill.info".
17+
*
18+
* As a counterpart to the access to the source code and rights to copy,
19+
* modify and redistribute granted by the license, users are provided only
20+
* with a limited warranty and the software's author, the holder of the
21+
* economic rights, and the successive licensors have only limited
22+
* liability.
23+
*
24+
* In this respect, the user's attention is drawn to the risks associated
25+
* with loading, using, modifying and/or developing or reproducing the
26+
* software by the user in light of its specific status of free software,
27+
* that may mean that it is complicated to manipulate, and that also
28+
* therefore means that it is reserved for developers and experienced
29+
* professionals having in-depth computer knowledge. Users are therefore
30+
* encouraged to load and test the software's suitability as regards their
31+
* requirements in conditions enabling the security of their systems and/or
32+
* data to be ensured and, more generally, to use and operate it in the
33+
* same conditions as regards security.
34+
*
35+
* The fact that you are presently reading this means that you have had
36+
* knowledge of the CeCILL-C license and that you accept its terms.
37+
*/
38+
package fr.gouv.vitam.tools.resip.event;
39+
40+
public class DigestAlgorithmChangedEvent implements Event {
41+
42+
private final String newDigestAlgorithm;
43+
44+
public DigestAlgorithmChangedEvent(String newDigestAlgorithm) {
45+
this.newDigestAlgorithm = newDigestAlgorithm;
46+
}
47+
48+
public String getNewDigestAlgorithm() {
49+
return newDigestAlgorithm;
50+
}
51+
}

resip/src/main/java/fr/gouv/vitam/tools/resip/frame/preferences/PreferencesDialog.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
5252
import fr.gouv.vitam.tools.sedalib.core.DataObjectPackage;
5353
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
54+
import fr.gouv.vitam.tools.sedalib.utils.digest.DigestComputer;
5455

5556
import javax.swing.*;
5657
import javax.swing.text.AbstractDocument;
@@ -130,6 +131,7 @@ public class PreferencesDialog extends JDialog {
130131
private final JRadioButton structuredInterfaceRadioButton;
131132
private final JCheckBox debugModeCheckBox;
132133
private final JCheckBox experimentalModeCheckBox;
134+
private final JComboBox<String> digestAlgorithmComboBox;
133135

134136
private final JFrame owner;
135137

@@ -222,7 +224,8 @@ public class PreferencesDialog extends JDialog {
222224
*
223225
* @param args the input arguments
224226
* @throws ClassNotFoundException the class not found exception
225-
* @throws UnsupportedLookAndFeelException the unsupported look and feel exception
227+
* @throws UnsupportedLookAndFeelException the unsupported look and feel
228+
* exception
226229
* @throws InstantiationException the instantiation exception
227230
* @throws IllegalAccessException the illegal access exception
228231
* @throws NoSuchMethodException the no such method exception
@@ -232,9 +235,9 @@ public class PreferencesDialog extends JDialog {
232235
*/
233236
public static void main(String[] args)
234237
throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ResipException, InterruptedException {
235-
ResipGraphicApp rga = new ResipGraphicApp(null); //NOSONAR used for debug run
238+
ResipGraphicApp rga = new ResipGraphicApp(null); // NOSONAR used for debug run
236239
Thread.sleep(1000);
237-
TestDialogWindow window = new TestDialogWindow(PreferencesDialog.class); //NOSONAR used for debug run
240+
TestDialogWindow window = new TestDialogWindow(PreferencesDialog.class); // NOSONAR used for debug run
238241
}
239242

240243
/**
@@ -1411,6 +1414,26 @@ public PreferencesDialog(JFrame owner) {
14111414
gbc.gridy = 5;
14121415
treatmentParametersPanel.add(sedaVersionSelector, gbc);
14131416

1417+
gbc.gridy = 5;
1418+
treatmentParametersPanel.add(sedaVersionSelector, gbc);
1419+
1420+
JLabel digestAlgorithmLabel = new JLabel("Algorithme de hachage par défaut:");
1421+
gbc = new GridBagConstraints();
1422+
gbc.anchor = GridBagConstraints.EAST;
1423+
gbc.insets = new Insets(0, 0, 5, 5);
1424+
gbc.gridx = 0;
1425+
gbc.gridy = 6;
1426+
treatmentParametersPanel.add(digestAlgorithmLabel, gbc);
1427+
1428+
digestAlgorithmComboBox = new JComboBox<>(DigestComputer.ALGORITHMS.toArray(new String[0]));
1429+
digestAlgorithmComboBox.setSelectedItem(tp.getDigestAlgorithm());
1430+
gbc = new GridBagConstraints();
1431+
gbc.anchor = GridBagConstraints.WEST;
1432+
gbc.insets = new Insets(0, 0, 5, 5);
1433+
gbc.gridx = 1;
1434+
gbc.gridy = 6;
1435+
treatmentParametersPanel.add(digestAlgorithmComboBox, gbc);
1436+
14141437
JLabel interfaceLabel = new JLabel("Interface");
14151438
interfaceLabel.setFont(MainWindow.BOLD_LABEL_FONT);
14161439
gbc = new GridBagConstraints();
@@ -1420,31 +1443,31 @@ public PreferencesDialog(JFrame owner) {
14201443
gbc.anchor = GridBagConstraints.NORTHWEST;
14211444
gbc.fill = GridBagConstraints.HORIZONTAL;
14221445
gbc.gridx = 0;
1423-
gbc.gridy = 6;
1446+
gbc.gridy = 7;
14241447
treatmentParametersPanel.add(interfaceLabel, gbc);
14251448

14261449
JLabel interfaceTypeLabel = new JLabel("Interface par défaut:");
14271450
gbc = new GridBagConstraints();
14281451
gbc.anchor = GridBagConstraints.EAST;
14291452
gbc.insets = new Insets(0, 0, 5, 5);
14301453
gbc.gridx = 0;
1431-
gbc.gridy = 7;
1454+
gbc.gridy = 8;
14321455
treatmentParametersPanel.add(interfaceTypeLabel, gbc);
14331456

14341457
structuredInterfaceRadioButton = new JRadioButton("Structurée");
14351458
gbc = new GridBagConstraints();
14361459
gbc.anchor = GridBagConstraints.WEST;
14371460
gbc.insets = new Insets(0, 0, 5, 5);
14381461
gbc.gridx = 1;
1439-
gbc.gridy = 7;
1462+
gbc.gridy = 8;
14401463
treatmentParametersPanel.add(structuredInterfaceRadioButton, gbc);
14411464

14421465
JRadioButton classicInterfaceRadioButton = new JRadioButton("XML-expert");
14431466
gbc = new GridBagConstraints();
14441467
gbc.anchor = GridBagConstraints.WEST;
14451468
gbc.insets = new Insets(0, 0, 5, 5);
14461469
gbc.gridx = 2;
1447-
gbc.gridy = 7;
1470+
gbc.gridy = 8;
14481471
treatmentParametersPanel.add(classicInterfaceRadioButton, gbc);
14491472

14501473
ButtonGroup interfaceTypeButtonGroup = new ButtonGroup();
@@ -1459,7 +1482,7 @@ public PreferencesDialog(JFrame owner) {
14591482
gbc.anchor = GridBagConstraints.NORTHEAST;
14601483
gbc.insets = new Insets(0, 0, 5, 5);
14611484
gbc.gridx = 0;
1462-
gbc.gridy = 8;
1485+
gbc.gridy = 9;
14631486
treatmentParametersPanel.add(debugModeLabel, gbc);
14641487

14651488
debugModeCheckBox = new JCheckBox("debug");
@@ -1468,7 +1491,7 @@ public PreferencesDialog(JFrame owner) {
14681491
gbc.anchor = GridBagConstraints.NORTHWEST;
14691492
gbc.insets = new Insets(0, 0, 5, 5);
14701493
gbc.gridx = 1;
1471-
gbc.gridy = 8;
1494+
gbc.gridy = 9;
14721495
treatmentParametersPanel.add(debugModeCheckBox, gbc);
14731496

14741497
experimentalModeCheckBox = new JCheckBox("experimental");
@@ -1477,7 +1500,7 @@ public PreferencesDialog(JFrame owner) {
14771500
gbc.anchor = GridBagConstraints.NORTHWEST;
14781501
gbc.insets = new Insets(0, 0, 5, 5);
14791502
gbc.gridx = 2;
1480-
gbc.gridy = 8;
1503+
gbc.gridy = 9;
14811504
treatmentParametersPanel.add(experimentalModeCheckBox, gbc);
14821505

14831506
// Buttons
@@ -1741,6 +1764,7 @@ private boolean extractFromDialog() {
17411764
return false;
17421765
}
17431766
tp.setDupMax(tmp);
1767+
tp.setDigestAlgorithm((String) digestAlgorithmComboBox.getSelectedItem());
17441768

17451769
SedaVersion selectedVersion = sedaVersionSelector.getSelectedVersion();
17461770

resip/src/main/java/fr/gouv/vitam/tools/resip/parameters/TreatmentParameters.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
package fr.gouv.vitam.tools.resip.parameters;
3939

40+
import fr.gouv.vitam.tools.resip.event.DigestAlgorithmChangedEvent;
4041
import fr.gouv.vitam.tools.resip.event.EventBus;
4142
import fr.gouv.vitam.tools.resip.event.SedaVersionChangedEvent;
4243
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
@@ -68,13 +69,21 @@ public class TreatmentParameters {
6869
*/
6970
SedaVersion sedaVersion;
7071

72+
/**
73+
* The digest algorithm.
74+
*/
75+
String digestAlgorithm;
76+
7177
/**
7278
* Instantiates a new creation context.
7379
*/
7480
public TreatmentParameters() {
7581
EventBus.subscribe(SedaVersionChangedEvent.class, event -> {
7682
this.sedaVersion = event.getNewVersion();
7783
});
84+
EventBus.subscribe(DigestAlgorithmChangedEvent.class, event -> {
85+
this.digestAlgorithm = event.getNewDigestAlgorithm();
86+
});
7887
}
7988

8089
private String canonizeCategoryName(String category) {
@@ -90,6 +99,9 @@ public TreatmentParameters(Preferences preferences) {
9099
EventBus.subscribe(SedaVersionChangedEvent.class, event -> {
91100
this.sedaVersion = event.getNewVersion();
92101
});
102+
EventBus.subscribe(DigestAlgorithmChangedEvent.class, event -> {
103+
this.digestAlgorithm = event.getNewDigestAlgorithm();
104+
});
93105

94106
final String categoriesString = preferences
95107
.getPrefProperties()
@@ -123,6 +135,8 @@ public TreatmentParameters(Preferences preferences) {
123135
.getProperty("treatmentParameters.seda2Version", defaultConfiguredSedaVersion);
124136

125137
EventBus.publish(new SedaVersionChangedEvent(parseSedaVersion(configuredSedaVersion)));
138+
139+
digestAlgorithm = preferences.getPrefProperties().getProperty("treatmentParameters.digestAlgorithm", "SHA-512");
126140
}
127141

128142
/**
@@ -144,6 +158,7 @@ public void toPrefs(Preferences preferences) {
144158
}
145159
preferences.getPrefProperties().setProperty("treatmentParameters.dupMax", Integer.toString(dupMax));
146160
preferences.getPrefProperties().setProperty("treatmentParameters.seda2Version", sedaVersion.toString());
161+
preferences.getPrefProperties().setProperty("treatmentParameters.digestAlgorithm", digestAlgorithm);
147162
}
148163

149164
/**
@@ -379,6 +394,7 @@ public void setDefaultPrefs() {
379394
formatByCategoryMap.put("Autres...", List.of("Other"));
380395
dupMax = 1000;
381396
sedaVersion = SedaVersion.V2_1;
397+
digestAlgorithm = "SHA-512";
382398
}
383399

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

449465
return SedaVersion.from(finalVersion);
450466
}
467+
468+
/**
469+
* Gets digest algorithm.
470+
*
471+
* @return the digest algorithm
472+
*/
473+
public String getDigestAlgorithm() {
474+
return digestAlgorithm;
475+
}
476+
477+
/**
478+
* Sets digest algorithm.
479+
*
480+
* @param digestAlgorithm the digest algorithm
481+
*/
482+
public void setDigestAlgorithm(String digestAlgorithm) {
483+
this.digestAlgorithm = digestAlgorithm;
484+
EventBus.publish(new DigestAlgorithmChangedEvent(digestAlgorithm));
485+
}
451486
}

0 commit comments

Comments
 (0)