Skip to content

Commit

Permalink
Fix #280
Browse files Browse the repository at this point in the history
  • Loading branch information
hmiguim committed Jul 30, 2024
1 parent 284baad commit ffa702a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ The report generated by the validator is in **JSON** format and has the followin
}
```

#### Available properties

Several properties are available to modify default behaviours.

Properties are added to the command line like this:

```bash
... -Dproperty=value -DanotherProperty=othervalue ...
```

Note: in Windows, each property and value pair must be enclosed in `"`, example `... "-Dproperty=value" ...`
##### Validation

* `skipChecksumCalculation` (Boolean) - Ignore checksum calculation during the validation process.

### Use as a Java Library

* Using Maven
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/roda_project/commons_ip2/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.roda_project.commons_ip.utils.METSEnums;
Expand Down Expand Up @@ -178,9 +179,8 @@ public static List<String> getFileRelativeFolders(Path basePath, Path filePath)
List<String> res = new ArrayList<>();
Path relativize = basePath.relativize(filePath).getParent();
if (relativize != null) {
Iterator<Path> iterator = relativize.iterator();
while (iterator.hasNext()) {
res.add(iterator.next().toString());
for (Path path : relativize) {
res.add(path.toString());
}
}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public boolean validate(String version) throws IOException {
subMets = structureValidatorState.getFolderManager().getSubMets(earksipPath);
}

if (subMets.size() > 0) {
if (!subMets.isEmpty()) {
validateSubMets(subMets, structureValidatorState.isZipFileFlag());
}
validateRootMets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -98,7 +98,8 @@ protected ReporterDetails validateCSIP60(final StructureValidatorState structure
final List<FileType.FLocat> fLocats = file.getFLocat();
if (structureValidatorState.isZipFileFlag()) {
for (FileType.FLocat flocat : fLocats) {
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()),
StandardCharsets.UTF_8);
final StringBuilder filePath = new StringBuilder();
if (metsValidatorState.isRootMets()) {
filePath.append(metsValidatorState.getMets().getOBJID()).append(Constants.SEPARATOR).append(href);
Expand All @@ -116,7 +117,7 @@ protected ReporterDetails validateCSIP60(final StructureValidatorState structure
} else {
for (FileType.FLocat flocat : fLocats) {
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()),
Constants.UTF_8);
StandardCharsets.UTF_8);
if (!structureValidatorState.getFolderManager()
.checkPathExists(Paths.get(metsValidatorState.getMetsPath()).resolve(filePath))) {
message.append("mets/fileSec/fileGrp[@USE=’Documentation’] ")
Expand Down Expand Up @@ -152,7 +153,7 @@ protected ReporterDetails validateCSIP113(final StructureValidatorState structur
final List<FileType.FLocat> fLocats = file.getFLocat();
if (structureValidatorState.isZipFileFlag()) {
for (FileType.FLocat flocat : fLocats) {
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), StandardCharsets.UTF_8);
final StringBuilder filePath = new StringBuilder();
if (metsValidatorState.isRootMets()) {
filePath.append(metsValidatorState.getMets().getOBJID()).append(Constants.SEPARATOR).append(href);
Expand All @@ -169,7 +170,7 @@ protected ReporterDetails validateCSIP113(final StructureValidatorState structur
}
} else {
for (FileType.FLocat flocat : fLocats) {
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), Constants.UTF_8);
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), StandardCharsets.UTF_8);
if (!structureValidatorState.getFolderManager()
.checkPathExists(Paths.get(metsValidatorState.getMetsPath()).resolve(filePath))) {
message.append("mets/fileSec/fileGrp[@USE=’Schemas’] ")
Expand Down Expand Up @@ -203,7 +204,7 @@ protected ReporterDetails validateCSIP114(final StructureValidatorState structur
final List<FileType.FLocat> fLocats = file.getFLocat();
if (structureValidatorState.isZipFileFlag()) {
for (FileType.FLocat flocat : fLocats) {
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), StandardCharsets.UTF_8);
final StringBuilder filePath = new StringBuilder();
if (metsValidatorState.isRootMets()) {
filePath.append(metsValidatorState.getMets().getOBJID()).append(Constants.SEPARATOR).append(href);
Expand All @@ -220,7 +221,7 @@ protected ReporterDetails validateCSIP114(final StructureValidatorState structur
}
} else {
for (FileType.FLocat flocat : fLocats) {
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), Constants.UTF_8);
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(flocat.getHref()), StandardCharsets.UTF_8);
if (!structureValidatorState.getFolderManager()
.checkPathExists(Paths.get(metsValidatorState.getMetsPath()).resolve(filePath))) {
message.append("mets/fileSec/fileGrp[@USE=’Representations’] ")
Expand Down Expand Up @@ -451,7 +452,7 @@ protected ReporterDetails validateCSIP66(final StructureValidatorState structure
if (!fLocats.isEmpty()) {
for (FileType.FLocat fLocat : fLocats) {
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(fLocat.getHref()),
Constants.UTF_8);
StandardCharsets.UTF_8);
final StringBuilder filePath = new StringBuilder();
if (structureValidatorState.isZipFileFlag()) {
if (metsValidatorState.isRootMets()) {
Expand Down Expand Up @@ -556,7 +557,7 @@ protected ReporterDetails validateCSIP69(final StructureValidatorState structure
final List<FileType.FLocat> flocat = file.getFLocat();
if (flocat != null) {
if (flocat.size() == 1) {
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.get(0).getHref()), Constants.UTF_8);
final String href = URLDecoder.decode(DecoderUtils.normalizePath(flocat.get(0).getHref()), StandardCharsets.UTF_8);
if (href != null) {
final Long size = file.getSIZE();
if (size != null) {
Expand Down Expand Up @@ -651,6 +652,15 @@ protected ReporterDetails validateCSIP70(final MetsValidatorState metsValidatorS
*/
protected ReporterDetails validateCSIP71(final StructureValidatorState structureValidatorState,
final MetsValidatorState metsValidatorState) throws IOException, NoSuchAlgorithmException {

boolean skipCalculationChecksum = Boolean.parseBoolean(System.getProperty("skipChecksumCalculation", "false"));
if (skipCalculationChecksum) {
ReporterDetails details = new ReporterDetails();
details.setSkipped(true);
details.addIssue("Checksum calculation is disabled");
return details;
}

final List<String> tmp = new ArrayList<>();
for (CHECKSUMTYPE check : CHECKSUMTYPE.values()) {
tmp.add(check.toString());
Expand Down Expand Up @@ -688,7 +698,7 @@ protected ReporterDetails validateCSIP71(final StructureValidatorState structure
metsValidatorState.getMetsName(), metsValidatorState.isRootMets()),
false, false);
} else {
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(href), Constants.UTF_8);
final String filePath = URLDecoder.decode(DecoderUtils.normalizePath(href), StandardCharsets.UTF_8);
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder finalPath = new StringBuilder();
if (!metsValidatorState.isRootMets()) {
Expand Down Expand Up @@ -795,13 +805,13 @@ protected ReporterDetails validateCSIP74(final MetsValidatorState metsValidatorS

// Get all identifiers for DigiprovMD
final List<String> amdIds = amdSec.stream().map(AmdSecType::getDigiprovMD).flatMap(List::stream)
.filter(dp -> dp.getMdRef() != null).map(dp -> dp.getMdRef().getID()).collect(Collectors.toList());
.filter(dp -> dp.getMdRef() != null).map(dp -> dp.getMdRef().getID()).toList();

// Get all file ADMIDs that are NOT in the list of DigiprovMD identifiers
final List<String> admidsNotInAmd = fileGrps.stream().map(FileGrpType::getFile).flatMap(List::stream)
.map(FileType::getADMID).flatMap(List::stream).filter(MdSecType.class::isInstance).map(MdSecType.class::cast)
.filter(md -> md.getMdRef() != null).map(md -> md.getMdRef().getID()).distinct()
.filter(admid -> !amdIds.contains(admid)).collect(Collectors.toList());
.filter(admid -> !amdIds.contains(admid)).toList();

// Report only valid if all ADMIDs are in DigiprovMD identifiers
final ReporterDetails r = new ReporterDetails();
Expand Down Expand Up @@ -1020,7 +1030,7 @@ protected ReporterDetails validateCSIP79(final StructureValidatorState structure
for (FileType.FLocat floc : flocat) {
final String href = floc.getHref();
if (href != null) {
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(href), Constants.UTF_8);
final String hrefDecoded = URLDecoder.decode(DecoderUtils.normalizePath(href), StandardCharsets.UTF_8);
if (structureValidatorState.isZipFileFlag()) {
final StringBuilder finalPath = new StringBuilder();
if (!metsValidatorState.isRootMets()) {
Expand Down

0 comments on commit ffa702a

Please sign in to comment.