Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
ed9a4ab2c8
|
@ -228,7 +228,7 @@ public class DescriptionPersist {
|
|||
.iff(() -> item.getStatus() == DescriptionStatus.Finalized)
|
||||
.on(DescriptionPersist._properties)
|
||||
.over(item.getProperties())
|
||||
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition).withRules(definition))
|
||||
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus()).withDefinition(definition).setVisibilityService(definition, item.getProperties()))
|
||||
// this.navSpec()
|
||||
// .iff(() -> !this.isNull(item.getTags()))
|
||||
// .on(DescriptionPersist._tags)
|
||||
|
|
|
@ -7,6 +7,7 @@ import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
|
|||
import eu.eudat.commons.types.descriptiontemplate.RuleEntity;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.model.persist.ReferencePersist;
|
||||
import eu.eudat.service.visibility.VisibilityService;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
|
@ -96,8 +97,8 @@ public class FieldPersist {
|
|||
private final MessageSource messageSource;
|
||||
private FieldEntity fieldEntity;
|
||||
private DescriptionStatus status;
|
||||
private List<List<RuleEntity>> rules;
|
||||
private Boolean fieldSetIsRuleTarget;
|
||||
private VisibilityService visibilityService;
|
||||
private Integer ordinal;
|
||||
|
||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
||||
super(conventionService, errors);
|
||||
|
@ -114,34 +115,34 @@ public class FieldPersist {
|
|||
protected List<Specification> specifications(FieldPersist item) {
|
||||
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;
|
||||
boolean isRuleTarget = this.checkIfFieldIsRuleTarget();
|
||||
boolean isVisible = this.visibilityService.isVisible(fieldEntity.getId(), ordinal);
|
||||
return Arrays.asList(
|
||||
this.spec()
|
||||
.iff(()-> FieldType.isTextType(fieldType) && !fieldType.equals(FieldType.CHECK_BOX) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
|
||||
.iff(()-> FieldType.isTextType(fieldType) && !fieldType.equals(FieldType.CHECK_BOX) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required)
|
||||
.must(() -> !this.isEmpty(item.getTextValue()))
|
||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
|
||||
.iff(()-> FieldType.isDateType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required)
|
||||
.must(() -> !this.isNull(item.getDateValue()))
|
||||
.failOn(FieldPersist._dateValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._dateValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
|
||||
.iff(()-> FieldType.isExternalIdentifierType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required)
|
||||
.must(() -> !this.isNull(item.getExternalIdentifier()))
|
||||
.failOn(FieldPersist._externalIdentifier).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._externalIdentifier}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required && !fieldType.equals(FieldType.TAGS))
|
||||
.iff(()-> FieldType.isTextListType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required && !fieldType.equals(FieldType.TAGS))
|
||||
.must(() -> !this.isListNullOrEmpty(item.getTextListValue()) || !this.isEmpty(item.getTextValue()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> fieldType.equals(FieldType.TAGS) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
|
||||
.iff(()-> fieldType.equals(FieldType.TAGS) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required)
|
||||
.must(() -> !this.isListNullOrEmpty(item.getTextListValue()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget && required)
|
||||
.iff(()-> FieldType.isReferenceType(fieldType) && DescriptionStatus.Finalized.equals(this.status) && isVisible && required)
|
||||
.must(() -> !this.isListNullOrEmpty(item.getReferences()) || !this.isNull(item.getReference()))
|
||||
.failOn(FieldPersist._textListValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldPersist._textListValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(()-> !this.isEmpty(item.getTextValue()) && (fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION)) && this.isListNullOrEmpty(fieldEntity.getVisibilityRules()) && !isRuleTarget && !fieldSetIsRuleTarget)
|
||||
.iff(()-> !this.isEmpty(item.getTextValue()) && (fieldType.equals(FieldType.CHECK_BOX) || fieldType.equals(FieldType.BOOLEAN_DECISION)))
|
||||
.must(() -> this.isBoolean(item.getTextValue()))
|
||||
.failOn(FieldPersist._textValue).failWith(messageSource.getMessage("Validation_UnexpectedValue", new Object[]{FieldPersist._textValue}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
|
@ -171,30 +172,19 @@ public class FieldPersist {
|
|||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator withRules(List<List<RuleEntity>> rules) {
|
||||
this.rules = rules;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator setStatus(DescriptionStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator ifFieldSetIsRuleTarget(Boolean fieldSetIsRuleTarget){
|
||||
this.fieldSetIsRuleTarget = fieldSetIsRuleTarget;
|
||||
return this;
|
||||
public PersistValidator withVisibilityService(VisibilityService visibilityService) {
|
||||
this.visibilityService = visibilityService;
|
||||
return this;
|
||||
}
|
||||
private boolean checkIfFieldIsRuleTarget(){
|
||||
if (this.isListNullOrEmpty(rules)) return false;
|
||||
for (List<RuleEntity> rulesBySection: rules) {
|
||||
if (!this.isListNullOrEmpty(rulesBySection)){
|
||||
for (RuleEntity rule :rulesBySection) {
|
||||
if (rule.getTarget().equals(this.fieldEntity.getId())) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
public PersistValidator withOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import eu.eudat.commons.types.descriptiontemplate.RuleEntity;
|
|||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.persist.DescriptionPersist;
|
||||
import eu.eudat.service.visibility.VisibilityService;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
@ -61,8 +61,8 @@ public class PropertyDefinitionFieldSetItemPersist {
|
|||
|
||||
private final MessageSource messageSource;
|
||||
private FieldSetEntity fieldSetEntity;
|
||||
private List<List<RuleEntity>> rules;
|
||||
private DescriptionStatus status;
|
||||
private VisibilityService visibilityService;
|
||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource) {
|
||||
super(conventionService, errors);
|
||||
this.validatorFactory = validatorFactory;
|
||||
|
@ -88,7 +88,7 @@ public class PropertyDefinitionFieldSetItemPersist {
|
|||
.using((itm) ->
|
||||
{
|
||||
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
||||
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity).withRules(rules).ifFieldSetIsRuleTarget(this.checkIfFieldSetIsRuleTarget()).setStatus(this.status);
|
||||
return this.validatorFactory.validator(FieldPersist.PersistValidator.class).withFieldEntity(fieldEntity).withVisibilityService(visibilityService).withOrdinal(item.getOrdinal()).setStatus(this.status);
|
||||
})
|
||||
|
||||
);
|
||||
|
@ -99,26 +99,14 @@ public class PropertyDefinitionFieldSetItemPersist {
|
|||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator withRules(List<List<RuleEntity>> rules) {
|
||||
this.rules = rules;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator setStatus(DescriptionStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Boolean checkIfFieldSetIsRuleTarget(){
|
||||
if (this.isListNullOrEmpty(rules)) return false;
|
||||
for (List<RuleEntity> rulesBySection: rules) {
|
||||
if (!this.isListNullOrEmpty(rulesBySection)){
|
||||
for (RuleEntity rule :rulesBySection) {
|
||||
if (rule.getTarget().equals(this.fieldSetEntity.getId())) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public PersistValidator withVisibilityService(VisibilityService visibilityService) {
|
||||
this.visibilityService = visibilityService;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import eu.eudat.commons.types.descriptiontemplate.RuleEntity;
|
|||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.service.visibility.VisibilityService;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.springframework.context.MessageSource;
|
||||
|
@ -36,7 +37,7 @@ public class PropertyDefinitionFieldSetPersist {
|
|||
private final MessageSource messageSource;
|
||||
private FieldSetEntity fieldSetEntity;
|
||||
private DescriptionStatus status;
|
||||
private List<List<RuleEntity>> rules;
|
||||
private VisibilityService visibilityService;
|
||||
protected PersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, ValidatorFactory validatorFactory, MessageSource messageSource, MessageSource messageSource1) {
|
||||
super(conventionService, errors);
|
||||
this.validatorFactory = validatorFactory;
|
||||
|
@ -58,7 +59,7 @@ public class PropertyDefinitionFieldSetPersist {
|
|||
.iff(() -> !this.isNull(item.getItems()))
|
||||
.on(PropertyDefinitionFieldSetPersist._items)
|
||||
.over(item.getItems())
|
||||
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity).withRules(this.rules).setStatus(this.status)),
|
||||
.using((itm) -> this.validatorFactory.validator(PropertyDefinitionFieldSetItemPersist.PersistValidator.class).withFieldSetEntity(this.fieldSetEntity).withVisibilityService(this.visibilityService).setStatus(this.status)),
|
||||
this.spec()
|
||||
.iff(() -> DescriptionStatus.Finalized.equals(this.status) && fieldSetEntity.getHasMultiplicity())
|
||||
.must(() -> !this.isListNullOrEmpty(item.getItems()) && min <= item.getItems().size())
|
||||
|
@ -75,8 +76,8 @@ public class PropertyDefinitionFieldSetPersist {
|
|||
return this;
|
||||
}
|
||||
|
||||
public PersistValidator withRules(List<List<RuleEntity>> rules) {
|
||||
this.rules = rules;
|
||||
public PersistValidator withVisibilityService(VisibilityService visibilityService) {
|
||||
this.visibilityService = visibilityService;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ import eu.eudat.commons.enums.FieldValidationType;
|
|||
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.RuleEntity;
|
||||
import eu.eudat.commons.validation.BaseValidator;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.model.persist.validation.StatusAware;
|
||||
import eu.eudat.service.visibility.VisibilityService;
|
||||
import eu.eudat.service.visibility.VisibilityServiceImpl;
|
||||
import gr.cite.tools.validation.ValidatorFactory;
|
||||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -47,8 +48,7 @@ public class PropertyDefinitionPersist {
|
|||
|
||||
private DescriptionStatus status;
|
||||
private DefinitionEntity definition;
|
||||
|
||||
private List<List<RuleEntity>> rules;
|
||||
private VisibilityService visibilityService;
|
||||
|
||||
protected PropertyDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
|
||||
super(conventionService, errors);
|
||||
|
@ -81,7 +81,7 @@ public class PropertyDefinitionPersist {
|
|||
.mapKey((k) -> ((String)k))
|
||||
.using((itm) -> {
|
||||
FieldSetEntity fieldSetEntity = definition != null ? definition.getFieldSetById((String)itm.getKey()).stream().findFirst().orElse(null) : null;
|
||||
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withRules(rules).setStatus(this.status);
|
||||
return this.validatorFactory.validator(PropertyDefinitionFieldSetPersist.PersistValidator.class).withFieldSetEntity(fieldSetEntity).withVisibilityService(visibilityService).setStatus(this.status);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -97,9 +97,8 @@ public class PropertyDefinitionPersist {
|
|||
return this;
|
||||
}
|
||||
|
||||
public PropertyDefinitionPersistValidator withRules(DefinitionEntity definition) {
|
||||
List<FieldEntity> fields = definition.getAllField();
|
||||
this.rules = fields.stream().filter(x -> x.getVisibilityRules() != null).map(FieldEntity::getVisibilityRules).collect(Collectors.toList());
|
||||
public PropertyDefinitionPersistValidator setVisibilityService(DefinitionEntity definition, PropertyDefinitionPersist propertyDefinition) {
|
||||
this.visibilityService = new VisibilityServiceImpl(definition, propertyDefinition);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent {
|
|||
this.loadDescriptionTemplates();
|
||||
}
|
||||
|
||||
public compareWith(object1: any, object2: any) {
|
||||
return object1 && object2 && object1.id === object2.id;
|
||||
public compareWith(value1: string, value2: string): boolean {
|
||||
return value1 && value2 && value1 === value2;
|
||||
}
|
||||
|
||||
private loadDescriptionTemplates(): void {
|
||||
|
|
Loading…
Reference in New Issue