reference type editor changes

This commit is contained in:
amentis 2024-01-31 18:39:18 +02:00
parent b4f55a721c
commit 3c32e57aad
7 changed files with 93 additions and 38 deletions

View File

@ -4,29 +4,33 @@ import eu.eudat.commons.validation.BaseValidator;
import gr.cite.tools.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import jakarta.xml.bind.annotation.XmlElement;
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.ArrayList;
import java.util.Arrays;
import java.util.List;
public class QueryConfigPersist {
private String condition;
public static final String _condition = "condition";
private String separator;
public static final String _separator = "separator";
private String value;
public static final String _value = "value";
private Integer ordinal;
public static final String _ordinal = "ordinal";
public String getCondition() {
return condition;
}
@XmlElement(name = "condition")
public void setCondition(String condition) {
this.condition = condition;
}
@ -35,7 +39,6 @@ public class QueryConfigPersist {
return separator;
}
@XmlElement(name = "separator")
public void setSeparator(String separator) {
this.separator = separator;
}
@ -44,7 +47,6 @@ public class QueryConfigPersist {
return value;
}
@XmlElement(name = "value")
public void setValue(String value) {
this.value = value;
}
@ -53,7 +55,6 @@ public class QueryConfigPersist {
return ordinal;
}
@XmlElement(name = "ordinal")
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
@ -63,9 +64,11 @@ public class QueryConfigPersist {
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
public static final String ValidatorName = "QueryConfigPersistValidator";
private final MessageSource messageSource;
protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
@ -75,7 +78,20 @@ public class QueryConfigPersist {
@Override
protected List<Specification> specifications(QueryConfigPersist item) {
return new ArrayList<>();
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getCondition()))
.failOn(QueryConfigPersist._condition).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._condition}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getSeparator()))
.failOn(QueryConfigPersist._separator).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._separator}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(QueryConfigPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._value}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getOrdinal()))
.failOn(QueryConfigPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._ordinal}, LocaleContextHolder.getLocale()))
);
}
}

View File

@ -76,13 +76,8 @@ public class ReferenceTypeDefinitionPersist {
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(ReferenceTypeDefinitionPersist._sources)
.over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.API).toList())
.using((itm) -> this.validatorFactory.validator(ReferenceTypeSourceExternalApiConfigurationPersist.ReferenceTypeSourceExternalApiConfigurationPersistValidator.class)),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
.on(ReferenceTypeDefinitionPersist._sources)
.over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.STATIC).toList())
.using((itm) -> this.validatorFactory.validator(ReferenceTypeSourceStaticOptionConfigurationPersist.ReferenceTypeSourceStaticOptionConfigurationPersistValidator.class))
.over(item.getSources())
.using((itm) -> ((ReferenceTypeSourceBaseConfigurationPersist) itm).getType() == ReferenceTypeSourceType.STATIC? this.validatorFactory.validator(ReferenceTypeSourceStaticOptionConfigurationPersist.ReferenceTypeSourceStaticOptionConfigurationPersistValidator.class): this.validatorFactory.validator(ReferenceTypeSourceExternalApiConfigurationPersist.ReferenceTypeSourceExternalApiConfigurationPersistValidator.class))
);
}
}

View File

