description field fixes

This commit is contained in:
amentis 2024-04-05 17:25:25 +03:00
parent 405bf0c9b2
commit 4503bc0bcf
5 changed files with 21 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package eu.eudat.model.builder.descriptionpropertiesdefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.description.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.SelectDataEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.BaseBuilder;
@ -70,7 +71,17 @@ public class FieldBuilder extends BaseBuilder<Field, FieldEntity> {
Field m = new Field();
if (fields.hasField(this.asIndexer(Field._dateValue)) && FieldType.isDateType(fieldType)) m.setDateValue(d.getDateValue());
if (fields.hasField(this.asIndexer(Field._textValue)) && FieldType.isTextType(fieldType)) m.setTextValue(d.getTextValue());
if (fields.hasField(this.asIndexer(Field._textListValue)) && FieldType.isTextListType(fieldType)) m.setTextListValue(d.getTextListValue());
if (fields.hasField(this.asIndexer(Field._textListValue)) && FieldType.isTextListType(fieldType)) {
boolean isSelectMultiSelect = true;
if(this.fieldEntity != null && this.fieldEntity.getData() != null && this.fieldEntity.getData().getFieldType().equals(FieldType.SELECT) && this.fieldEntity.getData() instanceof SelectDataEntity){
isSelectMultiSelect = ((SelectDataEntity) this.fieldEntity.getData()).getMultipleSelect();
}
if (fieldType.equals(FieldType.SELECT) && !isSelectMultiSelect && !this.conventionService.isListNullOrEmpty(d.getTextListValue())){
m.setTextValue(d.getTextListValue().stream().findFirst().orElse(null));
} else{
m.setTextListValue(d.getTextListValue());
}
}
if (!referenceFields.isEmpty() && FieldType.isReferenceType(fieldType) && referenceItemsMap != null && d.getTextListValue() != null && !d.getTextListValue().isEmpty()) {
m.setReferences(new ArrayList<>());
for (UUID referenceId : d.getTextListValue().stream().map(UUID::fromString).toList()){

View File

@ -67,7 +67,7 @@ public class PropertyDefinitionFieldSetItemBuilder extends BaseBuilder<PropertyD
if (!fieldsFields.isEmpty() && d.getFields() != null && !d.getFields().isEmpty()) {
m.setFields(new HashMap<>());
for (String key : d.getFields().keySet()){
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
m.getFields().put(key, this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).withFieldEntity(fieldEntity).build(fieldsFields, d.getFields().get(key)));
}
}

View File

@ -381,7 +381,7 @@ public class DescriptionServiceImpl implements DescriptionService {
data.setComment(persist.getComment());
data.setFields(new HashMap<>());
for (String key: persist.getFields().keySet()) {
eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getAllField().stream().findFirst().orElse(null) : null;
eu.eudat.commons.types.descriptiontemplate.FieldEntity fieldEntity = fieldSetEntity != null ? fieldSetEntity.getFieldById(key).stream().findFirst().orElse(null) : null;
data.getFields().put(key, this.buildFieldEntity(persist.getFields().get(key), fieldEntity, fieldToReferenceMap));
}
}
@ -416,8 +416,12 @@ public class DescriptionServiceImpl implements DescriptionService {
if (!existingIds.contains(id)) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
}
}
if (fieldType.equals(FieldType.SELECT) && this.conventionService.isListNullOrEmpty(persist.getTextListValue()) && !this.conventionService.isNullOrEmpty(persist.getTextValue())){
data.setTextListValue(List.of(persist.getTextValue()));
} else{
data.setTextListValue(persist.getTextListValue());
}
}
else if (FieldType.isReferenceType(fieldType) && fieldEntity != null ) {
List<UUID> referenceIds = fieldToReferenceMap.getOrDefault(fieldEntity.getId(), null);
if (referenceIds != null) data.setTextListValue(referenceIds.stream().map(UUID::toString).toList());

View File

@ -36,7 +36,7 @@
</div>
</div>
<div class="col-auto">
<button mat-icon-button (click)="addNewRow()" type="button">
<button mat-icon-button [disabled]="this.form.disabled" (click)="addNewRow()" type="button">
<mat-icon>add</mat-icon>
</button>

View File

@ -37,7 +37,7 @@
</div>
</div>
<mat-error *ngIf="form.get('data').get('options').hasError('backendError')">{{form.get('data').get('options').getError('backendError').message}}</mat-error>
<div class="col-auto"><button mat-icon-button (click)="addNewRow()">
<div class="col-auto"><button mat-icon-button [disabled]="this.form.disabled" (click)="addNewRow()">
<mat-icon>add</mat-icon>
</button></div>
</div>