reference type editor changes
This commit is contained in:
parent
b4f55a721c
commit
3c32e57aad
|
@ -4,29 +4,33 @@ import eu.eudat.commons.validation.BaseValidator;
|
||||||
import gr.cite.tools.validation.specification.Specification;
|
import gr.cite.tools.validation.specification.Specification;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import jakarta.xml.bind.annotation.XmlElement;
|
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QueryConfigPersist {
|
public class QueryConfigPersist {
|
||||||
|
|
||||||
private String condition;
|
private String condition;
|
||||||
|
public static final String _condition = "condition";
|
||||||
|
|
||||||
private String separator;
|
private String separator;
|
||||||
|
public static final String _separator = "separator";
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
public static final String _value = "value";
|
||||||
|
|
||||||
private Integer ordinal;
|
private Integer ordinal;
|
||||||
|
public static final String _ordinal = "ordinal";
|
||||||
|
|
||||||
public String getCondition() {
|
public String getCondition() {
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "condition")
|
|
||||||
public void setCondition(String condition) {
|
public void setCondition(String condition) {
|
||||||
this.condition = condition;
|
this.condition = condition;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +39,6 @@ public class QueryConfigPersist {
|
||||||
return separator;
|
return separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "separator")
|
|
||||||
public void setSeparator(String separator) {
|
public void setSeparator(String separator) {
|
||||||
this.separator = separator;
|
this.separator = separator;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +47,6 @@ public class QueryConfigPersist {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "value")
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +55,6 @@ public class QueryConfigPersist {
|
||||||
return ordinal;
|
return ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "ordinal")
|
|
||||||
public void setOrdinal(Integer ordinal) {
|
public void setOrdinal(Integer ordinal) {
|
||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
}
|
}
|
||||||
|
@ -63,9 +64,11 @@ public class QueryConfigPersist {
|
||||||
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
|
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
|
||||||
|
|
||||||
public static final String ValidatorName = "QueryConfigPersistValidator";
|
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);
|
super(conventionService, errors);
|
||||||
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +78,20 @@ public class QueryConfigPersist {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Specification> specifications(QueryConfigPersist item) {
|
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()))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,13 +76,8 @@ public class ReferenceTypeDefinitionPersist {
|
||||||
this.navSpec()
|
this.navSpec()
|
||||||
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
|
.iff(() -> !this.isListNullOrEmpty(item.getSources()))
|
||||||
.on(ReferenceTypeDefinitionPersist._sources)
|
.on(ReferenceTypeDefinitionPersist._sources)
|
||||||
.over(item.getSources().stream().filter(x -> x.getType() == ReferenceTypeSourceType.API).toList())
|
.over(item.getSources())
|
||||||
.using((itm) -> this.validatorFactory.validator(ReferenceTypeSourceExternalApiConfigurationPersist.ReferenceTypeSourceExternalApiConfigurationPersistValidator.class)),
|
.using((itm) -> ((ReferenceTypeSourceBaseConfigurationPersist) itm).getType() == ReferenceTypeSourceType.STATIC? this.validatorFactory.validator(ReferenceTypeSourceStaticOptionConfigurationPersist.ReferenceTypeSourceStaticOptionConfigurationPersistValidator.class): 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))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,8 +264,8 @@ export class NotificationFieldOptionsEditorModel implements NotificationFieldOpt
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}optional[${index}].`
|
rootPath: `${rootPath}optional[${index}].`
|
||||||
}), context.getValidation('optional')
|
})
|
||||||
)
|
), context.getValidation('optional').validators
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -550,6 +550,8 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</div>
|
</div>
|
||||||
|
@ -561,6 +563,8 @@
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|
|
@ -172,9 +172,9 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
||||||
|
|
||||||
formSubmit(): void {
|
formSubmit(): void {
|
||||||
this.formService.touchAllFormFields(this.formGroup);
|
this.formService.touchAllFormFields(this.formGroup);
|
||||||
if (!this.isFormValid()) {
|
// if (!this.isFormValid()) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.persistEntity();
|
this.persistEntity();
|
||||||
}
|
}
|
||||||
|
@ -352,13 +352,21 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
addQuery(sourceIndex: number): void {
|
addQuery(sourceIndex: number): void {
|
||||||
const query: QueryConfigEditorModel = new QueryConfigEditorModel();
|
const queryArray= ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
|
||||||
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray).push(query.buildForm());
|
queryArray.push(this.editorModel.createQuery(sourceIndex, queryArray.length));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeQuery(sourceIndex: number, queryIndex: number): void {
|
removeQuery(sourceIndex: number, queryIndex: number): void {
|
||||||
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
|
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('queries') as FormArray);
|
||||||
formArray.removeAt(queryIndex);
|
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
|
// Options
|
||||||
|
|
|
@ -79,6 +79,11 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen
|
||||||
return fieldMapping.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].options[' + index + '].'});
|
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 {
|
createDepedency(sourceIndex: number, index: number): UntypedFormGroup {
|
||||||
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel(this.validationErrorModel);
|
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel(this.validationErrorModel);
|
||||||
return dependency.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].dependencies[' + index + '].'});
|
return dependency.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].dependencies[' + index + '].'});
|
||||||
|
@ -156,8 +161,8 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}fields[${index}].`
|
rootPath: `${rootPath}fields[${index}].`
|
||||||
}), context.getValidation('fields')
|
})
|
||||||
)
|
), context.getValidation('fields').validators
|
||||||
),
|
),
|
||||||
sources: this.formBuilder.array(
|
sources: this.formBuilder.array(
|
||||||
(this.sources ?? []).map(
|
(this.sources ?? []).map(
|
||||||
|
@ -165,8 +170,8 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}sources[${index}].`
|
rootPath: `${rootPath}sources[${index}].`
|
||||||
}), context.getValidation('sources')
|
})
|
||||||
)
|
), context.getValidation('sources').validators
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -394,8 +399,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}queries[${index}].`
|
rootPath: `${rootPath}queries[${index}].`
|
||||||
}), context.getValidation('queries')
|
})
|
||||||
)
|
), context.getValidation('queries').validators
|
||||||
),
|
),
|
||||||
options: this.formBuilder.array(
|
options: this.formBuilder.array(
|
||||||
(this.options ?? []).map(
|
(this.options ?? []).map(
|
||||||
|
@ -403,8 +408,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}options[${index}].`
|
rootPath: `${rootPath}options[${index}].`
|
||||||
}), context.getValidation('options')
|
})
|
||||||
)
|
), context.getValidation('options').validators
|
||||||
),
|
),
|
||||||
dependencies: this.formBuilder.array(
|
dependencies: this.formBuilder.array(
|
||||||
(this.dependencies ?? []).map(
|
(this.dependencies ?? []).map(
|
||||||
|
@ -412,8 +417,8 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}dependencies[${index}].`
|
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(
|
(formGroup.get('dependencies') as FormArray).controls?.forEach(
|
||||||
(control, index) => ReferenceTypeSourceBaseDependencyEditorModel.reapplyDepedencyValidators({
|
(control, index) => ReferenceTypeSourceBaseDependencyEditorModel.reapplyDepedencyValidators({
|
||||||
formGroup: control as UntypedFormGroup,
|
formGroup: control as UntypedFormGroup,
|
||||||
|
@ -541,8 +554,8 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}fieldsMapping[${index}].`
|
rootPath: `${rootPath}fieldsMapping[${index}].`
|
||||||
}), context.getValidation('fieldsMapping')
|
})
|
||||||
)
|
), context.getValidation('fieldsMapping').validators
|
||||||
)
|
)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -808,6 +821,25 @@ export class QueryConfigEditorModel implements QueryConfigPersist {
|
||||||
baseContext.validation = baseValidationArray;
|
baseContext.validation = baseValidationArray;
|
||||||
return baseContext;
|
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 {
|
export class ReferenceTypeStaticOptionEditorModel implements ReferenceTypeStaticOptionPersist {
|
||||||
|
@ -928,8 +960,8 @@ export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTy
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}properties[${index}].`
|
rootPath: `${rootPath}properties[${index}].`
|
||||||
}), context.getValidation('properties')
|
})
|
||||||
)
|
), context.getValidation('properties').validators
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,8 +133,8 @@ export class DefinitionEditorModel implements DefinitionPersist {
|
||||||
this.validationErrorModel
|
this.validationErrorModel
|
||||||
).fromModel(item).buildForm({
|
).fromModel(item).buildForm({
|
||||||
rootPath: `${rootPath}fields[${index}].`
|
rootPath: `${rootPath}fields[${index}].`
|
||||||
}), context.getValidation('fields')
|
})
|
||||||
)
|
), context.getValidation('fields').validators
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue