dmp blueprint reference add multiple

This commit is contained in:
Efstratios Giannopoulos 2024-04-19 11:10:51 +03:00
parent 7daafdae2e
commit eb38e1d948
29 changed files with 193 additions and 36 deletions

View File

@ -12,6 +12,8 @@ public class ReferenceTypeFieldEntity extends FieldEntity {
@XmlAttribute(name="referenceTypeId")
private UUID referenceTypeId;
@XmlAttribute(name = "multipleSelect")
private Boolean multipleSelect;
public UUID getReferenceTypeId() {
return referenceTypeId;
}
@ -19,4 +21,12 @@ public class ReferenceTypeFieldEntity extends FieldEntity {
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
}

View File

@ -24,6 +24,9 @@ public class ReferenceTypeFieldImportExport {
@XmlAttribute(name = "required")
private boolean required;
@XmlAttribute(name = "multipleSelect")
private Boolean multipleSelect;
public UUID getId() {
return id;
}
@ -80,5 +83,11 @@ public class ReferenceTypeFieldImportExport {
this.required = required;
}
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
}

View File

@ -4,6 +4,7 @@ import eu.eudat.commonmodels.models.dmpblueprint.ReferenceTypeFieldModel;
import eu.eudat.commons.types.dmpblueprint.ReferenceTypeFieldEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.commonmodels.ReferenceTypeCommonModelBuilder;
import eu.eudat.model.dmpblueprintdefinition.ReferenceTypeField;
import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -31,6 +32,7 @@ public class ReferenceTypeFieldCommonModelBuilder extends FieldCommonModelBuilde
protected ReferenceTypeFieldModel buildChild(ReferenceTypeFieldEntity data, ReferenceTypeFieldModel model) {
if (data.getReferenceTypeId() != null ) model.setReferenceType(this.builderFactory.builder(ReferenceTypeCommonModelBuilder.class).build(this.queryFactory.query(ReferenceTypeQuery.class).ids(data.getReferenceTypeId()).first())); //TODO: Optimize
//model.setMultipleSelect(data.getMultipleSelect()); //TODO: add to common model
return model;
}

View File

@ -40,8 +40,9 @@ public class ReferenceFieldBuilder extends FieldBuilder<ReferenceTypeField, Refe
protected ReferenceTypeField buildChild(FieldSet fields, ReferenceTypeFieldEntity data, ReferenceTypeField model) {
FieldSet referenceTypeFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeField._referenceType));
if (data.getReferenceTypeId() != null && !referenceTypeFields.isEmpty() ) model.setReferenceType(this.builderFactory.builder(ReferenceTypeBuilder.class).build(referenceTypeFields, this.queryFactory.query(ReferenceTypeQuery.class).ids(data.getReferenceTypeId()).first())); //TODO: Optimize
if (fields.hasField(this.asIndexer(ReferenceTypeField._multipleSelect))) model.setMultipleSelect(data.getMultipleSelect());
return model;
}
}

View File

@ -9,6 +9,9 @@ public class ReferenceTypeField extends Field {
public final static String _referenceType = "referenceType";
private ReferenceType referenceType;
public final static String _multipleSelect = "multipleSelect";
private Boolean multipleSelect;
public ReferenceType getReferenceType() {
return referenceType;
}
@ -16,4 +19,12 @@ public class ReferenceTypeField extends Field {
public void setReferenceType(ReferenceType referenceType) {
this.referenceType = referenceType;
}
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
}

View File

@ -9,6 +9,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@ -18,6 +19,11 @@ public class ReferenceTypeFieldPersist extends FieldPersist {
public static final String _referenceTypeId = "referenceTypeId";
private Boolean multipleSelect;
public static final String _multipleSelect = "multipleSelect";
public UUID getReferenceTypeId() {
return referenceTypeId;
}
@ -26,6 +32,14 @@ public class ReferenceTypeFieldPersist extends FieldPersist {
this.referenceTypeId = referenceTypeId;
}
public Boolean getMultipleSelect() {
return multipleSelect;
}
public void setMultipleSelect(Boolean multipleSelect) {
this.multipleSelect = multipleSelect;
}
@Component(ReferenceFieldPersistPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceFieldPersistPersistValidator extends BaseFieldPersistValidator<ReferenceTypeFieldPersist> {
@ -44,10 +58,14 @@ public class ReferenceTypeFieldPersist extends FieldPersist {
@Override
protected List<Specification> specifications(ReferenceTypeFieldPersist item) {
List<Specification> specifications = getBaseSpecifications(item);
specifications.add(
specifications.addAll(Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getReferenceTypeId()))
.failOn(ReferenceTypeFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale()))
.failOn(ReferenceTypeFieldPersist._referenceTypeId).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._referenceTypeId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getMultipleSelect()))
.failOn(ReferenceTypeFieldPersist._multipleSelect).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeFieldPersist._multipleSelect}, LocaleContextHolder.getLocale())))
);
return specifications;
}

