XmlValidationResponse.java: Added field "List<RuleInfo> fairRules;" to separate fair validation results from the other guidelines when running together | ValidatorController.java: Validate for fair guidelines only with DataArchiveGuidelinesV2Profile & separate fair validation results & in fair validation removed check "if (!entry.getValue().toString().contains("eu.dnetlib.validator2"))".

This commit is contained in:
Konstantina Galouni 2022-12-23 10:13:43 +02:00
parent 03dab724b7
commit 2c5a934b36
2 changed files with 27 additions and 12 deletions

View File

@ -29,8 +29,9 @@ public class ValidatorController {
// public List<String> validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
public XmlValidationResponse validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
log.debug(xml);
List<String> resultMessages = new ArrayList<>();
List<RuleInfo> resultRules = new ArrayList<>();
// List<String> resultMessages = new ArrayList<>();
List<RuleInfo> resultRules = null;
List<RuleInfo> fairRules = null;
XmlValidationResponse xmlValidationResponse = new XmlValidationResponse();
AbstractOpenAireProfile profile = null;
@ -40,10 +41,10 @@ public class ValidatorController {
fairProfile = new FAIR_Data_GuidelinesProfile();
} else if(guidelinesProfileName.equals("literatureGuidelinesV3Profile")) {
profile = new LiteratureGuidelinesV3Profile();
fairProfile = new FAIR_Data_GuidelinesProfile();
// fairProfile = new FAIR_Data_GuidelinesProfile();
} else if(guidelinesProfileName.equals("literatureGuidelinesV4Profile")) {
profile = new LiteratureGuidelinesV4Profile();
fairProfile = new FAIR_Data_GuidelinesProfile();
// fairProfile = new FAIR_Data_GuidelinesProfile();
} else if(guidelinesProfileName.equals("fairDataGuidelinesProfile")) {
fairProfile = new FAIR_Data_GuidelinesProfile();
}
@ -63,6 +64,8 @@ public class ValidatorController {
Document doc = db.parse(new InputSource(new StringReader(xml)));
if(profile != null) {
resultRules = new ArrayList<>();
log.debug("Max score: " + profile.maxScore());
result = profile.validate("id", doc);
@ -72,7 +75,7 @@ public class ValidatorController {
log.debug("\n\nPrinting results...");
for (Map.Entry entry : results.entrySet()) {
log.debug(entry.getKey() + " = " + entry.getValue());
resultMessages.add(entry.getKey() + " = " + entry.getValue());
// resultMessages.add(entry.getKey() + " = " + entry.getValue());
RuleInfo ruleInfo = new RuleInfo();
ruleInfo.setName(entry.getKey().toString());
@ -89,7 +92,7 @@ public class ValidatorController {
map(entry -> {
xmlValidationResponse.setValidationScore(entry.getValue().toString());
resultMessages.add("score: " + entry.getValue());
// resultMessages.add("score: " + entry.getValue());
return entry.getValue() + ": " + entry.getKey();
}).collect(Collectors.joining("\n"));
log.debug("\n\nPrinting scorePerDoc...");
@ -97,6 +100,8 @@ public class ValidatorController {
}
if(fairProfile != null) {
fairRules = new ArrayList<>();
log.debug("Max score: " + fairProfile.maxScore());
result = fairProfile.validate("id", doc);
@ -105,9 +110,9 @@ public class ValidatorController {
Map<String, Guideline.Result> results = result.results();
log.debug("\n\nPrinting FAIR results...");
for (Map.Entry entry : results.entrySet()) {
if (!entry.getValue().toString().contains("eu.dnetlib.validator2")) {
// if (!entry.getValue().toString().contains("eu.dnetlib.validator2")) {
log.debug(entry.getKey() + " = " + entry.getValue());
resultMessages.add(entry.getKey() + " = " + entry.getValue());
// resultMessages.add(entry.getKey() + " = " + entry.getValue());
RuleInfo ruleInfo = new RuleInfo();
ruleInfo.setName(entry.getKey().toString());
@ -118,14 +123,14 @@ public class ValidatorController {
ruleInfo.setScore(res.score());
ruleInfo.setStatus(res.status());
resultRules.add(ruleInfo);
}
fairRules.add(ruleInfo);
// }
}
String printout = scorePerDoc.entrySet().stream().
map(entry -> {
xmlValidationResponse.setFairScore(entry.getValue().toString());
resultMessages.add("fair score: " + entry.getValue());
// resultMessages.add("fair score: " + entry.getValue());
return entry.getValue() + ": " + entry.getKey();
}).collect(Collectors.joining("\n"));
log.debug("\n\nPrinting fair scorePerDoc...");
@ -136,11 +141,12 @@ public class ValidatorController {
log.debug(e.getMessage());
log.debug(e);
e.printStackTrace();
resultMessages.add("Error processing input");
// resultMessages.add("Error processing input");
}
// return resultMessages;
xmlValidationResponse.setRules(resultRules);
xmlValidationResponse.setFairRules(fairRules);
return xmlValidationResponse;
}

View File

@ -6,6 +6,7 @@ public class XmlValidationResponse {
String validationScore;
String fairScore;
List<RuleInfo> rules;
List<RuleInfo> fairRules;
public String getValidationScore() {
return validationScore;
@ -30,4 +31,12 @@ public class XmlValidationResponse {
public void setRules(List<RuleInfo> rules) {
this.rules = rules;
}
public List<RuleInfo> getFairRules() {
return fairRules;
}
public void setFairRules(List<RuleInfo> fairRules) {
this.fairRules = fairRules;
}
}