Skip to content

Commit

Permalink
Dependencies for CITS ERMS
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Nov 28, 2024
1 parent fee73f5 commit 9a28fc6
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IPStatus parse(String value) {
}

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

}
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 <[email protected]>
*/
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 <[email protected]>
*/
public class ReportTypeEnums {
public enum ReportType {
COMMONS_IP("commons-ip"), PYIP("eark-validator");

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, citserms_v2_1, 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,8 @@ public String asString() {
public static IPContentType getMIXED() {
return new IPContentType(IPContentTypeEnum.MIXED);
}
public static IPContentType getDataset() {
return new IPContentType(IPContentTypeEnum.DATASET);
}

}
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 @@ -212,7 +226,6 @@ public Path build(WriteStrategy writeStrategy, final String fileNameWithoutExten
throw e;
} finally {
ModelUtils.deleteBuildDir(buildDir);
notifySipBuildPackagingEnded();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
final boolean isRepresentationsData = (representation.getData() != null && !representation.getData().isEmpty());
final IPHeader header = new IPHeader(IPEnums.IPStatus.NEW).setAgents(representation.getAgents());
final MetsWrapper representationMETSWrapper;
if (!IPEnums.SipType.EARK2S.equals(sipType)) {

if (IPEnums.SipType.ERMS.equals(sipType)) {
representationMETSWrapper = metsGenerator.generateMETS(representationId, representation.getDescription(),
ip.getProfile(), 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 @@ -178,8 +185,13 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
representationMETSWrapper.getMainDiv().setTYPE(representation.getStatus().asString());

// representation data
addRepresentationDataFilesToZipAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
if (IPEnums.SipType.ERMS.equals(sipType)) {
addRepresentationDataFilesToZipErmsAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
} else {
addRepresentationDataFilesToZipAndMETS(ip, zipEntries, representationMETSWrapper, representation,
representationId);
}

// representation descriptive metadata
addDescriptiveMetadataToZipAndMETS(zipEntries, representationMETSWrapper,
Expand All @@ -201,17 +213,62 @@ protected void addRepresentationsToZipAndMETS(IPInterface ip, List<IPRepresentat
representationId);

// add representation METS to Zip file and to main METS file
metsGenerator.addRepresentationMETSToZipAndToMainMETS(zipEntries, mainMETSWrapper, representationId,
representationMETSWrapper, IPConstants.REPRESENTATIONS_FOLDER + representationId
+ IPConstants.ZIP_PATH_SEPARATOR + IPConstants.METS_FILE,
buildDir);
if (IPEnums.SipType.ERMS.equals(sipType)) {
metsGenerator.addRepresentationMETSToZipAndToMainMETS(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
+ IPConstants.ZIP_PATH_SEPARATOR + IPConstants.METS_FILE,
buildDir);
}

metsGenerator.cleanFileGrpStructure();
}
if (ip instanceof SIP) {
((SIP) ip).notifySipBuildRepresentationsProcessingEnded();
}
}

}

private void addRepresentationDataFilesToZipErmsAndMETS(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());

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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ public InputStream getMetsRootInputStream(final Path path) throws FileNotFoundEx
return new FileInputStream(metsPath);
}

public InputStream getErmsInputStream(final Path path) throws FileNotFoundException {
folder = path.toFile();
String ermsPath = null;
for (File f : folder.listFiles()) {
if (f.getName().endsWith("erms.xml")) {
ermsPath = f.getPath();
}
}
if (ermsPath == null) {
LOGGER.debug("ERMS.xml not Found");
throw new FileNotFoundException("ERMS.xml not Found");
}
return new FileInputStream(ermsPath);
}

public String getSipRootFolderName(final Path path) {
final String[] tmp = path.toString().split("/");
return tmp[tmp.length - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ public InputStream getMetsRootInputStream(Path path) throws IOException {
return zipFile.getInputStream(zipArchiveEntry);
}

/**
* Get ERMS file in IP {@link InputStream}.
*
* @param path
* {@link Path} to the IP
* @return {@link InputStream} to the file.
* @throws IOException
* if some I/O error occurs
*/
public InputStream getErmsInputStream(Path path) throws IOException {
if (zipFile == null) {
zipFile = new ZipFile(path.toFile());
}

Enumeration entries = zipFile.entries();
String entry = null;
while (entries.hasMoreElements()) {
ZipEntry entr = (ZipEntry) entries.nextElement();
if (entr.getName().endsWith("erms.xml")) {
if (entr.getName().split("/").length == 4) {
entry = entr.getName();
}
}
}
if (entry == null) {
LOGGER.debug("ERMS.xml not Found");
throw new IOException("ERMS.xml not Found");
}
ZipEntry zipArchiveEntry = zipFile.getEntry(entry);
return zipFile.getInputStream(zipArchiveEntry);
}

public Enumeration getEntries() {
return zipFile.entries();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<Term lang="en">Datasets</Term>
<Definition>Data encoded in a defined structure.</Definition>
</Entry>
<Entry>
<Term lang="en">Dataset</Term>
<Definition>Data encoded in a defined structure.</Definition>
</Entry>
<Entry>
<Term lang="en">Geospatial Data</Term>
<Definition></Definition>
Expand Down

0 comments on commit 9a28fc6

Please sign in to comment.