View File

@ -33,6 +33,8 @@ public class DmpBlueprintValuePersist {
public static final String _fieldValue = "fieldValue";
private List<ReferencePersist> references;
public static final String _references = "references";
private ReferencePersist reference;
public static final String _reference = "reference";
public UUID getFieldId() {
return fieldId;
@ -58,6 +60,14 @@ public class DmpBlueprintValuePersist {
this.references = references;
}
public ReferencePersist getReference() {
return reference;
}
public void setReference(ReferencePersist reference) {
this.reference = reference;
}
@Component(DmpBlueprintValuePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class DmpBlueprintValuePersistValidator extends BaseValidator<DmpBlueprintValuePersist> {
@ -97,16 +107,27 @@ public class DmpBlueprintValuePersist {
.must(() -> !this.isEmpty(item.getFieldValue()))
.failOn(DmpBlueprintValuePersist._fieldValue).failWith(messageSource.getMessage("Validation_Required", new Object[]{fieldEntity.getLabel()}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && required)
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && ((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect() && required)
.must(() -> !this.isListNullOrEmpty(item.getReferences()))
// TODO: Cast Exception
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(fieldEntity)}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : DmpBlueprintValuePersist._references}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> fieldEntity.getCategory().equals(DmpBlueprintFieldCategory.ReferenceType) && this.isEmpty(item.getFieldValue()) && !((ReferenceTypeFieldEntity)fieldEntity).getMultipleSelect() && required)
.must(() -> !this.isNull(item.getReference()))
// TODO: Cast Exception
// .failOn(DmpBlueprintValuePersist._references).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : this.getReferenceTypeName(fieldEntity)}, LocaleContextHolder.getLocale())),
.failOn(DmpBlueprintValuePersist._reference).failWith(messageSource.getMessage("Validation_Required", new Object[]{!this.isEmpty(fieldEntity.getLabel()) ? fieldEntity.getLabel() : DmpBlueprintValuePersist._reference}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getReferences()))
.on(DmpBlueprintValuePersist._references)
.over(item.getReferences())
.using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferenceWithoutTypePersistValidator.class))
.using((itm) -> this.validatorFactory.validator(ReferencePersist.ReferenceWithoutTypePersistValidator.class)),
this.refSpec()
.iff(() -> !this.isNull(item.getReference()))
.on(DmpBlueprintValuePersist._reference)
.over(item.getReferences())
.using(() -> this.validatorFactory.validator(ReferencePersist.ReferenceWithoutTypePersistValidator.class))
);
}

View File

