Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -416,20 +416,31 @@ public Pair<Element, Boolean> doValidate(AbstractMetadata metadata, String lang)
theNSs.add(Namespace.getNamespace("geonet", "http://www.fao.org/geonetwork"));
theNSs.add(Namespace.getNamespace("svrl", "http://purl.oclc.org/dsdl/svrl"));

List<?> failedAssert = Xml.selectNodes(schemaTronReport,
"geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/svrl:schematron-output/svrl:failed-assert",
// Get all the errors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file contains some non-used imports, I'm not sure if related to the pull request, but can you update it to remove them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in latest push

List<?> errors = Xml.selectNodes(schemaTronReport,
"geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/svrl:schematron-output/svrl:failed-assert" +
" | geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/geonet:schematronVerificationError",
theNSs);

List<?> failedSchematronVerification = Xml.selectNodes(schemaTronReport,
"geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/geonet:schematronVerificationError",
// Get all the warnings
List<?> warnings = Xml.selectNodes(schemaTronReport,
"geonet:report[@geonet:required = '" + SchematronRequirement.REPORT_ONLY + "']/svrl:schematron-output/svrl:failed-assert" +
" | geonet:report[@geonet:required = '" + SchematronRequirement.REPORT_ONLY + "']/geonet:schematronVerificationError",
theNSs);

if (failedAssert.size() > 0 || failedSchematronVerification.size() > 0) {
// If there are errors the report is not valid
if (!errors.isEmpty()) {
valid = false;
errorReport.addContent(schemaTronReport);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" - Schematron error: {}", Xml.getString(schemaTronReport));
}
} else if (!warnings.isEmpty()) {
LOGGER.debug(" - Schematron warning: {}", Xml.getString(schemaTronReport));
}

// Add the schematron report content if there are errors or warnings
if (!errors.isEmpty() || !warnings.isEmpty()) {
errorReport.addContent(schemaTronReport);
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

package org.fao.geonet.api.processing;

import java.util.ArrayList;
import java.util.List;
import java.util.*;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand All @@ -35,6 +34,7 @@
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.ApiParams;
import org.fao.geonet.api.ApiUtils;
import org.fao.geonet.api.processing.report.MetadataValidationProcessingReport;
import org.fao.geonet.api.processing.report.SimpleMetadataProcessingReport;
import org.fao.geonet.api.processing.report.registry.IProcessingReportRegistry;
import org.fao.geonet.domain.AbstractMetadata;
Expand All @@ -53,9 +53,7 @@
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.repository.MetadataValidationRepository;
import org.fao.geonet.kernel.search.index.BatchOpsMetadataReindexer;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.filter.Filter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand All @@ -72,8 +70,6 @@
import javax.management.MalformedObjectNameException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayDeque;
import java.util.Set;

import static org.fao.geonet.api.ApiParams.*;
import static org.fao.geonet.api.records.InspireValidationApi.API_PARAM_INSPIRE_VALIDATION_MODE;
Expand Down Expand Up @@ -143,7 +139,7 @@ public void iniMBeansSlidingWindowWithEmptySlot() {
})
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public SimpleMetadataProcessingReport validateRecords(
public MetadataValidationProcessingReport validateRecords(
@Parameter(description = API_PARAM_RECORD_UUIDS_OR_SELECTION,
required = false,
example = "")
Expand All @@ -168,8 +164,8 @@ public SimpleMetadataProcessingReport validateRecords(
) throws Exception {
UserSession userSession = ApiUtils.getUserSession(session);

SimpleMetadataProcessingReport report =
new SimpleMetadataProcessingReport();
MetadataValidationProcessingReport report =
new MetadataValidationProcessingReport();
try {
ApplicationContext applicationContext = ApplicationContextHolder.get();
ServiceContext serviceContext = ApiUtils.createServiceContext(request);
Expand Down Expand Up @@ -197,28 +193,23 @@ public SimpleMetadataProcessingReport validateRecords(
} else {
Pair<Element, String> validationPair = validator.doValidate(userSession, record.getDataInfo().getSchemaId(), Integer.toString(record.getId()), xmlSerializer.select(serviceContext, String.valueOf(record.getId())), serviceContext.getLanguage(), false);
boolean isValid = !validationPair.one().getDescendants(ErrorFinder).hasNext();
Element schemaTronReport = validationPair.one();
if (schemaTronReport != null) {
// If the schematron report is not null, add any warnings to the MetadataValidationProcessingReport
report.addAllReportsMatchingRequirement(record, schemaTronReport, SchematronRequirement.REPORT_ONLY);
}
if (isValid) {
report.addMetadataInfos(record, "Is valid");
// If the record is valid, we add it to the valid metadata list
report.addValidMetadata(record);
new RecordValidationTriggeredEvent(record.getId(), ApiUtils.getUserSession(request.getSession()).getUserIdAsInt(), "1").publish(applicationContext);
} else {
report.addMetadataError(record, "(" + record.getUuid() + ") Is invalid");
Element schemaTronReport = validationPair.one();
// If the record is not valid, we add it to the invalid metadata list
if (!report.getInvalidMetadata().containsKey(record.getId())) {
report.addInvalidMetadata(record);
}
if (schemaTronReport != null) {
List<Namespace> theNSs = new ArrayList<Namespace>();
theNSs.add(Namespace.getNamespace("geonet", "http://www.fao.org/geonetwork"));
theNSs.add(Namespace.getNamespace("svrl", "http://purl.oclc.org/dsdl/svrl"));

// Extract all the know errors that exists in the report as List of Text
List<?> schemaTronReportErrors = Xml.selectNodes(schemaTronReport,
"geonet:xsderrors/geonet:error/geonet:message[normalize-space(.) != '']" +
"| geonet:schematronerrors/geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/svrl:schematron-output/svrl:failed-assert/svrl:text[normalize-space(.) != '']" +
"| geonet:schematronerrors/geonet:report[@geonet:required = '" + SchematronRequirement.REQUIRED + "']/geonet:schematronVerificationError[normalize-space(.) != '']",
theNSs);

for (Object schemaTronReportError :schemaTronReportErrors) {
// Add normalized string to the report.
report.addMetadataError(record, Xml.selectString((Element) schemaTronReportError, "normalize-space(.)", theNSs));
}
// If the schematron report is not null, add any errors to the MetadataValidationProcessingReport
report.addAllReportsMatchingRequirement(record, schemaTronReport, SchematronRequirement.REQUIRED);
}

new RecordValidationTriggeredEvent(record.getId(), ApiUtils.getUserSession(request.getSession()).getUserIdAsInt(), "0").publish(applicationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void addMetadataInfos(AbstractMetadata metadata, String message) {
isMetadataApproved(metadata.getId()), message);
}

private boolean isMetadataDraft(int metadataId) {
protected boolean isMetadataDraft(int metadataId) {
boolean metadataDraft = false;
try {
metadataDraft = ApplicationContextHolder.get().getBean(IMetadataUtils.class).isMetadataDraft(metadataId);
Expand All @@ -166,7 +166,7 @@ private boolean isMetadataDraft(int metadataId) {
return metadataDraft;
}

private boolean isMetadataApproved(int metadataId) {
protected boolean isMetadataApproved(int metadataId) {
boolean metadataApproved = false;
try {
metadataApproved = ApplicationContextHolder.get().getBean(IMetadataUtils.class).isMetadataApproved(metadataId);
Expand Down
Loading
Loading