@ -264,8 +264,8 @@ export class NotificationFieldOptionsEditorModel implements NotificationFieldOpt
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}optional[${index}].`
}), context.getValidation('optional')
)
})
), context.getValidation('optional').validators
),
});

View File

@ -550,6 +550,8 @@
</div>
</div>
<mat-error *ngIf="dependency.get('properties').dirty && dependency.get('properties').hasError('required')">{{'REFERENCE-TYPE-EDITOR.SOURCES-REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="dependency.get('properties').hasError('backendError')">{{dependency.get('properties').getError('backendError').message}}</mat-error>
</div>
</mat-card-content>
</div>
@ -561,6 +563,8 @@
</mat-card-content>
</div>
</div>
<mat-error *ngIf="formGroup.get('definition').get('sources').dirty && formGroup.get('definition').get('sources').hasError('required')">{{'REFERENCE-TYPE-EDITOR.SOURCES-REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="formGroup.get('definition').get('sources').hasError('backendError')">{{formGroup.get('definition').get('sources').getError('backendError').message}}</mat-error>
</div>
</form>
</mat-card-content>

View File

@ -172,9 +172,9 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
formSubmit(): void {
this.formService.touchAllFormFields(this.formGroup);
if (!this.isFormValid()) {
return;
}
// if (!this.isFormValid()) {
// return;
// }
this.persistEntity();
}
@ -352,13 +352,21 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
//
//
addQuery(sourceIndex: number): void {
const query: QueryConfigEditorModel = new QueryConfigEditorModel();
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray).push(query.buildForm());
const queryArray= ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
queryArray.push(this.editorModel.createQuery(sourceIndex, queryArray.length));
}
removeQuery(sourceIndex: number, queryIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
formArray.removeAt(queryIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
);
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries').markAsDirty();
}
// Options

View File

@ -79,6 +79,11 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen
return fieldMapping.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].options[' + index + '].'});
}
createQuery(sourceIndex: number, index: number): UntypedFormGroup {
const query: QueryConfigEditorModel = new QueryConfigEditorModel(this.validationErrorModel);
return query.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].queries[' + index + '].'});
}
createDepedency(sourceIndex: number, index: number): UntypedFormGroup {
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel(this.validationErrorModel);
return dependency.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].dependencies[' + index + '].'});
@ -156,8 +161,8 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}fields[${index}].`
}), context.getValidation('fields')
)
})
), context.getValidation('fields').validators
),
sources: this.formBuilder.array(
(this.sources ?? []).map(
@ -165,8 +170,8 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}sources[${index}].`
}), context.getValidation('sources')
)
})
), context.getValidation('sources').validators
)
});
}
@ -394,8 +399,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}queries[${index}].`
}), context.getValidation('queries')
)
})
), context.getValidation('queries').validators
),
options: this.formBuilder.array(
(this.options ?? []).map(
@ -403,8 +408,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}options[${index}].`
}), context.getValidation('options')
)
})
), context.getValidation('options').validators
),
dependencies: this.formBuilder.array(
(this.dependencies ?? []).map(
@ -412,8 +417,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}dependencies[${index}].`
}), context.getValidation('dependencies')
)
})
), context.getValidation('dependencies').validators
)
});
@ -489,6 +494,14 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
)
);
(formGroup.get('queries') as FormArray).controls?.forEach(
(control, index) => QueryConfigEditorModel.reapplyValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}queries[${index}].`,
validationErrorModel: validationErrorModel
})
);
(formGroup.get('dependencies') as FormArray).controls?.forEach(
(control, index) => ReferenceTypeSourceBaseDependencyEditorModel.reapplyDepedencyValidators({
formGroup: control as UntypedFormGroup,
@ -541,8 +554,8 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}fieldsMapping[${index}].`
}), context.getValidation('fieldsMapping')
)
})
), context.getValidation('fieldsMapping').validators
)
});
@ -808,6 +821,25 @@ export class QueryConfigEditorModel implements QueryConfigPersist {
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = QueryConfigEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['condition', 'separator', 'value', 'ordinal'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
export class ReferenceTypeStaticOptionEditorModel implements ReferenceTypeStaticOptionPersist {
@ -928,8 +960,8 @@ export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTy
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}properties[${index}].`
}), context.getValidation('properties')
)
})
), context.getValidation('properties').validators
),
});
}

View File

@ -133,8 +133,8 @@ export class DefinitionEditorModel implements DefinitionPersist {
this.validationErrorModel
).fromModel(item).buildForm({
rootPath: `${rootPath}fields[${index}].`
}), context.getValidation('fields')
)
})
), context.getValidation('fields').validators
),
});
}