@ -750,6 +750,10 @@ public class DmpServiceImpl implements DmpService {
List<DmpReferencePersist> dmpReferencePersists = new ArrayList<>();
if (persist.getDmpBlueprintValues() != null && !persist.getDmpBlueprintValues().isEmpty()){
for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues().values()) {
if (fieldValuePersist.getReference() != null) {
if (fieldValuePersist.getReferences() == null) fieldValuePersist.setReferences(new ArrayList<>());
fieldValuePersist.getReferences().add(fieldValuePersist.getReference());
}
if (this.conventionService.isNullOrEmpty(fieldValuePersist.getFieldValue()) && !this.conventionService.isListNullOrEmpty( fieldValuePersist.getReferences())) {
for (ReferencePersist referencePersist : fieldValuePersist.getReferences()) {
DmpReferencePersist dmpReferencePersist = new DmpReferencePersist();

View File

@ -265,6 +265,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
case ReferenceType -> {
ReferenceTypeFieldEntity dataTyped = new ReferenceTypeFieldEntity();
dataTyped.setReferenceTypeId(((ReferenceTypeFieldPersist) persist).getReferenceTypeId());
dataTyped.setMultipleSelect(((ReferenceTypeFieldPersist) persist).getMultipleSelect());
data = dataTyped;
}
default -> throw new InternalError("unknown type: " + persist.getCategory());
@ -540,6 +541,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
xml.setDescription(entity.getDescription());
xml.setOrdinal(entity.getOrdinal());
xml.setRequired(entity.isRequired());
xml.setMultipleSelect(entity.getMultipleSelect());
return xml;
}
@ -670,6 +672,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService {
persist.setDescription(importXml.getDescription());
persist.setOrdinal(importXml.getOrdinal());
persist.setRequired(importXml.isRequired());
persist.setMultipleSelect(importXml.getMultipleSelect());
return persist;
}

View File

@ -60,11 +60,12 @@ export interface ExtraFieldInSection extends FieldInSection {
export interface ReferenceTypeFieldInSection extends FieldInSection {
referenceType: ReferenceType;
multipleSelect: boolean;
}
//
//
// Persist
//
//
export interface DmpBlueprintPersist extends BaseEntityPersist {
label: string;
definition: DmpBlueprintDefinitionPersist;
@ -120,4 +121,5 @@ export interface ExtraFieldInSectionPersist extends FieldInSectionPersist {
export interface ReferenceTypeFieldInSectionPersist extends FieldInSectionPersist {
referenceTypeId: Guid;
}
multipleSelect: boolean;
}

View File

@ -95,6 +95,7 @@ export interface DmpBlueprintValuePersist {
fieldId: Guid;
fieldValue: string;
references: DmpReferencePersist[];
reference: DmpReferencePersist;
}
export interface DmpContactPersist {

View File

@ -178,6 +178,12 @@
<mat-error *ngIf="field.get('semantics').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-auto section-field" *ngIf="field.get('category').value === dmpBlueprintSectionFieldCategory.ReferenceType">
<mat-checkbox [disabled]="formGroup.disabled" [checked]="field.get('multipleSelect').value" (change)="field.get('multipleSelect').setValue($event.checked)"><span>{{'DMP-BLUEPRINT-EDITOR.FIELDS.FIELD-MULTIPLE-SELECT' | translate}}</span></mat-checkbox>
<mat-error *ngIf="field.get('multipleSelect')?.hasError('backendError')">{{field.get('multipleSelect')?.getError('backendError').message}}</mat-error>
<mat-error *ngIf="field.get('multipleSelect')?.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</div>
</div>
</div>
<div class="col-12 col-xl-auto">

View File

@ -71,6 +71,7 @@ export class DmpBlueprintEditorModel extends BaseEditorModel implements DmpBluep
const field: FieldInSectionEditorModel = new FieldInSectionEditorModel(this.validationErrorModel);
field.id = Guid.create();
field.ordinal = index + 1;
field.multipleSelect = false;
return field.buildForm({ rootPath: 'definition.sections[' + sectionIndex + '].fields[' + index + '].' });
}
@ -91,7 +92,7 @@ export class DmpBlueprintEditorModel extends BaseEditorModel implements DmpBluep
rootPath: `definition.`,
validationErrorModel: validationErrorModel
});
formGroup.updateValueAndValidity();
formGroup.updateValueAndValidity();
}
}
@ -308,6 +309,7 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
public dataType: DmpBlueprintExtraFieldDataType;
public systemFieldType: DmpBlueprintSystemFieldType;
public referenceTypeId: Guid;
public multipleSelect: boolean;
static get alwaysRequiredSystemFieldTypes(): DmpBlueprintSystemFieldType[] {
return [DmpBlueprintSystemFieldType.Title, DmpBlueprintSystemFieldType.Description, DmpBlueprintSystemFieldType.Language, DmpBlueprintSystemFieldType.AccessRights];
@ -338,6 +340,7 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
this.dataType = (item as ExtraFieldInSection).dataType;
} else if (this.category == DmpBlueprintFieldCategory.ReferenceType) {
this.referenceTypeId = (item as ReferenceTypeFieldInSection).referenceType?.id;
this.multipleSelect= (item as ReferenceTypeFieldInSection).multipleSelect;
}
return this;
@ -369,6 +372,7 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
dataType: [{ value: this.dataType, disabled: disabled }, context.getValidation('dataType').validators],
systemFieldType: [{ value: this.systemFieldType, disabled: disabled }, context.getValidation('systemFieldType').validators],
referenceTypeId: [{ value: this.referenceTypeId, disabled: disabled }, context.getValidation('referenceTypeId').validators],
multipleSelect: [{ value: this.multipleSelect, disabled: disabled }, context.getValidation('multipleSelect').validators],
});
}
@ -394,6 +398,7 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
baseValidationArray.push({ key: 'dataType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] });
baseValidationArray.push({ key: 'systemFieldType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}systemFieldType`)] });
baseValidationArray.push({ key: 'referenceTypeId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}referenceTypeId`)] });
baseValidationArray.push({ key: 'multipleSelect', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}multipleSelect`)] });
baseContext.validation = baseValidationArray;
return baseContext;
@ -411,7 +416,7 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
validationErrorModel
});
['id', 'category', 'dataType', 'systemFieldType', 'referenceTypeId', 'label', 'placeholder', 'description', 'semantics', 'required', 'ordinal'].forEach(keyField => {
['id', 'category', 'dataType', 'systemFieldType', 'referenceTypeId', 'multipleSelect', 'label', 'placeholder', 'description', 'semantics', 'required', 'ordinal'].forEach(keyField => {
const control = formGroup?.get(keyField);
control?.clearValidators();
if (keyField == 'label') {
@ -419,7 +424,10 @@ export class FieldInSectionEditorModel implements FieldInSectionPersist {
} else if (keyField == 'referenceTypeId') {
if (formGroup.get('category').value === DmpBlueprintFieldCategory.ReferenceType) control?.addValidators([Validators.required, ...context.getValidation('referenceTypeId').validators]);
else control?.addValidators([...context.getValidation('referenceTypeId').validators]);
} else if (keyField == 'systemFieldType') {
} else if (keyField == 'multipleSelect') {
if (formGroup.get('category').value === DmpBlueprintFieldCategory.ReferenceType) control?.addValidators([Validators.required, ...context.getValidation('multipleSelect').validators]);
else control?.addValidators([...context.getValidation('multipleSelect').validators]);
}else if (keyField == 'systemFieldType') {
if (formGroup.get('category').value === DmpBlueprintFieldCategory.System) control?.addValidators([Validators.required, ...context.getValidation('systemFieldType').validators]);
else control?.addValidators([...context.getValidation('systemFieldType').validators]);
} else if (keyField == 'dataType') {
@ -508,4 +516,4 @@ export class DescriptionTemplatesInSectionEditorModel implements DescriptionTemp
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
}

View File

@ -42,6 +42,7 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver {
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.name)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.code)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.multipleSelect)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateGroupId)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
@ -50,7 +51,7 @@ export class DmpBlueprintEditorResolver extends BaseEditorResolver {
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.prefillingSources), nameof<PrefillingSource>(x => x.label)].join('.'),
nameof<DmpBlueprint>(x => x.createdAt),
nameof<DmpBlueprint>(x => x.hash),
nameof<DmpBlueprint>(x => x.isActive)

View File

@ -249,9 +249,12 @@
</div>
</div>
<div *ngIf="field.category === dmpBlueprintSectionFieldCategoryEnum.ReferenceType">
<div>
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [dependencies]="formGroup.get('properties').get('dmpBlueprintValues')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="field.referenceType"></app-reference-field-component>
</div>
<ng-container *ngIf="field.multipleSelect">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [dependencies]="formGroup.get('properties').get('dmpBlueprintValues')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="field.referenceType" [multiple]="true"></app-reference-field-component>
</ng-container>
<ng-container *ngIf="!(field.multipleSelect)">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('reference')" [dependencies]="formGroup.get('properties').get('dmpBlueprintValues')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="field.referenceType" [multiple]="false"></app-reference-field-component>
</ng-container>
</div>
<div *ngIf="field.category === dmpBlueprintSectionFieldCategoryEnum.Extra">
<div *ngIf="field.dataType === dmpBlueprintExtraFieldDataTypeEnum.Text">

View File

@ -6,7 +6,7 @@ import { DmpStatus } from "@app/core/common/enum/dmp-status";
import { DmpUserRole } from "@app/core/common/enum/dmp-user-role";
import { DmpUserType } from "@app/core/common/enum/dmp-user-type";
import { IsActive } from "@app/core/common/enum/is-active.enum";
import { DmpBlueprint, FieldInSection } from "@app/core/model/dmp-blueprint/dmp-blueprint";
import { DmpBlueprint, FieldInSection, ReferenceTypeFieldInSection } from "@app/core/model/dmp-blueprint/dmp-blueprint";
import { Dmp, DmpBlueprintValue, DmpBlueprintValuePersist, DmpContact, DmpContactPersist, DmpDescriptionTemplate, DmpDescriptionTemplatePersist, DmpPersist, DmpProperties, DmpPropertiesPersist, DmpReferenceDataPersist, DmpReferencePersist, DmpUser, DmpUserPersist } from "@app/core/model/dmp/dmp";
import { DmpReference } from "@app/core/model/dmp/dmp-reference";
import { ReferencePersist } from "@app/core/model/reference/reference";
@ -291,7 +291,8 @@ export class DmpPropertiesEditorModel implements DmpPropertiesPersist {
formGroup: control as UntypedFormGroup,
rootPath: `${rootPath}dmpBlueprintValues[${key}].`,
validationErrorModel: validationErrorModel,
isRequired: params.blueprint.definition.sections.flatMap(x => x.fields).find(x => x.id.toString() == key).required
isRequired: params.blueprint.definition.sections.flatMap(x => x.fields).find(x => x.id.toString() == key).required,
multipleSelect: (params.blueprint.definition.sections.flatMap(x => x.fields).find(x => x.id.toString() == key) as ReferenceTypeFieldInSection).multipleSelect
})
});
@ -309,7 +310,9 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
fieldId: Guid;
fieldValue: string;
references: DmpReferencePersist[] = [];
reference: DmpReferencePersist;
isRequired: boolean = false;
multipleSelect: boolean = false;
category: DmpBlueprintFieldCategory;
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
@ -321,7 +324,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
fromModel(item: DmpBlueprintValue, dmpReferences: DmpReference[], field: FieldInSection): DmpBlueprintValueEditorModel {
this.fieldId = item.fieldId;
this.fieldValue = item.fieldValue;
this.references = dmpReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => {
const references = dmpReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => {
return {
data: x.data,
reference: {
@ -337,7 +340,18 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
}
}
});
if ((field as ReferenceTypeFieldInSection).multipleSelect) {
this.references = references;
this.multipleSelect = true;
} else {
if (references?.length == 1) this.reference = references[0];
if (references?.length > 1) {
console.error("multiple references on single reference field: " + references);
this.reference = references[0];
}
this.multipleSelect = false;
}
this.isRequired = field.required;
if (this.isRequired) console.log(field);
this.category = field.category;
@ -355,7 +369,8 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
context = DmpBlueprintValueEditorModel.createValidationContext({
validationErrorModel: this.validationErrorModel,
rootPath,
isRequired: this.isRequired
isRequired: this.isRequired,
multipleSelect: this.multipleSelect
});
}
@ -365,6 +380,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
switch (this.category) {
case DmpBlueprintFieldCategory.ReferenceType:
formGroup.addControl('references', new FormControl({ value: this.references?.map(x => x.reference), disabled: disabled }, context.getValidation('references').validators));
formGroup.addControl('reference', new FormControl({ value: this.reference?.reference, disabled: disabled }, context.getValidation('reference').validators));
break;
case DmpBlueprintFieldCategory.System:
case DmpBlueprintFieldCategory.Extra:
@ -378,6 +394,7 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
static createValidationContext(params: {
rootPath?: string,
validationErrorModel: ValidationErrorModel,
multipleSelect: boolean,
isRequired: boolean,
}): ValidationContext {
const { rootPath = '', validationErrorModel } = params;
@ -386,7 +403,8 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
const baseValidationArray: Validation[] = new Array<Validation>();
baseValidationArray.push({ key: 'fieldId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fieldId`)] });
baseValidationArray.push({ key: 'fieldValue', validators: params.isRequired ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}fieldValue`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}fieldValue`)] });
baseValidationArray.push({ key: 'references', validators: params.isRequired ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] });
baseValidationArray.push({ key: 'references', validators: params.isRequired && params.multipleSelect ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}references`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] });
baseValidationArray.push({ key: 'reference', validators: params.isRequired && !params.multipleSelect ? [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}reference`)] : [BackendErrorValidator(validationErrorModel, `${rootPath}reference`)] });
baseContext.validation = baseValidationArray;
return baseContext;
@ -397,13 +415,15 @@ export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist {
validationErrorModel: ValidationErrorModel,
rootPath: string,
isRequired: boolean
multipleSelect: boolean
}): void {
const { formGroup, rootPath, validationErrorModel } = params;
const context = DmpBlueprintValueEditorModel.createValidationContext({
rootPath,
validationErrorModel,
isRequired: params.isRequired
isRequired: params.isRequired,
multipleSelect: params.multipleSelect
});
['fieldId', 'fieldValue', 'references'].forEach(keyField => {
@ -710,4 +730,4 @@ export class DmpDescriptionTemplateEditorModel implements DmpDescriptionTemplate
control?.addValidators(context.getValidation(keyField).validators);
})
}
}
}

