Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.xml.parsers.ParserConfigurationException;

import org.roda_project.commons_ip2.cli.model.exception.UnmarshallerException;
import org.roda_project.commons_ip2.mets_v1_12.beans.MetsType;
import org.roda_project.commons_ip2.validator.common.InstatiateMets;
import org.roda_project.commons_ip2.validator.components.MetsValidator;
import org.roda_project.commons_ip2.validator.components.StructureValidatorImpl;
Expand Down Expand Up @@ -264,7 +265,8 @@ private void validateSubMets(final Map<String, InputStream> subMets, final boole
for (Map.Entry<String, InputStream> entry : subMets.entrySet()) {
final InstatiateMets instatiateMets = new InstatiateMets(entry.getValue());
metsValidatorState.setMets(instatiateMets.instatiateMetsFile(entry.getKey()));
metsValidatorState.setIpType(metsValidatorState.getMets().getMetsHdr().getOAISPACKAGETYPE());
final MetsType.MetsHdr subMetsHdr = metsValidatorState.getMets().getMetsHdr();
metsValidatorState.setIpType(subMetsHdr == null ? null : subMetsHdr.getOAISPACKAGETYPE());
setupMetsValidatorState(entry.getKey(), isZip, false);
validateComponents();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.xml.parsers.ParserConfigurationException;

import org.roda_project.commons_ip2.cli.model.exception.UnmarshallerException;
import org.roda_project.commons_ip2.mets_v1_12.beans.MetsType;
import org.roda_project.commons_ip2.validator.common.InstatiateMets;
import org.roda_project.commons_ip2.validator.components.MetsValidator;
import org.roda_project.commons_ip2.validator.components.StructureValidatorImpl;
Expand Down Expand Up @@ -245,7 +246,8 @@ private void validateSubMets(final Map<String, InputStream> subMets, final boole
final InstatiateMets instatiateMets = new InstatiateMets(entry.getValue());
try {
metsValidatorState.setMets(instatiateMets.instatiateMetsFile(entry.getKey()));
metsValidatorState.setIpType(metsValidatorState.getMets().getMetsHdr().getOAISPACKAGETYPE());
final MetsType.MetsHdr subMetsHdr = metsValidatorState.getMets().getMetsHdr();
metsValidatorState.setIpType(subMetsHdr == null ? null : subMetsHdr.getOAISPACKAGETYPE());
setupMetsValidatorState(entry.getKey(), isZip, false);
validateComponents();
} catch (IOException | UnmarshallerException e) {
Expand Down Expand Up @@ -319,7 +321,8 @@ private void validateRootMets() {
metsValidatorState.setIsRootMets(true);

metsValidatorState.setMets(metsRoot.instatiateMetsFile(Constants.METS_FILE));
metsValidatorState.setIpType(metsValidatorState.getMets().getMetsHdr().getOAISPACKAGETYPE());
final MetsType.MetsHdr rootMetsHdr = metsValidatorState.getMets().getMetsHdr();
metsValidatorState.setIpType(rootMetsHdr == null ? null : rootMetsHdr.getOAISPACKAGETYPE());
validateComponents();
} catch (IOException | UnmarshallerException e) {
final String message = createExceptionMessage(e,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -92,8 +93,15 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
if (mdRef != null && mdRef.getHref() != null) {

String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()), Constants.UTF_8);
Path path = Paths.get(hrefDecoded);
hrefDecoded = path.normalize().toString();
try {
hrefDecoded = Paths.get(hrefDecoded).normalize().toString();
} catch (InvalidPathException e) {
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(
"mets/dmdSec/mdRef/@href (" + hrefDecoded + ") in %1$s is not a valid path: " + e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
}
if (metsValidatorState.isRootMets()) {
if (metadataFiles.containsKey(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded)) {
metadataFiles.replace(mets.getOBJID() + Constants.SEPARATOR + hrefDecoded, true);
Expand Down Expand Up @@ -183,9 +191,17 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
metadataFiles.replace(path, true);
try {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
metadataFiles.replace(path, true);
}
} catch (InvalidPathException e) {
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(
"mets/dmdSec/mdRef/@href (" + hrefDecoded + ") in %1$s is not a valid path: " + e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
}
}
}
Expand All @@ -198,9 +214,19 @@ protected ReporterDetails validateCSIP17(final StructureValidatorState structure
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(mdRef.getHref()),
Constants.UTF_8);
if (hrefDecoded != null) {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded).toString();
if (metadataFiles.containsKey(path)) {
metadataFiles.replace(path, true);
try {
final String path = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded)
.toString();
if (metadataFiles.containsKey(path)) {
metadataFiles.replace(path, true);
}
} catch (InvalidPathException e) {
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(
"mets/amdSec/*/mdRef/@href (" + hrefDecoded + ") in %1$s is not a valid path: "
+ e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
}
}
}
Expand Down Expand Up @@ -444,22 +470,28 @@ protected ReporterDetails validateCSIP24(final StructureValidatorState structure
metsValidatorState.isRootMets()));
}
} else {
if (StringUtils.isBlank(href)){
message.append("mets/dmdSec/mdRef/@xlink:href ")
.append(Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded))
.append(" in %1$s is empty");
Path resolvedPath = null;
try {
resolvedPath = Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded);
} catch (InvalidPathException e) {
details.setValid(false);
details.addIssue(Message.createErrorMessage(message.toString(), metsValidatorState.getMetsName(),
metsValidatorState.isRootMets()));
details.addIssue(Message.createErrorMessage(
"mets/dmdSec/mdRef/@xlink:href (" + hrefDecoded + ") in %1$s is not a valid path: " + e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()));
}
if (!structureValidatorState.getFolderManager()
.checkPathExists(Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded))) {
message.append("mets/dmdSec/mdRef/@xlink:href ")
.append(Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded))
.append(" in %1$s does not exist");
details.setValid(false);
details.addIssue(Message.createErrorMessage(message.toString(), metsValidatorState.getMetsName(),
metsValidatorState.isRootMets()));
if (resolvedPath != null) {
if (StringUtils.isBlank(href)) {
message.append("mets/dmdSec/mdRef/@xlink:href ").append(resolvedPath).append(" in %1$s is empty");
details.setValid(false);
details.addIssue(Message.createErrorMessage(message.toString(), metsValidatorState.getMetsName(),
metsValidatorState.isRootMets()));
}
if (!structureValidatorState.getFolderManager().checkPathExists(resolvedPath)) {
message.append("mets/dmdSec/mdRef/@xlink:href ").append(resolvedPath).append(" in %1$s does not exist");
details.setValid(false);
details.addIssue(Message.createErrorMessage(message.toString(), metsValidatorState.getMetsName(),
metsValidatorState.isRootMets()));
}
}
}
} else {
Expand Down Expand Up @@ -567,22 +599,23 @@ protected ReporterDetails validateCSIP27(final StructureValidatorState structure
metsValidatorState.isRootMets()),false, false);
}
} else {
if (metsValidatorState.isRootMets()) {
if (!structureValidatorState.getFolderManager()
.verifySize(structureValidatorState.getIpPath().resolve(hrefDecoded), size)) {
message.append("mets/dmdSec/mdRef/@SIZE ").append(size).append(" in %1$s and size of file (")
.append(structureValidatorState.getIpPath().resolve(hrefDecoded)).append(") isn't equal");
return new ReporterDetails(getCSIPVersion(), Message.createErrorMessage(
message.toString(), metsValidatorState.getMetsName(), metsValidatorState.isRootMets()), false, false);
}
} else {
if (!structureValidatorState.getFolderManager()
.verifySize(Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded), size)) {
message.append("mets/dmdSec/mdRef/@SIZE ").append(size).append(" in %1$s and size of file (")
.append(structureValidatorState.getIpPath().resolve(hrefDecoded).toString()).append(") isn't equal");
return new ReporterDetails(getCSIPVersion(), Message.createErrorMessage(
message.toString(), metsValidatorState.getMetsName(), metsValidatorState.isRootMets()), false, false);
}
final Path resolvedHrefPath;
try {
resolvedHrefPath = metsValidatorState.isRootMets()
? structureValidatorState.getIpPath().resolve(hrefDecoded)
: Paths.get(metsValidatorState.getMetsPath()).resolve(hrefDecoded);
} catch (InvalidPathException e) {
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(
"mets/dmdSec/mdRef/@href (" + hrefDecoded + ") in %1$s is not a valid path: " + e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
}
if (!structureValidatorState.getFolderManager().verifySize(resolvedHrefPath, size)) {
message.append("mets/dmdSec/mdRef/@SIZE ").append(size).append(" in %1$s and size of file (")
.append(resolvedHrefPath).append(") isn't equal");
return new ReporterDetails(getCSIPVersion(), Message.createErrorMessage(message.toString(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()), false, false);
}
}
} else {
Expand Down Expand Up @@ -662,11 +695,20 @@ protected ReporterDetails validateCSIP29(final StructureValidatorState structure
false, false);
}
} else {
if (!structureValidatorState.getFolderManager()
.verifyChecksum(Paths.get(metsValidatorState.getMetsPath()).resolve(file), checksumType, checksum)) {
final Path resolvedPath;
try {
resolvedPath = Paths.get(metsValidatorState.getMetsPath()).resolve(file);
} catch (InvalidPathException e) {
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(
"mets/dmdSec/mdRef/@href (" + file + ") in %1$s is not a valid path: " + e.getReason(),
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
}
if (!structureValidatorState.getFolderManager().verifyChecksum(resolvedPath, checksumType,
checksum)) {
message.append("mets/dmdSec/mdRef/@CHECKSUM ").append(checksum)
.append(" in %1$s and checksum of file (")
.append(Paths.get(metsValidatorState.getMetsPath()).resolve(file)).append(") isn't equal");
.append(" in %1$s and checksum of file (").append(resolvedPath).append(") isn't equal");
return new ReporterDetails(getCSIPVersion(),
Message.createErrorMessage(message.toString(), metsValidatorState.getMetsName(),
metsValidatorState.isRootMets()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ protected ReporterDetails validateCSIPSTR16(final StructureValidatorState struct
* @return if the IP is a ZIP file
*/
protected boolean isZipFile(Path ipPath, byte[] zipMagicNumber, String moduleName) {
if (Files.isDirectory(ipPath)) {
return false;
}

boolean isZip = true;

byte[] buffer = new byte[zipMagicNumber.length];
Expand Down
Loading
Loading