Commit a20f5dc8 authored by marceteau's avatar marceteau
Browse files

fix repertoire erreur de langue + gestion noteFichier dans properties

parent f0ea7b73
......@@ -25,6 +25,7 @@ import java.io.File;
import java.nio.file.Path;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
/**
* @author Florent MARCETEAU
......@@ -37,8 +38,9 @@ public interface ArchiveConverter {
* @param archiveFolder
* @return {@link File} L'archive tar au format SEDA21
* @throws DuplicateLanguageException
* @throws IngestRejectException
*/
public File convert(Path archiveFolder) throws DuplicateLanguageException;
public File convert(Path archiveFolder) throws DuplicateLanguageException, IngestRejectException;
/**
* répertoire de sortie
......@@ -55,4 +57,8 @@ public interface ArchiveConverter {
public String getSipFileName();
public void setSipFileName(String ipType);
public void setErrorLanguageDir(String dir);
public String getErrorLanguageDir();
}
......@@ -161,7 +161,7 @@ public class ArchiveConverterMain {
}
private void manageLanguageRejectException(IngestRejectException e) {
private void manageLanguageRejectException(DuplicateLanguageException e) {
try {
logger.error(e.getMessage());
Files.move(currentArchivePath, errorLanguageFolder.resolve(currentArchivePath.getFileName()), StandardCopyOption.REPLACE_EXISTING);
......@@ -214,6 +214,9 @@ public class ArchiveConverterMain {
} catch (DuplicateLanguageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IngestRejectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......@@ -262,6 +265,10 @@ public class ArchiveConverterMain {
archiveConverter.setOutputDir(commandLine.getOptionValue("o"));
}
if (commandLine.hasOption("l")) {
archiveConverter.setErrorLanguageDir(commandLine.getOptionValue("l"));
}
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.");
......@@ -287,6 +294,8 @@ public class ArchiveConverterMain {
ac.convert(file.toPath());
} catch (DuplicateLanguageException e) {
manageLanguageRejectException(e);
} catch (IngestRejectException e) {
manageRejectException(e);
}
});
System.exit(0);
......
......@@ -98,6 +98,7 @@ import fr.cines.pac.aip.StringNotNULLtext;
import fr.cines.pac.aip.StructureFichier;
import fr.cines.pac.aip.TraitementEnum;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
import fr.cines.validator.ValidatorFactory;
import fr.gouv.culture.archivesdefrance.seda.v2.AccessRuleType;
import fr.gouv.culture.archivesdefrance.seda.v2.AgentType;
......@@ -227,6 +228,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
private static final String IDENTIFIANT_DOC_PRODUCTEUR = "IdentifiantDocProducteur";
private static final String VERSION = "version";
private static final String COVERAGE = "coverage";
private static final String NOTE_FICHIER = "noteFichier";
private static final String ORIGINATING_SYSTEM_ID = "OriginatingSystemId";
private static final String ORIGINATING_AGENCY_ARCHIVE_UNIT_IDENTIFIER = "OriginatingAgencyArchiveUnitIdentifier";
private static final String TRANSFERRING_AGENCY_ARCHIVE_UNIT_IDENTIFIER = "TransferringAgencyArchiveUnitIdentifier";
......@@ -269,7 +271,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
this.rootFolder = Paths.get("DEPOT");
}
public static void main(String[] args) throws FileNotFoundException, DuplicateLanguageException {
public static void main(String[] args) throws FileNotFoundException, IngestRejectException {
String agencyPropertyFile = args[0];
String filePlanPath = args[1];
ManifestConverter archiveConverter = new DCToSeda21Converter(agencyPropertyFile, filePlanPath);
......@@ -282,7 +284,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
}
@Override
public ArchiveTransferType convertManifest(File originalManifest, File convertedManifest) throws FileNotFoundException, DuplicateLanguageException {
public ArchiveTransferType convertManifest(File originalManifest, File convertedManifest) throws FileNotFoundException, IngestRejectException {
this.rootFolder = Paths.get(originalManifest.getAbsolutePath()).getParent().resolve("DEPOT");
informationPackage.setDepositIdentifier(rootFolder.getParent().getFileName().toString());
try(InputStream inputStreamOriginal = new FileInputStream(originalManifest)) {
......@@ -347,10 +349,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// On peuple avec les dataObjects, seul le chemin original est gardé
for (BinaryDataObjectTypeWithType oldBinary : binaryDataObjectWithTypeList) {
......@@ -440,10 +439,10 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
* @param dataObjectPackage
* @param submissionAgency
* @param currentArchive
* @throws Exception
* @throws IngestRejectException
*/
@SuppressWarnings("null")
private DataObjectPackageType mapArchiveBlock(ArchiveUnitType currentArchive, PacType sip) throws Exception {
private DataObjectPackageType mapArchiveBlock(ArchiveUnitType currentArchive, PacType sip) throws IngestRejectException{
DataObjectPackageType dataObjectPackage = objectFactory.createDataObjectPackageType();
// Contrat d'archive
......@@ -483,7 +482,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
disseminationRule.getRuleAndStartDate().add(ruleId);
managementMetadata.setDisseminationRule(disseminationRule);
}
//TODO : AccessRestrictionRule pas dans le mapping excel
AccessRuleType accessRestrictionRule = mapAccessRule(sip.getDocMeta());
if (sip.getDocMeta().getCommunicabilite() != null)
......@@ -725,7 +724,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
relation.setExternalReference(identifiantSourceRelation);
} else {
//Ce cas ne devrait pas se produire
throw new Exception("La valeur de sourceRelation est incorrecte" + docRelationType.getSourceRelation());
throw new IngestRejectException("La valeur de sourceRelation est incorrecte" + docRelationType.getSourceRelation(), "EXXX");
}
RelatedObjectReferenceType relatedObjectReference;
......@@ -1067,8 +1066,9 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
* @param listBinaryDataObject
* @param objectFactory
* @param document
* @throws IngestRejectException
*/
private BinaryDataObjectTypeWithType mapBinaryDataObject(FichMetaType document) {
private BinaryDataObjectTypeWithType mapBinaryDataObject(FichMetaType document) throws IngestRejectException{
ObjectFactory objectFactory = new ObjectFactory();
BinaryDataObjectTypeWithType binaryDataObject = new BinaryDataObjectTypeWithType();
......@@ -1194,8 +1194,9 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
String declaredChecksum = empreinte;
String declaredTypeChecksum = type;
String computedChecksum = computeChecksum(filePath.toString(), declaredTypeChecksum);
if(!computedChecksum.equalsIgnoreCase(declaredChecksum) && !document.getNomFichier().equals("aip.xml") && !document.getNomFichier().equals("sip.xml")) {
if(!computedChecksum.equalsIgnoreCase(declaredChecksum.trim()) && !document.getNomFichier().equals("aip.xml") && !document.getNomFichier().equals("sip.xml")) {
logger.error("Le checksum du bordereau est différent du checksum calculé pour le fichier : {}", document.getNomFichier());
throw new IngestRejectException("Le checksum du bordereau est différent du checksum calculé pour le fichier : " + document.getNomFichier(), "EXXX");
}
String algorithm = "SHA-512";
String sha512 = computeChecksum(filePath.toString(), algorithm);
......@@ -1240,7 +1241,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
JAXBElement<String> jaxbElementSchema = createXMLElement(schemaValue, "Schema");
text.getAny().add(jaxbElementSchema);
representation_information_files.add(schemaValue);
representation_information_files.add(sf.getValue());
}
metadata.setText(text);
}
......@@ -1439,8 +1440,9 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
*
* @param sip
* @return La liste des BinaryDataObject avec en plus le Type de l'objet binaire : CDO. PDI etc.
* @throws IngestRejectException
*/
private List<DataObjectGroupType> mapDataObjectGroup(PacType sip) {
private List<DataObjectGroupType> mapDataObjectGroup(PacType sip) throws IngestRejectException{
/**
* Liste contenant les BinaryDataObject du SEDA 2.1
*/
......@@ -1467,8 +1469,9 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
*
* @param fichMetaType Un FichMetaType DC
* @param listBinaryDataObject La liste des <BinaryDataObject> du SEDA 2.1
* @throws IngestRejectException
*/
private void extractArchiveObject(FichMetaType fichMetaType, List<BinaryDataObjectTypeWithType> listBinaryDataObject) {
private void extractArchiveObject(FichMetaType fichMetaType, List<BinaryDataObjectTypeWithType> listBinaryDataObject) throws IngestRejectException{
BinaryDataObjectTypeWithType binaryDataObject = mapBinaryDataObject(fichMetaType);
listBinaryDataObject.add(binaryDataObject);
}
......@@ -1851,6 +1854,12 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
content.setType(type);
}
//noteFichier
String noteFichier = properties.getProperty(NOTE_FICHIER);
if ("true".equalsIgnoreCase(noteFichier.trim()) && fichMeta.getNoteFichier() != null) {
content.setSource(fichMeta.getNoteFichier().getValue());
}
/*if(fichMeta.getVersionFormatFichier() != null && !fichMeta.getVersionFormatFichier().equals("NA"))
content.setVersion(fichMeta.getVersionFormatFichier());*/
}
......@@ -1897,7 +1906,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
* Réalise le mapping des langues entre
* @param listChaine liste de chaine avec des attributs language
*
* TODO : Si 'und' est déjà pris, il faut arrêter le traitement et partir en erreur
* TODO : Si 'und' est déjà pris, il faut continuer le traitement et placer le paquet dans le répertoire d'erreur de langue
*/
private List<TextType> mapLanguage(List<StringNotNULLtext> listChaine) throws DuplicateLanguageException {
List<TextType> list = new ArrayList<TextType>();
......@@ -1920,7 +1929,8 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
if(listLang.contains(proposedLanguage)) {
if(listLang.contains("und")) {
elemSeda21.setLang(proposedLanguage);
throw new DuplicateLanguageException(informationPackage.getDepositIdentifier(), DUPLICATE_ERROR_LANGUAGE, null);
setErrorLanguage(true);
//throw new DuplicateLanguageException(informationPackage.getDepositIdentifier(), DUPLICATE_ERROR_LANGUAGE, null);
} else {
listLang.add("und");
elemSeda21.setLang("und");
......
......@@ -42,6 +42,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
import fr.cines.pac.service.ingest.xml.SipConstants;
import fr.cines.pac.storage.tar.TarMaker;
import fr.cines.pac.storage.tar.TarMakerImpl;
......@@ -61,6 +62,8 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
private String outputDir;
private String errorLanguageDir;
private String sipType = "sip";
private String sipFileName;
......@@ -90,7 +93,7 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
tarMaker = new TarMakerImpl();
}
public static void main(String[] args) throws IOException, DuplicateLanguageException {
public static void main(String[] args) throws IOException, DuplicateLanguageException, IngestRejectException, Exception {
System.out.println(args[0]);
String archiveFolder = args[0];
DCToSeda21TarMaker converter = new DCToSeda21TarMaker("", "", "");
......@@ -99,7 +102,7 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
}
public File convert(Path rootFolderDC) throws DuplicateLanguageException {
public File convert(Path rootFolderDC) throws DuplicateLanguageException, IngestRejectException {
ManifestConverter xmlConverter = new DCToSeda21Converter(this.getAgencyPropertyFilePath(), this.getPlanClassementPath());
((AbstractArchiveConverter)xmlConverter).setSipType(this.sipType);
......@@ -163,11 +166,23 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
try {
// File tarFile = tarMaker.tarFiles(fileList, targetName, rootFolderDC.toString(), rootFolderDC.toString());
Path zipPath = null;
if ("".equals(this.outputDir)) {
zipPath = rootFolderDC.resolveSibling(rootFolderDC.getFileName() + ".zip");
if(((DCToSeda21Converter)xmlConverter).isErrorLanguage()) {
//Dans le cas d'une erreur de langue dans les balises title ou description
if ("".equals(this.errorLanguageDir)) {
zipPath = rootFolderDC.resolveSibling(rootFolderDC.getFileName() + ".zip");
throw new Exception("Une erreur de langue a été détectée, mais aucun répertoire n'a été indique pour déposer le paquet");
} else {
zipPath = Paths.get(this.errorLanguageDir, rootFolderDC.getFileName().toString()).resolveSibling(rootFolderDC.getFileName() + ".zip");
}
} else {
zipPath = Paths.get(this.outputDir, rootFolderDC.getFileName().toString()).resolveSibling(rootFolderDC.getFileName() + ".zip");
//Dans le cas normal
if ("".equals(this.outputDir)) {
zipPath = rootFolderDC.resolveSibling(rootFolderDC.getFileName() + ".zip");
} else {
zipPath = Paths.get(this.outputDir, rootFolderDC.getFileName().toString()).resolveSibling(rootFolderDC.getFileName() + ".zip");
}
}
logger.info("Création de l'archive SEDA 2.1 {}", zipPath);
AbstractArchiveConverter.zip(fileList, zipPath, rootFolderDC);
// Nettoyage
......@@ -180,6 +195,9 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
return null;
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
......@@ -250,4 +268,12 @@ public class DCToSeda21TarMaker implements ArchiveConverter {
public void setPlanClassementPath(String planClassementPath) {
this.planClassementPath = planClassementPath;
}
public String getErrorLanguageDir() {
return errorLanguageDir;
}
public void setErrorLanguageDir(String errorLanguageDir) {
this.errorLanguageDir = errorLanguageDir;
}
}
......@@ -7,6 +7,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
import fr.gouv.culture.archivesdefrance.seda.v2.ArchiveTransferType;
/**
......@@ -23,8 +24,9 @@ public interface ManifestConverter {
* @param originalManifest
* @param convertedManifest
* @return
* @throws IngestRejectException
*/
ArchiveTransferType convertManifest(File originalManifest, File convertedManifest) throws FileNotFoundException, DuplicateLanguageException;
ArchiveTransferType convertManifest(File originalManifest, File convertedManifest) throws FileNotFoundException, DuplicateLanguageException, IngestRejectException;
public boolean isOnlyManifest();
......
......@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
import fr.cines.ip.DataObject;
import fr.cines.ip.InformationPackage;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
import fr.cines.pac.service.ingest.xml.SedaConstants;
import fr.cines.pac.storage.tar.TarMaker;
import fr.cines.pac.storage.tar.TarMakerImpl;
......@@ -71,7 +72,7 @@ public class Seda1ToSeda21TarMaker implements ArchiveConverter {
this.sipFileName = "ArchiveTransfer.xml";
}
public static void main(String[] args) throws DuplicateLanguageException {
public static void main(String[] args) throws DuplicateLanguageException, IngestRejectException {
System.out.println(args[0]);
String archiveFolder = args[0];
Seda1ToSeda21TarMaker converter = new Seda1ToSeda21TarMaker();
......@@ -79,7 +80,7 @@ public class Seda1ToSeda21TarMaker implements ArchiveConverter {
System.out.println("Archive SEDA 2.1 Créé : " + archiveSeda21.getAbsolutePath());
}
public File convert(Path rootFolderSEDA1) throws DuplicateLanguageException {
public File convert(Path rootFolderSEDA1) throws DuplicateLanguageException, IngestRejectException {
ManifestConverter xmlConverter = new Seda1ToSeda21Converter();
......@@ -188,4 +189,11 @@ public class Seda1ToSeda21TarMaker implements ArchiveConverter {
this.sipFileName = sipFileName;
}
public String getErrorLanguageDir() {
return null;
}
public void setErrorLanguageDir(String errorLanguageDir) {
}
}
......@@ -14,6 +14,7 @@ import org.junit.Test;
import fr.cines.format.validator.UnknownFormatException;
import fr.cines.pac.converter.exception.DuplicateLanguageException;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
/**
* @author Alexandre Granier <granier@cines.fr> <granier.alexandre@free.fr>
......@@ -31,7 +32,7 @@ public class Seda1ToSeda21TarMakerTest {
*/
@Test
@Ignore
public void testCreateArchive() throws UnknownFormatException, DuplicateLanguageException {
public void testCreateArchive() throws UnknownFormatException, DuplicateLanguageException, IngestRejectException {
Seda1ToSeda21TarMaker converter = new Seda1ToSeda21TarMaker();
String filePath = getClass().getResource("/SEDA_OK_Generic/").getFile();
......
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