2023-11-03 15:02:47 +01:00
package eu.eudat.model.persist.dmpproperties ;
2024-01-02 16:39:50 +01:00
import eu.eudat.commons.validation.BaseValidator ;
2024-01-31 11:30:21 +01:00
import gr.cite.tools.validation.ValidatorFactory ;
2024-01-17 10:20:02 +01:00
import gr.cite.tools.validation.specification.Specification ;
2024-01-02 16:39:50 +01:00
import eu.eudat.convention.ConventionService ;
import eu.eudat.errorcode.ErrorThesaurusProperties ;
2024-01-12 14:00:34 +01:00
import eu.eudat.model.persist.ReferencePersist ;
2024-01-02 16:39:50 +01:00
import org.springframework.beans.factory.config.ConfigurableBeanFactory ;
2024-01-12 14:00:34 +01:00
import org.springframework.context.MessageSource ;
2024-01-02 16:39:50 +01:00
import org.springframework.context.annotation.Scope ;
2024-01-12 14:00:34 +01:00
import org.springframework.context.i18n.LocaleContextHolder ;
2024-01-02 16:39:50 +01:00
import org.springframework.stereotype.Component ;
import java.util.ArrayList ;
2024-01-12 14:00:34 +01:00
import java.util.Arrays ;
2024-01-02 16:39:50 +01:00
import java.util.List ;
2024-01-12 14:00:34 +01:00
import java.util.UUID ;
2024-01-02 16:39:50 +01:00
2023-11-03 15:02:47 +01:00
public class DmpBlueprintValuePersist {
2024-01-12 14:00:34 +01:00
private UUID fieldId ;
2023-11-03 15:02:47 +01:00
2024-01-12 14:00:34 +01:00
public static final String _fieldId = " fieldId " ;
2023-11-03 15:02:47 +01:00
private String fieldValue ;
2024-01-12 14:00:34 +01:00
public static final String _fieldValue = " fieldValue " ;
private List < ReferencePersist > references ;
public static final String _references = " references " ;
2023-11-03 15:02:47 +01:00
2024-01-12 14:00:34 +01:00
public UUID getFieldId ( ) {
2023-11-03 15:02:47 +01:00
return fieldId ;
}
2024-01-12 14:00:34 +01:00
public void setFieldId ( UUID fieldId ) {
2023-11-03 15:02:47 +01:00
this . fieldId = fieldId ;
}
public String getFieldValue ( ) {
return fieldValue ;
}
public void setFieldValue ( String fieldValue ) {
this . fieldValue = fieldValue ;
}
2024-01-12 14:00:34 +01:00
public List < ReferencePersist > getReferences ( ) {
return references ;
}
public void setReferences ( List < ReferencePersist > references ) {
this . references = references ;
}
2024-01-02 16:39:50 +01:00
@Component ( DmpBlueprintValuePersistValidator . ValidatorName )
@Scope ( ConfigurableBeanFactory . SCOPE_PROTOTYPE )
public static class DmpBlueprintValuePersistValidator extends BaseValidator < DmpBlueprintValuePersist > {
2024-01-31 11:30:21 +01:00
private final ValidatorFactory validatorFactory ;
2024-01-12 14:00:34 +01:00
private final MessageSource messageSource ;
2024-01-02 16:39:50 +01:00
public static final String ValidatorName = " DmpBlueprintValuePersistValidator " ;
2024-01-31 11:30:21 +01:00
protected DmpBlueprintValuePersistValidator ( ConventionService conventionService , ErrorThesaurusProperties errors , ValidatorFactory validatorFactory , MessageSource messageSource ) {
2024-01-02 16:39:50 +01:00
super ( conventionService , errors ) ;
2024-01-31 11:30:21 +01:00
this . validatorFactory = validatorFactory ;
2024-01-12 14:00:34 +01:00
this . messageSource = messageSource ;
2024-01-02 16:39:50 +01:00
}
@Override
protected Class < DmpBlueprintValuePersist > modelClass ( ) {
return DmpBlueprintValuePersist . class ;
}
@Override
protected List < Specification > specifications ( DmpBlueprintValuePersist item ) {
2024-01-12 14:00:34 +01:00
return Arrays . asList (
2024-01-31 11:30:21 +01:00
// this.spec()
// .must(() -> !this.isValidGuid(item.getFieldId()))
// .failOn(DmpBlueprintValuePersist._fieldId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldId}, LocaleContextHolder.getLocale())),
// this.spec()
// .iff(() -> this.isNull(item.getReferences()) || item.getReferences().isEmpty())
// .must(() -> !this.isEmpty(item.getFieldValue()))
// .failOn(DmpBlueprintValuePersist._fieldValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{DmpBlueprintValuePersist._fieldValue}, LocaleContextHolder.getLocale())),
2024-01-31 16:07:16 +01:00
this . navSpec ( )
. iff ( ( ) - > ! this . isListNullOrEmpty ( item . getReferences ( ) ) )
. on ( DmpBlueprintValuePersist . _references )
. over ( item . getReferences ( ) )
. using ( ( itm ) - > this . validatorFactory . validator ( ReferencePersist . ReferencePersistValidator . class ) )
2024-01-12 14:00:34 +01:00
) ;
2024-01-02 16:39:50 +01:00
}
}
2023-11-03 15:02:47 +01:00
}