Skip to content
Merged
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
42 changes: 23 additions & 19 deletions resip/src/main/java/fr/gouv/vitam/tools/resip/app/ResipApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.vitam.tools.resip.data.Work;
import fr.gouv.vitam.tools.resip.event.EventBus;
import fr.gouv.vitam.tools.resip.event.SedaVersionChangedEvent;
import fr.gouv.vitam.tools.resip.parameters.CSVImportContext;
import fr.gouv.vitam.tools.resip.parameters.CSVMetadataImportContext;
import fr.gouv.vitam.tools.resip.parameters.CreationContext;
Expand All @@ -40,13 +42,13 @@
import fr.gouv.vitam.tools.resip.utils.ResipException;
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
import fr.gouv.vitam.tools.sedalib.core.ArchiveTransfer;
import fr.gouv.vitam.tools.sedalib.core.SEDA2Version;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaContext;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
import fr.gouv.vitam.tools.sedalib.droid.DroidIdentifier;
import fr.gouv.vitam.tools.sedalib.inout.exporter.ArchiveTransferToSIPExporter;
import fr.gouv.vitam.tools.sedalib.inout.importer.CSVMetadataToDataObjectPackageImporter;
import fr.gouv.vitam.tools.sedalib.inout.importer.DiskToArchiveTransferImporter;
import fr.gouv.vitam.tools.sedalib.inout.importer.SIPToArchiveTransferImporter;
import fr.gouv.vitam.tools.sedalib.utils.SEDALibException;
import fr.gouv.vitam.tools.sedalib.utils.SEDALibProgressLogger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand All @@ -65,7 +67,9 @@
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* ResipApp class for launching the command or the graphic application.
Expand Down Expand Up @@ -236,6 +240,8 @@ public static void main(String[] args) throws

System.out.println("Resip launched");

EventBus.subscribe(SedaVersionChangedEvent.class, event -> SedaContext.setVersion(event.getNewVersion()));

String workdirString;
int logLevel;
CreationContext creationContext;
Expand Down Expand Up @@ -335,24 +341,22 @@ public static void main(String[] args) throws
}

