XmlValidationResponse.java: Added XmlValidationResponse class for structured results including validationScore and fairScore | ValidatorController.java: Return results as XmlValidationResponse.
This commit is contained in:
parent
e28198e1d7
commit
c512a31b72
|
@ -5,6 +5,7 @@ import eu.dnetlib.validator2.validation.guideline.Guideline;
|
||||||
import eu.dnetlib.validator2.validation.guideline.StandardResult;
|
import eu.dnetlib.validator2.validation.guideline.StandardResult;
|
||||||
import eu.dnetlib.validator2.validation.guideline.openaire.*;
|
import eu.dnetlib.validator2.validation.guideline.openaire.*;
|
||||||
import eu.dnetlib.validatorapi.entities.RuleInfo;
|
import eu.dnetlib.validatorapi.entities.RuleInfo;
|
||||||
|
import eu.dnetlib.validatorapi.entities.XmlValidationResponse;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -26,10 +27,11 @@ public class ValidatorController {
|
||||||
|
|
||||||
@RequestMapping(value = {"/validate"}, method = RequestMethod.POST)
|
@RequestMapping(value = {"/validate"}, method = RequestMethod.POST)
|
||||||
// public List<String> validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
|
// public List<String> validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
|
||||||
public List<RuleInfo> validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
|
public XmlValidationResponse validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
|
||||||
log.debug(xml);
|
log.debug(xml);
|
||||||
List<String> resultMessages = new ArrayList<>();
|
List<String> resultMessages = new ArrayList<>();
|
||||||
List<RuleInfo> resultRules = new ArrayList<>();
|
List<RuleInfo> resultRules = new ArrayList<>();
|
||||||
|
XmlValidationResponse xmlValidationResponse = new XmlValidationResponse();
|
||||||
|
|
||||||
AbstractOpenAireProfile profile = null;
|
AbstractOpenAireProfile profile = null;
|
||||||
AbstractOpenAireProfile fairProfile = null;
|
AbstractOpenAireProfile fairProfile = null;
|
||||||
|
@ -83,6 +85,15 @@ public class ValidatorController {
|
||||||
|
|
||||||
resultRules.add(ruleInfo);
|
resultRules.add(ruleInfo);
|
||||||
}
|
}
|
||||||
|
String printout = scorePerDoc.entrySet().stream().
|
||||||
|
map(entry -> {
|
||||||
|
xmlValidationResponse.setValidationScore(entry.getValue().toString());
|
||||||
|
|
||||||
|
resultMessages.add("score: " + entry.getValue());
|
||||||
|
return entry.getValue() + ": " + entry.getKey();
|
||||||
|
}).collect(Collectors.joining("\n"));
|
||||||
|
log.debug("\n\nPrinting scorePerDoc...");
|
||||||
|
log.debug(printout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fairProfile != null) {
|
if(fairProfile != null) {
|
||||||
|
@ -110,6 +121,15 @@ public class ValidatorController {
|
||||||
resultRules.add(ruleInfo);
|
resultRules.add(ruleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String printout = scorePerDoc.entrySet().stream().
|
||||||
|
map(entry -> {
|
||||||
|
xmlValidationResponse.setFairScore(entry.getValue().toString());
|
||||||
|
|
||||||
|
resultMessages.add("fair score: " + entry.getValue());
|
||||||
|
return entry.getValue() + ": " + entry.getKey();
|
||||||
|
}).collect(Collectors.joining("\n"));
|
||||||
|
log.debug("\n\nPrinting fair scorePerDoc...");
|
||||||
|
log.debug(printout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
|
@ -118,16 +138,10 @@ public class ValidatorController {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
resultMessages.add("Error processing input");
|
resultMessages.add("Error processing input");
|
||||||
}
|
}
|
||||||
String printout = scorePerDoc.entrySet().stream().
|
|
||||||
map(entry -> {
|
|
||||||
resultMessages.add("score: " + entry.getValue());
|
|
||||||
return entry.getValue() + ": " + entry.getKey();
|
|
||||||
}).collect(Collectors.joining("\n"));
|
|
||||||
log.debug("\n\nPrinting scorePerDoc...");
|
|
||||||
log.debug(printout);
|
|
||||||
|
|
||||||
// return resultMessages;
|
// return resultMessages;
|
||||||
return resultRules;
|
xmlValidationResponse.setRules(resultRules);
|
||||||
|
return xmlValidationResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/validate-file"})
|
@RequestMapping(method = RequestMethod.POST, value = {"/validate-file"})
|
||||||
|
|
|
@ -9,7 +9,6 @@ import java.util.List;
|
||||||
public class RuleInfo {
|
public class RuleInfo {
|
||||||
String name;
|
String name;
|
||||||
String description;
|
String description;
|
||||||
// Guideline.Result result;
|
|
||||||
List<String> warnings;
|
List<String> warnings;
|
||||||
List<String> errors;
|
List<String> errors;
|
||||||
String internalError;
|
String internalError;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package eu.dnetlib.validatorapi.entities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class XmlValidationResponse {
|
||||||
|
String validationScore;
|
||||||
|
String fairScore;
|
||||||
|
List<RuleInfo> rules;
|
||||||
|
|
||||||
|
public String getValidationScore() {
|
||||||
|
return validationScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValidationScore(String validationScore) {
|
||||||
|
this.validationScore = validationScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFairScore() {
|
||||||
|
return fairScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFairScore(String fairScore) {
|
||||||
|
this.fairScore = fairScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RuleInfo> getRules() {
|
||||||
|
return rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRules(List<RuleInfo> rules) {
|
||||||
|
this.rules = rules;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue