fix reference type editor validators

This commit is contained in:
amentis 2024-01-18 14:40:51 +02:00
parent 5e32f1e74d
commit 9356352e7d
5 changed files with 369 additions and 97 deletions

View File

@ -7,6 +7,7 @@ import eu.eudat.errorcode.ErrorThesaurusProperties;
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.List;
@ -45,7 +46,7 @@ public class ReferenceTypeSourceStaticOptionConfigurationPersist extends Referen
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
this.navSpec()
.iff(() -> !this.isNull(item.getOptions()))
.iff(() -> !this.isListNullOrEmpty(item.getOptions()))
.on(ReferenceTypeSourceStaticOptionConfigurationPersist._options)
.over(item.getOptions())
.using(() -> this.validatorFactory.validator(ReferenceTypeStaticOptionPersist.ReferenceTypeStaticOptionPersistValidator.class))

View File

@ -188,14 +188,14 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
inClause.value(item);
predicates.add(inClause);
}
if (this.dmpQuery != null) {
QueryContext<DmpEntity, UUID> subQuery = this.applySubQuery(this.dmpQuery, queryContext, UUID.class, dmpEntityRoot -> dmpEntityRoot.get(DmpEntity._id));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId)).value(subQuery.Query));
}
if (this.referenceQuery != null) {
QueryContext<ReferenceEntity, UUID> subQuery = this.applySubQuery(this.referenceQuery, queryContext, UUID.class, root -> root.get(ReferenceEntity._id));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._referenceId)).value(subQuery.Query));
}
// if (this.dmpQuery != null) {
// QueryContext<DmpEntity, UUID> subQuery = this.applySubQuery(this.dmpQuery, queryContext, UUID.class, dmpEntityRoot -> dmpEntityRoot.get(DmpEntity._id));
// predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId)).value(subQuery.Query));
// }
// if (this.referenceQuery != null) {
// QueryContext<ReferenceEntity, UUID> subQuery = this.applySubQuery(this.referenceQuery, queryContext, UUID.class, root -> root.get(ReferenceEntity._id));
// predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._referenceId)).value(subQuery.Query));
// }
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);

View File