View File

@ -121,6 +121,7 @@ export class DmpEditorResolver extends BaseEditorResolver {
(prefix ? prefix + '.' : '') + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.id)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.name)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.code)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.multipleSelect)].join('.'),
(prefix ? prefix + '.' : '') + [nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<ReferenceTypeFieldInSection>(x => x.referenceType), nameof<ReferenceType>(x => x.definition), nameof<ReferenceTypeDefinition>(x=> x.sources), nameof<ExternalFetcherBaseSourceConfiguration>(x=> x.referenceTypeDependencies) , nameof<ReferenceType>(x => x.id)].join('.'),
]
}

View File

@ -14,6 +14,7 @@ import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup';
import { Guid } from '@common/types/guid';
import { nameof } from 'ts-simple-nameof';
import { Subscription } from 'rxjs';
import { FormService } from '@common/forms/form-service';
@Component({
selector: 'app-reference-field-component',
@ -42,6 +43,7 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
constructor(
private referenceService: ReferenceService,
public enumUtils: EnumUtils,
public formService: FormService,
private dialog: MatDialog,
) { super(); }
@ -75,7 +77,9 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
const referenceToUse : Reference[]= [];
Object.keys(this.dependencies.controls).forEach(controlName => {
// (this.dependencies.get(controlName).get('references').value as Reference[]).filter(x=> sourcesWithDependencies.some(y => y.referenceTypeDependencies) x.type.id == this.referenceType.id &&)
const foudReferences: any[] = this.dependencies.get(controlName).get('references')?.value;
const ctrlValue = this.formService.getValue(this.dependencies.get(controlName).value);
const foudReferences: any[] = ctrlValue?.references || [];
if (ctrlValue?.reference) foudReferences.push(ctrlValue?.reference);
if (foudReferences != null) {
for (let i = 0; i < foudReferences.length; i++) {
const foudReference = foudReferences[i];
@ -106,7 +110,7 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
if (!isInitial && (!referenceToUse.map(x => x.reference).every(x => this.referenceToUse.map(y => y.reference).includes(x)) ||
!this.referenceToUse.map(x => x.reference).every(x => referenceToUse.map(y => y.reference).includes(x)))) {
this.referenceToUse = referenceToUse;
this.form.setValue([]);
this.form.setValue(this.multiple ? [] : null);
this.form.updateValueAndValidity();
} else {
this.referenceToUse = referenceToUse;
@ -145,10 +149,14 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
.pipe(takeUntil(this._destroyed))
.subscribe(newResult => {
if (!newResult) { return; }
let results = this.form.value as ReferencePersist[];
if (results == undefined) results = [];
results.push(newResult);
this.form.setValue(results);
if (this.multiple) {
let results = this.form.value as ReferencePersist[];
if (results == undefined) results = [];
results.push(newResult);
this.form.setValue(results);
} else {
this.form.setValue(newResult);
}
});
}
);

View File

@ -1020,6 +1020,7 @@
"TYPE": "Type",
"DATATYPE": "Data Type",
"REQUIRED": "Pflichtfeld",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Autocomplete Data",
"MULTIPLE-AUTOCOMPLETE": "Multiple Autocomplete",

View File

@ -1355,6 +1355,7 @@
"DATA-TYPE": "Data Type",
"CATEGORY": "Field Type",
"FIELD-REQUIRED": "Required",
"FIELD-MULTIPLE-SELECT": "Multiple",
"SEMANTICS": "Semantics",
"DESCRIPTION-TEMPLATES": "Description Templates",
"DESCRIPTION-TEMPLATE": "Description Template",
@ -2022,4 +2023,4 @@
"CONFIRM": "Confirm"
}
}
}
}

View File

@ -1020,6 +1020,7 @@
"TYPE": "Tipo",
"DATATYPE": "Tipo de datos",
"REQUIRED": "Obligatorio",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Datos autocompletados",
"MULTIPLE-AUTOCOMPLETE": "Multiple Autocomplete",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Τύπος",
"DATATYPE": "Τύπος Δεδομένων",
"REQUIRED": "Υποχρεωτικά",
"FIELD-MULTIPLE-SELECT": "Πολλαπλό",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Αυτόματη Συμπλήρωση Δεδομένων",
"MULTIPLE-AUTOCOMPLETE": "Πολλαπλή Αυτόματη Συμπλήρωση",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Vrsta",
"DATATYPE": "Tip podataka",
"REQUIRED": "Obavezno",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Automatski unos podataka",
"MULTIPLE-AUTOCOMPLETE": "Višestruki automatski unos",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Typ",
"DATATYPE": "Typ danych",
"REQUIRED": "Wymagane",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Autouzupełnanie danych",
"MULTIPLE-AUTOCOMPLETE": "Wielokrotne autouzupełnianie",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Tipo",
"DATATYPE": "Tipo de Dados",
"REQUIRED": "Obrigatório",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Autocompletar Dados",
"MULTIPLE-AUTOCOMPLETE": "Autopreenchimento Múltiplo",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Typ",
"DATATYPE": "Typ dát",
"REQUIRED": "Povinné",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Automatické dopĺňanie údajov",
"MULTIPLE-AUTOCOMPLETE": "Viacnásobné automatické dokončenie",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Tip",
"DATATYPE": "Tip podataka",
"REQUIRED": "Obavezno",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Automatski unos podataka",
"MULTIPLE-AUTOCOMPLETE": "Višestruki automatski unos",

View File

@ -1020,6 +1020,7 @@
"TYPE": "Tip",
"DATATYPE": "Veri Tipi",
"REQUIRED": "Gerekli",
"FIELD-MULTIPLE-SELECT": "Multiple",
"EXTERNAL-AUTOCOMPLETE": {
"TITLE": "Verileri Otomatik Tamamla",
"MULTIPLE-AUTOCOMPLETE": "Çoklu Otomatik Tamamlama",

View File

@ -183,12 +183,30 @@ public class DmpBlueprintXmlMigrationService {
case ACCESS_RIGHTS -> dataTyped.setType(DmpBlueprintSystemFieldType.AccessRights);
case CONTACT -> dataTyped.setType(DmpBlueprintSystemFieldType.Contact);
case LANGUAGE -> dataTyped.setType(DmpBlueprintSystemFieldType.Language);
case FUNDER -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Funder);
case GRANT -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Grants);
case LICENSE -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.License);
case ORGANIZATIONS -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Organizations);
case PROJECT -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Project);
case RESEARCHERS -> referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Researcher);
case FUNDER -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Funder);
referenceTypeFieldEntity.setMultipleSelect(false);
}
case GRANT -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Grants);
referenceTypeFieldEntity.setMultipleSelect(false);
}
case LICENSE -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.License);
referenceTypeFieldEntity.setMultipleSelect(true);
}
case ORGANIZATIONS -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Organizations);
referenceTypeFieldEntity.setMultipleSelect(true);
}
case PROJECT -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Project);
referenceTypeFieldEntity.setMultipleSelect(false);
}
case RESEARCHERS -> {
referenceTypeFieldEntity.setReferenceTypeId(ReferenceTypeIds.Researcher);
referenceTypeFieldEntity.setMultipleSelect(true);
}
default -> throw new MyApplicationException("Type not found " + systemField.getType());
}
if (systemField.getType().equals(SystemFieldType.TEXT) || systemField.getType().equals(SystemFieldType.HTML_TEXT) ||