2024-01-05 17:32:24 +01:00
package eu.eudat.model.persist ;
import eu.eudat.commons.validation.BaseValidator ;
2024-01-17 10:20:02 +01:00
import gr.cite.tools.validation.specification.Specification ;
2024-01-05 17:32:24 +01:00
import eu.eudat.convention.ConventionService ;
import eu.eudat.errorcode.ErrorThesaurusProperties ;
import gr.cite.tools.fieldset.BaseFieldSet ;
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 java.util.Arrays ;
import java.util.List ;
2024-03-05 12:41:58 +01:00
import java.util.Map ;
2024-01-05 17:32:24 +01:00
import java.util.UUID ;
public class DescriptionProfilingRequest {
2024-03-05 12:41:58 +01:00
private Map < String , String > data ;
public static final String _data = " data " ;
private String prefillId ;
public static final String _prefillId = " prefillId " ;
2024-03-01 10:14:27 +01:00
private UUID prefillingSourceId ;
2024-01-05 17:32:24 +01:00
2024-03-01 10:14:27 +01:00
public static final String _prefillingSourceId = " prefillingSourceId " ;
2024-01-05 17:32:24 +01:00
private UUID descriptionTemplateId ;
public static final String _descriptionTemplateId = " descriptionTemplateId " ;
private BaseFieldSet project ;
public static final String _project = " project " ;
2024-03-05 12:41:58 +01:00
public Map < String , String > getData ( ) {
return data ;
}
public void setData ( Map < String , String > data ) {
this . data = data ;
}
public String getPrefillId ( ) {
return prefillId ;
}
public void setPrefillId ( String prefillId ) {
this . prefillId = prefillId ;
}
2024-01-05 17:32:24 +01:00
2024-03-01 10:14:27 +01:00
public UUID getPrefillingSourceId ( ) {
return prefillingSourceId ;
2024-01-05 17:32:24 +01:00
}
2024-03-01 10:14:27 +01:00
public void setPrefillingSourceId ( UUID prefillingSourceId ) {
this . prefillingSourceId = prefillingSourceId ;
2024-01-05 17:32:24 +01:00
}
public UUID getDescriptionTemplateId ( ) {
return descriptionTemplateId ;
}
public void setDescriptionTemplateId ( UUID descriptionTemplateId ) {
this . descriptionTemplateId = descriptionTemplateId ;
}
public BaseFieldSet getProject ( ) {
return project ;
}
public void setProject ( BaseFieldSet project ) {
this . project = project ;
}
@Component ( DescriptionProfilingRequestValidator . ValidatorName )
@Scope ( ConfigurableBeanFactory . SCOPE_PROTOTYPE )
public static class DescriptionProfilingRequestValidator extends BaseValidator < DescriptionProfilingRequest > {
public static final String ValidatorName = " DescriptionProfilingRequestValidator " ;
private final MessageSource messageSource ;
protected DescriptionProfilingRequestValidator ( ConventionService conventionService , ErrorThesaurusProperties errors , MessageSource messageSource ) {
super ( conventionService , errors ) ;
this . messageSource = messageSource ;
}
@Override
protected Class < DescriptionProfilingRequest > modelClass ( ) {
return DescriptionProfilingRequest . class ;
}
@Override
protected List < Specification > specifications ( DescriptionProfilingRequest item ) {
return Arrays . asList (
this . spec ( )
. must ( ( ) - > this . isValidGuid ( item . getDescriptionTemplateId ( ) ) )
. failOn ( DescriptionProfilingRequest . _descriptionTemplateId ) . failWith ( messageSource . getMessage ( " Validation_Required " , new Object [ ] { DescriptionProfilingRequest . _descriptionTemplateId } , LocaleContextHolder . getLocale ( ) ) ) ,
this . spec ( )
2024-03-01 10:14:27 +01:00
. must ( ( ) - > this . isValidGuid ( item . getPrefillingSourceId ( ) ) )
2024-03-05 12:41:58 +01:00
. failOn ( DescriptionProfilingRequest . _prefillingSourceId ) . failWith ( messageSource . getMessage ( " Validation_Required " , new Object [ ] { DescriptionProfilingRequest . _prefillingSourceId } , LocaleContextHolder . getLocale ( ) ) ) ,
this . spec ( )
. must ( ( ) - > ! this . isEmpty ( item . getPrefillId ( ) ) )
. failOn ( DescriptionProfilingRequest . _prefillId ) . failWith ( messageSource . getMessage ( " Validation_Required " , new Object [ ] { DescriptionProfilingRequest . _prefillId } , LocaleContextHolder . getLocale ( ) ) )
// this.spec()
// .must(() -> item.getData() != null)
// .failOn(DescriptionProfilingWithDataRequest._data).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._data}, LocaleContextHolder.getLocale()))
// this.spec()
2024-03-01 17:45:32 +01:00
// .must(() -> item.getProject() != null)
2024-03-05 12:41:58 +01:00
// .failOn(DescriptionProfilingWithDataRequest._project).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionProfilingWithDataRequest._project}, LocaleContextHolder.getLocale()))
2024-01-05 17:32:24 +01:00
) ;
}
}
}