@ -43,10 +43,8 @@
<mat-form-field class="col-lg-6">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" name="name" [formControl]="formGroup.get('code')" required>
<mat-error *ngIf="formGroup.get('code').hasError('backendError')">
{{formGroup.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="formGroup.get('code').hasError('backendError')">{{formGroup.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="formGroup.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
@ -115,8 +113,8 @@
{{enumUtils.toReferenceFieldDataTypeString(fieldDataType)}}
</mat-option>
</mat-select>
<mat-error *ngIf="field.get('dataType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="field.get('dataType').hasError('backendError')">{{field.get('dataType').getError('backendError').message}}</mat-error>
<mat-error *ngIf="field.get('dataType').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
@ -160,24 +158,24 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
<input matInput type="text" name="key" [formControl]="source.get('key')" required>
<mat-error *ngIf="source.get('key').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('key').hasError('backendError')">{{source.get('key').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('key').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}}</mat-label>
<input matInput type="text" name="label" [formControl]="source.get('label')" required>
<mat-error *ngIf="source.get('label').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('label').hasError('backendError')">{{source.get('label').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('label').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.ORDINAL' | translate}}</mat-label>
<input matInput type="text" name="ordinal" [formControl]="source.get('ordinal')" required>
<mat-error *ngIf="source.get('ordinal').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('ordinal').hasError('backendError')">{{source.get('ordinal').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('ordinal').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
@ -188,8 +186,8 @@
{{enumUtils.toReferenceTypeSourceTypeString(sourceType)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('type').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('type').hasError('backendError')">{{source.get('type').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
@ -198,32 +196,32 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}}</mat-label>
<input matInput type="text" name="ordinal" [formControl]="source.get('url')">
<mat-error *ngIf="source.get('url').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('url').hasError('backendError')">{{source.get('url').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('url').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.PAGINATION-PATH' | translate}}</mat-label>
<input matInput type="text" name="paginationPath" [formControl]="source.get('paginationPath')">
<mat-error *ngIf="source.get('paginationPath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('paginationPath').hasError('backendError')">{{source.get('paginationPath').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('paginationPath').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CONTENT-TYPE' | translate}}</mat-label>
<input matInput type="text" name="contentType" [formControl]="source.get('contentType')">
<mat-error *ngIf="source.get('contentType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('contentType').hasError('backendError')">{{source.get('contentType').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('contentType').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.FIRST-PAGE' | translate}}</mat-label>
<input matInput type="text" name="firstPage" [formControl]="source.get('firstPage')">
<mat-error *ngIf="source.get('firstPage').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('firstPage').hasError('backendError')">{{source.get('firstPage').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('firstPage').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
@ -234,24 +232,24 @@
{{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('httpMethod').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('httpMethod').hasError('backendError')">{{source.get('httpMethod').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('httpMethod').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6" *ngIf="source.get('httpMethod').value == referenceTypeExternalApiHTTPMethodType.POST" >
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}}</mat-label>
<input matInput type="text" name="requestBody" [formControl]="source.get('requestBody')">
<mat-error *ngIf="source.get('requestBody').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('requestBody').hasError('backendError')">{{source.get('requestBody').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('requestBody').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.FILTER-TYPE' | translate}}ype</mat-label>
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.FILTER-TYPE' | translate}}</mat-label>
<input matInput type="text" name="filterType" [formControl]="source.get('filterType')">
<mat-error *ngIf="source.get('filterType').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('filterType').hasError('backendError')">{{source.get('filterType').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('filterType').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<!-- Results info -->
@ -260,8 +258,8 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.RESULTS-PATH' | translate}}</mat-label>
<input matInput type="text" name="resultsArrayPath" [formControl]="source.get('results').get('resultsArrayPath')">
<mat-error *ngIf="source.get('results').get('resultsArrayPath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('results').get('resultsArrayPath').hasError('backendError')">{{source.get('results').get('resultsArrayPath').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('results').get('resultsArrayPath').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<!-- fields mapping -->
@ -281,16 +279,16 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="field.get('code').disabled" name="code" [formControl]="field.get('code')">
<mat-error *ngIf="field.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="field.get('code').hasError('backendError')">{{field.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="field.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.RESPONSE-PATH' | translate}}</mat-label>
<input matInput type="text" name="responsePath" [formControl]="field.get('responsePath')">
<mat-error *ngIf="field.get('responsePath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="field.get('responsePath').hasError('backendError')">{{field.get('responsePath').getError('backendError').message}}</mat-error>
<mat-error *ngIf="field.get('responsePath').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
@ -307,8 +305,8 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.URL' | translate}}</mat-label>
<input matInput type="text" name="authUrl" [formControl]="source.get('auth').get('authUrl')">
<mat-error *ngIf="source.get('auth').get('authUrl').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authUrl').hasError('backendError')">{{source.get('auth').get('authUrl').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authUrl').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
@ -319,32 +317,32 @@
{{enumUtils.toReferenceTypeExternalApiHTTPMethodTypeString(httpMethod)}}
</mat-option>
</mat-select>
<mat-error *ngIf="source.get('auth').get('authMethod').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authMethod').hasError('backendError')">{{source.get('auth').get('authMethod').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authMethod').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TOKEN-PATH' | translate}}</mat-label>
<input matInput type="text" name="authTokenPath" [formControl]="source.get('auth').get('authTokenPath')">
<mat-error *ngIf="source.get('auth').get('authTokenPath').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authTokenPath').hasError('backendError')">{{source.get('auth').get('authTokenPath').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authTokenPath').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUEST-BODY' | translate}}</mat-label>
<input matInput type="text" name="authRequestBody" [formControl]="source.get('auth').get('authRequestBody')">
<mat-error *ngIf="source.get('auth').get('authRequestBody').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authRequestBody').hasError('backendError')">{{source.get('auth').get('authRequestBody').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('auth').get('authRequestBody').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.TYPE' | translate}}</mat-label>
<input matInput type="text" name="type" [formControl]="source.get('auth').get('type')">
<mat-error *ngIf="source.get('auth').get('type').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="source.get('auth').get('type').hasError('backendError')">{{source.get('auth').get('type').getError('backendError').message}}</mat-error>
<mat-error *ngIf="source.get('auth').get('type').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
@ -373,32 +371,32 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CONDITION' | translate}}</mat-label>
<input matInput type="text" name="condition" [formControl]="query.get('condition')" required>
<mat-error *ngIf="query.get('condition').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="query.get('condition').hasError('backendError')">{{query.get('condition').getError('backendError').message}}</mat-error>
<mat-error *ngIf="query.get('condition').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.SEPARATOR' | translate}}</mat-label>
<input matInput type="text" name="separator" [formControl]="query.get('separator')" required>
<mat-error *ngIf="query.get('separator').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="query.get('separator').hasError('backendError')">{{query.get('separator').getError('backendError').message}}</mat-error>
<mat-error *ngIf="query.get('separator').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="query.get('value')" required>
<mat-error *ngIf="query.get('value').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="query.get('value').hasError('backendError')">{{query.get('value').getError('backendError').message}}</mat-error>
<mat-error *ngIf="query.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.ORDINAL' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="query.get('ordinal')" required>
<mat-error *ngIf="query.get('ordinal').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="query.get('ordinal').hasError('backendError')">{{query.get('ordinal').getError('backendError').message}}</mat-error>
<mat-error *ngIf="query.get('ordinal').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
@ -426,16 +424,16 @@
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" [readonly]="option.get('code').disabled" name="code" [formControl]="option.get('code')">
<mat-error *ngIf="option.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="option.get('code').hasError('backendError')">{{option.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="option.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
<input matInput type="text" name="value" [formControl]="option.get('value')">
<mat-error *ngIf="option.get('value').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="option.get('value').hasError('backendError')">{{option.get('value').getError('backendError').message}}</mat-error>
<mat-error *ngIf="option.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
@ -473,8 +471,8 @@
{{referenceType.code}}
</mat-option>
</mat-select>
<mat-error *ngIf="dependency.get('referenceTypeCode').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="dependency.get('referenceTypeCode').hasError('backendError')">{{dependency.get('referenceTypeCode').getError('backendError').message}}</mat-error>
<mat-error *ngIf="dependency.get('referenceTypeCode').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6" *ngIf="dependency.get('referenceTypeCode').value">
@ -485,16 +483,16 @@
{{key}}
</mat-option>
</mat-select>
<mat-error *ngIf="dependency.get('key').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="dependency.get('key').hasError('backendError')">{{dependency.get('key').getError('backendError').message}}</mat-error>
<mat-error *ngIf="dependency.get('key').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-label>
<input matInput type="text" name="required" [formControl]="dependency.get('required')" required>
<mat-error *ngIf="dependency.get('required').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="dependency.get('required').hasError('backendError')">{{dependency.get('required').getError('backendError').message}}</mat-error>
<mat-error *ngIf="dependency.get('required').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>
@ -524,8 +522,8 @@
{{code}}
</mat-option>
</mat-select>
<mat-error *ngIf="property.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="property.get('code').hasError('backendError')">{{property.get('code').getError('backendError').message}}</mat-error>
<mat-error *ngIf="property.get('code').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
@ -536,16 +534,16 @@
{{targetCode}}
</mat-option>
</mat-select>
<mat-error *ngIf="property.get('target').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="property.get('target').hasError('backendError')">{{property.get('target').getError('backendError').message}}</mat-error>
<mat-error *ngIf="property.get('target').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-6">
<mat-form-field class="w-100">
<mat-label>{{'REFERENCE-TYPE-EDITOR.FIELDS.REQUIRED' | translate}}</mat-label>
<input matInput type="text" name="required" [formControl]="property.get('required')" required>
<mat-error *ngIf="property.get('required').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<mat-error *ngIf="property.get('required').hasError('backendError')">{{property.get('required').getError('backendError').message}}</mat-error>
<mat-error *ngIf="property.get('required').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
</div>

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();
}
@ -213,13 +213,12 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
//
//
addField(): void {
(this.formGroup.get('definition').get('fields') as FormArray).push(this.editorModel.createChildField((this.formGroup.get('definition').get('fields') as FormArray).length));
(this.formGroup.get('definition').get('fields') as FormArray).push(this.editorModel.createChildField((this.formGroup.get('definition').get('fields') as FormArray).length));
}
removeField(fieldIndex: number): void {
const fieldCode = (this.formGroup.get('definition').get('fields') as FormArray).at(fieldIndex).get('code').value
if (this.propertyCodes.length > 0) {
if (this.propertyCodes.includes(fieldCode)) {
this.propertyCodes.splice(this.propertyCodes.indexOf(fieldCode), 1);
@ -279,8 +278,7 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
addSource(): void {
const source: ReferenceTypeSourceBaseConfigurationEditorModel = new ReferenceTypeSourceBaseConfigurationEditorModel();
(this.formGroup.get('definition').get('sources') as FormArray).push(source.buildForm());
(this.formGroup.get('definition').get('sources') as FormArray).push(this.editorModel.createChildSource((this.formGroup.get('definition').get('sources') as FormArray).length));
const sourceIndex = (this.formGroup.get('definition').get('sources') as FormArray).length - 1;
this.addFieldMapping(sourceIndex, "reference_id");
@ -302,6 +300,14 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
removeSource(sourceIndex: number): void {
(this.formGroup.get('definition').get('sources') as FormArray).removeAt(sourceIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
)
this.formGroup.get('definition').get('sources').markAsDirty();
}
//
@ -321,13 +327,22 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
}
}
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).push(fieldMapping.buildForm());
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).push(this.editorModel.createFieldsMapping(sourceIndex, fieldMappingSize));
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping') as FormArray).at(fieldMappingSize).get('code').patchValue(code);
}
removeFieldMapping(sourceIndex: number, fieldMappingIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex) as FormArray);
(formArray.get('results').get('fieldsMapping') as FormArray).removeAt(fieldMappingIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
);
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('fieldsMapping').markAsDirty();
}
@ -360,13 +375,21 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
}
}
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).push(options.buildForm());
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).push(this.editorModel.createOptions(sourceIndex, optionsSize));
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options') as FormArray).at(optionsSize).get('code').patchValue(code);
}
removeOption(sourceIndex: number, optionIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex) as FormArray);
(formArray.get('options') as FormArray).removeAt(optionIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
);
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('options').markAsDirty();
}
@ -374,15 +397,23 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
addDependency(sourceIndex: number): void {
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel();
const formArray = (this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray;
formArray.push(dependency.buildForm());
this.addProperty(sourceIndex, (formArray.length - 1));
const depedencySize = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).length;
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray)
.push(this.editorModel.createDepedency(sourceIndex, depedencySize));
//this.addProperty(sourceIndex, (depedencySize));
}
removeDependency(sourceIndex: number, dependencyIndex: number): void {
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray);
formArray.removeAt(dependencyIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
);
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies').markAsDirty();
}
private getReferenceTypes(excludedId?: Guid): void {
@ -447,13 +478,21 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
return;
}
const property: DependencyPropertyEditorModel = new DependencyPropertyEditorModel();
(((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties") as FormArray).push(property.buildForm());
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties") as FormArray
formArray.push(this.editorModel.createProperty(sourceIndex, dependencyIndex, formArray.length));
}
removeProperty(sourceIndex: number, dependencyIndex: number, propertyIndex: number): void {
const formArray = (((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties") as FormArray);
formArray.removeAt(propertyIndex);
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
{
formGroup: this.formGroup,
validationErrorModel: this.editorModel.validationErrorModel
}
);
((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('dependencies') as FormArray).at(dependencyIndex).get("properties").markAsDirty();
}
}

View File

@ -1,4 +1,4 @@
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { FormArray, UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { ReferenceFieldDataType } from "@app/core/common/enum/reference-field-data-type";
import { ReferenceTypeExternalApiHTTPMethodType } from "@app/core/common/enum/reference-type-external-api-http-method-type";
import { ReferenceTypeSourceType } from "@app/core/common/enum/reference-type-source-type";
@ -64,6 +64,31 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen
return field.buildForm({ rootPath: 'definition.fields[' + index + '].' });
}
createChildSource(index: number): UntypedFormGroup {
const source: ReferenceTypeSourceBaseConfigurationEditorModel = new ReferenceTypeSourceBaseConfigurationEditorModel(this.validationErrorModel);
return source.buildForm({ rootPath: 'definition.sources[' + index + '].' });
}
createFieldsMapping(sourceIndex: number, index: number): UntypedFormGroup {
const fieldMapping: ResultFieldsMappingConfigurationEditorModel = new ResultFieldsMappingConfigurationEditorModel(this.validationErrorModel);
return fieldMapping.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].results.fieldsMapping[' + index + '].'});
}
createOptions(sourceIndex: number, index: number): UntypedFormGroup {
const fieldMapping: ReferenceTypeStaticOptionEditorModel = new ReferenceTypeStaticOptionEditorModel(this.validationErrorModel);
return fieldMapping.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].options[' + index + '].'});
}
createDepedency(sourceIndex: number, index: number): UntypedFormGroup {
const dependency: ReferenceTypeSourceBaseDependencyEditorModel = new ReferenceTypeSourceBaseDependencyEditorModel(this.validationErrorModel);
return dependency.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].dependencies[' + index + '].'});
}
createProperty(sourceIndex: number, dependencyIndex: number, index: number): UntypedFormGroup {
const property: DependencyPropertyEditorModel = new DependencyPropertyEditorModel(this.validationErrorModel);
return property.buildForm({ rootPath: 'definition.sources[' + sourceIndex + '].dependencies[' + dependencyIndex + '].properties[' + index + '].'});
}
static reApplyDefinitionFieldsValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
@ -77,6 +102,20 @@ export class ReferenceTypeEditorModel extends BaseEditorModel implements Referen
validationErrorModel: validationErrorModel
});
}
static reApplyDefinitionSourcesValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
}): void {
const { formGroup, validationErrorModel } = params;
const control = formGroup?.get('definition');
ReferenceTypeDefinitionEditorModel.reapplySourcesValidators({
formArray: control.get('sources') as UntypedFormArray,
rootPath: `definition.`,
validationErrorModel: validationErrorModel
});
}
}
export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefinitionPersist {
@ -162,6 +201,21 @@ export class ReferenceTypeDefinitionEditorModel implements ReferenceTypeDefiniti
);
}
static reapplySourcesValidators(params: {
formArray: UntypedFormArray,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { validationErrorModel, rootPath, formArray } = params;
formArray?.controls?.forEach(
(control, index) => ReferenceTypeSourceBaseConfigurationEditorModel.reapplyValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}sources[${index}].`,
validationErrorModel: validationErrorModel
})
);
}
}
export class ReferenceTypeFieldEditorModel implements ReferenceTypeFieldPersist {
@ -258,7 +312,7 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
httpMethod: ReferenceTypeExternalApiHTTPMethodType;
requestBody?: string;
filterType?: string;
auth: AuthenticationConfigurationEditorModel = new AuthenticationConfigurationEditorModel();
auth: AuthenticationConfigurationEditorModel = new AuthenticationConfigurationEditorModel(this.validationErrorModel);
queries?: QueryConfigEditorModel[] = [];
options: ReferenceTypeStaticOptionEditorModel[] = [];
@ -333,7 +387,7 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
requestBody: [{ value: this.requestBody, disabled: disabled }, context.getValidation('requestBody').validators],
filterType: [{ value: this.filterType, disabled: disabled }, context.getValidation('filterType').validators],
auth: this.auth.buildForm({
rootPath: `auth.`
rootPath: `${rootPath}auth.`
}),
queries: this.formBuilder.array(
(this.queries ?? []).map(
@ -396,6 +450,54 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = ReferenceTypeSourceBaseConfigurationEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['type', 'key', 'label', 'ordinal', 'url', 'paginationPath', 'contentType', 'firstPage', 'httpMethod', 'requestBody','filterType'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
});
AuthenticationConfigurationEditorModel.reapplyAuthValidators({
formGroup: formGroup?.get('auth') as UntypedFormGroup,
rootPath: `${rootPath}auth.`,
validationErrorModel: validationErrorModel
});
ResultsConfigurationEditorModel.reapplyValidators({
formGroup: formGroup?.get('results') as UntypedFormGroup,
rootPath: `${rootPath}results.`,
validationErrorModel: validationErrorModel
});
(formGroup.get('options') as FormArray).controls?.forEach(
(control, index) => ReferenceTypeStaticOptionEditorModel.reapplyStaticOptionsValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}options[${index}].`,
validationErrorModel: validationErrorModel
}
)
);
(formGroup.get('dependencies') as FormArray).controls?.forEach(
(control, index) => ReferenceTypeSourceBaseDependencyEditorModel.reapplyDepedencyValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}dependencies[${index}].`,
validationErrorModel: validationErrorModel
})
);
}
}
export class ResultsConfigurationEditorModel implements ResultsConfigurationPersist {
@ -461,6 +563,34 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = ResultsConfigurationEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['resultsArrayPath'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
});
(formGroup.get('fieldsMapping') as FormArray).controls?.forEach(
(control, index) => ResultFieldsMappingConfigurationEditorModel.reapplyFieldsMappingValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}fieldsMapping[${index}].`,
validationErrorModel: validationErrorModel
}
)
);
}
}
export class ResultFieldsMappingConfigurationEditorModel implements ResultFieldsMappingConfigurationPersist {
@ -513,10 +643,29 @@ export class ResultFieldsMappingConfigurationEditorModel implements ResultFields
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyFieldsMappingValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = ResultFieldsMappingConfigurationEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['code', 'responsePath'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
});
}
}
export class AuthenticationConfigurationEditorModel implements AuthenticationConfigurationPersist {
public enabled: boolean;
public enabled: boolean = false;
public authUrl: string;
public authMethod: ReferenceTypeExternalApiHTTPMethodType;
public authTokenPath: string;
@ -581,6 +730,25 @@ export class AuthenticationConfigurationEditorModel implements AuthenticationCon
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyAuthValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = AuthenticationConfigurationEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['enabled', 'authUrl', 'authMethod', 'authTokenPath', 'authRequestBody', 'type'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
export class QueryConfigEditorModel implements QueryConfigPersist {
@ -694,6 +862,26 @@ export class ReferenceTypeStaticOptionEditorModel implements ReferenceTypeStatic
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyStaticOptionsValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = ReferenceTypeStaticOptionEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['code', 'value'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
});
}
}
export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTypeSourceBaseDependencyPersist {
@ -763,6 +951,33 @@ export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTy
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyDepedencyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = ReferenceTypeSourceBaseDependencyEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['referenceTypeCode', 'key', 'required'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
});
(formGroup.get('properties') as FormArray).controls?.forEach(
(control, index) => DependencyPropertyEditorModel.reapplyPropertyValidators({
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}properties[${index}].`,
validationErrorModel: validationErrorModel
})
);
}
}
export class DependencyPropertyEditorModel implements DependencyPropertyPersist {
@ -820,4 +1035,23 @@ export class DependencyPropertyEditorModel implements DependencyPropertyPersist
baseContext.validation = baseValidationArray;
return baseContext;
}
static reapplyPropertyValidators(params: {
formGroup: UntypedFormGroup,
validationErrorModel: ValidationErrorModel,
rootPath: string
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DependencyPropertyEditorModel.createValidationContext({
rootPath,
validationErrorModel
});
['code', 'target', 'required'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
control?.addValidators(context.getValidation(keyField).validators);
})
}
}