Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Jul 19, 2024
1 parent ed6005c commit 4c571b5
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 23 deletions.
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 @@ -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 @@ -7,6 +7,15 @@
*/
package org.roda_project.commons_ip2.model.impl.eark;

import java.io.IOException;
import java.nio.channels.ClosedByInterruptException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.roda_project.commons_ip.model.ParseException;
import org.roda_project.commons_ip.utils.IPEnums;
Expand All @@ -24,15 +33,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.channels.ClosedByInterruptException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public class EARKSIP extends SIP {
private static final Logger LOGGER = LoggerFactory.getLogger(EARKSIP.class);

Expand Down Expand Up @@ -217,12 +217,19 @@ public Path build(final Path destinationDirectory, final String fileNameWithoutE
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 All @@ -242,7 +249,6 @@ public Path build(final Path destinationDirectory, final String fileNameWithoutE
}
}


private Path getZipPath(Path destinationDirectory, String fileNameWithoutExtension) throws IPException {
Path zipPath;
if (fileNameWithoutExtension != null) {
Expand Down Expand Up @@ -280,5 +286,4 @@ public Set<String> getExtraChecksumAlgorithms() {
return Collections.emptySet();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

import jakarta.xml.bind.JAXBException;

import javax.xml.namespace.QName;

public class EARKUtils {

private EARKMETSCreator metsGenerator;
Expand Down Expand Up @@ -165,10 +167,11 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
final MetsWrapper representationMETSWrapper;

if (IPEnums.SipType.SIARD.equals(sipType)) {
representationMETSWrapper = metsGenerator.generateMETS(representationId, representation.getDescription(),
"https://citssiard.dilcis.eu/profile/E-ARK-SIARDREPRESENTATION.xml", false, Optional.empty(), null, header,
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(),
new IPContentInformationType("citssiard_v1_0"), isRepresentationMetadata, isRepresentationMetadataOther,
representation.getContentInformationType(), isRepresentationMetadata, isRepresentationMetadataOther,
isRepresentationSchemas, isRepresentationDocumentation, false, false, isRepresentationsData);
} else if (!IPEnums.SipType.EARK2S.equals(sipType)) {
representationMETSWrapper = metsGenerator.generateMETS(representationId, representation.getDescription(),
Expand Down Expand Up @@ -215,7 +218,7 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat

// add representation METS to Zip file and to main METS file
if (IPEnums.SipType.SIARD.equals(sipType)) {
metsGenerator.addRepresentationMETSToZipAndToMainMETS(zipEntries, mainMETSWrapper, representationId,
metsGenerator.addRepresentationSiardMETSToZipAndToMainMETS(zipEntries, mainMETSWrapper, representationId,
representationMETSWrapper,
IPConstants.REPRESENTATIONS_FOLDER + representationId + IPConstants.ZIP_PATH_SEPARATOR + IPConstants.DATA
+ IPConstants.ZIP_PATH_SEPARATOR + IPConstants.METS_FILE,
Expand Down Expand Up @@ -252,7 +255,9 @@ private void addRepresentationDataFilesToZipSiardAndMETS(IPInterface ip, Map<Str
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;
Expand Down

0 comments on commit 4c571b5

Please sign in to comment.