2024-02-08 17:12:47 +01:00
|
|
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
|
|
|
|
|
|
|
import eu.eudat.convention.ConventionService;
|
|
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
|
|
|
import gr.cite.tools.validation.specification.Specification;
|
|
|
|
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;
|
|
|
|
|
2024-04-19 10:10:51 +02:00
|
|
|
import java.util.Arrays;
|
2024-02-08 17:12:47 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2024-02-08 17:27:54 +01:00
|
|
|
public class ReferenceTypeFieldPersist extends FieldPersist {
|
2024-02-08 17:12:47 +01:00
|
|
|
|
|
|
|
private UUID referenceTypeId;
|
|
|
|
|
|
|
|
public static final String _referenceTypeId = "referenceTypeId";
|
|
|
|
|
2024-04-19 10:10:51 +02:00
|
|
|
private Boolean multipleSelect;
|
|
|
|
|
|
|
|
public static final String _multipleSelect = "multipleSelect";
|
|
|
|
|
|
|
|
|
2024-02-08 17:12:47 +01:00
|
|
|
public UUID getReferenceTypeId() {
|
|
|
|
return referenceTypeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setReferenceTypeId(UUID referenceTypeId) {
|
|
|
|
this.referenceTypeId = referenceTypeId;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:10:51 +02:00
|
|
|
public Boolean getMultipleSelect() {
|
|
|
|
return multipleSelect;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMultipleSelect(Boolean multipleSelect) {
|
|
|
|
this.multipleSelect = multipleSelect;
|
|
|
|
}
|
|
|
|
|
2024-02-08 17:12:47 +01:00
|
|
|
@Component(ReferenceFieldPersistPersistValidator.ValidatorName)
|
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
2024-02-08 17:27:54 +01:00
|
|
|
public static class ReferenceFieldPersistPersistValidator extends BaseFieldPersistValidator<ReferenceTypeFieldPersist> {
|
2024-02-08 17:12:47 +01:00
|
|
|
|
|
|
|
public static final String ValidatorName = "DmpBlueprint.ReferenceFieldPersistPersistValidator";
|
|
|
|
|
|
|
|
protected ReferenceFieldPersistPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
|
|
|
|
super(conventionService, errors, messageSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-08 17:27:54 +01:00
|
|
|
protected Class<ReferenceTypeFieldPersist> modelClass() {
|
|
|
|
return ReferenceTypeFieldPersist.class;
|
2024-02-08 17:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-08 17:27:54 +01:00
|
|
|
protected List<Specification> specifications(ReferenceTypeFieldPersist item) {
|
2024-02-08 17:12:47 +01:00
|
|
|
List<Specification> specifications = getBaseSpecifications(item);
|
2024-04-19 10:10:51 +02:00
|
|
|
specifications.addAll(Arrays.asList(
|
2024-02-08 17:12:47 +01:00
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getReferenceTypeId()))
|
2024-04-19 10:10:51 +02:00
|
|
|
.failOn(ReferenceTypeFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale())),
|
|
|
|
this.spec()
|
|
|
|
.must(() -> !this.isNull(item.getMultipleSelect()))
|
|
|
|
.failOn(ReferenceTypeFieldPersist._multipleSelect).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._multipleSelect}, LocaleContextHolder.getLocale())))
|
|
|
|
|
2024-02-08 17:12:47 +01:00
|
|
|
);
|
|
|
|
return specifications;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|