Merge remote-tracking branch 'origin/dmp-refactoring' into dmp-refactoring
This commit is contained in:
commit
3b12e89ac2
|
@ -0,0 +1,115 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
import eu.eudat.commons.validation.specification.*;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.tools.exception.MyValidationException;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractValidator<T> implements Validator {
|
||||
private BeanPropertyBindingResult bindingResult;
|
||||
|
||||
protected abstract Class<T> modelClass();
|
||||
|
||||
protected abstract List<Specification> specifications(T item);
|
||||
|
||||
@Override
|
||||
public boolean supports(Class clazz) {
|
||||
return clazz == null ? false : this.modelClass().equals(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors e) {
|
||||
if (obj == null) return;
|
||||
T item = this.modelClass().cast(obj);
|
||||
List<Specification> specifications = this.specifications(item);
|
||||
if (specifications == null) return;;
|
||||
List<PropertySpecification> propertySpecifications = specifications.stream().filter(x-> x instanceof PropertySpecification).map(x-> (PropertySpecification)x).toList();
|
||||
for (PropertySpecification propertySpecification : propertySpecifications){
|
||||
if ((propertySpecification.getPrecondition() == null || propertySpecification.getPrecondition().get()) &&
|
||||
(propertySpecification.getSpecification() == null || !propertySpecification.getSpecification().get())
|
||||
){
|
||||
e.rejectValue(propertySpecification.getErrorKey(), propertySpecification.getErrorCode(), propertySpecification.getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
List<NavigationReferenceSpecification> navigationReferenceSpecifications = specifications.stream().filter(x-> x instanceof NavigationReferenceSpecification).map(x-> (NavigationReferenceSpecification)x).toList();
|
||||
for (NavigationReferenceSpecification navigationReferenceSpecification : navigationReferenceSpecifications){
|
||||
if (navigationReferenceSpecification.getReference() != null && (navigationReferenceSpecification.getPrecondition() == null || navigationReferenceSpecification.getPrecondition().get())){
|
||||
try {
|
||||
e.pushNestedPath(navigationReferenceSpecification.getKey());
|
||||
ValidationUtils.invokeValidator(navigationReferenceSpecification.getValidator().get(), navigationReferenceSpecification.getReference(), e);
|
||||
} finally {
|
||||
e.popNestedPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<NavigationDetailsSpecification> navigationDetailsSpecifications = specifications.stream().filter(x-> x instanceof NavigationDetailsSpecification).map(x-> (NavigationDetailsSpecification)x).toList();
|
||||
for (NavigationDetailsSpecification navigationDetailsSpecification : navigationDetailsSpecifications){
|
||||
if (navigationDetailsSpecification.getDetails() != null && (navigationDetailsSpecification.getPrecondition() == null || navigationDetailsSpecification.getPrecondition().get())){
|
||||
|
||||
for (int i = 0; i < navigationDetailsSpecification.getDetails().size(); i++) {
|
||||
try {
|
||||
e.pushNestedPath(MessageFormat.format("{0}[{1}]", navigationDetailsSpecification.getKey(), i));
|
||||
ValidationUtils.invokeValidator(navigationDetailsSpecification.getValidator().get(), navigationDetailsSpecification.getDetails().get(i), e);
|
||||
} finally {
|
||||
e.popNestedPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target){
|
||||
this.bindingResult = new BeanPropertyBindingResult(target, target.getClass().getName());
|
||||
this.validate(target, this.bindingResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult result() {
|
||||
ValidationResult validationResult = new ValidationResult();
|
||||
if (this.bindingResult != null && bindingResult.hasErrors()){
|
||||
for (FieldError fieldError : bindingResult.getFieldErrors()){
|
||||
validationResult.add(new ValidationFailure(fieldError.getField(), fieldError.getDefaultMessage()));
|
||||
}
|
||||
}
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
protected List<Map.Entry<String, List<String>>> flattenValidationResult() {
|
||||
ValidationResult result = result();
|
||||
List<Map.Entry<String, List<String>>> errorsMap = new ArrayList<>();
|
||||
for (ValidationFailure fieldError : result.getErrors()){
|
||||
Map.Entry<String, List<String>> entry = errorsMap.stream().filter(x-> Objects.equals(x.getKey(), fieldError.getErrorKey())).findFirst().orElse(null);
|
||||
if (entry == null) {
|
||||
entry = new AbstractMap.SimpleEntry<>(fieldError.getErrorKey(), new ArrayList<>());
|
||||
errorsMap.add(entry);
|
||||
}
|
||||
entry.getValue().add(fieldError.getErrorMessage());
|
||||
}
|
||||
|
||||
return errorsMap;
|
||||
}
|
||||
|
||||
protected PropertySpecificationBuilder spec() {
|
||||
return new PropertySpecificationBuilder();
|
||||
}
|
||||
|
||||
protected NavigationReferenceSpecificationBuilder refSpec() {
|
||||
return new NavigationReferenceSpecificationBuilder();
|
||||
}
|
||||
|
||||
protected NavigationDetailsSpecificationBuilder navSpec()
|
||||
{
|
||||
return new NavigationDetailsSpecificationBuilder();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +1,42 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.tools.exception.MyValidationException;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.FieldError;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseValidator implements ModelValidator {
|
||||
private BeanPropertyBindingResult result;
|
||||
public abstract class BaseValidator<T> extends AbstractValidator<T> {
|
||||
protected final ConventionService conventionService;
|
||||
protected final ErrorThesaurusProperties errors;
|
||||
|
||||
protected BaseValidator(ErrorThesaurusProperties errors) {
|
||||
protected BaseValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
|
||||
this.conventionService = conventionService;
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target){
|
||||
this.result = new org.springframework.validation.BeanPropertyBindingResult(target, target.getClass().getName());
|
||||
this.validate(target, this.result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateForce(Object target) {
|
||||
this.validate(target);
|
||||
|
||||
if (this.result != null && result.hasErrors()){
|
||||
List<Map.Entry<String, List<String>>> errorsMap = new ArrayList<>();
|
||||
for (FieldError fieldError : result.getFieldErrors()){
|
||||
errorsMap.add(new AbstractMap.SimpleEntry<>(fieldError.getField(), List.of(fieldError.getDefaultMessage())));
|
||||
}
|
||||
ValidationResult result = result();
|
||||
if (!result.isValid()) {
|
||||
List<Map.Entry<String, List<String>>> errorsMap = this.flattenValidationResult();
|
||||
throw new MyValidationException(this.errors.getModelValidation().getCode(), errorsMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Errors result() {
|
||||
return this.result;
|
||||
|
||||
protected Boolean isValidGuid(UUID guid) {
|
||||
return this.conventionService.isValidGuid(guid);
|
||||
}
|
||||
|
||||
protected Boolean isValidHash(String hash) {
|
||||
return this.conventionService.isValidHash(hash);
|
||||
}
|
||||
|
||||
protected Boolean isEmpty(String value) {
|
||||
return this.conventionService.isNullOrEmpty(value);
|
||||
}
|
||||
protected Boolean lessEqual(String value, int size) {
|
||||
return value.length() <= size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
public class ValidationFailure {
|
||||
public String errorKey;
|
||||
|
||||
public String errorMessage;
|
||||
|
||||
public ValidationFailure(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public ValidationFailure(String errorKey, String errorMessage) {
|
||||
this.errorKey = errorKey;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
|
||||
public String getErrorKey() {
|
||||
return errorKey;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ValidationResult {
|
||||
private final List<ValidationFailure> errors;
|
||||
|
||||
public ValidationResult() {
|
||||
this.errors = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Boolean isValid() {
|
||||
return this.errors.isEmpty();
|
||||
}
|
||||
public ValidationResult add(ValidationFailure failure) {
|
||||
if (failure != null) {
|
||||
errors.add(failure);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValidationResult addAll(List<ValidationFailure> failures) {
|
||||
if (failures != null) {
|
||||
errors.addAll(failures);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<ValidationFailure> getErrors() {
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
public interface ModelValidator extends Validator {
|
||||
public interface Validator extends org.springframework.validation.Validator {
|
||||
void validate(Object target);
|
||||
void validateForce(Object target);
|
||||
Errors result();
|
||||
ValidationResult result();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package eu.eudat.commons.validation;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ValidatorFactory {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public ValidatorFactory(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public <T extends Validator> T validator(Class<T> type){
|
||||
|
||||
T item = this.applicationContext.getBean(type);
|
||||
|
||||
if (item == null || !(item instanceof Validator)) throw new RuntimeException("unrecognized validator " + type.getSimpleName());
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public Validator validator(String validtor){
|
||||
|
||||
Validator item = this.applicationContext.getBean(validtor, Validator.class);
|
||||
|
||||
if (item == null || !(item instanceof Validator)) throw new RuntimeException("unrecognized validator " + validtor);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
|
||||
import jakarta.validation.Constraint;
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.commons.validation.old.FieldsValueMatch;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.commons.validation.old.RequiredOneField;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.commons.validation.old.EnumNotNull;
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
import java.lang.annotation.*;
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
|
||||
import jakarta.validation.Constraint;
|
|
@ -1,5 +1,6 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package eu.eudat.commons.validation;
|
||||
package eu.eudat.commons.validation.old;
|
||||
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.tools.exception.MyValidationException;
|
|
@ -0,0 +1,16 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import eu.eudat.commons.validation.Validator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface NavigationDetailsSpecification extends Specification {
|
||||
Supplier<Boolean> getPrecondition();
|
||||
|
||||
String getKey();
|
||||
|
||||
List<?> getDetails();
|
||||
|
||||
Supplier<Validator> getValidator();
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import eu.eudat.commons.validation.Validator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NavigationDetailsSpecificationBuilder implements NavigationDetailsSpecification {
|
||||
private Supplier<Boolean> precondition;
|
||||
private String key;
|
||||
private List<?> details;
|
||||
private Supplier<Validator> validator;
|
||||
|
||||
public NavigationDetailsSpecificationBuilder iff(Supplier<Boolean> value){
|
||||
this.precondition = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationDetailsSpecificationBuilder on(String value){
|
||||
this.key = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationDetailsSpecificationBuilder over(List<?> value){
|
||||
this.details = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationDetailsSpecificationBuilder using(Supplier<Validator> value){
|
||||
this.validator = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Boolean> getPrecondition() {
|
||||
return precondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Validator> getValidator() {
|
||||
return validator;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import eu.eudat.commons.validation.Validator;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface NavigationReferenceSpecification extends Specification{
|
||||
Supplier<Boolean> getPrecondition();
|
||||
|
||||
String getKey();
|
||||
|
||||
Object getReference();
|
||||
|
||||
Supplier<Validator> getValidator();
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import eu.eudat.commons.validation.Validator;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NavigationReferenceSpecificationBuilder implements NavigationReferenceSpecification {
|
||||
private Supplier<Boolean> precondition;
|
||||
private String key;
|
||||
private Object reference;
|
||||
private Supplier<Validator> validator;
|
||||
|
||||
public NavigationReferenceSpecificationBuilder iff(Supplier<Boolean> value){
|
||||
this.precondition = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationReferenceSpecificationBuilder on(String value){
|
||||
this.key = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationReferenceSpecificationBuilder over(Object value){
|
||||
this.reference = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NavigationReferenceSpecificationBuilder using(Supplier<Validator> value){
|
||||
this.validator = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Boolean> getPrecondition() {
|
||||
return precondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Validator> getValidator() {
|
||||
return validator;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface PropertySpecification extends Specification {
|
||||
|
||||
Supplier<Boolean> getPrecondition();
|
||||
|
||||
Supplier<Boolean> getSpecification();
|
||||
|
||||
String getErrorKey();
|
||||
|
||||
String getErrorMessage();
|
||||
String getErrorCode();
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PropertySpecificationBuilder implements PropertySpecification{
|
||||
private Supplier<Boolean> precondition;
|
||||
private Supplier<Boolean> specification;
|
||||
private String errorKey;
|
||||
private String errorMessage;
|
||||
private String errorCode = "validationerror";
|
||||
|
||||
public PropertySpecificationBuilder iff(Supplier<Boolean> value){
|
||||
this.precondition = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertySpecificationBuilder must(Supplier<Boolean> value){
|
||||
this.specification = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertySpecificationBuilder failOn(String value){
|
||||
this.errorKey = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertySpecificationBuilder failWith(String value){
|
||||
this.errorMessage = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertySpecificationBuilder failWithCode(String value){
|
||||
this.errorCode = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Boolean> getPrecondition() {
|
||||
return precondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Boolean> getSpecification() {
|
||||
return specification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorKey() {
|
||||
return errorKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package eu.eudat.commons.validation.specification;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Specification {
|
||||
}
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
|||
|
||||
import eu.eudat.commons.enums.ActionConfirmationStatus;
|
||||
import eu.eudat.commons.enums.ActionConfirmationType;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
|
||||
import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist;
|
||||
import jakarta.validation.Valid;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||
|
|
|
@ -2,19 +2,15 @@ package eu.eudat.model.persist;
|
|||
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
||||
import eu.eudat.commons.enums.UserDescriptionTemplateRole;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -2,47 +2,44 @@ package eu.eudat.model.persist;
|
|||
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.*;
|
||||
|
||||
import eu.eudat.commons.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.Description;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||
public class DescriptionTemplateTypePersist {
|
||||
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID id;
|
||||
|
||||
@NotNull(message = "{validation.empty}")
|
||||
@NotEmpty(message = "{validation.empty}")
|
||||
@Size(max = DescriptionTemplateTypeEntity._nameLength, message = "{validation.largerthanmax}")
|
||||
public final static String _id = "id";
|
||||
|
||||
private String name = null;
|
||||
|
||||
public final static String _name = "name";
|
||||
|
||||
private String hash;
|
||||
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
public final static String _hash = "hash";
|
||||
|
||||
private DescriptionTemplateTypeStatus status;
|
||||
|
||||
private List<DescriptionTemplateTypePersist> nested;
|
||||
|
||||
private DescriptionTemplateTypePersist obj;
|
||||
// private List<DescriptionTemplateTypePersist> nested;
|
||||
//
|
||||
// public final static String _nested = "nested";
|
||||
//
|
||||
// private DescriptionTemplateTypePersist obj;
|
||||
//
|
||||
// public final static String _obj = "obj";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
@ -76,79 +73,52 @@ public class DescriptionTemplateTypePersist {
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
public List<DescriptionTemplateTypePersist> getNested() {
|
||||
return nested;
|
||||
}
|
||||
|
||||
public void setNested(List<DescriptionTemplateTypePersist> nested) {
|
||||
this.nested = nested;
|
||||
}
|
||||
|
||||
public DescriptionTemplateTypePersist getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(DescriptionTemplateTypePersist obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
@Component(DescriptionTemplateTypePersistValidator.ValidatorName)
|
||||
public static class DescriptionTemplateTypePersistValidator extends BaseValidator {
|
||||
|
||||
@Autowired
|
||||
private DescriptionTemplateTypePersistValidator1 descriptionTemplateTypePersistValidator;
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public static class DescriptionTemplateTypePersistValidator extends BaseValidator<DescriptionTemplateTypePersist> {
|
||||
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator";
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ErrorThesaurusProperties errors) {
|
||||
super(errors);
|
||||
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ConventionService conventionService, ErrorThesaurusProperties errors) {
|
||||
super(conventionService, errors);
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return DescriptionTemplateTypePersist.class.equals(clazz);
|
||||
@Override
|
||||
protected Class<DescriptionTemplateTypePersist> modelClass() {
|
||||
return DescriptionTemplateTypePersist.class;
|
||||
}
|
||||
|
||||
public void validate(Object obj, Errors e) {
|
||||
e.rejectValue("name", "negativevalue", messageSource.getMessage("General_ItemNotFound", new Object[]{"aaa", Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
DescriptionTemplateTypePersist p = (DescriptionTemplateTypePersist) obj;
|
||||
try {
|
||||
e.pushNestedPath("obj");
|
||||
ValidationUtils.invokeValidator(descriptionTemplateTypePersistValidator, p.getObj(), e);
|
||||
} finally {
|
||||
e.popNestedPath();
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < p.getNested().size(); i++) {
|
||||
try {
|
||||
e.pushNestedPath("nested["+i+"]");
|
||||
ValidationUtils.invokeValidator(descriptionTemplateTypePersistValidator, p.getObj(), e);
|
||||
} finally {
|
||||
e.popNestedPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component(DescriptionTemplateTypePersistValidator1.ValidatorName)
|
||||
public static class DescriptionTemplateTypePersistValidator1 extends BaseValidator {
|
||||
|
||||
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator1";
|
||||
private final MessageSource messageSource;
|
||||
|
||||
public DescriptionTemplateTypePersistValidator1(MessageSource messageSource, ErrorThesaurusProperties errors) {
|
||||
super(errors);
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
return DescriptionTemplateTypePersist.class.equals(clazz);
|
||||
}
|
||||
|
||||
public void validate(Object obj, Errors e) {
|
||||
e.rejectValue("name", "negativevalue", messageSource.getMessage("General_ItemNotFound", new Object[]{"aaa", Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
|
||||
@Override
|
||||
protected List<Specification> specifications(DescriptionTemplateTypePersist item) {
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.iff(() -> this.isValidGuid(item.getId()))
|
||||
.must(() -> this.isValidHash(item.getHash()))
|
||||
.failOn(DescriptionTemplateTypePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplateTypePersist._hash}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isValidGuid(item.getId()))
|
||||
.must(() -> !this.isValidHash(item.getHash()))
|
||||
.failOn(DescriptionTemplateTypePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getName()))
|
||||
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isEmpty(item.getName()))
|
||||
.must(() -> this.lessEqual(item.getName(), DescriptionTemplateTypeEntity._nameLength))
|
||||
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale()))
|
||||
// this.refSpec()
|
||||
// .iff(() -> item.getObj() != null)
|
||||
// .on(DescriptionTemplateTypePersist._obj)
|
||||
// .over(item.getObj())
|
||||
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class)),
|
||||
// this.navSpec()
|
||||
// .iff(() -> item.getNested() != null)
|
||||
// .on(DescriptionTemplateTypePersist._nested)
|
||||
// .over(item.getNested())
|
||||
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.model.dmpblueprintdefinition.Definition;
|
||||
import eu.eudat.model.persist.dmpblueprintdefinition.DefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -2,10 +2,9 @@ package eu.eudat.model.persist;
|
|||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
||||
import jakarta.validation.Valid;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.RequiredOneField;
|
||||
import eu.eudat.commons.validation.old.RequiredOneField;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DmpAccessType;
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DmpUserRemovePersist {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.LockTargetType;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
|||
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.DescriptionTemplateEntity;
|
||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
|||
|
||||
import eu.eudat.commons.enums.ReferenceType;
|
||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.model.persist.referencetypedefinition.ReferenceTypeDefinitionPersist;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.StorageType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.data.StorageFileEntity;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.SupportiveMaterialFieldType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DmpBlueprintEntity;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.model.persist.tenantconfig.TenantConfigPersist;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.UserDescriptionTemplateRole;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
|
||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import eu.eudat.model.UserAdditionalInfo;
|
||||
import eu.eudat.model.UserContactInfo;
|
||||
import eu.eudat.model.UserCredential;
|
||||
import eu.eudat.model.UserRole;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.data.UserEntity;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.UserSettingsType;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package eu.eudat.model.persist.actionconfirmation;
|
||||
|
||||
import eu.eudat.commons.enums.DmpUserRole;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlAttribute;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist.deposit;
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
||||
|
||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -3,7 +3,7 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import eu.eudat.commons.enums.FieldType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
|||
|
||||
|
||||
import eu.eudat.commons.enums.FieldDataExternalDatasetType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public class ExternalDatasetDataPersist extends BaseFieldDataPersist {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
|
||||
|
||||
public class ExtraFieldPersist extends FieldPersist {
|
||||
|
|
|
@ -3,8 +3,8 @@ package eu.eudat.model.persist.dmpblueprintdefinition;
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||
|
||||
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
|
||||
public class SystemFieldPersist extends FieldPersist {
|
||||
@ValidEnum(message = "{validation.empty}")
|
||||
|
|
|
@ -4,8 +4,8 @@ import eu.eudat.commons.enums.notification.NotificationContactType;
|
|||
import eu.eudat.commons.enums.notification.NotificationNotifyState;
|
||||
import eu.eudat.commons.enums.notification.NotificationTrackingProcess;
|
||||
import eu.eudat.commons.enums.notification.NotificationTrackingState;
|
||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||
import eu.eudat.commons.validation.old.ValidId;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.referencedefinition;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.referencetypedefinition;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public class AuthenticationConfigurationPersist {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package eu.eudat.model.persist.referencetypedefinition;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package eu.eudat.model.persist.referencetypedefinition;
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package eu.eudat.model.persist.referencetypedefinition;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
||||
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
||||
import eu.eudat.commons.validation.ValidEnum;
|
||||
import eu.eudat.commons.validation.old.ValidEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
|
@ -1,30 +1,191 @@
|
|||
package eu.eudat.controllers.controllerhandler;
|
||||
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import gr.cite.tools.exception.MyValidationException;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import gr.cite.tools.exception.*;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Map;
|
||||
|
||||
@RestControllerAdvice
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(GlobalExceptionHandler.class));
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
|
||||
private final ErrorThesaurusProperties errors;
|
||||
|
||||
public GlobalExceptionHandler(ErrorThesaurusProperties errors) {
|
||||
this.errors = errors;
|
||||
public GlobalExceptionHandler(JsonHandlingService jsonHandlingService) {
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<?> handleUnexpectedErrors(Exception e, WebRequest request) throws Exception {
|
||||
if (e instanceof MyValidationException argumentNotValidException) {
|
||||
return new ResponseEntity<>(argumentNotValidException.getErrors(), HttpStatus.BAD_REQUEST);
|
||||
public ResponseEntity<?> handleUnexpectedErrors(Exception exception, WebRequest request) throws Exception {
|
||||
HandledException handled = this.handleException(exception, request);
|
||||
this.log(handled.getLevel(), exception, MessageFormat.format("returning code {0} and payload {1}", handled.getStatusCode(), handled.getMessage()));
|
||||
return new ResponseEntity<>(handled.getMessage(), handled.getStatusCode());
|
||||
}
|
||||
|
||||
public void log(System.Logger.Level level, Exception e, String message) {
|
||||
if (level != null) {
|
||||
switch (level) {
|
||||
case TRACE:
|
||||
logger.trace(message, e);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(message, e);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(message, e);
|
||||
break;
|
||||
case WARNING:
|
||||
logger.warn(message, e);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(message, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
|
||||
public HandledException handleException(Exception exception, WebRequest request) throws Exception {
|
||||
HttpStatus statusCode;
|
||||
Map<String, Object> result;
|
||||
System.Logger.Level logLevel;
|
||||
|
||||
switch (exception){
|
||||
case MyNotFoundException myNotFoundException -> {
|
||||
logLevel = System.Logger.Level.DEBUG;
|
||||
statusCode = HttpStatus.NOT_FOUND;
|
||||
int code = myNotFoundException.getCode();
|
||||
if (code > 0) {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("code", code),
|
||||
Map.entry("error", myNotFoundException.getMessage())
|
||||
);
|
||||
}
|
||||
else {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", myNotFoundException.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
case MyUnauthorizedException myUnauthorizedException -> {
|
||||
logLevel = System.Logger.Level.DEBUG;
|
||||
statusCode = HttpStatus.UNAUTHORIZED;
|
||||
int code = myUnauthorizedException.getCode();
|
||||
if (code > 0) {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("code", code),
|
||||
Map.entry("error", myUnauthorizedException.getMessage())
|
||||
);
|
||||
}
|
||||
else {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", myUnauthorizedException.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
case MyForbiddenException myForbiddenException -> {
|
||||
logLevel = System.Logger.Level.DEBUG;
|
||||
statusCode = HttpStatus.FORBIDDEN;
|
||||
int code = myForbiddenException.getCode();
|
||||
if (code > 0) {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("code", code),
|
||||
Map.entry("error", myForbiddenException.getMessage())
|
||||
);
|
||||
}
|
||||
else {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", myForbiddenException.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
case MyValidationException myValidationException -> {
|
||||
logLevel = System.Logger.Level.DEBUG;
|
||||
statusCode = HttpStatus.BAD_REQUEST;
|
||||
int code = myValidationException.getCode();
|
||||
if (code > 0) {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("code", code),
|
||||
Map.entry("error", myValidationException.getMessage()),
|
||||
Map.entry("message", myValidationException.getErrors())
|
||||
);
|
||||
}
|
||||
else {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", myValidationException.getMessage()),
|
||||
Map.entry("message", myValidationException.getErrors())
|
||||
);
|
||||
}
|
||||
}
|
||||
case MyApplicationException myApplicationException -> {
|
||||
logLevel = System.Logger.Level.ERROR;
|
||||
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
int code = myApplicationException.getCode();
|
||||
if (code > 0) {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("code", code),
|
||||
Map.entry("error", myApplicationException.getMessage())
|
||||
);
|
||||
}
|
||||
else {
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", myApplicationException.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
logLevel = System.Logger.Level.ERROR;
|
||||
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
result = Map.ofEntries(
|
||||
Map.entry("error", "System error")
|
||||
);
|
||||
}
|
||||
};
|
||||
String serialization = this.jsonHandlingService.toJsonSafe(result);
|
||||
return new HandledException(statusCode, serialization, logLevel);
|
||||
}
|
||||
|
||||
public static class HandledException{
|
||||
public HttpStatus statusCode;
|
||||
public String message;
|
||||
public System.Logger.Level level;
|
||||
|
||||
public HandledException(HttpStatus statusCode, String message, System.Logger.Level level) {
|
||||
this.statusCode = statusCode;
|
||||
this.message = message;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
}
|
||||
public HttpStatus getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(HttpStatus statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public System.Logger.Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(System.Logger.Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package eu.eudat.controllers.controllerhandler;
|
||||
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.commons.validation.Validator;
|
||||
import eu.eudat.commons.validation.ValidatorFactory;
|
||||
import eu.eudat.commons.validation.ValidationFilterAnnotation;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
|
@ -19,21 +18,27 @@ import java.util.Objects;
|
|||
@ControllerAdvice
|
||||
@RestControllerAdvice
|
||||
public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
|
||||
@Autowired
|
||||
private ApiContext apiContext;
|
||||
private final ValidatorFactory validatorFactory;
|
||||
|
||||
public ValidatorRequestBodyAdvice(ValidatorFactory validatorFactory) {
|
||||
this.validatorFactory = validatorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
if (parameter.getMethod() != null) {
|
||||
ValidationFilterAnnotation annotation = parameter.getMethod().getAnnotation((ValidationFilterAnnotation.class));
|
||||
ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class));
|
||||
|
||||
if (annotation == null || !Objects.equals(parameter.getParameterName(), annotation.argumentName())) return body;
|
||||
if (annotations == null) return body;
|
||||
for (ValidationFilterAnnotation annotation : annotations){
|
||||
if (!Objects.equals(parameter.getParameterName(), annotation.argumentName())) continue;
|
||||
|
||||
BaseValidator validator = this.apiContext.getOperationsContext().getApplicationContext().getBean(annotation.validator(), BaseValidator.class);
|
||||
if (validator == null) throw new MyApplicationException("validator not provided");
|
||||
|
||||
validator.validateForce(body);
|
||||
Validator validator = validatorFactory.validator(annotation.validator());
|
||||
if (validator == null) throw new MyApplicationException("validator not provided");
|
||||
|
||||
validator.validateForce(body);
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
@ -44,8 +49,8 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return true;
|
||||
public boolean supports(MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,4 +16,7 @@ validation.lowerthanmin=Value must be larger than {value}
|
|||
validation.largerthanmax=Value must be less than {value}
|
||||
validation.invalidid=Not valid id
|
||||
General_ItemNotFound=Item {0} of type {1} not found
|
||||
Validation_Required={0} is required
|
||||
Validation_Required={0} is required
|
||||
Validation_OverPosting=Too much info
|
||||
Validation_MaxLength={0} too long
|
||||
Validation_UnexpectedValue=Unexpected value in field {0}
|
|
@ -12,6 +12,7 @@ public class DatasetCriteria extends Criteria {
|
|||
private String like;
|
||||
private List<UUID> datasetTemplates;
|
||||
private Short status;
|
||||
private List<UUID> ids;
|
||||
private List<UUID> dmps;
|
||||
private List<UUID> groupIds;
|
||||
private List<UUID> grants;
|
||||
|
@ -50,6 +51,14 @@ public class DatasetCriteria extends Criteria {
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
public List<UUID> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(List<UUID> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
public List<UUID> getDmps() {
|
||||
return dmps;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.old.eudat.elastic.repository;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.old.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.old.eudat.elastic.entities.Dataset;
|
||||
import eu.old.eudat.elastic.entities.Dmp;
|
||||
|
@ -13,10 +14,8 @@ import org.elasticsearch.client.RestHighLevelClient;
|
|||
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.InnerHitBuilder;
|
||||
import org.elasticsearch.index.query.NestedQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.filter.FiltersAggregationBuilder;
|
||||
|
@ -78,6 +77,24 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<Dataset> findByIds(List<String> ids) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
SearchRequest searchRequest = new SearchRequest(this.environment.getProperty("elasticsearch.index"));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().should(QueryBuilders.termsQuery("datasets.id.keyword", ids));
|
||||
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery( "datasets", boolQuery, ScoreMode.Avg).innerHit(new InnerHitBuilder());
|
||||
searchSourceBuilder.query(nestedQueryBuilder);
|
||||
searchSourceBuilder.size(100000);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
return Arrays.stream(response.getHits().getHits())
|
||||
.map(hit -> hit.getInnerHits().values()).flatMap(Collection::stream)
|
||||
.map(SearchHits::getHits).flatMap(Arrays::stream)
|
||||
.map(x -> new Dataset().fromElasticEntity(this.transformFromString(x.getSourceAsString(), Map.class))).toList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dataset findDocument(String id) throws IOException {
|
||||
if (this.getClient() != null) {
|
||||
|
@ -205,7 +222,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
}
|
||||
|
||||
NestedQueryBuilder nestedQueryBuilder = QueryBuilders.nestedQuery("datasets", boolQuery, ScoreMode.None).innerHit(new InnerHitBuilder().setFetchSourceContext(new FetchSourceContext(true, new String[]{"datasets.id"}, null)).setSize(this.environment.getProperty("elasticsearch.innerHitsSize", Integer.class)));
|
||||
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/.fetchSource("datasets.id", null);
|
||||
searchSourceBuilder.query(nestedQueryBuilder)/*.from(criteria.getOffset()).size(criteria.getSize())*/;
|
||||
sortBuilders.forEach(searchSourceBuilder::sort);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse response = this.getClient().search(searchRequest, RequestOptions.DEFAULT);
|
||||
|
@ -267,6 +284,11 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
boolQuery = boolQuery.should(QueryBuilders.termQuery("datasets.status", criteria.getStatus().toString()));
|
||||
}
|
||||
|
||||
if (criteria.getIds() != null && criteria.getIds().size() > 0) {
|
||||
criteria.setIds(criteria.getIds().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.id.keyword", criteria.getIds().stream().map(UUID::toString).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
if (criteria.getDmps() != null && criteria.getDmps().size() > 0) {
|
||||
criteria.setDmps(criteria.getDmps().stream().filter(Objects::nonNull).collect(Collectors.toList()));
|
||||
boolQuery = boolQuery.should(QueryBuilders.termsQuery("datasets.dmp", criteria.getDmps().stream().map(UUID::toString).collect(Collectors.toList())));
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* Created by ikalyvas on 7/5/2018.
|
||||
*/
|
||||
public abstract class ElasticRepository<T extends ElasticEntity,C extends Criteria> implements Repository<T,C> {
|
||||
public abstract class ElasticRepository<T extends ElasticEntity<?>,C extends Criteria> implements Repository<T,C> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ElasticRepository.class);
|
||||
private RestHighLevelClient client;
|
||||
|
||||
|
|
|
@ -6,10 +6,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import eu.eudat.commons.JsonHandlingService;
|
||||
import eu.eudat.commons.XmlHandlingService;
|
||||
import eu.eudat.commons.enums.*;
|
||||
import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpContactEntity;
|
||||
import eu.eudat.commons.types.dmp.DmpPropertiesEntity;
|
||||
import eu.eudat.commons.types.reference.DefinitionEntity;
|
||||
import eu.eudat.commons.types.reference.FieldEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.data.DmpReferenceEntity;
|
||||
import eu.eudat.data.ReferenceEntity;
|
||||
|
@ -23,6 +27,7 @@ import gr.cite.tools.exception.MyApplicationException;
|
|||
import gr.cite.tools.logging.LoggerService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -34,20 +39,22 @@ public class DmpMigrationService {
|
|||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpMigrationService.class));
|
||||
private final DatabaseRepository databaseRepository;
|
||||
|
||||
private final JsonHandlingService jsonHandlingService;
|
||||
private final EntityManager entityManager;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final ConventionService conventionService;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private final Environment environment;
|
||||
|
||||
private static final int PageSize = 500;
|
||||
private static final boolean TestMode = false;
|
||||
|
||||
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, QueryFactory queryFactory) {
|
||||
public DmpMigrationService(DatabaseRepository databaseRepository, JsonHandlingService jsonHandlingService, EntityManager entityManager, ConventionService conventionService, XmlHandlingService xmlHandlingService, Environment environment) {
|
||||
this.databaseRepository = databaseRepository;
|
||||
this.jsonHandlingService = jsonHandlingService;
|
||||
this.entityManager = entityManager;
|
||||
this.queryFactory = queryFactory;
|
||||
this.conventionService = conventionService;
|
||||
this.xmlHandlingService = xmlHandlingService;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public void migrate() throws JsonProcessingException, NoSuchFieldException, IllegalAccessException {
|
||||
|
@ -118,53 +125,6 @@ public class DmpMigrationService {
|
|||
contactEntity.setUserId((String) model.getExtraProperties().get("contact"));
|
||||
dmpProperties.getContacts().add(contactEntity);
|
||||
}
|
||||
if (model.getExtraProperties().containsKey("license") && model.getExtraProperties().get("license") != null) {
|
||||
Object license = model.getExtraProperties().get("license");
|
||||
HashMap<String, String> licenseMap = jsonHandlingService.mapFromJson(jsonHandlingService.toJson(license));
|
||||
ReferenceEntity referenceEntity = new ReferenceEntity();
|
||||
if (licenseMap.containsKey("pid")) {
|
||||
referenceEntity.setReference(licenseMap.get("pid"));
|
||||
}
|
||||
ReferenceQuery referenceQuery = queryFactory.query(ReferenceQuery.class)
|
||||
.references(referenceEntity.getReference())
|
||||
.types(ReferenceType.Licenses)
|
||||
.isActive(IsActive.Active);
|
||||
List<ReferenceEntity> foundReferences = referenceQuery.collect();
|
||||
boolean licenseExists = foundReferences != null && !foundReferences.isEmpty();
|
||||
if (!licenseExists) {
|
||||
if (licenseMap.containsKey("name")) {
|
||||
referenceEntity.setLabel(licenseMap.get("name"));
|
||||
}
|
||||
if (licenseMap.containsKey("uri")) {
|
||||
referenceEntity.setSource(licenseMap.get("uri"));
|
||||
}
|
||||
if (licenseMap.containsKey("abbreviation")) {
|
||||
referenceEntity.setAbbreviation(licenseMap.get("abbreviation"));
|
||||
}
|
||||
referenceEntity.setId(UUID.randomUUID());
|
||||
referenceEntity.setSourceType(ReferenceSourceType.External);
|
||||
referenceEntity.setType(ReferenceType.Licenses);
|
||||
referenceEntity.setCreatedAt(Instant.now());
|
||||
referenceEntity.setUpdatedAt(Instant.now());
|
||||
referenceEntity.setIsActive(IsActive.Active);
|
||||
}
|
||||
|
||||
DmpReferenceEntity dmpReferenceEntity = new DmpReferenceEntity();
|
||||
dmpReferenceEntity.setId(UUID.randomUUID());
|
||||
dmpReferenceEntity.setDmpId(data.getId());
|
||||
if (licenseExists) {
|
||||
dmpReferenceEntity.setReferenceId(foundReferences.getFirst().getId());
|
||||
} else {
|
||||
dmpReferenceEntity.setReferenceId(referenceEntity.getId());
|
||||
}
|
||||
dmpReferenceEntity.setCreatedAt(Instant.now());
|
||||
dmpReferenceEntity.setUpdatedAt(Instant.now());
|
||||
dmpReferenceEntity.setIsActive(IsActive.Active);
|
||||
|
||||
if (!licenseExists)
|
||||
entityManager.persist(referenceEntity);
|
||||
entityManager.persist(dmpReferenceEntity);
|
||||
}
|
||||
}
|
||||
if (model.getProperties() != null) {
|
||||
model.getProperties().forEach((key,val) -> {
|
||||
|
@ -205,4 +165,117 @@ public class DmpMigrationService {
|
|||
} while (items != null && !items.isEmpty() && !TestMode);
|
||||
}
|
||||
|
||||
public void migrateDmpLicenses() throws JsonProcessingException {
|
||||
DMPDao dmpDao = databaseRepository.getDmpDao();
|
||||
long total = dmpDao.asQueryable().count();
|
||||
logger.debug("Migrate Licenses for Dmp Total : " + total);
|
||||
int page = 0;
|
||||
|
||||
Set<String> collectedLicenses = new HashSet<>();
|
||||
Map<String, UUID> licenseIdByName = new HashMap<>();
|
||||
List<DMP> items;
|
||||
do {
|
||||
items = dmpDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
|
||||
|
||||
if (items != null && !items.isEmpty()) {
|
||||
logger.debug("Migrate Licenses for Dmp " + page * PageSize + " of " + total);
|
||||
|
||||
for (DMP item : items) {
|
||||
DataManagementPlan model = new DataManagementPlan();
|
||||
model.fromDataModel(item);
|
||||
if (model.getExtraProperties() != null) {
|
||||
if (model.getExtraProperties().containsKey("license") && model.getExtraProperties().get("license") != null) {
|
||||
Object license = model.getExtraProperties().get("license");
|
||||
HashMap<String, String> licenseMap = this.jsonHandlingService.mapFromJson(this.jsonHandlingService.toJson(license));
|
||||
ReferenceEntity referenceEntity = new ReferenceEntity();
|
||||
String licensePid;
|
||||
if (licenseMap.containsKey("pid") && licenseMap.get("pid") != null) {
|
||||
licensePid = licenseMap.get("pid");
|
||||
referenceEntity.setReference(licensePid);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
boolean licenseExists = collectedLicenses.contains(licensePid);
|
||||
if (!licenseExists) {
|
||||
DefinitionEntity definitionEntity = new DefinitionEntity();
|
||||
List<FieldEntity> fields = new ArrayList<>();
|
||||
if (licenseMap.containsKey("name")) {
|
||||
referenceEntity.setLabel(licenseMap.get("name"));
|
||||
}
|
||||
if (licenseMap.containsKey("uri")) {
|
||||
referenceEntity.setReference(licenseMap.get("uri"));
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("uri"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("uri");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("uri"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("tag")) {
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("tag"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("tag");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("tag"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("hint")) {
|
||||
if (!this.conventionService.isNullOrEmpty(licenseMap.get("hint"))){
|
||||
FieldEntity fieldEntity = new FieldEntity();
|
||||
fieldEntity.setCode("hint");
|
||||
fieldEntity.setDataType(ReferenceFieldDataType.Text);
|
||||
fieldEntity.setValue(licenseMap.get("hint"));
|
||||
fields.add(fieldEntity);
|
||||
}
|
||||
}
|
||||
if (licenseMap.containsKey("abbreviation")) {
|
||||
referenceEntity.setAbbreviation(licenseMap.get("abbreviation"));
|
||||
}
|
||||
if (licenseMap.containsKey("created") && licenseMap.get("created") != null) {
|
||||
referenceEntity.setUpdatedAt(Instant.parse(licenseMap.get("created")));
|
||||
} else {
|
||||
referenceEntity.setCreatedAt(item.getCreated() == null ? Instant.now() : item.getCreated().toInstant());
|
||||
}
|
||||
if (licenseMap.containsKey("modified") && licenseMap.get("modified") != null) {
|
||||
referenceEntity.setUpdatedAt(Instant.parse(licenseMap.get("modified")));
|
||||
} else {
|
||||
referenceEntity.setUpdatedAt(item.getModified() == null ? Instant.now() : item.getModified().toInstant());
|
||||
}
|
||||
referenceEntity.setId(UUID.randomUUID());
|
||||
referenceEntity.setSourceType(ReferenceSourceType.External);
|
||||
referenceEntity.setSource(this.environment.getProperty("migration.default-license-source", "null"));
|
||||
referenceEntity.setType(ReferenceType.Licenses);
|
||||
referenceEntity.setIsActive(IsActive.Active);
|
||||
definitionEntity.setFields(fields);
|
||||
referenceEntity.setDefinition(this.xmlHandlingService.toXmlSafe(definitionEntity));
|
||||
|
||||
collectedLicenses.add(licensePid);
|
||||
licenseIdByName.put(licensePid, referenceEntity.getId());
|
||||
logger.debug("License '{}' migrated", licensePid);
|
||||
}
|
||||
|
||||
DmpReferenceEntity dmpReferenceEntity = new DmpReferenceEntity();
|
||||
dmpReferenceEntity.setId(UUID.randomUUID());
|
||||
dmpReferenceEntity.setDmpId(item.getId());
|
||||
dmpReferenceEntity.setReferenceId(licenseIdByName.get(licensePid));
|
||||
dmpReferenceEntity.setCreatedAt(Instant.now());
|
||||
dmpReferenceEntity.setUpdatedAt(Instant.now());
|
||||
dmpReferenceEntity.setIsActive(IsActive.Active);
|
||||
|
||||
if (!licenseExists)
|
||||
entityManager.persist(referenceEntity);
|
||||
entityManager.persist(dmpReferenceEntity);
|
||||
}
|
||||
}
|
||||
this.entityManager.flush();
|
||||
}
|
||||
|
||||
page++;
|
||||
}
|
||||
} while (items != null && !items.isEmpty() && !TestMode);
|
||||
logger.info("Dmp licenses migration finished");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import eu.eudat.data.DescriptionTagEntity;
|
|||
import eu.eudat.data.TagEntity;
|
||||
import eu.old.eudat.data.dao.entities.DatasetDao;
|
||||
import eu.old.eudat.data.entities.Dataset;
|
||||
import eu.old.eudat.elastic.criteria.DatasetCriteria;
|
||||
import eu.old.eudat.elastic.entities.Tag;
|
||||
import eu.old.eudat.elastic.repository.DatasetRepository;
|
||||
import eu.old.eudat.logic.services.operations.DatabaseRepository;
|
||||
|
@ -50,18 +51,24 @@ public class TagMigrationService {
|
|||
Set<String> savedTagNames = new HashSet<>();
|
||||
Map<String, UUID> savedTagIdsByName = new HashMap<>();
|
||||
|
||||
DatasetCriteria criteria = new DatasetCriteria();
|
||||
List<Dataset> items;
|
||||
do {
|
||||
items = datasetDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
|
||||
if (items != null && !items.isEmpty()) {
|
||||
logger.debug("Migrate Dataset tags " + page * PageSize + " of " + total);
|
||||
|
||||
for (Dataset item : items) {
|
||||
eu.old.eudat.elastic.entities.Dataset elasticDataset = this.datasetRepository.findDocument(item.getId().toString());
|
||||
if (elasticDataset == null) {
|
||||
criteria.setIds(items.stream().map(Dataset::getId).toList());
|
||||
// List<eu.old.eudat.elastic.entities.Dataset> elasticDatasets = this.datasetRepository.queryIds(criteria);
|
||||
List<eu.old.eudat.elastic.entities.Dataset> elasticDatasets = this.datasetRepository.findByIds(items.stream().map(x -> x.getId().toString()).toList());
|
||||
|
||||
for (Dataset item : items) {
|
||||
List<eu.old.eudat.elastic.entities.Dataset> found = elasticDatasets.stream().filter(x -> item.getId().toString().equals(x.getId())).toList();
|
||||
if (found.isEmpty()) {
|
||||
logger.error("No dataset with id {} found on elastic search. Skipping tag migration for this dataset", item.getId());
|
||||
continue;
|
||||
}
|
||||
eu.old.eudat.elastic.entities.Dataset elasticDataset = found.getFirst();
|
||||
boolean tagAlreadyExists;
|
||||
if (elasticDataset.getTags() != null && !elasticDataset.getTags().isEmpty()) {
|
||||
for(Tag tag : elasticDataset.getTags()) {
|
||||
|
|
|
@ -87,6 +87,7 @@ public class MigrationController {
|
|||
this.serviceMigrationService.migrate();
|
||||
|
||||
this.dmpMigrationService.migrate();
|
||||
this.dmpMigrationService.migrateDmpLicenses();
|
||||
this.dmpDatasetProfileMigrationService.migrate();
|
||||
this.datasetMigrationService.migrate();
|
||||
this.tagMigrationService.migrate();
|
||||
|
@ -125,6 +126,13 @@ public class MigrationController {
|
|||
return true;
|
||||
}
|
||||
|
||||
@GetMapping("dmps/licenses")
|
||||
@Transactional
|
||||
public boolean migrateDmpLicenses() throws JsonProcessingException, NoSuchFieldException, IllegalAccessException {
|
||||
this.dmpMigrationService.migrateDmpLicenses();
|
||||
return true;
|
||||
}
|
||||
|
||||
@GetMapping("datasets")
|
||||
@Transactional
|
||||
public boolean migrateDatasets() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
|
||||
|
|
|
@ -4,6 +4,7 @@ server.tomcat.max-connections = 10000
|
|||
logging.file=/logs/spring-boot-logging.log
|
||||
spring.profiles.active=devel
|
||||
eu.eudat.logic.proxy.allowed.host=https://eestore.paas2.uninett.no
|
||||
migration.default-license-source=opendefinition
|
||||
|
||||
####################Metrics##############
|
||||
management.endpoint.metrics.enabled=true
|
||||
|
|
Loading…
Reference in New Issue