parent
a545e34f04
commit
6d2838f480
4
pom.xml
4
pom.xml
|
@ -44,13 +44,13 @@
|
|||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.13.0</version>
|
||||
<version>2.15.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>32.1.2-jre</version>
|
||||
<version>32.1.3-jre</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -42,20 +42,16 @@ class ElementSpecCompiler {
|
|||
|
||||
specs.add(currentElement.spec);
|
||||
|
||||
if (currentElement.parent == null) {
|
||||
if ( currentElement.parent == null )
|
||||
currentElement.createRootElemRule(compilationResult);
|
||||
}
|
||||
else {
|
||||
else
|
||||
currentElement.createSubElemRule(compilationResult);
|
||||
}
|
||||
|
||||
for (AttributeSpec attrSpec : currentElement.spec.attributeSpecs()) {
|
||||
for ( AttributeSpec attrSpec : currentElement.spec.attributeSpecs() )
|
||||
currentElement.createAttrRule(compilationResult, attrSpec);
|
||||
}
|
||||
|
||||
for(ElementSpec subElementSpec: currentElement.spec.subElementSpecs()) {
|
||||
for ( ElementSpec subElementSpec: currentElement.spec.subElementSpecs() )
|
||||
generateRulesForElement(new ElementStruct(currentElement.elementsArray, subElementSpec, currentElement));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,21 +93,17 @@ class ElementSpecCompiler {
|
|||
String valuePrefix,
|
||||
Predicate<String> allowedValuesPredicate,
|
||||
Cardinality cardinality) {
|
||||
|
||||
StringBuilder builder =
|
||||
new StringBuilder(requirementLevel.name()).append(" rule: The ").append(nodeName).append(" ").append(nodeType);
|
||||
|
||||
if (position != ElementPosition.ALL) {
|
||||
if ( position != ElementPosition.ALL )
|
||||
builder.append(" at ").append(position.name().toLowerCase()).append(" position");
|
||||
}
|
||||
|
||||
if (valuePrefix != null) {
|
||||
if ( valuePrefix != null )
|
||||
builder.append(" has values that start with ").append(valuePrefix).append(",");
|
||||
}
|
||||
|
||||
if (!allowsAllValues(allowedValuesPredicate)) {
|
||||
if ( !allowsAllValues(allowedValuesPredicate) )
|
||||
builder.append(" contains allowed values only,");
|
||||
}
|
||||
|
||||
builder.append(" has cardinality ").append(cardinality.asText());
|
||||
|
||||
|
@ -123,12 +115,10 @@ class ElementSpecCompiler {
|
|||
Cardinality cardinality,
|
||||
String valuePrefix) {
|
||||
String id = requirementLevel.name() + " rule: " + nodeName + " has cardinality " + cardinality.asText();
|
||||
if(Helper.isEmpty(valuePrefix)) {
|
||||
if ( Helper.isEmpty(valuePrefix) )
|
||||
return id;
|
||||
}
|
||||
else {
|
||||
else
|
||||
return id + " for values starting with '" + valuePrefix + "'";
|
||||
}
|
||||
}
|
||||
|
||||
static final String mergeNodeNames(String... names) {
|
||||
|
@ -228,6 +218,7 @@ class ElementSpecCompiler {
|
|||
if (parents == null) {
|
||||
return (Integer count) -> false; // There are no parents, actually
|
||||
}
|
||||
|
||||
int parentsLength = parents.getLength();
|
||||
if (cardinality == Cardinality.ONE) {
|
||||
return (Integer count) -> count == parentsLength; // A sub-element can be present in each parent
|
||||
|
@ -241,10 +232,8 @@ class ElementSpecCompiler {
|
|||
else if (cardinality == Cardinality.FOUR_TO_N){
|
||||
return (Integer count) -> count >= parentsLength * 4; // Four or more sub-elements can be present in each parent
|
||||
}
|
||||
else{ // not reachable
|
||||
else // not reachable
|
||||
throw new RuleEvaluationException(" Unsupported cardinality " + cardinality, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static NodeList attributesOf(NodeList elements, String attrName, Predicate<String> allowedValues) {
|
||||
|
@ -494,10 +483,8 @@ class ElementSpecCompiler {
|
|||
} catch (Throwable t) {
|
||||
throw new RuleEvaluationException(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,10 +574,8 @@ class ElementSpecCompiler {
|
|||
guidelineEvaluation.setNodesOf(thisId, nodes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -601,7 +586,6 @@ class ElementSpecCompiler {
|
|||
|
||||
private static Predicate<Document> isApplicable(SyntheticRule<Document> rule,
|
||||
GuidelineEvaluation guidelineEvaluation) {
|
||||
|
||||
return (Document doc) -> {
|
||||
Rule<Document> applicabilityRule = rule.applicabilityRule();
|
||||
if (applicabilityRule == null) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class SyntheticGuideline extends AbstractGuideline<Document> {
|
|||
logger.debug("Validating document {} in {}", id, Thread.currentThread());
|
||||
evaluation.set(new GuidelineEvaluation(id, document, getWeight()));
|
||||
Result result = evaluation.get().evaluate(compilationResult);
|
||||
logger.debug("Evaluated: {} in {} with result {}", evaluation.get(), Thread.currentThread(), result);
|
||||
logger.debug("Evaluated: {} in thread_{} with result {}", evaluation.get(), Thread.currentThread().getName(), result);
|
||||
evaluation.remove();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -308,8 +308,7 @@ public class DataArchiveGuidelinesV2Profile extends AbstractOpenAireProfile {
|
|||
)
|
||||
);
|
||||
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.
|
||||
stream().
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.stream().
|
||||
collect(Collectors.toMap(SyntheticGuideline::getName, (guideline) -> guideline));
|
||||
|
||||
private static final int MAX_SCORE = GUIDELINES.stream().map(SyntheticGuideline::getWeight).reduce(0, Integer::sum);
|
||||
|
|
|
@ -281,8 +281,7 @@ public final class FAIR_Data_GuidelinesProfile extends AbstractOpenAireProfile {
|
|||
)
|
||||
);
|
||||
|
||||
private static final Map<String, Guideline> GUIDELINE_MAP = GUIDELINES.
|
||||
stream().
|
||||
private static final Map<String, Guideline> GUIDELINE_MAP = GUIDELINES.stream().
|
||||
collect(Collectors.toMap(Guideline::getName, (guideline) -> guideline));
|
||||
|
||||
private static final int MAX_SCORE = GUIDELINES.stream().map(Guideline::getWeight).reduce(0, Integer::sum);
|
||||
|
|
|
@ -241,8 +241,7 @@ public final class FAIR_Literature_GuidelinesV4Profile extends AbstractOpenAireP
|
|||
)
|
||||
);
|
||||
|
||||
private static final Map<String, Guideline> GUIDELINE_MAP = GUIDELINES.
|
||||
stream().
|
||||
private static final Map<String, Guideline> GUIDELINE_MAP = GUIDELINES.stream().
|
||||
collect(Collectors.toMap(Guideline::getName, (guideline) -> guideline));
|
||||
|
||||
private static final int MAX_SCORE = GUIDELINES.stream().map(Guideline::getWeight).reduce(0, Integer::sum);
|
||||
|
|
|
@ -295,8 +295,7 @@ public final class LiteratureGuidelinesV3Profile extends AbstractOpenAireProfile
|
|||
)
|
||||
);
|
||||
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.
|
||||
stream().
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.stream().
|
||||
collect(Collectors.toMap(SyntheticGuideline::getName, (guideline) -> guideline));
|
||||
|
||||
private static final int MAX_SCORE = GUIDELINES.stream().map(SyntheticGuideline::getWeight).reduce(0, Integer::sum);
|
||||
|
|
|
@ -527,8 +527,7 @@ public final class LiteratureGuidelinesV4Profile extends AbstractOpenAireProfile
|
|||
)
|
||||
);
|
||||
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.
|
||||
stream().
|
||||
private static final Map<String, SyntheticGuideline> GUIDELINE_MAP = GUIDELINES.stream().
|
||||
collect(Collectors.toMap(SyntheticGuideline::getName, (guideline) -> guideline));
|
||||
|
||||
private static final int MAX_SCORE = GUIDELINES.stream().map(SyntheticGuideline::getWeight).reduce(0, Integer::sum);
|
||||
|
|
|
@ -9,6 +9,8 @@ public class TestUtils {
|
|||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestUtils.class);
|
||||
|
||||
public static final String TEST_FILES_BASE_DIR = "src/test/resources/";
|
||||
|
||||
|
||||
public static DocumentBuilder getDocumentBuilder()
|
||||
{
|
||||
|
|
|
@ -18,12 +18,13 @@ public class Test_v4 {
|
|||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Test_v4.class);
|
||||
|
||||
private static final String TEST_FILES_V4_DIR = TestUtils.TEST_FILES_BASE_DIR + "openaireguidelinesV4/";
|
||||
|
||||
private static final String[] FILES = new String[] {
|
||||
// "src/test/resources/openaireguidelinesV4/v4_literature_all_invalid_guidelines_record.xml",
|
||||
"src/test/resources/openaireguidelinesV4/v4_literature_all_guidelines_record.xml",
|
||||
// "src/test/resources/openaireguidelinesV4/oai_mediarep_org_doc_2534.xml",
|
||||
// "src/test/resources/openaireguidelinesV4/01_gv4.xml"
|
||||
// TEST_FILES_V4_DIR + "v4_literature_all_invalid_guidelines_record.xml",
|
||||
// TEST_FILES_V4_DIR + "v4_literature_all_guidelines_record.xml",
|
||||
// TEST_FILES_V4_DIR + "oai_mediarep_org_doc_2534.xml",
|
||||
TEST_FILES_V4_DIR + "01_gv4.xml"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
Loading…
Reference in New Issue