Compare commits
2 Commits
40b3ff6b7c
...
f031a79718
Author | SHA1 | Date |
---|---|---|
Katerina | f031a79718 | |
Katerina | e324211595 |
|
@ -6,6 +6,7 @@ import eu.dnetlib.validator2.validation.guideline.openaire.*;
|
|||
import eu.dnetlib.validatorapi.entities.RuleInfo;
|
||||
import eu.dnetlib.validatorapi.entities.ValidationJob;
|
||||
import eu.dnetlib.validatorapi.entities.ValidationRuleResult;
|
||||
import eu.dnetlib.validatorapi.exceptions.ValidationException;
|
||||
import eu.dnetlib.validatorapi.repositories.ValidationIssueRepository;
|
||||
import eu.dnetlib.validatorapi.repositories.ValidationJobRepository;
|
||||
import eu.dnetlib.validatorapi.repositories.ValidationResultRepository;
|
||||
|
@ -14,10 +15,12 @@ import eu.dnetlib.validatorapi.routes.SimpleOaiPmhRoute;
|
|||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
@ -131,9 +134,11 @@ public class ValidationController {
|
|||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Validation job stopped unexpectedly." + e.getMessage());
|
||||
System.out.println("ERROR " + e.getMessage());
|
||||
log.error("Validation job stopped unexpectedly. " + e.getMessage());
|
||||
validationJob.progress = "STOPPED";
|
||||
validationJob.exceptionClass = e.getClass().getCanonicalName();
|
||||
validationJob.exceptionMessage = e.getMessage();
|
||||
|
||||
|
||||
} finally {
|
||||
validationJob.endDate = new Date();
|
||||
|
@ -179,7 +184,7 @@ public class ValidationController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = {"/realValidator"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ValidationJob validateWithApacheCamel(@RequestParam(name = "guidelines") String guidelinesProfileName,
|
||||
public ResponseEntity<ValidationJob> validateWithApacheCamel(@RequestParam(name = "guidelines") String guidelinesProfileName,
|
||||
@RequestParam(name = "baseUrl", defaultValue = "http://repositorium.sdum.uminho.pt/oai/request") String baseURL, //not in use now
|
||||
@RequestParam(name="numberOfRecords", defaultValue = "10") int numberOfRecords,
|
||||
@RequestParam(name="set", required = false) Optional<String> set
|
||||
|
@ -191,7 +196,8 @@ public class ValidationController {
|
|||
|
||||
if (profile == null && fairProfile == null) {
|
||||
log.error("Exception: No valid guidelines " + guidelinesProfileName + ".");
|
||||
new Exception("Validation Job stopped unexpectedly. No valid guidelines " +
|
||||
|
||||
throw new ValidationException("Validation Job stopped unexpectedly. No valid guidelines " +
|
||||
guidelinesProfileName + " were provided.");
|
||||
}
|
||||
|
||||
|
@ -228,18 +234,19 @@ public class ValidationController {
|
|||
|
||||
camelContext.addRoutes(oaiPmhRouteBuilder);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Validation job stopped unexpectedly." + e.getMessage());
|
||||
System.out.println("ERROR " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("Validation job stopped unexpectedly. " + e.getMessage());
|
||||
validationJob.progress = "STOPPED";
|
||||
validationJob.endDate = new Date();
|
||||
validationJob.score = resultSum / validationJob.recordsTested;
|
||||
validationJob.status = validationResultRepository.getStatus(validationJob.id);
|
||||
validationJob.exceptionClass = e.getClass().getCanonicalName();
|
||||
validationJob.exceptionMessage = e.getMessage();
|
||||
validationJobRepository.save(validationJob);
|
||||
return ResponseEntity.status(HttpStatus.SC_UNPROCESSABLE_ENTITY).body(validationJob);
|
||||
}
|
||||
|
||||
return validationJob;
|
||||
return ResponseEntity.ok(validationJob);
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/getSets"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
|
@ -492,8 +499,10 @@ public class ValidationController {
|
|||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("Validation job stopped unexpectedly." + e.getMessage());
|
||||
log.error("Validation job stopped unexpectedly. " + e.getMessage());
|
||||
validationJob.progress = "STOPPED";
|
||||
validationJob.exceptionClass = e.getClass().getCanonicalName();
|
||||
validationJob.exceptionMessage = e.getMessage();
|
||||
|
||||
} finally {
|
||||
validationJob.endDate = new Date();
|
||||
|
@ -552,7 +561,6 @@ public class ValidationController {
|
|||
|
||||
//String response = camelContext.createProducerTemplate().requestBody("direct:oaipmhRequest", endpoint, String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ public class SummaryResult {
|
|||
@Id
|
||||
String rule_name;
|
||||
int rule_weight;
|
||||
String requirement_level;
|
||||
String description;
|
||||
String fair_principles;
|
||||
String link;
|
||||
String guidelines;
|
||||
String internal_error;
|
||||
String rule_status;
|
||||
|
@ -30,10 +34,16 @@ public class SummaryResult {
|
|||
this.failed_records = failed_records;
|
||||
}
|
||||
|
||||
public SummaryResult(String rule_name, int rule_weight, String guidelines, String internal_error, long passed_records,
|
||||
long failed_records, String rule_status, boolean has_errors, boolean has_warnings) {
|
||||
|
||||
public SummaryResult(String rule_name, int rule_weight, String requirement_level, String description, String fair_principles,
|
||||
String link, String guidelines, String internal_error, long passed_records, long failed_records,
|
||||
String rule_status, boolean has_errors, boolean has_warnings) {
|
||||
this.rule_name = rule_name;
|
||||
this.rule_weight = rule_weight;
|
||||
this.requirement_level = requirement_level;
|
||||
this.description = description;
|
||||
this.fair_principles = fair_principles;
|
||||
this.link = link;
|
||||
this.guidelines = guidelines;
|
||||
this.internal_error = internal_error;
|
||||
this.rule_status = rule_status;
|
||||
|
@ -43,6 +53,8 @@ public class SummaryResult {
|
|||
this.has_warnings = has_warnings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getRule_name() {
|
||||
return rule_name;
|
||||
}
|
||||
|
@ -59,6 +71,38 @@ public class SummaryResult {
|
|||
this.rule_weight = rule_weight;
|
||||
}
|
||||
|
||||
public String getRequirement_level() {
|
||||
return requirement_level;
|
||||
}
|
||||
|
||||
public void setRequirement_level(String requirement_level) {
|
||||
this.requirement_level = requirement_level;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getFair_principles() {
|
||||
return fair_principles;
|
||||
}
|
||||
|
||||
public void setFair_principles(String fair_principles) {
|
||||
this.fair_principles = fair_principles;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public String getGuidelines() {
|
||||
return guidelines;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,13 @@ public class ValidationJob {
|
|||
@Column(name="score")
|
||||
public double score;
|
||||
|
||||
@Column(name="exception_class")
|
||||
public String exceptionClass;
|
||||
|
||||
@Column(name="exception_message")
|
||||
public String exceptionMessage;
|
||||
|
||||
|
||||
public ValidationJob(){
|
||||
startDate = new Date();
|
||||
}
|
||||
|
@ -61,6 +68,8 @@ public class ValidationJob {
|
|||
", progress='" + progress + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", score=" + score +
|
||||
", exceptionClass='" + exceptionClass + '\'' +
|
||||
", exceptionMessage='" + exceptionMessage + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,18 @@ public class ValidationRuleResult implements Serializable {
|
|||
@Column(name = "record_url")
|
||||
public String recordUrl;
|
||||
|
||||
@Column(name="requirement_level")
|
||||
public String requirement_level;
|
||||
|
||||
@Column(name="description")
|
||||
public String description;
|
||||
|
||||
@Column(name="fair_principles")
|
||||
public String fair_principles;
|
||||
|
||||
@Column(name="link")
|
||||
public String link;
|
||||
|
||||
@Column(name = "internal_error")
|
||||
public String internalError;
|
||||
|
||||
|
@ -44,7 +56,6 @@ public class ValidationRuleResult implements Serializable {
|
|||
|
||||
public ValidationRuleResult() {}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ValidationRuleResult{" +
|
||||
|
@ -53,6 +64,10 @@ public class ValidationRuleResult implements Serializable {
|
|||
", ruleName='" + ruleName + '\'' +
|
||||
", ruleWeight=" + ruleWeight +
|
||||
", recordUrl='" + recordUrl + '\'' +
|
||||
", requirement_level='" + requirement_level + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", fairPrinciples='" + fair_principles + '\'' +
|
||||
", link='" + link + '\'' +
|
||||
", internalError='" + internalError + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", score=" + score +
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package eu.dnetlib.validatorapi.exceptions;
|
||||
|
||||
public class ErrorMessage {
|
||||
private String message;
|
||||
|
||||
ErrorMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package eu.dnetlib.validatorapi.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
@ControllerAdvice
|
||||
public class ExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
@ResponseBody
|
||||
@org.springframework.web.bind.annotation.ExceptionHandler(value = {ValidationException.class})
|
||||
protected ResponseEntity<ErrorMessage> handleValidationError(RuntimeException exception, WebRequest request) {
|
||||
return new ResponseEntity(new ErrorMessage(exception.getMessage()), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package eu.dnetlib.validatorapi.exceptions;
|
||||
|
||||
public class ValidationException extends RuntimeException {
|
||||
public ValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
|
@ -129,6 +129,14 @@ public class XmlProcessor implements Processor {
|
|||
validationRuleResult.guidelines = guidelines;
|
||||
validationRuleResult.ruleName = ruleName;
|
||||
validationRuleResult.ruleWeight = profile.guideline(ruleName).getWeight();
|
||||
validationRuleResult.requirement_level = profile.guideline(ruleName).getRequirementLevel().name();
|
||||
System.out.println(validationRuleResult.requirement_level);
|
||||
validationRuleResult.description = profile.guideline(ruleName).getDescription();
|
||||
System.out.println(validationRuleResult.description);
|
||||
validationRuleResult.fair_principles = profile.guideline(ruleName).getFairPrinciples();
|
||||
System.out.println(validationRuleResult.fair_principles);
|
||||
validationRuleResult.link = profile.guideline(ruleName).getLink();
|
||||
System.out.println(validationRuleResult.link);
|
||||
validationRuleResult.recordUrl = recordUrl;
|
||||
validationRuleResult.score = engineResult.score();
|
||||
validationRuleResult.status = engineResult.status().toString();
|
||||
|
|
|
@ -25,7 +25,8 @@ public interface ValidationResultRepository extends JpaRepository<ValidationRule
|
|||
"WHERE vr.validationJobId = :id AND vr.status = 'FAILURE' OR vr.internalError != null")
|
||||
public String getStatus(@Param("id") int validationJobId);
|
||||
|
||||
@Query(value = "SELECT NEW eu.dnetlib.validatorapi.entities.SummaryResult(sr.ruleName, sr.ruleWeight, sr.guidelines, sr.internalError," +
|
||||
@Query(value = "SELECT NEW eu.dnetlib.validatorapi.entities.SummaryResult(sr.ruleName, sr.ruleWeight, sr.requirement_level, " +
|
||||
"sr.description, sr.fair_principles, sr.link, sr.guidelines, sr.internalError," +
|
||||
"COUNT(CASE WHEN sr.status = 'SUCCESS' THEN 1 END) AS passedRecords," +
|
||||
"COUNT(CASE WHEN sr.status = 'FAILURE' OR sr.status = 'ERROR' THEN 1 END) AS failedRecords," +
|
||||
"(SELECT CASE" +
|
||||
|
@ -38,7 +39,7 @@ public interface ValidationResultRepository extends JpaRepository<ValidationRule
|
|||
"CASE WHEN COUNT(CASE WHEN has_warnings IS TRUE THEN 1 END) > 0 THEN TRUE ELSE FALSE END AS hasWarnings)" +
|
||||
"FROM eu.dnetlib.validatorapi.entities.ValidationRuleResult sr " +
|
||||
"WHERE sr.validationJobId = :id " +
|
||||
"GROUP BY sr.ruleName, sr.ruleWeight, sr.guidelines, sr.internalError, sr.validationJobId")
|
||||
"GROUP BY sr.ruleName, sr.ruleWeight, sr.description, sr.fair_principles, sr.link, sr.requirement_level, sr.guidelines, sr.internalError, sr.validationJobId")
|
||||
List<SummaryResult> getFullSummaryResult(@Param("id") int validationJobId);
|
||||
|
||||
@Query(value =
|
||||
|
@ -54,7 +55,8 @@ public interface ValidationResultRepository extends JpaRepository<ValidationRule
|
|||
"WHERE vr.validationJobId = :id AND vr.guidelines = :guidelines AND vr.status = 'FAILURE' OR vr.internalError != null")
|
||||
public String getStatus(@Param("id") int validationJobId, @Param("guidelines") String guidelines);
|
||||
|
||||
@Query(value = "SELECT NEW eu.dnetlib.validatorapi.entities.SummaryResult(sr.ruleName, sr.ruleWeight, sr.guidelines, sr.internalError," +
|
||||
@Query(value = "SELECT NEW eu.dnetlib.validatorapi.entities.SummaryResult(sr.ruleName, sr.ruleWeight, sr.requirement_level, " +
|
||||
"sr.description, sr.fair_principles, sr.link, sr.guidelines, sr.internalError," +
|
||||
"COUNT(CASE WHEN sr.status = 'SUCCESS' THEN 1 END) AS passedRecords," +
|
||||
"COUNT(CASE WHEN sr.status = 'FAILURE' OR sr.status = 'ERROR' THEN 1 END) AS failedRecords," +
|
||||
"(SELECT CASE" +
|
||||
|
@ -67,7 +69,7 @@ public interface ValidationResultRepository extends JpaRepository<ValidationRule
|
|||
"CASE WHEN COUNT(CASE WHEN has_warnings IS TRUE THEN 1 END) > 0 THEN TRUE ELSE FALSE END AS hasWarnings)" +
|
||||
"FROM eu.dnetlib.validatorapi.entities.ValidationRuleResult sr " +
|
||||
"WHERE sr.validationJobId = :id AND sr.guidelines = :guidelines " +
|
||||
"GROUP BY sr.ruleName, sr.ruleWeight, sr.guidelines, sr.internalError, sr.validationJobId")
|
||||
"GROUP BY sr.ruleName, sr.ruleWeight, sr.requirement_level, sr.description, sr.fair_principles, sr.link, sr.description, sr.internalError, sr.validationJobId")
|
||||
List<SummaryResult> getFullSummaryResult(@Param("id") int validationJobId, @Param("guidelines") String guidelines);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue