Skip to content

Commit

Permalink
Dependencies for CITS SIARD
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Nov 28, 2024
1 parent fee73f5 commit 27b515c
Show file tree
Hide file tree
Showing 13 changed files with 302 additions and 57 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
EARK2S, EARK2, SIARD
}

}
43 changes: 22 additions & 21 deletions src/main/java/org/roda_project/commons_ip2/cli/Validate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.xml.parsers.ParserConfigurationException;

import org.roda_project.commons_ip2.cli.model.ExitCodes;
import org.roda_project.commons_ip2.cli.model.enums.ReportType;
import org.roda_project.commons_ip2.cli.model.enums.ReportTypeEnums;
import org.roda_project.commons_ip2.cli.model.exception.CLIException;
import org.roda_project.commons_ip2.cli.model.exception.ValidationException;
import org.roda_project.commons_ip2.cli.utils.CLI.ValidateCommandUtils;
Expand All @@ -27,6 +27,9 @@

import picocli.CommandLine;

import static org.roda_project.commons_ip2.cli.model.enums.ReportTypeEnums.ReportType.COMMONS_IP;
import static org.roda_project.commons_ip2.cli.model.enums.ReportTypeEnums.ReportType.PYIP;

/**
* @author Miguel Guimarães <mguimaraes@keep.pt>
*/
Expand All @@ -48,7 +51,7 @@ public class Validate implements Callable<Integer> {

@CommandLine.Option(names = {"-r",
"--reporter-type"}, paramLabel = "<type>", description = "Report type (possible values: ${COMPLETION-CANDIDATES})")
ReportType reportType = ReportType.COMMONS_IP;
ReportTypeEnums.ReportType reportType = COMMONS_IP;

@CommandLine.Option(names = {"-v",
"--verbose"}, description = "Verbose command line output with all validation steps")
Expand All @@ -72,7 +75,7 @@ public Integer call() throws ValidationException, CLIException {
return ExitCodes.EXIT_CODE_OK;
}

private void handleSipValidation(final String sip, final String reportPathDir, final ReportType reportType,
private void handleSipValidation(final String sip, final String reportPathDir, final ReportTypeEnums.ReportType reportType,
final boolean verbose)
throws IOException, ParserConfigurationException, SAXException, CLIException, NoSuchAlgorithmException {
final Path sipPath = Paths.get(sip);
Expand All @@ -83,27 +86,25 @@ private void handleSipValidation(final String sip, final String reportPathDir, f

LogSystem.logOperatingSystemInfo();
LOGGER.debug("command executed: {}", commandLineString);
switch (reportType) {
case COMMONS_IP -> {
final OutputStream outputStream = ValidateCommandUtils.createReportOutputStream(reportPath);
if (outputStream != null) {
final ValidationReportOutputJson jsonReporter = new ValidationReportOutputJson(sipPath, outputStream);
final EARKSIPValidator earksipValidator = new EARKSIPValidator(jsonReporter, version);
if (verbose) {
earksipValidator.addObserver(new ProgressValidationLoggerObserver());
}
earksipValidator.validate(version);
}
}
case PYIP -> {
final ValidationReportOutputJSONPyIP jsonReporter = new ValidationReportOutputJSONPyIP(reportPath, sipPath);
final EARKPyIPValidator earkPyIPValidator = new EARKPyIPValidator(jsonReporter, version);
if (reportType.equals(COMMONS_IP)) {
final OutputStream outputStream = ValidateCommandUtils.createReportOutputStream(reportPath);
if (outputStream != null) {
final ValidationReportOutputJson jsonReporter = new ValidationReportOutputJson(sipPath, outputStream);
final EARKSIPValidator earksipValidator = new EARKSIPValidator(jsonReporter, version);
if (verbose) {
earkPyIPValidator.addObserver(new ProgressValidationLoggerObserver());
earksipValidator.addObserver(new ProgressValidationLoggerObserver());
}
earkPyIPValidator.validate();
earksipValidator.validate(version);
}
} else if (reportType.equals(PYIP)) {
final ValidationReportOutputJSONPyIP jsonReporter = new ValidationReportOutputJSONPyIP(reportPath, sipPath);
final EARKPyIPValidator earkPyIPValidator = new EARKPyIPValidator(jsonReporter, version);
if (verbose) {
earkPyIPValidator.addObserver(new ProgressValidationLoggerObserver());
}
default -> throw new CLIException("Unexpected value: " + reportType);
earkPyIPValidator.validate();
} else {
throw new CLIException("Unexpected value: " + reportType);
}
new CommandLine(this).getOut().printf("E-ARK SIP validation report at '%s'%n",
reportPath.normalize().toAbsolutePath());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.roda_project.commons_ip2.cli.model.enums;

/**
* @author Miguel Guimarães <mguimaraes@keep.pt>
*/
public class ReportTypeEnums {
public enum ReportType {
COMMONS_IP("commons-ip"), PYIP("eark-validator"), SIARD("siard");

private final String type;

ReportType(String type) {
this.type = type;
}

@Override
public String toString() {
return type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ private static void addRepresentationToSIP(SIP sip, final RepresentationGroup re
}
}

public static void addRepresentationGroupsToErmsSIP(SIP sip, final List<RepresentationGroup> representationGroups,
boolean targetOnly) throws IPException {
if (representationGroups != null) {
for (RepresentationGroup representationGroup : representationGroups) {
addRepresentationToSIP(sip, representationGroup, targetOnly);
}
}
}

private static void addFileToRepresentation(final IPRepresentation representation, final boolean targetOnly,
final Path dataPath, final List<String> relativePath) {
if (Files.isDirectory(dataPath)) {
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, SIARD1, SIARD2, SIARDDK, GEODATA, MIXED, OTHER;
ERMS, citssiard_v1_0, SIARD1, SIARD2, SIARDDK, GEODATA, MIXED, OTHER, Dataset;
}

private IPContentInformationTypeEnum type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum IPContentTypeEnum {
AUDIO_ON_TANGIBLE_MEDIUM("Audio – On Tangible Medium (digital or analog)"),
AUDIO_MEDIA_INDEPENDENT("Audio – Media-independent (digital)"),
MOTION_PICTURES("Motion Pictures – Digital and Physical Media"), VIDEO("Video – File-based and Physical Media"),
SOFTWARE("Software"), DATASETS("Datasets"), GEOSPATIAL_DATA("Geospatial Data"), DATABASES("Databases"),
SOFTWARE("Software"), DATASETS("Datasets"), DATASET("Dataset"), GEOSPATIAL_DATA("Geospatial Data"), DATABASES("Databases"),
WEBSITES("Websites"), COLLECTION("Collection"), EVENT("Event"), INTERACTIVE_RESOURCE("Interactive resource"),
PHYSICAL_OBJECT("Physical object"), SERVICE("Service"), MIXED("Mixed"), OTHER("Other");

Expand Down Expand Up @@ -131,4 +131,12 @@ public String asString() {
public static IPContentType getMIXED() {
return new IPContentType(IPContentTypeEnum.MIXED);
}
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 @@ -147,6 +147,20 @@ public Path build(WriteStrategy writeStrategy) throws IPException, InterruptedEx
return build(writeStrategy, false);
}

/**
* Builds a SIP.
*
* @param destinationDirectory
* the {@link Path} where the SIP should be build.
* @param onlyManifest
* build only the manifest file? (<strong>this parameter is
* ignored</strong>).
* @return the {@link Path}.
* @throws IPException
* if some error occurs.
* @throws InterruptedException
* if some error occurs.
*/
@Override
public Path build(WriteStrategy writeStrategy, final boolean onlyManifest)
throws IPException, InterruptedException {
Expand Down Expand Up @@ -190,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
Loading

0 comments on commit 27b515c

Please sign in to comment.