- Fix missing import in groovy test.

- Code polishing.
This commit is contained in:
Lampros Smyrnaios 2023-07-14 14:26:11 +03:00
parent b63f09bfc4
commit 8b4da5c4eb
3 changed files with 9 additions and 13 deletions

View File

@ -32,13 +32,11 @@ public final class SyntheticGuideline extends AbstractGuideline<Document> {
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty")); String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
// Here we define a guideline with a specific elementSpec as origin, we cannot allow null // Here we define a guideline with a specific elementSpec as origin, we cannot allow null
if (elementSpec == null) { if ( elementSpec == null )
throw new IllegalArgumentException("ElementSpec cannot be empty"); throw new IllegalArgumentException("ElementSpec cannot be empty");
}
if (weight < 0) { if ( weight < 0 )
throw new IllegalArgumentException("Weight cannot be negative"); throw new IllegalArgumentException("Weight cannot be negative");
}
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight); SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
guideline.compilationResult = new ElementSpecCompiler().compile(elementSpec, evaluation::get); guideline.compilationResult = new ElementSpecCompiler().compile(elementSpec, evaluation::get);
@ -49,17 +47,14 @@ public final class SyntheticGuideline extends AbstractGuideline<Document> {
public static SyntheticGuideline of(String name, int weight, RequirementLevel requirementLevel, Rule<Document> rule) { public static SyntheticGuideline of(String name, int weight, RequirementLevel requirementLevel, Rule<Document> rule) {
String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty")); String canonical = Helper.ensureNonEmpty(name, () -> new IllegalArgumentException("Name cannot be empty"));
if (weight < 0) { if ( weight < 0 )
throw new IllegalArgumentException("Weight cannot be negative"); throw new IllegalArgumentException("Weight cannot be negative");
}
if (requirementLevel == null) { if ( requirementLevel == null )
throw new IllegalArgumentException("Requirement level cannot be empty"); throw new IllegalArgumentException("Requirement level cannot be empty");
}
if (rule == null) { if ( rule == null )
throw new IllegalArgumentException("Rule cannot be empty"); throw new IllegalArgumentException("Rule cannot be empty");
}
SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight); SyntheticGuideline guideline = new SyntheticGuideline(canonical, weight);
CompilationResult compilationResult = new CompilationResult(); CompilationResult compilationResult = new CompilationResult();

View File

@ -42,7 +42,7 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
final Map<String, Guideline.Result> results = new HashMap<>(); final Map<String, Guideline.Result> results = new HashMap<>();
// Validate the document against all guideline-elements. // Validate the document against all guideline-elements.
for (Guideline<Document> guidelineElement : guidelines()) for ( Guideline<Document> guidelineElement : guidelines() )
{ {
String guidelineElementName = guidelineElement.getName(); String guidelineElementName = guidelineElement.getName();
if ( logger.isTraceEnabled() ) if ( logger.isTraceEnabled() )
@ -79,10 +79,10 @@ public abstract class AbstractOpenAireProfile implements XMLApplicationProfile {
// The nodes contain all the elementName nodes // The nodes contain all the elementName nodes
int len = nodes.getLength(); int len = nodes.getLength();
if (len == 0) { return false; } // element is not present if (len == 0) { return false; } // element is not present
for(int i = 0; i < len; i++) { for ( int i = 0; i < len; i++ ) {
Node elem = nodes.item(i); Node elem = nodes.item(i);
String value = Helper.getAttributeValue(elem, attrName); String value = Helper.getAttributeValue(elem, attrName);
if (!attrValue.equals(value)) { return false; } if ( !attrValue.equals(value) ) { return false; }
} }
return true; return true;
}); });

View File

@ -1,5 +1,6 @@
package eu.dnetlib.validator2.engine package eu.dnetlib.validator2.engine
import eu.dnetlib.validator2.engine.Helper
import groovy.xml.DOMBuilder import groovy.xml.DOMBuilder
import groovy.xml.FactorySupport import groovy.xml.FactorySupport
import org.w3c.dom.Document import org.w3c.dom.Document