diff --git a/src/main/java/eu/dnetlib/validatorapi/controllers/ValidatorController.java b/src/main/java/eu/dnetlib/validatorapi/controllers/ValidatorController.java index 3b61493..db9809f 100644 --- a/src/main/java/eu/dnetlib/validatorapi/controllers/ValidatorController.java +++ b/src/main/java/eu/dnetlib/validatorapi/controllers/ValidatorController.java @@ -29,8 +29,9 @@ public class ValidatorController { // public List validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) { public XmlValidationResponse validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) { log.debug(xml); - List resultMessages = new ArrayList<>(); - List resultRules = new ArrayList<>(); +// List resultMessages = new ArrayList<>(); + List resultRules = null; + List 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 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; } diff --git a/src/main/java/eu/dnetlib/validatorapi/entities/XmlValidationResponse.java b/src/main/java/eu/dnetlib/validatorapi/entities/XmlValidationResponse.java index 6f1c86f..ab04d99 100644 --- a/src/main/java/eu/dnetlib/validatorapi/entities/XmlValidationResponse.java +++ b/src/main/java/eu/dnetlib/validatorapi/entities/XmlValidationResponse.java @@ -6,6 +6,7 @@ public class XmlValidationResponse { String validationScore; String fairScore; List rules; + List fairRules; public String getValidationScore() { return validationScore; @@ -30,4 +31,12 @@ public class XmlValidationResponse { public void setRules(List rules) { this.rules = rules; } + + public List getFairRules() { + return fairRules; + } + + public void setFairRules(List fairRules) { + this.fairRules = fairRules; + } }