// define the SEDA 2 version
if (cmd.hasOption("sedaversion")){
try {
int tmp = Integer.parseInt(cmd.getOptionValue("sedaversion"));
switch (tmp){
case 1:
case 2:
SEDA2Version.setSeda2Version(tmp);
break;
default:
throw new NumberFormatException("Doit valoir 1 ou 2");
}
} catch (NumberFormatException e) {
System.err.println(
"Resip: La sous-version du SEDA 2 est non conforme, elle doit être dans la liste (1|2)");
if (cmd.hasOption("sedaversion")) {
final Map<String, SedaVersion> supportedSedaVersions = new HashMap<>();
supportedSedaVersions.put("2.1", SedaVersion.V2_1);
supportedSedaVersions.put("2.2", SedaVersion.V2_2);
supportedSedaVersions.put("2.3", SedaVersion.V2_3);

String sedaVersion = cmd.getOptionValue("sedaversion");
boolean isNotSupportedVersion = !supportedSedaVersions.containsKey(sedaVersion);

if (isNotSupportedVersion) {
System.err.println("Doit valoir " + String.join(",", supportedSedaVersions.keySet()));
System.exit(1);
} catch (SEDALibException ignored) {
// no real case
}

final SedaVersion version = supportedSedaVersions.get(sedaVersion);
EventBus.publish(new SedaVersionChangedEvent(version));
}

// define the global logger
Expand Down Expand Up @@ -447,7 +451,7 @@ else if (cmd.hasOption("listimport")) {
cmi.doImport();

packet = new ArchiveTransfer();
Work work = new Work(cmi.getDataObjectPackage(), cSVMetadataImportContext, exportContext, SEDA2Version.getSeda2Version());
Work work = new Work(cmi.getDataObjectPackage(), cSVMetadataImportContext, exportContext);
work.getDataObjectPackage()
.setManagementMetadataXmlData(work.getExportContext().getManagementMetadataXmlData());
packet.setDataObjectPackage(work.getDataObjectPackage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import fr.gouv.vitam.tools.mailextractlib.core.StoreExtractor;
import fr.gouv.vitam.tools.resip.data.Work;
import fr.gouv.vitam.tools.resip.event.EventBus;
import fr.gouv.vitam.tools.resip.event.SedaVersionChangedEvent;
import fr.gouv.vitam.tools.resip.frame.*;
import fr.gouv.vitam.tools.resip.frame.preferences.PreferencesDialog;
import fr.gouv.vitam.tools.resip.parameters.*;
Expand All @@ -43,7 +45,8 @@
import fr.gouv.vitam.tools.resip.threads.ImportThread;
import fr.gouv.vitam.tools.resip.utils.ResipException;
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
import fr.gouv.vitam.tools.sedalib.core.SEDA2Version;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaContext;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
import fr.gouv.vitam.tools.sedalib.droid.DroidIdentifier;
import fr.gouv.vitam.tools.sedalib.utils.SEDALibException;

Expand Down Expand Up @@ -159,13 +162,20 @@ public class ResipGraphicApp implements ActionListener, Runnable {
*/
public DuplicatesWindow duplicatesWindow;

private SedaVersion sedaVersion;

/**
* Instantiates a new Resip graphic app.
*
* @param creationContext the creation context
* @throws ResipException the resip exception
*/
public ResipGraphicApp(CreationContext creationContext) throws ResipException {
EventBus.subscribe(
SedaVersionChangedEvent.class,
event -> this.sedaVersion = event.getNewVersion()
);

try {
if (System.getProperty("os.name").toLowerCase().contains("win"))
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Expand Down Expand Up @@ -195,13 +205,6 @@ public ResipGraphicApp(CreationContext creationContext) throws ResipException {
this.interfaceParameters = new InterfaceParameters(Preferences.getInstance());
this.treatmentParameters = new TreatmentParameters(Preferences.getInstance());

try {
SEDA2Version.setSeda2Version(treatmentParameters.getSeda2Version());
} catch (SEDALibException e) {
getGlobalLogger().getLogger().error(e.getLocalizedMessage());
System.exit(-1);
}

getGlobalLogger().setDebugFlag(interfaceParameters.isDebugFlag());
getGlobalLogger().logIfDebug("Resip prefs accessed from " + Preferences.getInstance().getPrefPropertiesFilename(), null);

Expand Down Expand Up @@ -377,13 +380,13 @@ public JMenuBar createMenu() {
actionByMenuItem.put(menuItem, "SeeManifest");
treatMenu.add(menuItem);

sedaValidationMenuItem = new JMenuItem("Vérifier la conformité " + SEDA2Version.getSeda2VersionString() + "...");
sedaValidationMenuItem = new JMenuItem("Vérifier la conformité " + sedaVersion.displayString() + "...");
sedaValidationMenuItem.addActionListener(this);
sedaValidationMenuItem.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
actionByMenuItem.put(sedaValidationMenuItem, "CheckSEDASchema");
treatMenu.add(sedaValidationMenuItem);

sedaProfileValidationMenuItem = new JMenuItem("Vérifier la conformité à un profil " + SEDA2Version.getSeda2VersionString() + "...");
sedaProfileValidationMenuItem = new JMenuItem("Vérifier la conformité à un profil " + sedaVersion.displayString() + "...");
sedaProfileValidationMenuItem.addActionListener(this);
sedaProfileValidationMenuItem.setAccelerator(KeyStroke.getKeyStroke('R', InputEvent.SHIFT_DOWN_MASK + Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
actionByMenuItem.put(sedaProfileValidationMenuItem, "CheckSpecificSEDASchemaProfile");
Expand Down Expand Up @@ -726,18 +729,18 @@ private void loadWork() {

if (fileChooser.showOpenDialog(mainWindow) == JFileChooser.APPROVE_OPTION) {
filename = fileChooser.getSelectedFile().getCanonicalPath();
int loadSeda2Version = Work.getSeda2VersionFromFile(filename);
if (loadSeda2Version != SEDA2Version.getSeda2Version()) {
final SedaVersion sedaVersionFromWorkspace = Work.getSeda2VersionFromFile(filename);

if (sedaVersionFromWorkspace != sedaVersion) {
if (UserInteractionDialog.getUserAnswer(mainWindow,
"Pour charger ce fichier il faut faire passer l'interface en " +
SEDA2Version.getSeda2VersionString(loadSeda2Version) + "\n" +
sedaVersion + "\n" +
"Voulez-vous continuer?",
"Confirmation", UserInteractionDialog.WARNING_DIALOG,
null) != OK_DIALOG)
return;
treatmentParameters.setSeda2Version(loadSeda2Version);
EventBus.publish(new SedaVersionChangedEvent(sedaVersionFromWorkspace));
treatmentParameters.toPrefs(Preferences.getInstance());
useSeda2Version(treatmentParameters.getSeda2Version());
}
mainWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
currentWork = Work.createFromFile(filename);
Expand Down Expand Up @@ -839,14 +842,6 @@ private void closeWork() {
}
}

private void useSeda2Version(int version) throws SEDALibException {
SEDA2Version.setSeda2Version(version);
if (currentWork != null)
currentWork.setSeda2Version(version);
sedaValidationMenuItem.setText("Vérifier la conformité " + SEDA2Version.getSeda2VersionString() + "...");
sedaProfileValidationMenuItem.setText("Vérifier la conformité à un profil " + SEDA2Version.getSeda2VersionString() + "...");
}

// MenuItem Edit Preferences

/**
Expand All @@ -866,8 +861,6 @@ void editPrefs() {
preferencesDialog.tp.toPrefs(Preferences.getInstance());
preferencesDialog.ip.toPrefs(Preferences.getInstance());
Preferences.getInstance().save();
treatmentParameters = preferencesDialog.tp;
useSeda2Version(treatmentParameters.getSeda2Version());
interfaceParameters = preferencesDialog.ip;
debugMenuItem.setState(interfaceParameters.isDebugFlag());
experimentalMenuItem.setState(interfaceParameters.isExperimentalFlag());
Expand All @@ -876,7 +869,7 @@ void editPrefs() {
ResipLogger.createGlobalLogger(preferencesDialog.cc.getWorkDir() + File.separator + "log.txt",
getGlobalLogger().getProgressLogLevel());
}
} catch (ResipException | SEDALibException e) {
} catch (ResipException e) {
UserInteractionDialog.getUserAnswer(mainWindow,
"Erreur fatale, impossible d'éditer les préférences \n->" + e.getMessage(),
"Erreur", UserInteractionDialog.ERROR_DIALOG,
Expand Down Expand Up @@ -997,7 +990,7 @@ void seeManifest() {
* Check seda schema.
*/
void checkSEDASchema() {
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Vérification " + SEDA2Version.getSeda2VersionString());
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Vérification " + sedaVersion.displayString());
CheckProfileThread checkProfileThread = new CheckProfileThread(null, inOutDialog);
completeResipWork();
checkProfileThread.execute();
Expand All @@ -1014,7 +1007,7 @@ void checkSpecificSEDASchemaProfile() {
JFileChooser fileChooser = new JFileChooser(Preferences.getInstance().getPrefsImportDir());
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (fileChooser.showOpenDialog(mainWindow) == JFileChooser.APPROVE_OPTION) {
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Vérification Profil " + SEDA2Version.getSeda2VersionString());
InOutDialog inOutDialog = new InOutDialog(mainWindow, "Vérification Profil " + sedaVersion.displayString());
CheckProfileThread checkProfileThread = new CheckProfileThread(fileChooser.getSelectedFile()
.getAbsolutePath(), inOutDialog);
completeResipWork();
Expand All @@ -1023,12 +1016,12 @@ void checkSpecificSEDASchemaProfile() {
}
} catch (Exception e) {
UserInteractionDialog.getUserAnswer(mainWindow,
"Erreur fatale, impossible de faire la vérification de confirmité au profil " + SEDA2Version.getSeda2VersionString() + "\n->"
"Erreur fatale, impossible de faire la vérification de confirmité au profil " + sedaVersion.displayString() + "\n->"
+ e.getMessage(),
"Erreur", UserInteractionDialog.ERROR_DIALOG,
null);
getGlobalLogger().log(ResipLogger.ERROR, "resip.graphicapp: erreur fatale, impossible de faire la " +
"vérification de confirmité au profil " + SEDA2Version.getSeda2VersionString(), e);
"vérification de confirmité au profil " + sedaVersion.displayString(), e);
}
}

Expand Down
40 changes: 14 additions & 26 deletions resip/src/main/java/fr/gouv/vitam/tools/resip/data/Work.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import fr.gouv.vitam.tools.resip.event.EventBus;
import fr.gouv.vitam.tools.resip.event.SedaVersionChangedEvent;
import fr.gouv.vitam.tools.resip.parameters.CreationContext;
import fr.gouv.vitam.tools.resip.parameters.ExportContext;
import fr.gouv.vitam.tools.resip.utils.ResipException;
import fr.gouv.vitam.tools.resip.utils.ResipLogger;
import fr.gouv.vitam.tools.sedalib.core.*;
import fr.gouv.vitam.tools.sedalib.core.json.DataObjectPackageDeserializer;
import fr.gouv.vitam.tools.sedalib.core.json.DataObjectPackageSerializer;
import fr.gouv.vitam.tools.sedalib.core.seda.SedaVersion;
import fr.gouv.vitam.tools.sedalib.utils.SEDALibException;
import fr.gouv.vitam.tools.sedalib.utils.SEDALibProgressLogger;

Expand Down Expand Up @@ -92,15 +95,15 @@ public class Work {
private DataObjectPackage dataObjectPackage;

/**
* The SEDA 2 version.
* SEDA version
*/
private int seda2Version;
private SedaVersion version;

/**
* Instantiates a new work for json serialization.
*/
public Work() {
this(null, null, null,1);
this(null, null, null);
}

/**
Expand All @@ -109,14 +112,17 @@ public Work() {
* @param dataObjectPackage the archive transfer
* @param creationContext the creation context
* @param exportContext the export context
* @param seda2Version the seda 2 version
*/
public Work(DataObjectPackage dataObjectPackage, CreationContext creationContext, ExportContext exportContext, int seda2Version) {
public Work(DataObjectPackage dataObjectPackage, CreationContext creationContext, ExportContext exportContext) {
this.serializationVersion = CURRENT_SERIALIZATION_VERSION;
this.seda2Version = seda2Version;
this.dataObjectPackage = dataObjectPackage;
this.creationContext = creationContext;
this.exportContext = exportContext;

EventBus.subscribe(
SedaVersionChangedEvent.class,
event -> this.version = event.getNewVersion()
);
}

/**
Expand Down Expand Up @@ -149,7 +155,7 @@ public String doVitamNormalize(SEDALibProgressLogger spl)
* @return the SEDA 2 version
* @throws ResipException the resip exception
*/
public static int getSeda2VersionFromFile(String file) throws ResipException {
public static SedaVersion getSeda2VersionFromFile(String file) throws ResipException {
Work ow;
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -167,7 +173,7 @@ public static int getSeda2VersionFromFile(String file) throws ResipException {
throw new ResipException("Resip: La lecture du fichier [" + file
+ "] ne permet pas de retrouver une session Resip", e);
}
return ow.seda2Version;
return ow.version;
}

/**
Expand Down Expand Up @@ -295,22 +301,4 @@ public ExportContext getExportContext() {
public void setExportContext(ExportContext exportContext) {
this.exportContext = exportContext;
}

/**
* Gets the SEDA 2 version used.
*
* @return the seda 2 version
*/
public int getSeda2Version() {
return seda2Version;
}

/**
* Sets the SEDA 2 version used.
*
* @param seda2Version the seda 2 version
*/
public void setSeda2Version(int seda2Version) {
this.seda2Version = seda2Version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package fr.gouv.vitam.tools.resip.event;

public interface Event {
}
31 changes: 31 additions & 0 deletions resip/src/main/java/fr/gouv/vitam/tools/resip/event/EventBus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.gouv.vitam.tools.resip.event;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class EventBus {

private static final Map<Class<? extends Event>, List<EventListener<?>>> listenersMap = new ConcurrentHashMap<>();

public static <T extends Event> void subscribe(Class<T> eventType, EventListener<T> listener) {
listenersMap
.computeIfAbsent(eventType, k -> new CopyOnWriteArrayList<>())
.add(listener);
}

@SuppressWarnings("unchecked")
public static <T extends Event> void publish(T event) {
List<EventListener<?>> listeners = listenersMap.getOrDefault(event.getClass(), Collections.emptyList());
for (EventListener<?> listener : listeners) {
((EventListener<T>) listener).onEvent(event);
}
}

public static <T extends Event> void unsubscribe(Class<T> eventType, EventListener<T> listener) {
List<EventListener<?>> listeners = listenersMap.get(eventType);
if (listeners != null) {
listeners.remove(listener);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fr.gouv.vitam.tools.resip.event;

@FunctionalInterface
public interface EventListener<T extends Event> {
void onEvent(T event);
}
Loading