Commit 41b63345 authored by marceteau's avatar marceteau
Browse files

refactor des arguments en entrée de la ligne de commande

parent 92dbe84b
......@@ -70,6 +70,9 @@ public class ArchiveConverterMain {
private Path planClassementFile;
private Path currentArchivePath;
private Path propertiesFolder;
private Path outputDir;
private Path inputFolder;
private Path manifestPath;
private String formalism;
private String agency;
......@@ -77,9 +80,14 @@ public class ArchiveConverterMain {
/**
* @param args
* @throws ParseException
* @throws NotSupportedException
* @throws IOException
* @throws IngestRejectException
* @throws DuplicateLanguageException
*/
public static void main(String[] args) throws ParseException {
new ArchiveConverterMain(args);
public static void main(String[] args) throws ParseException, DuplicateLanguageException, IngestRejectException, IOException, NotSupportedException {
ArchiveConverterMain converter = new ArchiveConverterMain(args);
File convertedArchive = converter.archiveConversion(args);
}
/**
......@@ -93,7 +101,7 @@ public class ArchiveConverterMain {
CommandLine commandLine = parser.parse(options, args);
parseCommandLine(options, commandLine);
parseCommandLine(options, commandLine, args);
}
/**
......@@ -115,8 +123,9 @@ public class ArchiveConverterMain {
/**
* @param options
* @param commandLine
* @throws ParseException
*/
private void parseCommandLine(Options options, CommandLine commandLine) {
private void parseCommandLine(Options options, CommandLine commandLine, String[] args) throws ParseException {
if(commandLine.hasOption("a")) {
agency = commandLine.getOptionValue("a") ;
} else {
......@@ -158,7 +167,13 @@ public class ArchiveConverterMain {
planClassementFile = Paths.get(commandLine.getOptionValue("p")) ;
if(!planClassementFile.toFile().exists()) {
System.err.println("Le fichier de plan de classement " + planClassementFile.toString() + " n'existe pas.");
System.exit(-1);
}
}
if(commandLine.hasOption("o")) {
outputDir = Paths.get(commandLine.getOptionValue("o")) ;
if(!outputDir.toFile().exists()) {
System.err.println("Le répertoire de sortie " + outputDir.toString() + " n'existe pas.");
}
}
......@@ -170,12 +185,28 @@ public class ArchiveConverterMain {
this.formalism = commandLine.getOptionValue("f");
}
if (commandLine.hasOption("d")) {
if (commandLine.hasOption("i")) {
System.err.println("Il n'est pas possible d'utiliser les options --input-folder et --manifest-path en même temps.");
System.exit(-1);
}
this.inputFolder = Paths.get(commandLine.getOptionValue('d'));
} else {
if (!commandLine.hasOption("i")) {
System.err.println("Il est obligatoire d'utiliser l'option --input-folder ou bien --manifest-path afin de connaitre l'objet en entrée.");
System.exit(-1);
} else {
this.manifestPath = Paths.get(commandLine.getOptionValue("i"));
}
}
if(commandLine.hasOption("m")) {
manifestConversion(commandLine);
manifestConversion(args);
} else {
try {
archiveConversion(commandLine);
archiveConversion(args);
System.exit(0);
} catch (DuplicateLanguageException e) {
manageLanguageRejectException(e);
......@@ -220,34 +251,23 @@ public class ArchiveConverterMain {
}
private void manifestConversion(CommandLine commandLine) {
private void manifestConversion(String[] args) {
ManifestConverter archiveConverter = null;
File originManifest = new File(commandLine.getOptionValue("i"));
File originManifest = new File(this.manifestPath.toString());
currentArchivePath = Paths.get(originManifest.getParent());
File manifestXML;
if (commandLine.hasOption("o")) {
manifestXML = new File(commandLine.getOptionValue("o") + "/" + "manifest.xml");
if (this.outputDir != null) {
manifestXML = new File(this.outputDir + "/" + "manifest.xml");
} else {
manifestXML = new File("manifest.xml");
}
if(formalism.equals("sip") || formalism.equals("aip")) {
if(!commandLine.hasOption("a")) {
logger.error("Le service versant est obligatoirement indiqué en argument.");
System.err.println("Le service versant est obligatoirement indiqué en argument.");
System.exit(-1);
}
String planClassementPath;
if(commandLine.hasOption("p")) {
planClassementPath = commandLine.getOptionValue("p");
} else {
planClassementPath = "";
}
archiveConverter = new DCToSeda21Converter(commandLine.getOptionValue("a"), Paths.get(commandLine.getOptionValue("c")), planClassementPath);
archiveConverter = new DCToSeda21Converter(this.agency, this.propertiesFolder, this.planClassementFile.toString());
archiveConverter.setOnlyManifest(true);
((AbstractArchiveConverter)archiveConverter).setSipType(formalism);
}else if(formalism.equals("seda1")) {
......@@ -259,7 +279,7 @@ public class ArchiveConverterMain {
}
try {
archiveConverter.convertManifest(originManifest, manifestXML, agency, Paths.get(commandLine.getOptionValue("c")));
archiveConverter.convertManifest(originManifest, manifestXML, agency, this.propertiesFolder);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DuplicateLanguageException e) {
......@@ -291,43 +311,26 @@ public class ArchiveConverterMain {
}
private void archiveConversion(CommandLine commandLine) throws IngestRejectException, IOException, NotSupportedException, DuplicateLanguageException {
private File archiveConversion(String[] args) throws IngestRejectException, IOException, NotSupportedException, DuplicateLanguageException, ParseException {
ArchiveConverter archiveConverter = null;
if(formalism.equals("sip") || formalism.equals("aip")) {
if(!commandLine.hasOption("a")) {
System.err.println("Le service versant est obligatoirement indiqué en argument.");
System.exit(-1);
}
String planClassementPath;
if(commandLine.hasOption("p")) {
planClassementPath = commandLine.getOptionValue("p");
} else {
planClassementPath = "";
}
archiveConverter = new DCToSeda21TarMaker(commandLine.getOptionValue("a"), planClassementPath, formalism);
archiveConverter = new DCToSeda21TarMaker(this.agency, this.planClassementFile.toString(), formalism);
}else if(formalism.equals("seda1")) {
archiveConverter = new Seda1ToSeda21TarMaker(commandLine.getOptionValue("a"));
archiveConverter = new Seda1ToSeda21TarMaker(this.agency);
}else {
System.err.println("Ce formalisme n'est pas reconnu, veuillez choisir sip ou seda1");
System.exit(-1);
}
if (commandLine.hasOption("o")) {
archiveConverter.setOutputDir(commandLine.getOptionValue("o"));
}
archiveConverter.setOutputDir(this.outputDir.toString());
if (commandLine.hasOption("l")) {
archiveConverter.setErrorLanguageDir(commandLine.getOptionValue("l"));
}
archiveConverter.setErrorLanguageDir(this.errorLanguageFolder.toString());
if (commandLine.hasOption("d")) {
if (commandLine.hasOption("i")) {
System.err.println("Il n'est pas possible d'utiliser les options --input-folder et --manifest-path en même temps.");
System.exit(-1);
}
if (this.inputFolder != null) {
// Workaround pour appeler archiveConverter dans une inner class
final ArchiveConverter ac = archiveConverter;
String folder = commandLine.getOptionValue("d");
String folder = this.inputFolder.toString();
if (!new File(folder).exists()) {
System.err.println("Le répertoire " + folder + " n'existe pas");
System.exit(-1);
......@@ -355,13 +358,14 @@ public class ArchiveConverterMain {
} catch (IOException e) {
e.printStackTrace();
}
return null;
} else {
Path aipPath = Paths.get(commandLine.getOptionValue("i"), archiveConverter.getSipFileName());
Path aipPath = Paths.get(this.manifestPath.toString(), archiveConverter.getSipFileName());
currentArchivePath = aipPath.getParent();
if(!formalism.equals("aip")) {
depositFormControl(aipPath);
}
archiveConverter.convert(Paths.get(commandLine.getOptionValue("i")), agency, propertiesFolder);
return archiveConverter.convert(this.manifestPath, agency, propertiesFolder);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment