Commit 13dd4389 authored by marceteau's avatar marceteau
Browse files

ajout access rule + file plan (travail en cours)

parent 74a25272
......@@ -112,7 +112,11 @@ public abstract class AbstractArchiveConverter implements ManifestConverter {
*/
public enum ACCESS_RULE {
AR038("ACC-00001"); // librement communicable
AR038("ACC-00001"), // librement communicable
AR039("ACC-00002"),
AR042("ACC-00005"),
AR048("ACC-00020"),
AR052("ACC-00023");
public final String value;
......
......@@ -94,6 +94,7 @@ public class ArchiveConverterMain {
options.addOption("o", "output-dir", true, "Répertoire de sortie");
options.addOption("e", "error-dir", true, "Répertoire où seront placés les paquets en erreur");
options.addOption("l", "language-error-dir", true, "Répertoire où seront placés les paquets en erreur à cause de l'attribut language");
options.addOption("p", "plan-classement", true, "Chemin du fichier csv indiquant le plan de classement");
CommandLine commandLine = parser.parse(options, args);
......
......@@ -27,10 +27,12 @@
*/
package fr.cines.pac.converter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
......@@ -55,7 +57,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
......@@ -93,6 +94,7 @@ import fr.cines.pac.aip.FichMetaType;
import fr.cines.pac.aip.PacType;
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.validator.ValidatorFactory;
import fr.gouv.culture.archivesdefrance.seda.v2.AccessRuleType;
......@@ -120,6 +122,7 @@ import fr.gouv.culture.archivesdefrance.seda.v2.LevelType;
import fr.gouv.culture.archivesdefrance.seda.v2.LogBookOgType;
import fr.gouv.culture.archivesdefrance.seda.v2.LogBookType;
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.OrganizationType;
......@@ -208,6 +211,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
private static final String TRANSFERING_AGENCY_IDENTIFIER = "TransferringAgency_Identifier";
private static final String ORIGINATING_AGENCY_IDENTIFIER = "OriginatingAgencyIdentifier";
private static final String SUBMISSION_AGENCY_IDENTIFIER = "SubmissionAgencyIdentifier";
private static final String ARCHIVE_UNIT_PROFILE = "ArchiveUnitProfile";
private static final String IDENTIFIANT_DOC_PRODUCTEUR = "IdentifiantDocProducteur";
private static final String VERSION = "version";
private static final String COVERAGE = "coverage";
......@@ -215,6 +219,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
private static final String ORIGINATING_AGENCY_ARCHIVE_UNIT_IDENTIFIER = "OriginatingAgencyArchiveUnitIdentifier";
private static final String TRANSFERRING_AGENCY_ARCHIVE_UNIT_IDENTIFIER = "TransferringAgencyArchiveUnitIdentifier";
private static final String CINES_DC_FORMAT = "format";
private static final String APPRAISAL_RULE = "AppraisalRule_Rule";
/**
* Label présent dans des balises, à ne pas mapper en Tag
*/
......@@ -474,6 +479,12 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
// Un par objet binaire
String archiveUnitProfileProp = properties.getProperty(ARCHIVE_UNIT_PROFILE);
if (!"".equals(archiveUnitProfileProp) && !"false".equalsIgnoreCase(archiveUnitProfileProp)) {
IdentifierType archiveUnitProfile = objectFactory.createIdentifierType();
rootArchiveUnit.setArchiveUnitProfile(archiveUnitProfile);
}
if (dataObjectGroupList.size() > 1) {
List<ArchiveUnitType> archiveUnits = mapDataObjectMetadataToArchiveUnit(binaryDataObjectWithTypeList, sip);
rootArchiveUnit.getArchiveUnitOrArchiveUnitReferenceAbstractOrDataObjectReference().addAll(archiveUnits);
......@@ -522,8 +533,42 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
boolean generateFilePlan = Boolean.parseBoolean(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();
content.getFilePlanPosition().add(filePlan);
try {
String[] filePlanLine = filePlanData("/home/marceteau/git/vitam-data-test/VITAM_CINES_CONNECTOR/Properties/BSG_PDC_test.txt", filePlan);
String systemId = filePlanLine[1];
String descriptionLevelStr = filePlanLine[2];
TextType title = objectFactory.createTextType();
title.setValue(filePlanLine[3]);
//Ajout de l'Archive Unit fantome
ArchiveUnitType ghostArchiveUnit = objectFactory.createArchiveUnitType();
ArchiveUnitType ghostArchiveUnitAttachment = objectFactory.createArchiveUnitType();
descriptiveMetadata.getArchiveUnit().add(ghostArchiveUnit);
archiveUnitCounter++;
ghostArchiveUnit.setId("ID" + archiveUnitCounter);
archiveUnitCounter++;
ghostArchiveUnitAttachment.setId("ID" + archiveUnitCounter);
String refId = rootArchiveUnit.getId();
//ghostArchiveUnitAttachment.setArchiveUnitRefId(refId);
DescriptiveMetadataContentType ghostContent = objectFactory.createDescriptiveMetadataContentType();
ManagementType ghostManagement = objectFactory.createManagementType();
ghostContent.getSystemId().add(systemId);
ghostContent.setDescriptionLevel(LevelType.fromValue(descriptionLevelStr));
ghostContent.getTitle().add(title);
//ghostManagement.getOtherManagementAbstract().add(createXMLElement("toto", "UpdateOperation"));
ghostArchiveUnit.setManagement(ghostManagement);
ghostArchiveUnit.setContent(ghostContent);
ghostArchiveUnit.getArchiveUnitOrArchiveUnitReferenceAbstractOrDataObjectReference().add(ghostArchiveUnitAttachment);
} catch (Exception e) {
e.printStackTrace();
}
}
String idDocProducteurTarget = properties.getProperty(IDENTIFIANT_DOC_PRODUCTEUR);
......@@ -645,9 +690,14 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
} else {
StringBuilder concatenateType = new StringBuilder();
List<StringNotNULLtext> listType = sip.getDocDC().getType();
for (StringNotNULLtext t : listType) {
concatenateType.append(t.getValue());
concatenateType.append(". ");
if(concatenateType.toString().equals("")) {
concatenateType.append(t.getValue());
} else {
concatenateType.append(" | ");
concatenateType.append(t.getValue());
}
}
documentTypeText.setValue(concatenateType.toString());
}
......@@ -734,7 +784,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
sourceString += " | " + source.getValue();
}
}
return sourceString.substring(0, sourceString.length()-1);
return sourceString;
}
private List<AgentType> mapWriters(DocDCType docDC) {
......@@ -798,6 +848,7 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
private AppraisalRuleType mapAppraisalRules(DocMetaType docMetaType) {
AppraisalRuleType appraisalRule = objectFactory.createAppraisalRuleType();
String appraisalRuleProperty = properties.getProperty(APPRAISAL_RULE);
// Règles d'évaluation - DUA et sort final
if (docMetaType.getSortFinal() != null) {
String sortFinal = docMetaType.getSortFinal().getValue();
......@@ -808,48 +859,49 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
finalActionCodeType = FinalActionAppraisalCodeType.DESTROY;
}
appraisalRule.setFinalAction(finalActionCodeType);
RuleIdType ruleIdType = objectFactory.createRuleIdType();
ruleIdType.setValue("APP-1069004");
if(!appraisalRuleProperty.equals("false")) {
XMLGregorianCalendar startDate = null;
String startDateFormated = null;
try {
startDate = getXMLGregorianCalendar(docMetaType.getDateArchivage(), "yyyy-MM-dd'T'HH:mm:ssX");
//startDate = getXMLGregorianCalendar(docMetaType.getEvaluation().getDateDebut(), "yyyy-MM-dd'T'HH:mm:ssX");
//startDateFormated = getDateFormated(startDate, "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
RuleIdType ruleIdType = objectFactory.createRuleIdType();
ruleIdType.setValue(appraisalRuleProperty);
appraisalRule.getRuleAndStartDate().add(ruleIdType);
appraisalRule.getRuleAndStartDate().add(startDate);
XMLGregorianCalendar startDate = null;
try {
startDate = getXMLGregorianCalendar(docMetaType.getDateArchivage(), "yyyy-MM-dd'T'HH:mm:ssX");
//startDate = getXMLGregorianCalendar(docMetaType.getEvaluation().getDateDebut(), "yyyy-MM-dd'T'HH:mm:ssX");
//startDateFormated = getDateFormated(startDate, "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
appraisalRule.getRuleAndStartDate().add(ruleIdType);
appraisalRule.getRuleAndStartDate().add(startDate);
}
}
if (docMetaType.getEvaluation() != null) {
RuleIdType ruleIdType = objectFactory.createRuleIdType();
ruleIdType.setValue("APP-00007");
ruleIdType.setValue(appraisalRuleProperty);
XMLGregorianCalendar startDate = null;
String startDateFormated = null;
try {
startDate = getXMLGregorianCalendar(docMetaType.getDateArchivage(), "yyyy-MM-dd'T'HH:mm:ssX");
//startDateFormated = getDateFormated(startDate, "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
}
startDate = docMetaType.getEvaluation().getDateDebut();
//startDateFormated = getDateFormated(startDate, "yyyy-MM-dd");
appraisalRule.getRuleAndStartDate().add(ruleIdType);
appraisalRule.getRuleAndStartDate().add(startDate);
appraisalRule.setFinalAction(FinalActionAppraisalCodeType.KEEP);
String sortFinal = docMetaType.getEvaluation().getTraitement().getValue().value().trim().toUpperCase();
FinalActionAppraisalCodeType finalActionCodeType = null;
if(sortFinal.equals("Conservation définitive".trim().toUpperCase())) {
finalActionCodeType = FinalActionAppraisalCodeType.KEEP;
} else {
finalActionCodeType = FinalActionAppraisalCodeType.DESTROY;
}
appraisalRule.setFinalAction(finalActionCodeType);
}
return appraisalRule;
......@@ -1584,6 +1636,45 @@ public class DCToSeda21Converter extends AbstractArchiveConverter {
return list;
}
/**
* cherche la ligne contenant le bon planClassement dans le fichier voulu
* puis retourne un tableau de string contenant les valeurs planClassement, sydtemId, descriptionLevel, title
* la ligne qui ne contient qu'un "/" est considérée comme valeur par défaut dans le cas où le plan de classement n'est pas trouvé dans la liste
*
* @param filePath
* @param planClassement
* @return
* @throws Exception
*/
public static String[] filePlanData(String filePath, String planClassement) throws Exception
{
BufferedReader br = new BufferedReader(new FileReader(filePath));
String ligne = null;
//Si planClassement termine ou commence par un / on le retire
if(planClassement.endsWith("/"))
planClassement = planClassement.substring(0, planClassement.length() - 1);
if(planClassement.startsWith("/") && planClassement.length() > 1)
planClassement = planClassement.substring(1, planClassement.length());
while ((ligne = br.readLine()) != null)
{
// Retourner la ligne dans un tableau
String[] data = ligne.split("\t");
if (data.length == 4) {
String planClassementFile = data[0].trim();
if(planClassement.equals(planClassementFile)) {
return data;
}
}
}
br.close();
//TODO : lever une exception car on n'a pas d'équivalent dans le fichier de référence
return null;
}
public List<DataObjectMapper> getDataObjectMapper() {
return dataObjectMapper;
......
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