Commit 84928017 authored by marceteau's avatar marceteau
Browse files

modif de mapping + correctif sur les imbrications des ArchiveUnit

parent 6041419e
......@@ -191,7 +191,13 @@ public class ArchiveConverterMain {
System.err.println("Le fichier de propriété du service versant est obligatoire pour un sip");
System.exit(-1);
}
archiveConverter = new DCToSeda21Converter(commandLine.getOptionValue("c"));
String planClassementPath;
if(commandLine.hasOption("p")) {
planClassementPath = commandLine.getOptionValue("p");
} else {
planClassementPath = "";
}
archiveConverter = new DCToSeda21Converter(commandLine.getOptionValue("c"), planClassementPath);
archiveConverter.setOnlyManifest(true);
}else if(formalism.equals("seda1")) {
archiveConverter = new Seda1ToSeda21Converter();
......@@ -238,7 +244,13 @@ public class ArchiveConverterMain {
System.err.println("Le fichier de propriété du service versant est obligatoire pour un sip");
System.exit(-1);
}
archiveConverter = new DCToSeda21TarMaker(commandLine.getOptionValue("c"), formalism);
String planClassementPath;
if(commandLine.hasOption("p")) {
planClassementPath = commandLine.getOptionValue("p");
} else {
planClassementPath = "";
}
archiveConverter = new DCToSeda21TarMaker(commandLine.getOptionValue("c"), planClassementPath, formalism);
}else if(formalism.equals("seda1")) {
archiveConverter = new Seda1ToSeda21TarMaker();
}else {
......
......@@ -239,10 +239,12 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
}
public static List<String> formatVideoList = Arrays.asList("AAC", "MPEG-4", "AIFF", "FLAC", "MKV", "OGG", "WAV");
private Properties properties;
private String planClassementFilePath;
private List<BinaryDataObjectTypeWithType> binaryDataObjectWithTypeList = new ArrayList<BinaryDataObjectTypeWithType>();;
public DCToSeda21Converter(String propertyFilePath) {
public DCToSeda21Converter(String propertyFilePath, String planClassementPath) {
informationPackage = new InformationPackage();
planClassementFilePath = planClassementPath;
properties = new Properties();
try {
......@@ -259,7 +261,8 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
public static void main(String[] args) throws FileNotFoundException, DuplicateLanguageException {
String agencyPropertyFile = args[0];
ManifestConverter archiveConverter = new DCToSeda21Converter(agencyPropertyFile);
String filePlanPath = args[1];
ManifestConverter archiveConverter = new DCToSeda21Converter(agencyPropertyFile, filePlanPath);
String originalManifest = args[1];
......@@ -526,11 +529,11 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
DescriptiveMetadataType descriptiveMetadata = objectFactory.createDescriptiveMetadataType();
ManagementType management = objectFactory.createManagementType();
//ManagementType management = objectFactory.createManagementType();
management.setUpdateOperation(null);
//management.setUpdateOperation(null);
rootArchiveUnit.setManagement(management);
//rootArchiveUnit.setManagement(management);
/**
* Balise <Content> de l'unité d'archive racine
......@@ -560,14 +563,22 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
// Plan de classement
//TODO : présent dans DocMeta et non pas dans FichMeta => problème, il n'y a pas 1 DocMeta pour 1 FichMeta
boolean generateFilePlan = Boolean.parseBoolean(properties.getProperty(MAP_FILE_PLAN));
String generateFilePlan = properties.getProperty(MAP_FILE_PLAN);
if (generateFilePlan && sip.getDocMeta().getPlanClassement() != null) {
//TODO: charger le fichier csv depuis les paramètres d'entrée
Path classificationScheme = Paths.get("/home/marceteau/git/vitam-data-test/VITAM_CINES_CONNECTOR/Properties/BSG_PDC_test.txt");
String filePlan = sip.getDocMeta().getPlanClassement().getValue();
if (!generateFilePlan.trim().equalsIgnoreCase("false")) {
String filePlan;
if (!(sip.getDocMeta().getPlanClassement() != null)) {
filePlan = "/";
} else {
filePlan = sip.getDocMeta().getPlanClassement().getValue();
}
try {
String[] filePlanLine = filePlanData("/home/marceteau/git/vitam-data-test/VITAM_CINES_CONNECTOR/Properties/BSG_PDC_test.txt", filePlan);
if(planClassementFilePath.equals(""))
throw new Exception("Aucun fichier de plan de classement fourni "
+ "alors que les propriétés demandent sa génération. "
+ "Ajoutez-le en entrée avec l'option -p ");
String[] filePlanLine = filePlanData(planClassementFilePath, filePlan);
String systemId = filePlanLine[1];
String descriptionLevelStr = filePlanLine[2];
TextType title = objectFactory.createTextType();
......@@ -581,7 +592,8 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
ghostArchiveUnit.setId("ID" + archiveUnitCounter);
archiveUnitCounter++;
ghostArchiveUnitAttachment.setId("ID" + archiveUnitCounter);
String refId = rootArchiveUnit.getId();
ghostArchiveUnitAttachment.setArchiveUnitRefId(rootArchiveUnit);
DescriptiveMetadataContentType ghostContent = objectFactory.createDescriptiveMetadataContentType();
ManagementType ghostManagement = objectFactory.createManagementType();
......@@ -1079,6 +1091,9 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
if (format.getPronomIds().size() > 0)
formatIdentification.setFormatId(format.getPronomIds().get(0));
if(!format.getTypeMimes().isEmpty()) {
formatIdentification.setMimeType(format.getTypeMimes().get(0));
}
}
binaryDataObject.setFormatIdentification(formatIdentification);
......@@ -1407,8 +1422,8 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
subListArchiveUnit.add((ArchiveUnitType) obj);
}
}
if (!subListArchiveUnit.isEmpty())
return containsAU(subListArchiveUnit, archiveUnit);
if (!subListArchiveUnit.isEmpty() && containsAU(subListArchiveUnit, archiveUnit))
return true;
}
return false;
......@@ -1555,12 +1570,13 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
folderAU.setContent(content);
}
if (pathElements.length > 1) {
if ((pathElements.length > 1) && (mapFolderArchiveUnit.get(subFolderPath) == null)) {
String subSubFolderName = Arrays.stream(pathElements, 1, pathElements.length).collect(Collectors.joining("/"));
ArchiveUnitType subFolderAU = buildSubFolderArchiveUnit(subSubFolderName);
ArchiveUnitType subFolderAU = null;
subFolderAU = buildSubFolderArchiveUnit(subSubFolderName);
folderAU.getArchiveUnitOrArchiveUnitReferenceAbstractOrDataObjectReference().add(subFolderAU);
mapFolderArchiveUnit.put(subFolderPath, folderAU);
return folderAU;
mapFolderArchiveUnit.put(subFolderPath, subFolderAU);
return subFolderAU;
} else {
mapFolderArchiveUnit.put(subFolderPath, folderAU);
return folderAU;
......@@ -1593,8 +1609,24 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
// Mapping du <nomFichier> DC vers <Title> SEDA 2.1
TextType title = objectFactory.createTextType();
TextType description = objectFactory.createTextType();
String[] pathNomFichier = fichMeta.getNomFichier().split("/");
title.setValue(pathNomFichier[pathNomFichier.length-1]);
if (fichMeta.getNomFichier().equals("aip.xml")) {
title.setValue("Certificat d'archivage");
title.setLang("fra");
description.setValue("Certificat d'archivage produit par PAC au format DC-CINES avant conversion en SEDA 2.1");
description.setLang("fra");
content.getDescription().add(description);
} else if(fichMeta.getNomFichier().equals("sip.xml")) {
title.setValue("Bordereau de versement");
title.setLang("fra");
description.setValue("Bordereau de versement au format DC-CINES avant conversion en SEDA 2.1");
description.setLang("fra");
content.getDescription().add(description);
} else {
//title.setValue(pathNomFichier[pathNomFichier.length-1]);
title.setValue(fichMeta.getNomFichier());
}
content.getTitle().add(title);
//TODO: voir dans quelles circonstances il faudra mettre la valeur RI au lieu de PDI ou CDO
......@@ -1713,7 +1745,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
String ligne = null;
//Si planClassement termine ou commence par un / on le retire
if(planClassement.endsWith("/"))
if(planClassement.endsWith("/") && planClassement.length() > 1)
planClassement = planClassement.substring(0, planClassement.length() - 1);
if(planClassement.startsWith("/") && planClassement.length() > 1)
planClassement = planClassement.substring(1, planClassement.length());
......
......@@ -65,13 +65,17 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
private String sipFileName;
private String planClassementPath;
/**
* Constructeur
* @param formalism
* @param String path chemin vers le fichier de propriétés du service versant
*/
public DCToSeda21TarMaker(String path, String aipOrSip) {
public DCToSeda21TarMaker(String path, String planClassementPath, String aipOrSip) {
this.agencyPropertyFilePath = path;
this.sipType = aipOrSip;
this.planClassementPath = planClassementPath;
tarMaker = new TarMakerImpl();
if(this.sipType.equals("aip")) {
this.sipFileName = "aip.xml";
......@@ -80,22 +84,24 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
}
}
public DCToSeda21TarMaker(String path) {
public DCToSeda21TarMaker(String path, String planClassementPath) {
this.agencyPropertyFilePath = path;
this.planClassementPath = planClassementPath;
tarMaker = new TarMakerImpl();
}
public static void main(String[] args) throws IOException, DuplicateLanguageException {
System.out.println(args[0]);
String archiveFolder = args[0];
DCToSeda21TarMaker converter = new DCToSeda21TarMaker("", "");
DCToSeda21TarMaker converter = new DCToSeda21TarMaker("", "", "");
File archiveSeda21 = converter.convert(Paths.get(archiveFolder).toAbsolutePath());
System.out.println("Archive SEDA 2.1 Créé : " + archiveSeda21.getAbsolutePath());
}
public File convert(Path rootFolderDC) throws DuplicateLanguageException {
ManifestConverter xmlConverter = new DCToSeda21Converter(this.getAgencyPropertyFilePath());
ManifestConverter xmlConverter = new DCToSeda21Converter(this.getAgencyPropertyFilePath(), this.getPlanClassementPath());
((AbstractArchiveConverter)xmlConverter).setSipType(this.sipType);
/**
* Le fichier du manifeste SEDA 2.1
......@@ -236,4 +242,12 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
this.sipFileName = sipFileName;
}
public String getPlanClassementPath() {
return planClassementPath;
}
public void setPlanClassementPath(String planClassementPath) {
this.planClassementPath = planClassementPath;
}
}
Supports Markdown
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