- Fix not overriding the methods of the "Result" interface, where needed.

- Fix the parameter-type of the "Result.setStatus()" method.
- Group duplicate code in one utilities-method.
This commit is contained in:
Lampros Smyrnaios 2023-12-22 15:53:22 +02:00
parent 0bf5473d90
commit 465534509a
6 changed files with 177 additions and 277 deletions

View File

@ -46,7 +46,7 @@ public interface Guideline<T> {
int getScore();
void setScore(int score);
Status getStatus();
void setStatus(String status);
void setStatus(Status status);
Iterable<String> getWarnings();
void setWarnings(Iterable<String> warnings);
Iterable<String> getErrors();

View File

@ -10,11 +10,11 @@ public final class StandardResult implements Guideline.Result, Serializable {
private static final List<String> EMPTY = Collections.emptyList();
private final List<String> warnings;
private final List<String> errors;
private final String internalError;
private final Status status;
private final int score;
private List<String> warnings;
private List<String> errors;
private String internalError;
private Status status;
private int score;
public StandardResult(int score, Status status, List<String> warnings, List<String> errors, String internalError) {
this.status = status;
@ -49,6 +49,56 @@ public final class StandardResult implements Guideline.Result, Serializable {
return internalError;
}
@Override
public int getScore() {
return score;
}
@Override
public void setScore(int score) {
this.score = score;
}
@Override
public Status getStatus() {
return status;
}
@Override
public void setStatus(Status status) {
this.status = status;
}
@Override
public Iterable<String> getWarnings() {
return warnings;
}
@Override
public void setWarnings(Iterable<String> warnings) {
this.warnings = (List<String>) warnings;
}
@Override
public Iterable<String> getErrors() {
return errors;
}
@Override
public void setErrors(Iterable<String> errors) {
this.errors = (List<String>) errors;
}
@Override
public String getInternalError() {
return internalError;
}
@Override
public void setInternalError(String internalError) {
this.internalError = internalError;
}
public static StandardResult forError(String message) {
return new StandardResult(-1, Status.ERROR, EMPTY, EMPTY, message);
}

View File

@ -5,6 +5,7 @@ package eu.dnetlib.validator2.validation.guideline.openaire;
import eu.dnetlib.validator2.engine.Status;
import eu.dnetlib.validator2.validation.XMLApplicationProfile;
import eu.dnetlib.validator2.validation.guideline.*;
import eu.dnetlib.validator2.validation.utils.ResultUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@ -447,34 +448,9 @@ class F2_01M_SPEC extends AbstractGuideline<Document> {
}
private static Result getResult(List<String> warnings2, List<String> errors2, int score) {
private static Result getResult(List<String> warnings2, List<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -527,34 +503,9 @@ class F3_01M_SPEC extends AbstractGuideline<Document> {
return null;
}
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -607,34 +558,9 @@ class I2_01M_SPEC extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -684,34 +610,9 @@ class R1_01M_SPEC extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -761,33 +662,8 @@ class R1_2_01M_SPEC extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}

View File

@ -5,6 +5,7 @@ package eu.dnetlib.validator2.validation.guideline.openaire;
import eu.dnetlib.validator2.engine.Status;
import eu.dnetlib.validator2.validation.XMLApplicationProfile;
import eu.dnetlib.validator2.validation.guideline.*;
import eu.dnetlib.validator2.validation.utils.ResultUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@ -405,34 +406,9 @@ class F2_01M_SPEC_LIT extends AbstractGuideline<Document> {
}
private static Result getResult(List<String> warnings2, List<String> errors2, int score) {
private static Result getResult(List<String> warnings2, List<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -485,34 +461,10 @@ class F3_01M_SPEC_LIT extends AbstractGuideline<Document> {
return null;
}
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
return ResultUtils.getNewResult(warnings2, errors2, score2);
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
}
}
@ -565,34 +517,9 @@ class I2_01M_SPEC_LIT extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -642,34 +569,9 @@ class R1_01M_SPEC_LIT extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}
@ -719,33 +621,8 @@ class R1_2_01M_SPEC_LIT extends AbstractGuideline<Document> {
return null;
}
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score) {
private static Result getResult(ArrayList<String> warnings2, ArrayList<String> errors2, int score2) {
return new Result() {
@Override
public int score() {
return score;
}
@Override
public Status status() {
return Status.valueOf((score > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return null;
}
};
return ResultUtils.getNewResult(warnings2, errors2, score2);
}
}

View File

@ -0,0 +1,97 @@
package eu.dnetlib.validator2.validation.utils;
import eu.dnetlib.validator2.engine.Status;
import eu.dnetlib.validator2.validation.guideline.Guideline;
import java.util.List;
public class ResultUtils {
public static Guideline.Result getNewResult(List<String> warnings2, List<String> errors2, int score2) {
return new Guideline.Result() {
int score;
Status status;
Iterable<String> warnings;
Iterable<String> errors;
String internalError;
@Override
public int score() {
return score2;
}
@Override
public Status status() {
return Status.valueOf((score2 > 0) ? "SUCCESS" : "FAILURE");
}
@Override
public Iterable<String> warnings() {
return warnings2;
}
@Override
public Iterable<String> errors() {
return errors2;
}
@Override
public String internalError() {
return internalError;
}
@Override
public int getScore() {
return score();
}
@Override
public void setScore(int score) {
this.score = score;
}
@Override
public Status getStatus() {
return status();
}
@Override
public void setStatus(Status status) {
this.status = status;
}
@Override
public Iterable<String> getWarnings() {
return warnings();
}
@Override
public void setWarnings(Iterable<String> warnings) {
this.warnings = warnings;
}
@Override
public Iterable<String> getErrors() {
return errors();
}
@Override
public void setErrors(Iterable<String> errors) {
this.errors = errors;
}
@Override
public String getInternalError() {
return internalError();
}
@Override
public void setInternalError(String internalError) {
this.internalError = internalError;
}
};
}
}

View File

@ -27,8 +27,8 @@ public class Test_FAIR_LIT {
// "src/test/resources/openaireguidelinesV3/cris.vtt.fi/04_data.xml",
// "src/test/resources/openaireguidelinesV3/cris.vtt.fi/03_data.xml",
// "src/test/resources/openaireguidelinesV4/01_gv4.xml",
// "src/test/resources/openaireguidelinesV4/v4_literature_all_guidelines_record.xml"
"src/test/resources/openaireguidelinesV4/test_minho.xml",
"src/test/resources/openaireguidelinesV4/v4_literature_all_guidelines_record.xml"
// "src/test/resources/openaireguidelinesV4/test_minho.xml",
};
public static void main(String[] args) {