add validate description
This commit is contained in:
parent
54e194e078
commit
9a99c0c300
|
@ -173,49 +173,47 @@ public class DescriptionPersist {
|
||||||
DescriptionTemplateEntity descriptionTemplate = this.isValidGuid(item.getDescriptionTemplateId()) ? this.entityManager.find(DescriptionTemplateEntity.class, item.getDescriptionTemplateId()) : null;
|
DescriptionTemplateEntity descriptionTemplate = this.isValidGuid(item.getDescriptionTemplateId()) ? this.entityManager.find(DescriptionTemplateEntity.class, item.getDescriptionTemplateId()) : null;
|
||||||
DefinitionEntity definition = descriptionTemplate == null ? null : this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, descriptionTemplate.getDefinition());
|
DefinitionEntity definition = descriptionTemplate == null ? null : this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, descriptionTemplate.getDefinition());
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .iff(() -> this.isValidGuid(item.getId()))
|
.iff(() -> this.isValidGuid(item.getId()))
|
||||||
// .must(() -> this.isValidHash(item.getHash()))
|
.must(() -> this.isValidHash(item.getHash()))
|
||||||
// .failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._hash}, LocaleContextHolder.getLocale())),
|
.failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._hash}, LocaleContextHolder.getLocale())),
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .iff(() -> !this.isValidGuid(item.getId()))
|
.iff(() -> !this.isValidGuid(item.getId()))
|
||||||
// .must(() -> !this.isValidHash(item.getHash()))
|
.must(() -> !this.isValidHash(item.getHash()))
|
||||||
// .failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
.failOn(DescriptionPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .must(() -> !this.isEmpty(item.getLabel()))
|
.must(() -> !this.isEmpty(item.getLabel()))
|
||||||
// .failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .iff(() -> !this.isEmpty(item.getLabel()))
|
.iff(() -> !this.isEmpty(item.getLabel()))
|
||||||
// .must(() -> this.lessEqualLength(item.getLabel(), DescriptionEntity._labelLength))
|
.must(() -> this.lessEqualLength(item.getLabel(), DescriptionEntity._labelLength))
|
||||||
// .failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
.failOn(DescriptionPersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionPersist._label}, LocaleContextHolder.getLocale())),
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .must(() -> this.isValidGuid(item.getDmpId()))
|
.must(() -> this.isValidGuid(item.getDmpId()))
|
||||||
// .failOn(DescriptionPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpId}, LocaleContextHolder.getLocale())),
|
.failOn(DescriptionPersist._dmpId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpId}, LocaleContextHolder.getLocale())),
|
||||||
// this.spec()
|
this.spec()
|
||||||
// .iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
.must(() -> this.isValidGuid(item.getDescriptionTemplateId()))
|
||||||
// .must(() -> this.isValidGuid(item.getDescriptionTemplateId()))
|
.failOn(DescriptionPersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._descriptionTemplateId}, LocaleContextHolder.getLocale())),
|
||||||
// .failOn(DescriptionPersist._descriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._descriptionTemplateId}, LocaleContextHolder.getLocale())),
|
this.spec()
|
||||||
// this.spec()
|
.must(() -> this.isValidGuid(item.getDmpDescriptionTemplateId()))
|
||||||
// .iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
.failOn(DescriptionPersist._dmpDescriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpDescriptionTemplateId}, LocaleContextHolder.getLocale())),
|
||||||
// .must(() -> this.isValidGuid(item.getDmpDescriptionTemplateId()))
|
this.spec()
|
||||||
// .failOn(DescriptionPersist._dmpDescriptionTemplateId).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._dmpDescriptionTemplateId}, LocaleContextHolder.getLocale())),
|
.must(() -> !this.isNull(item.getStatus()))
|
||||||
// this.spec()
|
.failOn(DescriptionPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._status}, LocaleContextHolder.getLocale())),
|
||||||
// .must(() -> !this.isNull(item.getStatus()))
|
this.spec()
|
||||||
// .failOn(DescriptionPersist._status).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._status}, LocaleContextHolder.getLocale())),
|
.iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
||||||
// this.spec()
|
.must(() -> !this.isNull(item.getProperties()))
|
||||||
// .iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
.failOn(DescriptionPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._properties}, LocaleContextHolder.getLocale())),
|
||||||
// .must(() -> !this.isListNullOrEmpty(item.getTags()))
|
this.refSpec()
|
||||||
// .failOn(DescriptionPersist._tags).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._tags}, LocaleContextHolder.getLocale())),
|
.iff(() -> !this.isNull(item.getProperties()))
|
||||||
//
|
.on(DescriptionPersist._properties)
|
||||||
// this.spec()
|
.over(item.getProperties())
|
||||||
// .iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition)),
|
||||||
// .must(() -> !this.isNull(item.getProperties()))
|
this.navSpec()
|
||||||
// .failOn(DescriptionPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionPersist._properties}, LocaleContextHolder.getLocale())),
|
.iff(() -> !this.isNull(item.getTags()))
|
||||||
// this.refSpec()
|
.on(DescriptionPersist._tags)
|
||||||
// .iff(() -> !this.isNull(item.getProperties()))
|
.over(item.getTags())
|
||||||
// .on(DescriptionPersist._properties)
|
.using((itm) -> this.validatorFactory.validator(TagPersist.TagPersistValidator.class))
|
||||||
// .over(item.getProperties())
|
|
||||||
// .using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package eu.eudat.model.persist.descriptionproperties;
|
package eu.eudat.model.persist.descriptionproperties;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.enums.FieldType;
|
import eu.eudat.commons.enums.FieldType;
|
||||||
|
import eu.eudat.commons.enums.FieldValidationType;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import eu.eudat.model.persist.ReferencePersist;
|
import eu.eudat.model.persist.ReferencePersist;
|
||||||
|
@ -81,6 +83,7 @@ public class FieldPersist {
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private FieldEntity fieldEntity;
|
private FieldEntity fieldEntity;
|
||||||
|
private DescriptionStatus status;
|
||||||
|
|
||||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
||||||
super(conventionService, errors);
|
super(conventionService, errors);
|
||||||
|
@ -96,29 +99,30 @@ public class FieldPersist {
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(FieldPersist item) {
|
protected List<Specification> specifications(FieldPersist item) {
|
||||||
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
|
FieldType fieldType = this.fieldEntity != null && this.fieldEntity.getData() != null ? this.fieldEntity.getData().getFieldType() : FieldType.FREE_TEXT;
|
||||||
|
boolean required = this.fieldEntity != null && this.fieldEntity.getValidations() != null ? this.fieldEntity.getValidations().contains(FieldValidationType.Required) : false;
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> FieldType.isTextType(fieldType))
|
.iff(()-> FieldType.isTextType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required)
|
||||||
.must(() -> !this.isEmpty(item.getTextValue()))
|
.must(() -> !this.isEmpty(item.getTextValue()))
|
||||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> FieldType.isDateType(fieldType))
|
.iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required)
|
||||||
.must(() -> !this.isNull(item.getDateValue()))
|
.must(() -> !this.isNull(item.getDateValue()))
|
||||||
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> FieldType.isExternalIdentifierType(fieldType))
|
.iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required)
|
||||||
.must(() -> !this.isNull(item.getExternalIdentifier()))
|
.must(() -> !this.isNull(item.getExternalIdentifier()))
|
||||||
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> FieldType.isTextListType(fieldType))
|
.iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required)
|
||||||
.must(() -> !this.isNull(item.getTextListValue()))
|
.must(() -> !this.isNull(item.getTextListValue()))
|
||||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> FieldType.isReferenceType(fieldType))
|
.iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && required)
|
||||||
.must(() -> !this.isNull(item.getTextListValue()))
|
.must(() -> !this.isNull(item.getTextListValue()))
|
||||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
.iff(()-> !this.isEmpty(item.getTextValue()) && fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION))
|
.iff(()-> !this.isEmpty(item.getTextValue()) && fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION) )
|
||||||
.must(() -> this.isBoolean(item.getTextValue()))
|
.must(() -> this.isBoolean(item.getTextValue()))
|
||||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||||
this.spec()
|
this.spec()
|
||||||
|
@ -146,6 +150,11 @@ public class FieldPersist {
|
||||||
this.fieldEntity = fieldEntity;
|
this.fieldEntity = fieldEntity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PersistValidator setStatus(DescriptionStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.model.persist.descriptionproperties;
|
package eu.eudat.model.persist.descriptionproperties;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
|
@ -59,6 +60,7 @@ public class PropertyDefinitionFieldSetItemPersist {
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
private FieldSetEntity fieldSetEntity;
|
private FieldSetEntity fieldSetEntity;
|
||||||
|
private DescriptionStatus status;
|
||||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
||||||
super(conventionService, errors);
|
super(conventionService, errors);
|
||||||
this.validatorFactory = validatorFactory;
|
this.validatorFactory = validatorFactory;
|
||||||
|
@ -84,7 +86,7 @@ public class PropertyDefinitionFieldSetItemPersist {
|
||||||
.using((itm) ->
|
.using((itm) ->
|
||||||
{
|
{
|
||||||
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
||||||
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity);
|
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity).setStatus(this.status);
|
||||||
})
|
})
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -94,6 +96,11 @@ public class PropertyDefinitionFieldSetItemPersist {
|
||||||
this.fieldSetEntity = fieldSetEntity;
|
this.fieldSetEntity = fieldSetEntity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PersistValidator setStatus(DescriptionStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.model.persist.descriptionproperties;
|
package eu.eudat.model.persist.descriptionproperties;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
@ -7,6 +8,7 @@ import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import gr.cite.tools.validation.specification.Specification;
|
import gr.cite.tools.validation.specification.Specification;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -30,10 +32,13 @@ public class PropertyDefinitionFieldSetPersist {
|
||||||
|
|
||||||
public static final String ValidatorName = "Description.PropertyDefinitionFieldSetPersistValidator";
|
public static final String ValidatorName = "Description.PropertyDefinitionFieldSetPersistValidator";
|
||||||
private final ValidatorFactory validatorFactory;
|
private final ValidatorFactory validatorFactory;
|
||||||
|
private final MessageSource messageSource;
|
||||||
private FieldSetEntity fieldSetEntity;
|
private FieldSetEntity fieldSetEntity;
|
||||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
private DescriptionStatus status;
|
||||||
|
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource, MessageSource messageSource1) {
|
||||||
super(conventionService, errors);
|
super(conventionService, errors);
|
||||||
this.validatorFactory = validatorFactory;
|
this.validatorFactory = validatorFactory;
|
||||||
|
this.messageSource = messageSource1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,12 +48,23 @@ public class PropertyDefinitionFieldSetPersist {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(PropertyDefinitionFieldSetPersist item) {
|
protected List<Specification> specifications(PropertyDefinitionFieldSetPersist item) {
|
||||||
|
Integer min = fieldSetEntity != null && fieldSetEntity.getMultiplicity() != null ? fieldSetEntity.getMultiplicity().getMin() : null;
|
||||||
|
Integer max = fieldSetEntity != null && fieldSetEntity.getMultiplicity() != null ? fieldSetEntity.getMultiplicity().getMax() : null;
|
||||||
|
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
this.navSpec()
|
this.navSpec()
|
||||||
.iff(() -> !this.isNull(item.getItems()))
|
.iff(() -> !this.isNull(item.getItems()))
|
||||||
.on(PropertyDefinitionFieldSetPersist._items)
|
.on(PropertyDefinitionFieldSetPersist._items)
|
||||||
.over(item.getItems())
|
.over(item.getItems())
|
||||||
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity))
|
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity).setStatus(this.status)),
|
||||||
|
this.spec()
|
||||||
|
.iff(() -> DescriptionStatus.Finalized.equals(this.status) && min != null)
|
||||||
|
.must(() -> !this.isNull(item.getItems()) && min >= item.getItems().size())
|
||||||
|
.failOn(PropertyDefinitionFieldSetPersist._items).failWith(messageSource.getMessage("Validation.LargerThenEqual", new Object[]{PropertyDefinitionFieldSetPersist._items, min}, LocaleContextHolder.getLocale())),
|
||||||
|
this.spec()
|
||||||
|
.iff(() -> DescriptionStatus.Finalized.equals(this.status) && max != null)
|
||||||
|
.must(() -> !this.isNull(item.getItems()) && max <= item.getItems().size())
|
||||||
|
.failOn(PropertyDefinitionFieldSetPersist._items).failWith(messageSource.getMessage("Validation.LessThenEqual", new Object[]{PropertyDefinitionFieldSetPersist._items, max}, LocaleContextHolder.getLocale()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +72,12 @@ public class PropertyDefinitionFieldSetPersist {
|
||||||
this.fieldSetEntity = fieldSetEntity;
|
this.fieldSetEntity = fieldSetEntity;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PropertyDefinitionFieldSetPersist.PersistValidator setStatus(DescriptionStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package eu.eudat.model.persist.descriptionproperties;
|
package eu.eudat.model.persist.descriptionproperties;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
|
import eu.eudat.commons.enums.FieldValidationType;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
import eu.eudat.commons.types.descriptiontemplate.DefinitionEntity;
|
||||||
|
import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
||||||
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
import eu.eudat.commons.types.descriptiontemplate.FieldSetEntity;
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.BaseValidator;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
@ -15,9 +17,8 @@ import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PropertyDefinitionPersist {
|
public class PropertyDefinitionPersist {
|
||||||
|
|
||||||
|
@ -64,7 +65,12 @@ public class PropertyDefinitionPersist {
|
||||||
.iff(() -> this.status == DescriptionStatus.Finalized)
|
.iff(() -> this.status == DescriptionStatus.Finalized)
|
||||||
.must(() -> !this.isNull(item.getFieldSets()) && !item.getFieldSets().isEmpty())
|
.must(() -> !this.isNull(item.getFieldSets()) && !item.getFieldSets().isEmpty())
|
||||||
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())),
|
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fieldSets}, LocaleContextHolder.getLocale())),
|
||||||
|
this.spec()
|
||||||
|
.must(() -> this.isListNullOrEmpty(this.getMissingFieldSetEntity(item)))
|
||||||
|
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFieldSets(this.getMissingFieldSetEntity(item))}, LocaleContextHolder.getLocale())),
|
||||||
|
this.spec()
|
||||||
|
.must(() -> this.isListNullOrEmpty(this.getMissingFieldsEntity(item)))
|
||||||
|
.failOn(PropertyDefinitionPersist._fieldSets).failWith(messageSource.getMessage("Validation.MissingFields", new Object[]{this.serializeMissingFields(this.getMissingFieldsEntity(item))}, LocaleContextHolder.getLocale())),
|
||||||
this.mapSpec()
|
this.mapSpec()
|
||||||
.iff(() -> !this.isNull(item.getFieldSets()))
|
.iff(() -> !this.isNull(item.getFieldSets()))
|
||||||
.on(PropertyDefinitionPersist._fieldSets)
|
.on(PropertyDefinitionPersist._fieldSets)
|
||||||
|
@ -72,7 +78,7 @@ public class PropertyDefinitionPersist {
|
||||||
.mapKey((k) -> ((String)k))
|
.mapKey((k) -> ((String)k))
|
||||||
.using((itm) -> {
|
.using((itm) -> {
|
||||||
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
||||||
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity);
|
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).setStatus(this.status);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +93,73 @@ public class PropertyDefinitionPersist {
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<FieldSetEntity> getMissingFieldSetEntity(PropertyDefinitionPersist item){
|
||||||
|
List<FieldSetEntity> missingMultipleFieldSets = new ArrayList<>();
|
||||||
|
|
||||||
|
if (definition == null || definition.getAllFieldSets() == null) return missingMultipleFieldSets;
|
||||||
|
for (FieldSetEntity fieldSet: definition.getAllFieldSets()) {
|
||||||
|
|
||||||
|
boolean requiredAtLeastOneFieldSet = fieldSet.getMultiplicity() != null && fieldSet.getMultiplicity().getMin() > 0;
|
||||||
|
if (requiredAtLeastOneFieldSet) {
|
||||||
|
if (item == null || item.getFieldSets() == null) missingMultipleFieldSets.add(fieldSet);
|
||||||
|
PropertyDefinitionFieldSetPersist fieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null);
|
||||||
|
if (fieldSetPersist == null) missingMultipleFieldSets.add(fieldSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return missingMultipleFieldSets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldEntity> getMissingFieldsEntity(PropertyDefinitionPersist item){
|
||||||
|
List<FieldEntity> missingFields = new ArrayList<>();
|
||||||
|
|
||||||
|
if (definition == null || definition.getAllFieldSets() == null) return missingFields;
|
||||||
|
for (FieldSetEntity fieldSet: definition.getAllFieldSets()) {
|
||||||
|
|
||||||
|
if (fieldSet.getFields() == null) continue;
|
||||||
|
|
||||||
|
for(FieldEntity field : fieldSet.getFields()){
|
||||||
|
|
||||||
|
if (field.getValidations() == null) continue;
|
||||||
|
if (field.getValidations().contains(FieldValidationType.Required)){
|
||||||
|
if (item == null || item.getFieldSets() == null) {
|
||||||
|
missingFields.add(field);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PropertyDefinitionFieldSetPersist propertyDefinitionFieldSetPersist = item.getFieldSets().getOrDefault(fieldSet.getId(), null);
|
||||||
|
if (propertyDefinitionFieldSetPersist == null || propertyDefinitionFieldSetPersist.getItems() == null) {
|
||||||
|
missingFields.add(field);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PropertyDefinitionFieldSetItemPersist propertyDefinitionFieldSetItemPersist: propertyDefinitionFieldSetPersist.getItems()) {
|
||||||
|
|
||||||
|
if (propertyDefinitionFieldSetItemPersist.getFields() == null){
|
||||||
|
missingFields.add(field);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FieldPersist fieldPersist = propertyDefinitionFieldSetItemPersist.getFields().getOrDefault(field.getId(), null);
|
||||||
|
if (fieldPersist == null){
|
||||||
|
missingFields.add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missingFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String serializeMissingFieldSets (List<FieldSetEntity> missingFieldSets){
|
||||||
|
if (missingFieldSets == null) return "";
|
||||||
|
return missingFieldSets.stream().map(x -> x.getId()).collect(Collectors.joining(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String serializeMissingFields (List<FieldEntity> missingFields){
|
||||||
|
if (missingFields == null) return "";
|
||||||
|
return missingFields.stream().map(x -> x.getId()).collect(Collectors.joining(", "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import gr.cite.tools.fieldset.FieldSet;
|
import gr.cite.tools.fieldset.FieldSet;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import gr.cite.tools.validation.ValidationResult;
|
||||||
import gr.cite.tools.validation.ValidatorFactory;
|
import gr.cite.tools.validation.ValidatorFactory;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
@ -379,10 +380,10 @@ public class DescriptionServiceImpl implements DescriptionService {
|
||||||
for (DescriptionEntity description: descriptions) {
|
for (DescriptionEntity description: descriptions) {
|
||||||
DescriptionValidationResult descriptionValidationResult = new DescriptionValidationResult(description.getId(), DescriptionValidationOutput.Invalid);
|
DescriptionValidationResult descriptionValidationResult = new DescriptionValidationResult(description.getId(), DescriptionValidationOutput.Invalid);
|
||||||
|
|
||||||
//TODO description template
|
// // TODO Persist
|
||||||
if (!this.conventionService.isNullOrEmpty(description.getLabel()) && description.getDmpId() != null && description.getDescriptionTemplateId() != null && description.getStatus() != null && !this.conventionService.isNullOrEmpty(description.getProperties())){
|
DescriptionPersist.DescriptionPersistValidator validator = this.validatorFactory.validator(DescriptionPersist.DescriptionPersistValidator.class);
|
||||||
descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);
|
validator.validate(new DescriptionPersist());
|
||||||
}
|
if (validator.result().isValid()) descriptionValidationResult.setResult(DescriptionValidationOutput.Valid);;
|
||||||
descriptionValidationResults.add(descriptionValidationResult);
|
descriptionValidationResults.add(descriptionValidationResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,3 +22,6 @@ Validation_MaxLength={0} too long
|
||||||
Validation_UnexpectedValue=Unexpected value in field {0}
|
Validation_UnexpectedValue=Unexpected value in field {0}
|
||||||
Validation_Unique= {0} must be unique
|
Validation_Unique= {0} must be unique
|
||||||
Validation.LowerThanMin= value must be equal or larger than {0}
|
Validation.LowerThanMin= value must be equal or larger than {0}
|
||||||
|
Validation.LessThenEqual= value {0} must be equal or less than {1}
|
||||||
|
Validation.LargerThenEqual= value {0} must be equal or larger than {1}
|
||||||
|
Validation.MissingFields= missing fields: {0}
|
Loading…
Reference in New Issue