Skip to content

Commit

Permalink
Dependencies for CITS SIARD
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard authored and hmiguim committed Nov 29, 2024
1 parent d4df5d0 commit 9ccf055
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/roda_project/commons_ip/utils/IPEnums.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class IPEnums {
public enum IPType {
SIP, AIP, DIP;
SIP, AIP, DIP, SIARD;
}

public enum IPStatus {
Expand All @@ -33,7 +33,7 @@ public static IPStatus parse(String value) {
}

public enum SipType {
EARK2S, EARK2, ERMS
EARK2S, EARK2, SIARD, ERMS
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public class ReportTypeEnums {
public enum ReportType {
COMMONS_IP("commons-ip"), PYIP("eark-validator");
COMMONS_IP("commons-ip"), PYIP("eark-validator"), SIARD("siard");

private final String type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class IPContentInformationType implements Serializable {
private static final long serialVersionUID = 1191075605637022551L;

public enum IPContentInformationTypeEnum {
ERMS, citserms_v2_1, SIARD1, SIARD2, SIARDDK, GEODATA, MIXED, OTHER, Dataset;
ERMS, citserms_v2_1, SIARD1, SIARD2, SIARDDK, GEODATA, MIXED, OTHER, Dataset, citssiard_v1_0;
}

private IPContentInformationTypeEnum type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ public static IPContentType getDataset() {
return new IPContentType(IPContentTypeEnum.DATASET);
}

public static IPContentType getDatabase() {
return new IPContentType(IPContentTypeEnum.DATABASES);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import org.apache.commons.lang3.StringUtils;
import org.roda_project.commons_ip.utils.IPEnums;
Expand Down Expand Up @@ -57,6 +58,54 @@ public abstract class EARKMETSCreator {
private static final Logger LOGGER = LoggerFactory.getLogger(EARKMETSCreator.class);
private final Map<String, MetsType.FileSec.FileGrp> dataFileGrp = new HashMap<>();

public MetsWrapper generateMetsSiard(final String id, final String label, final String profile, final boolean mainMets,
final Optional<List<String>> ancestors, final Path metsPath, final IPHeader ipHeader, final String type,
final IPContentType contentType, final IPContentInformationType contentInformationType, final boolean isMetadata,
final boolean isMetadataOther, final boolean isSchemas, final boolean isDocumentation, final boolean isSubmission,
final boolean isRepresentations, final boolean isRepresentationsData) throws IPException {
final Mets mets = new Mets();
final MetsWrapper metsWrapper = new MetsWrapper(mets, metsPath);

// basic attributes
addBasicAttributesToMets(mets, id, label, profile, contentType, contentInformationType);
// header

addHeaderToMets(mets, ipHeader, type);

// administrative section
addAmdSecToMets(mets);

// file section

final MetsType.FileSec fileSec = createFileSec();

// Add data file grp
addDataFileGrpToMets(metsWrapper, fileSec, mainMets, isRepresentationsData);

// Add schemas, documentation, submission to main div
addCommonFileGrpToMets(metsWrapper, fileSec, isSchemas, isSubmission, isDocumentation, type);

if ((mainMets && isRepresentations) || !fileSec.getFileGrp().isEmpty()) {
mets.setFileSec(fileSec);
}

// E-ARK struct map
final StructMapType structMap = createStructMap();

final DivType mainDiv = addCommonDivsToMainDiv(metsWrapper, id, isMetadata, isMetadataOther, isSchemas,
isDocumentation, isSubmission, type);

// data div
addDataDivToMets(metsWrapper, mainDiv, mainMets, isRepresentationsData);

structMap.setDiv(mainDiv);
mets.getStructMap().add(structMap);

addAncestorsToMets(mets, ancestors);

return metsWrapper;
}

public MetsWrapper generateMETS(final String id, final String label, final String profile, final boolean mainMets,
final Optional<List<String>> ancestors, final Path metsPath, final IPHeader ipHeader, final String type,
final IPContentType contentType, final IPContentInformationType contentInformationType, final boolean isMetadata,
Expand Down Expand Up @@ -251,6 +300,47 @@ public void addRepresentationMETSToZipAndToMainMETS(final Map<String, ZipEntryIn
}
}

public void addRepresentationSiardMETSToZipAndToMainMETS(final Map<String, ZipEntryInfo> zipEntries,
final MetsWrapper mainMETSWrapper, final String representationId, final MetsWrapper representationMETSWrapper,
final String representationMetsPath, final Path buildDir) throws IPException, InterruptedException {
try {
if (Thread.interrupted()) {
throw new InterruptedException();
}

// create mets pointer
final DivType.Mptr mptr = new DivType.Mptr();
mptr.setLOCTYPE(METSEnums.LocType.URL.toString());
mptr.setType(IPConstants.METS_TYPE_SIMPLE);
mptr.setHref(METSUtils.encodeHref(representationMetsPath));


// create file
final FileType fileType = new FileType();
fileType.setID(Utils.generateRandomAndPrefixedFileID());

addMETSToZip(zipEntries, representationMETSWrapper, representationMetsPath, buildDir, false, fileType);

// add to file group and then to file section
final MetsType.FileSec.FileGrp fileGrp = createFileGroup(
IPConstants.REPRESENTATIONS_WITH_FIRST_LETTER_CAPITAL + "/" + representationId);
final FileType.FLocat fileLocation = METSUtils.createFileLocation(representationMetsPath);
fileType.getFLocat().add(fileLocation);
fileGrp.getFile().add(fileType);
fileGrp.getOtherAttributes().put(QName.valueOf("csip:CONTENTINFORMATIONTYPE"), "citssiard_v1_0");
fileGrp.getOtherAttributes().put(QName.valueOf("csip:OTHERCONTENTINFORMATIONTYPE"), mainMETSWrapper.getMets().getOTHERCONTENTINFORMATIONTYPE());

mainMETSWrapper.getMets().getFileSec().getFileGrp().add(fileGrp);

// set mets pointer
final DivType representationDiv = createRepresentationDivForStructMap(representationId, mptr);
mptr.setTitle(fileGrp.getID());
mainMETSWrapper.getMainDiv().getDiv().add(representationDiv);
} catch (JAXBException | IOException e) {
throw new IPException("Error saving representation METS", e);
}
}

protected void addMETSToZip(final Map<String, ZipEntryInfo> zipEntries, final MetsWrapper metsWrapper,
final String metsPath, final Path buildDir, final boolean mainMets, final FileType fileType)
throws JAXBException, IOException, IPException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,19 @@ public Path build(WriteStrategy writeStrategy, final String fileNameWithoutExten
boolean isDocumentation = (this.getDocumentation() != null && !this.getDocumentation().isEmpty());
boolean isSchemas = (this.getSchemas() != null && !this.getSchemas().isEmpty());
boolean isRepresentations = (this.getRepresentations() != null && !this.getRepresentations().isEmpty());

MetsWrapper mainMETSWrapper = metsCreator.generateMETS(StringUtils.join(this.getIds(), " "),
this.getDescription(), this.getProfile(), true, Optional.ofNullable(this.getAncestors()), null,
this.getHeader(), this.getType(), this.getContentType(), this.getContentInformationType(), isMetadata,
isMetadataOther, isSchemas, isDocumentation, false, isRepresentations, false);

MetsWrapper mainMETSWrapper;

if (this.getType().equals("SIARD")) {
mainMETSWrapper = metsCreator.generateMetsSiard(StringUtils.join(this.getIds(), " "), this.getDescription(),
this.getProfile(), true, Optional.ofNullable(this.getAncestors()), null, this.getHeader(), this.getType(),
this.getContentType(), this.getContentInformationType(), isMetadata, isMetadataOther, isSchemas,
isDocumentation, false, isRepresentations, false);
} else {
mainMETSWrapper = metsCreator.generateMETS(StringUtils.join(this.getIds(), " "), this.getDescription(),
this.getProfile(), true, Optional.ofNullable(this.getAncestors()), null, this.getHeader(), this.getType(),
this.getContentType(), this.getContentInformationType(), isMetadata, isMetadataOther, isSchemas,
isDocumentation, false, isRepresentations, false);
}
earkUtils.addDescriptiveMetadataToZipAndMETS(zipEntries, mainMETSWrapper, getDescriptiveMetadata(), null);
earkUtils.addPreservationMetadataToZipAndMETS(zipEntries, mainMETSWrapper, getPreservationMetadata(), null);
earkUtils.addOtherMetadataToZipAndMETS(zipEntries, mainMETSWrapper, getOtherMetadata(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

import jakarta.xml.bind.JAXBException;

import javax.xml.namespace.QName;

public class EARKUtils {

private EARKMETSCreator metsGenerator;
Expand Down Expand Up @@ -169,7 +171,16 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
mainMETSWrapper.getMets().getMetsHdr().getOAISPACKAGETYPE(), representation.getContentType(),
representation.getContentInformationType(), isRepresentationMetadata, isRepresentationMetadataOther,
isRepresentationSchemas, isRepresentationDocumentation, false, false, isRepresentationsData);
} else if (!IPEnums.SipType.EARK2S.equals(sipType)) {
} else if (IPEnums.SipType.SIARD.equals(sipType)) {
representation.setContentInformationType(representation.getContentInformationType());
representationMETSWrapper = metsGenerator.generateMetsSiard(representationId, representation.getDescription(),
"https://citssiard.dilcis.eu/profile/E-ARK-SIARD-REPRESENTATION.xml", false, Optional.empty(), null, header,
mainMETSWrapper.getMets().getMetsHdr().getOAISPACKAGETYPE(), representation.getContentType(),
representation.getContentInformationType(), isRepresentationMetadata, isRepresentationMetadataOther,
isRepresentationSchemas, isRepresentationDocumentation, false, false, isRepresentationsData);
}

else if (!IPEnums.SipType.EARK2S.equals(sipType)) {
representationMETSWrapper = metsGenerator.generateMETS(representationId, representation.getDescription(),
ip.getProfile(), false, Optional.empty(), null, header,
mainMETSWrapper.getMets().getMetsHdr().getOAISPACKAGETYPE(), representation.getContentType(),
Expand All @@ -188,6 +199,9 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
if (IPEnums.SipType.ERMS.equals(sipType)) {
addRepresentationDataFilesToZipErmsAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
} else if (IPEnums.SipType.SIARD.equals(sipType)) {
addRepresentationDataFilesToZipSiardAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
} else {
addRepresentationDataFilesToZipAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
Expand Down Expand Up @@ -219,6 +233,13 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
IPConstants.REPRESENTATIONS_FOLDER + representationId + IPConstants.ZIP_PATH_SEPARATOR + IPConstants.DATA
+ IPConstants.ZIP_PATH_SEPARATOR + IPConstants.METS_FILE,
buildDir);
} else if (IPEnums.SipType.SIARD.equals(sipType)) {
metsGenerator.addRepresentationSiardMETSToZipAndToMainMETS(zipEntries, mainMETSWrapper, representationId,
representationMETSWrapper,
IPConstants.REPRESENTATIONS_FOLDER + representationId + IPConstants.ZIP_PATH_SEPARATOR + IPConstants.DATA
+ IPConstants.ZIP_PATH_SEPARATOR + IPConstants.METS_FILE,
buildDir);

} else {
metsGenerator.addRepresentationMETSToZipAndToMainMETS(zipEntries, mainMETSWrapper, representationId,
representationMETSWrapper, IPConstants.REPRESENTATIONS_FOLDER + representationId
Expand Down Expand Up @@ -269,6 +290,46 @@ private void addRepresentationDataFilesToZipErmsAndMETS(IPInterface ip, Map<Stri
sip.notifySipBuildRepresentationProcessingEnded();
}
}

}

private void addRepresentationDataFilesToZipSiardAndMETS(IPInterface ip, Map<String, ZipEntryInfo> zipEntries,
MetsWrapper representationMETSWrapper, IPRepresentation representation, String representationId)
throws InterruptedException, IPException {
if (representation.getData() != null && !representation.getData().isEmpty()) {
if (ip instanceof SIP sip) {
sip.notifySipBuildRepresentationProcessingStarted(representation.getData().size());
}
int i = 0;
for (IPFileInterface file : representation.getData()) {
if (Thread.interrupted()) {
throw new InterruptedException();
}

if (file instanceof IPFile) {
String dataFilePath = ModelUtils.getFoldersFromList(file.getRelativeFolders()) + file.getFileName();
FileType fileType = metsGenerator.addDataFileToMETS(representationMETSWrapper, dataFilePath, file.getPath());
if (representation.getContentInformationType().getOtherType() != null) {
fileType.getOtherAttributes().put(QName.valueOf("csip:OTHERCONTENTINFORMATIONTYPE"),
representation.getContentInformationType().getOtherType());
}
dataFilePath = IPConstants.DATA_FOLDER + dataFilePath;
dataFilePath = IPConstants.REPRESENTATIONS_FOLDER + representationId + IPConstants.ZIP_PATH_SEPARATOR
+ dataFilePath;
ZIPUtils.addFileTypeFileToZip(zipEntries, file.getPath(), dataFilePath, fileType);
} else if (file instanceof IPFileShallow shallow && (shallow.getFileLocation() != null)) {
metsGenerator.addDataFileToMETS(representationMETSWrapper, shallow);
}

i++;
if (ip instanceof SIP sip) {
sip.notifySipBuildRepresentationProcessingCurrentStatus(i);
}
}
if (ip instanceof SIP sip) {
sip.notifySipBuildRepresentationProcessingEnded();
}
}
}

protected void addRepresentationDataFilesToZipAndMETS(IPInterface ip, Map<String, ZipEntryInfo> zipEntries,
Expand Down

0 comments on commit 9ccf055

Please sign in to comment.