Commit 4abd5f49 authored by marceteau's avatar marceteau
Browse files

mapping divers seda1 vers 2.1

parent e46dff40
......@@ -40,6 +40,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
......@@ -66,7 +67,6 @@ import fr.cines.format.validator.model.ValidableFormat;
import fr.cines.ip.DataObject;
import fr.cines.ip.InformationPackage;
import fr.cines.pac.ingest.util.exception.IngestRejectException;
import fr.cines.util.FileUtils;
import fr.cines.validator.ValidatorFactory;
import fr.gouv.culture.archivesdefrance.seda.v1.AccessRestrictionRuleType;
import fr.gouv.culture.archivesdefrance.seda.v1.AppraisalRuleType;
......@@ -96,19 +96,18 @@ import fr.gouv.culture.archivesdefrance.seda.v2.DataObjectPackageType;
import fr.gouv.culture.archivesdefrance.seda.v2.DataObjectRefType;
import fr.gouv.culture.archivesdefrance.seda.v2.DescriptiveMetadataContentType;
import fr.gouv.culture.archivesdefrance.seda.v2.DescriptiveMetadataType;
import fr.gouv.culture.archivesdefrance.seda.v2.EventType;
import fr.gouv.culture.archivesdefrance.seda.v2.FileInfoType;
import fr.gouv.culture.archivesdefrance.seda.v2.FinalActionAppraisalCodeType;
import fr.gouv.culture.archivesdefrance.seda.v2.FormatIdentificationType;
import fr.gouv.culture.archivesdefrance.seda.v2.IdentifierType;
import fr.gouv.culture.archivesdefrance.seda.v2.LevelType;
import fr.gouv.culture.archivesdefrance.seda.v2.ManagementMetadataType;
import fr.gouv.culture.archivesdefrance.seda.v2.ManagementType;
import fr.gouv.culture.archivesdefrance.seda.v2.MessageDigestBinaryObjectType;
import fr.gouv.culture.archivesdefrance.seda.v2.ObjectFactory;
import fr.gouv.culture.archivesdefrance.seda.v2.OrganizationDescriptiveMetadataType;
import fr.gouv.culture.archivesdefrance.seda.v2.OrganizationWithIdType;
import fr.gouv.culture.archivesdefrance.seda.v2.RuleIdType;
import un.unece.uncefact.codelist.draft.daf.accessrestrictioncode.AccessRestrictionCodeType;
import un.unece.uncefact.codelist.draft.daf.appraisalcode._2009_08_18.AppraisalCodeType;
import un.unece.uncefact.codelist.draft.daf.descriptionlevelcode._2009_08_18.LevelDescriptionType;
import un.unece.uncefact.codelist.draft.daf.documenttypecode._2009_08_18.DocumentTypeCodeType;
......@@ -143,7 +142,10 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
//variables liées au fichier properties
private static final String APPRAISAL_RULE = "AppraisalRule_Rule";
private static final String ORIGINATING_AGENCY_IDENTIFIER = "OriginatingAgencyIdentifier";
private static final String ORIGINATING_AGENCY_IDENTIFIER_BOOL = "OriginatingAgency_Identifier";
private static final String SUBMISSION_AGENCY_IDENTIFIER = "SubmissionAgencyIdentifier";
private static final String ARCHIVAL_AGENCY_IDENTIFIER = "ArchivalAgency_Identifier";
private static final String TRANSFERRING_AGENCY_IDENTIFIER = "TransferringAgency_Identifier";
/**
* Le répertoire déposé, celui contenant le bordereau
......@@ -314,18 +316,25 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
manifest.setCodeListVersions(codeListVersion);
// Service versant
OrganizationType archivalAgencySEDA1 = archiveTransferSEDA10.getArchivalAgency();
ArchivesIDType identification = archivalAgencySEDA1.getIdentification();
TextType archivalAgencyName = archivalAgencySEDA1.getName();
OrganizationWithIdType archivalAgency = objectFactory.createOrganizationWithIdType();
IdentifierType archivalAgencyIdentifier = objectFactory.createIdentifierType();
archivalAgencyIdentifier.setValue(properties.getProperty(ARCHIVAL_AGENCY_IDENTIFIER));
OrganizationWithIdType archivalAgency = buildOrganization(identification, archivalAgencyName, OrganizationWithIdType.class);
archivalAgency.setIdentifier(archivalAgencyIdentifier);
OrganizationWithIdType transferringAgency = objectFactory.createOrganizationWithIdType();
IdentifierType transferringAgencyIdentifier = objectFactory.createIdentifierType();
transferringAgencyIdentifier.setValue(properties.getProperty(TRANSFERRING_AGENCY_IDENTIFIER));
transferringAgency.setIdentifier(transferringAgencyIdentifier);
// Service versant de transfert
OrganizationType transferringAgencySEDA1 = archiveTransferSEDA10.getTransferringAgency();
ArchivesIDType identificationTransferringAgency = transferringAgencySEDA1.getIdentification();
TextType transferringAgencyName = transferringAgencySEDA1.getName();
OrganizationWithIdType transferringAgency = buildOrganization(identificationTransferringAgency, transferringAgencyName, OrganizationWithIdType.class);
// OrganizationWithIdType transferringAgency = buildOrganization(identificationTransferringAgency, transferringAgencyName, OrganizationWithIdType.class);
fr.gouv.culture.archivesdefrance.seda.v2.OrganizationType submissionAgency = buildOrganization(identificationTransferringAgency, transferringAgencyName, fr.gouv.culture.archivesdefrance.seda.v2.OrganizationType.class);
manifest.setArchivalAgency(archivalAgency);
......@@ -370,6 +379,7 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
AccessRuleType accessRestrictionRule = mapAccessRule(currentArchive.getAccessRestrictionRule());
// String seda2Value = ACCESS_RULE.valueOf(accessRule.ge).value;
managementMetadata.setAccessRule(accessRestrictionRule);
......@@ -421,13 +431,13 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
content.setDescriptionLevel(descriptionLevel);
// Plan de classement
List<ArchivesIDType> filePlans = contentDescription.getFilePlanPosition();
for (ArchivesIDType filePlan : filePlans) {
filePlan.getSchemeName();
filePlan.getSchemeAgencyName();
filePlan.getValue();
content.getFilePlanPosition().add(filePlan.getValue());
}
// List<ArchivesIDType> filePlans = contentDescription.getFilePlanPosition();
// for (ArchivesIDType filePlan : filePlans) {
// filePlan.getSchemeName();
// filePlan.getSchemeAgencyName();
// filePlan.getValue();
// content.getFilePlanPosition().add(filePlan.getValue());
// }
// Identifiant du service versant d'origine - peut être null
ArchivesIDType origAgencyId = currentArchive.getOriginatingAgencyArchiveIdentifier();
......@@ -455,9 +465,44 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
if (!descriptionLanguageList.isEmpty())
content.setDescriptionLanguage(descriptionLanguageList.get(0).getValue().toString());
// OriginatingAgency
String originatingAgencyBool = properties.getProperty(ORIGINATING_AGENCY_IDENTIFIER_BOOL);
if (originatingAgencyBool != null && "true".equalsIgnoreCase(originatingAgencyBool.trim()) ) {
List<OrganizationType> originatingAgencyList = currentArchive.getContentDescription().getOriginatingAgency();
//Si plusieurs name en SEDA 1 on concatene (le cas ne devrait pas se présenter)
for(OrganizationType originatingType : originatingAgencyList) {
String idValue = "";
if((content.getOriginatingAgency() != null) && (content.getOriginatingAgency().getIdentifier()!=null)
&& (!content.getOriginatingAgency().getIdentifier().getValue().trim().equals(""))) {
idValue = idValue + " | ";
}
idValue = idValue + originatingType.getName().getValue();
fr.gouv.culture.archivesdefrance.seda.v2.OrganizationType originatingAgency = objectFactory.createOrganizationType();
IdentifierType originatingAgencyIdentifierFromName = objectFactory.createIdentifierType();
originatingAgencyIdentifierFromName.setValue(idValue);
originatingAgency.setIdentifier(originatingAgencyIdentifierFromName);
content.setOriginatingAgency(originatingAgency);
}
}
// Le service versant soumettant <SubmissionAgency>
// On reprends la <TransferringAgency> du paquet dans son ensemble
content.setSubmissionAgency(submissionAgency);
// content.setSubmissionAgency(submissionAgency);
content.setStartDate(currentArchive.getContentDescription().getOldestDate().toString());
content.setEndDate(currentArchive.getContentDescription().getLatestDate().toString());
// Event
if(this.getArchiveType().equalsIgnoreCase("Archive.xml")) {
EventType event = objectFactory.createEventType();
event.setEventType("Archivage dans PAC");
String custodialHistoryEvent = currentArchive.getContentDescription().getCustodialHistory().getCustodialHistoryItem().get(1).getValue().trim();
String dateArchivagePAC = custodialHistoryEvent.substring(custodialHistoryEvent.length()-25, custodialHistoryEvent.length());
event.setEventDateTime(dateArchivagePAC);
content.getEvent().add(event);
}
rootArchiveUnit.setContent(content);
......@@ -465,8 +510,8 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
fr.gouv.culture.archivesdefrance.seda.v2.CustodialHistoryType custodialHistory = mapCustodialHistory(currentArchive);
content.setCustodialHistory(custodialHistory);
ManagementType management = mapArchiveUnitManagementBlock(currentArchive);
rootArchiveUnit.setManagement(management);
// ManagementType management = mapArchiveUnitManagementBlock(currentArchive);
// rootArchiveUnit.setManagement(management);
descriptiveMetadata.getArchiveUnit().add(rootArchiveUnit);
......@@ -500,16 +545,13 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
ArchiveObjectType archiveObject = new ArchiveObjectType();
TextType name = new TextType();
name.setValue(type);
name.setValue("Certificat d'archivage");
archiveObject.setName(name);
ContentDescriptionType contentDescription = new ContentDescriptionType();
CodeDescriptionLevelType codeDescriptionLevelType = new CodeDescriptionLevelType();
codeDescriptionLevelType.setValue(LevelDescriptionType.ITEM);
contentDescription.setDescriptionLevel(codeDescriptionLevelType);
CodeLanguageType codeLanguageType = new CodeLanguageType();
codeLanguageType.setValue(Locale.FRENCH);
contentDescription.getLanguage().add(codeLanguageType );
archiveObject.setContentDescription(contentDescription);
DocumentType documentType = new DocumentType();
......@@ -527,61 +569,8 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
archiveObject.getDocument().add(documentType );
archiveTransfer.getArchive().get(0).getArchiveObject().add(archiveObject);
// sipfichmeta.setNomFichier("ArchiveTransfer.xml");
// sipfichmeta.setFormatFichier("XML");
// sipfichmeta.setEncodage("UTF_8");
// //aipfichmeta.setVersionFormatFichier("1.0");
// EmpreinteType empreinteType = new EmpreinteType();
// Path sipPath = Paths.get(this.rootFolder.getParent().toString(), "sip.xml");
// empreinteType.setValue(computeChecksum(sipPath.toString(), "SHA-256"));
// empreinteType.setType("SHA-256");
// sipfichmeta.setEmpreinte(empreinteType);
// sipfichmeta.setTailleEnOctets(BigInteger.valueOf(sipPath.toFile().length()));
// archiveTransfer.getFichMeta().add(sipfichmeta);
}
/**
* Réalise le mapping du bloc <Management> d'ununité d'archive
* Il contient les règles d'évaluation, d'accès
* @param currentArchive Le bloc <Archive> du SEDA 1.0
* @return Une instance ManagementType
*/
private ManagementType mapArchiveUnitManagementBlock(ArchiveType currentArchive) {
ObjectFactory objectFactory = new ObjectFactory();
// Bloc <Management> de l'unité d'archive racine
ManagementType management = objectFactory.createManagementType();
AccessRuleType accessRule = mapAccessRule(currentArchive.getAccessRestrictionRule());
management.setAccessRule(accessRule);
if (currentArchive.getAppraisalRule() != null) {
fr.gouv.culture.archivesdefrance.seda.v2.AppraisalRuleType appraisalRule = mapAppraisalRules(currentArchive.getAppraisalRule());
management.setAppraisalRule(appraisalRule);
}
return management;
}
/**
* Comme ci-dessus mais avec un ArchiveObject du SEDA 1.0
* @param archiveObject
* @return Une instance ManagementType
*/
private ManagementType mapArchiveUnitManagementBlock(ArchiveObjectType archiveObject) {
ObjectFactory objectFactory = new ObjectFactory();
// Bloc <Management> de l'unité d'archive racine
ManagementType management = objectFactory.createManagementType();
if (archiveObject.getAccessRestrictionRule() != null) {
AccessRuleType accessRule = mapAccessRule(archiveObject.getAccessRestrictionRule());
management.setAccessRule(accessRule);
}
if (archiveObject.getAppraisalRule() != null) {
fr.gouv.culture.archivesdefrance.seda.v2.AppraisalRuleType appraisalRule = mapAppraisalRules(archiveObject.getAppraisalRule());
management.setAppraisalRule(appraisalRule);
}
return management;
}
/**
* Réalise le mapping des langues entre
......@@ -612,7 +601,6 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
try {
organization = classOrganisationName.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (organization instanceof OrganizationWithIdType) {
......@@ -659,11 +647,11 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
XMLGregorianCalendar accessStartDate = accessRestrictionRule.getStartDate();
CodeAccessRestrictionType accessRuleCode = accessRestrictionRule.getCode();
AccessRestrictionCodeType accessRuleCodevalue = accessRuleCode.getValue();
String seda2Value = ACCESS_RULE.valueOf(accessRuleCode.getValue().value()).value;
AccessRuleType accessRule = objectFactory.createAccessRuleType();
RuleIdType accessRuleIdType = objectFactory.createRuleIdType();
accessRuleIdType.setValue(accessRuleCodevalue.value());
accessRuleIdType.setValue(seda2Value);
// ATTENTION : il faut mettre la règle d'abord, la date ensuite
accessRule.getRuleAndStartDate().add(accessRuleIdType);
accessRule.getRuleAndStartDate().add(accessStartDate);
......@@ -739,7 +727,7 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
// Avec une référence BinaryDataObject SEDA 2.1
List<DocumentType> documents = archiveObject.getDocument();
for (DocumentType document : documents) {
DataObjectRefType objectRef = buildDataReferenceObject(document.getId());
DataObjectRefType objectRef = buildDataReferenceObject("OID" + document.getId().substring(8));
archiveUnit.getArchiveUnitOrArchiveUnitReferenceAbstractOrDataObjectReference().add(objectRef);
}
......@@ -762,11 +750,6 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
mapDescriptiveMetadataContent(archiveObject, content);
// Règle d'évaluation au niveau d'un BinaryDataObject
ManagementType management = mapArchiveUnitManagementBlock(archiveObject);
archiveUnit.setManagement(management);
archiveUnit.setContent(content);
return archiveUnit;
}
......@@ -812,7 +795,7 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
content.getDescription().add(descriptionSEDA21);
}
if(content.isSetDescriptionLevel()) {
if(!content.isSetDescriptionLevel()) {
content.setDescriptionLevel(mapDescriptionLevel(contentDescription));
}
......@@ -828,8 +811,6 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
* @return CustodialHistoryType
*/
private static String archiveDateRegexp = "Archivé sur la plateforme du CINES le (.*)";
private fr.gouv.culture.archivesdefrance.seda.v2.CustodialHistoryType mapCustodialHistory(fr.gouv.culture.archivesdefrance.seda.v1.ArchiveType archive) {
ObjectFactory objectFactory = new ObjectFactory();
ContentDescriptionType contentDescription = archive.getContentDescription();
......@@ -841,9 +822,11 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
for (CustodialHistoryItemType custodialHistoryItem : custodialHistoryItems) {
fr.gouv.culture.archivesdefrance.seda.v2.CustodialHistoryItemType custodialHistoryItemSEDA2 = objectFactory.createCustodialHistoryItemType();
if(!custodialHistoryItem.getValue().trim().substring(0, 37).equalsIgnoreCase("Archivé sur la plateforme du CINES le")) {
custodialHistoryItemSEDA2.setValue(custodialHistoryItem.getValue());
custodialHistorySEDA2.getCustodialHistoryItem().add(custodialHistoryItemSEDA2);
}
}
return custodialHistorySEDA2;
}
......@@ -898,7 +881,6 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
binaryDataObject.setId("OID" + Integer.toString(binaryObjectCounter));
binaryDataObject.setDataObjectVersion(BINARY_DATA_OBJECT_DEFAULT_VERSION);
// binaryDataObject.setDataObjectGroupId("IDOBJECT" + binaryObjectCounter);
// On attribut un ID à l'objet document pour pouvoir associer plus simplement
......@@ -918,6 +900,10 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
File currentFile = filePath.toFile();
if (currentFile.exists()) {
size = currentFile.length();
} else if(document.getAttachment().getFilename().equalsIgnoreCase("Content/" + this.archiveType)) {
//Le fichier n'est pas encore transféré dans le répertoire Content, il faut donc le peser à la racine
File archiveFile = this.rootFolder.resolve(Paths.get(this.archiveType)).toFile();
size = archiveFile.length();
}
}
......@@ -952,17 +938,17 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
}
FormatIdentificationType formatIdentification = extractFormatIdentification(document);
if (document.getAttachment().getFormat() != null
&& !document.getAttachment().getFormat().equals("")) {
binaryDataObject.setFormatIdentification(formatIdentification);
}
formatIdentification.setFormatLitteral(format.getLongName());
if (format.getTypeMimes() != null && format.getTypeMimes().size() > 0)
formatIdentification.setMimeType(format.getTypeMimes().get(0));
if (!format.getEncoding().equals("NA"))
formatIdentification.setEncoding(format.getEncoding());
formatIdentification.setFormatId(document.getAttachment().getFormat());
if ((formatIdentification.getMimeType()!= null) || (formatIdentification.getEncoding() != null)
|| (formatIdentification.getFormatId() != null) || (formatIdentification.getFormatLitteral() != null)) {
binaryDataObject.setFormatIdentification(formatIdentification);
}
}
if (!isOnlyManifest() && formatVideoList.contains(format.getName())) {
JAXBElement<String> jaxbElementEncoding =
......@@ -983,18 +969,15 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
}
// Checksum va dans <MessageDigest>
if (!isOnlyManifest() && document.getIntegrity() != null) {
String declaredChecksum = FileUtils.bytesToHex(empreinte);
String declaredChecksum = Base64.getEncoder().encodeToString(empreinte);
String declaredTypeChecksum = type;
String computedChecksum = computeChecksum(filePath.toString(), declaredTypeChecksum);
// if(!computedChecksum.equalsIgnoreCase(declaredChecksum) && !document.getAttachment().getFilename().equals(this.getArchiveType())) {
// logger.error("Le checksum du bordereau est différent du checksum calculé pour le fichier : {}", document.getAttachment().getFilename());
// throw new IngestRejectException("Le checksum du bordereau est différent du checksum calculé pour le fichier : " + document.getAttachment().getFilename(), "EXXX");
// }
if(!computedChecksum.equalsIgnoreCase(declaredChecksum) && !document.getAttachment().getFilename().equals("Content/" + this.getArchiveType())) {
logger.error("Le checksum du bordereau est différent du checksum calculé pour le fichier : {}", document.getAttachment().getFilename());
throw new IngestRejectException("Le checksum du bordereau est différent du checksum calculé pour le fichier : " + document.getAttachment().getFilename(), "EXXX");
}
String algorithm = "SHA-512";
String sha512 = computeChecksum(filePath.toString(), algorithm);
ArchivesHashcodeBinaryObjectType integrity = document.getIntegrity();
// String algorithm = integrity.getAlgorithme();
// String checksumValue = FileUtils.bytesToHex(integrity.getValue()).toLowerCase();
MessageDigestBinaryObjectType messageDigest = objectFactory.createMessageDigestBinaryObjectType();
messageDigest.setAlgorithm(algorithm);
......@@ -1013,7 +996,8 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
binaryDataObject.setSize(sizeValue.toBigInteger());
} else {
if (size != 0) binaryDataObject.setSize(BigInteger.valueOf(size));
if (size != 0)
binaryDataObject.setSize(BigInteger.valueOf(size));
}
// Récupération du type de document
......@@ -1090,7 +1074,6 @@ public class Seda1ToSeda21Converter extends AbstractArchiveConverter {
// Règles d'évaluation - DUA et sort final
// Attention la classe AppraisalRuleType porte le même nom en SEDA 1.0 et SEDA 2.1
ArchivesDurationType currentDuration = currentAppraisalRule.getDuration();
String appraisalRuleProperty = properties.getProperty(APPRAISAL_RULE);
CodeAppraisalType code = currentAppraisalRule.getCode();
......
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