Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Efstratios Giannopoulos 2024-02-01 16:58:26 +02:00
commit cba0741149
10 changed files with 124 additions and 50 deletions

View File

@ -44,6 +44,7 @@ public class FieldSetBuilder extends BaseBuilder<eu.eudat.model.descriptiontempl
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet fieldsFields = fields.extractPrefixed(this.asPrefix(eu.eudat.model.descriptiontemplatedefinition.FieldSet._fields));
FieldSet multiplicityFields = fields.extractPrefixed(this.asPrefix(eu.eudat.model.descriptiontemplatedefinition.FieldSet._multiplicity));
List<eu.eudat.model.descriptiontemplatedefinition.FieldSet> models = new ArrayList<>();
for (FieldSetEntity d : data) {
@ -56,6 +57,7 @@ public class FieldSetBuilder extends BaseBuilder<eu.eudat.model.descriptiontempl
if (fields.hasField(this.asIndexer(eu.eudat.model.descriptiontemplatedefinition.FieldSet._extendedDescription))) m.setExtendedDescription(d.getExtendedDescription());
if (fields.hasField(this.asIndexer(eu.eudat.model.descriptiontemplatedefinition.FieldSet._additionalInformation))) m.setAdditionalInformation(d.getAdditionalInformation());
if (fields.hasField(this.asIndexer(eu.eudat.model.descriptiontemplatedefinition.FieldSet._hasCommentField))) m.setHasCommentField(d.getHasCommentField());
if (!multiplicityFields.isEmpty() && d.getMultiplicity() != null) m.setMultiplicity(this.builderFactory.builder(MultiplicityBuilder.class).authorize(this.authorize).build(multiplicityFields, d.getMultiplicity()));
if (!fieldsFields.isEmpty() && d.getFields() != null) m.setFields(this.builderFactory.builder(FieldBuilder.class).authorize(this.authorize).build(fieldsFields, d.getFields()));
models.add(m);
}

View File

@ -0,0 +1,57 @@
package eu.eudat.model.builder.descriptiontemplatedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.descriptiontemplate.MultiplicityEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.descriptiontemplatedefinition.Multiplicity;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component("descriptiontemplatedefinitionmultiplicitybuilder")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MultiplicityBuilder extends BaseBuilder<Multiplicity, MultiplicityEntity> {
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public MultiplicityBuilder(
ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(MultiplicityBuilder.class)));
}
public MultiplicityBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<Multiplicity> build(FieldSet fields, List<MultiplicityEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<Multiplicity> models = new ArrayList<>();
for (MultiplicityEntity d : data) {
Multiplicity m = new Multiplicity();
if (fields.hasField(this.asIndexer(Multiplicity._min))) m.setMin(d.getMin());
if (fields.hasField(this.asIndexer(Multiplicity._max))) m.setMax(d.getMax());
if (fields.hasField(this.asIndexer(Multiplicity._placeholder))) m.setPlaceholder(d.getPlaceholder());
if (fields.hasField(this.asIndexer(Multiplicity._tableView))) m.setTableView(d.getTableView());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -35,6 +35,8 @@ public class UploadDataBuilder extends BaseFieldDataBuilder<UploadData, UploadDa
@Override
protected void buildChild(FieldSet fields, UploadDataEntity d, UploadData m) {
FieldSet typesFields = fields.extractPrefixed(this.asPrefix(UploadData._types));
if (fields.hasField(this.asIndexer(UploadData._maxFileSizeInMB))) m.setMaxFileSizeInMB(d.getMaxFileSizeInMB());
if (!typesFields.isEmpty() && d.getTypes() != null) m.setTypes(this.builderFactory.builder(UploadOptionBuilder.class).build(typesFields, d.getTypes()));
}

View File

@ -4,7 +4,7 @@ import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import java.util.UUID;
public abstract class Multiplicity {
public class Multiplicity {
public final static String _min = "min";
private Integer min;

View File

@ -357,11 +357,10 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
data.setTitle(persist.getTitle());
data.setNumbering(persist.getNumbering());
data.setAdditionalInformation(persist.getAdditionalInformation());
data.setTitle(persist.getTitle());
data.setExtendedDescription(persist.getExtendedDescription());
if (persist.getMultiplicity() != null)
data.setMultiplicity(this.buildMultiplicityEntity(persist.getMultiplicity()));
data.setHasCommentField(persist.getHasCommentField());
data.setTitle(persist.getTitle());
if (!this.conventionService.isListNullOrEmpty(persist.getFields())) {
data.setFields(new ArrayList<>());

View File

@ -46,8 +46,8 @@
</div>
<div class="row">
<mat-form-field *ngIf="isMultiplicityEnabled" class="col pl-0 underline-line-field">
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-PLACEHOLDER' | translate}}" type="text" [formControl]="form.get('multiplicity').get('multiplicity')">
<mat-error *ngIf="form.get('multiplicity').get('multiplicity').hasError('backendError')">{{form.get('multiplicity').get('multiplicity').getError('backendError').message}}</mat-error>
<input matInput placeholder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.COMPOSITE-FIELD.FIELDS.MULTIPLICITY-PLACEHOLDER' | translate}}" type="text" [formControl]="form.get('multiplicity').get('placeholder')">
<mat-error *ngIf="form.get('multiplicity').get('placeholder').hasError('backendError')">{{form.get('placeholder').get('multiplicity').getError('backendError').message}}</mat-error>
</mat-form-field>
</div>
<div class="row">
@ -98,8 +98,8 @@
</div>
<div [id]="'preview_container'+ form.get('id').value" class="w-100" style="margin-right: -15px; margin-left: -15px;">
<div *ngIf="previewForm && showPreview && firstField?.get('data')?.get('fieldType')?.value" [@fade-in-fast]>
<!-- Check what we need to do with this. -->
<!-- <app-form-section-inner [form]="previewForm" [tableView]="form.getRawValue().multiplicity?.tableView" [datasetProfileId]="datasetProfileId">
<!-- Check what we need to do with this. -->
<!-- <app-form-section-inner [form]="previewForm" [tableView]="form.getRawValue().multiplicity?.tableView" [datasetProfileId]="datasetProfileId">
</app-form-section-inner> -->
</div>
</div>
@ -245,29 +245,32 @@
Argos Entities
</button>
<mat-action-list class="ml-4">
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.InternalDmpEntities)">
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_DMPS)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Internal Dmp icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.InternalDmpEntities)}}
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_DMPS)}}
</button>
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.Tags)">
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_DATASETS)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Internal Dmp icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_DATASETS)}}
</button>
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_RESEARCHERS)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Internal Dmp icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.INTERNAL_DMP_ENTRIES_RESEARCHERS)}}
</button>
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.TAGS)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Tags icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.Tags)}}
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.TAGS)}}
</button>
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.DatasetIdentifier)">
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.DATASET_IDENTIFIER)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Datset Identifier icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.DatasetIdentifier)}}
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.DATASET_IDENTIFIER)}}
</button>
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.Validation)">
<button mat-list-item (click)="addNewInput(descriptionTemplateFieldTypeEnum.VALIDATION)">
<img src="/assets/images/editor/icons/api_entity.svg" class="input_icon" alt="Validation icon">
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.Validation)}}
{{enumUtils.toDescriptionTemplateFieldTypeString(descriptionTemplateFieldTypeEnum.VALIDATION)}}
</button>
</mat-action-list>
</mat-action-list>
</mat-menu>
</li>

View File

@ -199,7 +199,7 @@
<ng-container *ngIf="form.get('visibilityRules')?.value.length">
<h4 class="col-12" style="font-weight: bold">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.FIELDS.RULES-TITLE' | translate}}
</h4>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [viewStyleForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly" [formControlForCheck]="form"></app-description-template-editor-visibility-rule-component>
<app-description-template-editor-visibility-rule-component class="col-12" [form]="form.get('visibilityRules')" [fieldTypeForCheck]="form.get('data').get('fieldType').value" [formArrayOptionsForCheck]="this.form.get('data')?.get('options')" [viewOnly]="viewOnly"></app-description-template-editor-visibility-rule-component>
<!-- <div class="col-12" *ngIf="!viewOnly">
<button mat-button class="full-width" (click)="addNewRule()" [disabled]="!form.get('data').get('fieldType').value">{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.FIELD.ACTIONS.ADD-RULE' | translate}}</button>
</div> -->

View File

@ -1,7 +1,7 @@
<div class="row" *ngFor="let ruleFormGroup of form['controls'] let i=index;" [formGroup]="ruleFormGroup">
<span class="col-auto align-self-center">{{i + 1}}</span>
<app-description-template-editor-default-value-component class="col align-self-center" [fieldType]="fieldTypeForCheck" [form]="ruleFormGroup" [formArrayOptions]="formArrayOptionsForCheck" placeHolder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.RULE.FIELDS.RULE-IF'| translate}}" required="true"></app-description-template-editor-default-value-component>
<app-description-template-editor-default-value-component class="col align-self-center" [fieldType]="fieldTypeForCheck" [form]="ruleFormGroup.get('value')" [formArrayOptions]="formArrayOptionsForCheck" placeHolder="{{'DESCRIPTION-TEMPLATE-EDITOR.STEPS.FORM.RULE.FIELDS.RULE-IF'| translate}}" required="true"></app-description-template-editor-default-value-component>
<!-- SELECTION -->
<mat-form-field class="col align-self-center">

View File

@ -1,5 +1,5 @@
import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateFieldType } from '@app/core/common/enum/description-template-field-type';
import { DescriptionTemplateRule } from '@app/core/model/description-template/description-template';
import { TranslateService } from '@ngx-translate/core';
@ -17,7 +17,6 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
@Input() form: UntypedFormArray;
@Input() fieldTypeForCheck: DescriptionTemplateFieldType;
@Input() formControlForCheck: UntypedFormControl;
@Input() formArrayOptionsForCheck: UntypedFormArray;
@Input() viewOnly: boolean;
@ -30,6 +29,8 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
parentIds: string[] = [];
hiddenBy: string[] = [];
rootForm: AbstractControl = null;
constructor(private language: TranslateService) {
}
@ -44,6 +45,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
}
ngOnInit(): void {
this.rootForm = this.findRootForm();
this._computeOptions();
}
@ -87,7 +89,7 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
private _buildHiddenBy(fo: OptionItem) {
try {
this.fieldOptions.forEach(foption => {
const rules = (foption.form.get('visible').get('rules') as UntypedFormArray).controls.map(c => (c as UntypedFormGroup).getRawValue()) as DescriptionTemplateRule[]
const rules = (foption.form.get('visibilityRules') as UntypedFormArray).controls.map(c => (c as UntypedFormGroup).getRawValue()) as DescriptionTemplateRule[]
const targets = rules.map(rule => rule.target);
targets.forEach(target => {
if (fo.parentsIds.includes(target) && !fo.hiddenBy.includes(foption.id)) {
@ -103,27 +105,33 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
findRootForm() {
let currentForm: AbstractControl = this.form;
while (currentForm.parent != null){
currentForm = currentForm.parent;
}
return currentForm;
}
getOptions(): OptionItem[] {
const rootForm = this.form.root;
if (rootForm) {
// const parentSections = rootForm.get('sections') as FormArray;
if (this.rootForm) {
const result: OptionItem[] = [];
const sections = rootForm.get('sections') as UntypedFormArray;
(this.rootForm.get('definition').get('pages') as UntypedFormArray).controls.forEach(pageForm => {
if (sections) {
sections.controls.forEach(section => {
const subResult = this.buildOptions(section as UntypedFormGroup, ToCEntryType.Section, []);
result.push(...subResult);
});
}
const sections = pageForm.get('sections') as UntypedFormArray;
if (sections) {
sections.controls.forEach(section => {
const subResult = this.buildOptions(section as UntypedFormGroup, ToCEntryType.Section, []);
result.push(...subResult);
});
}
});
//return options
return result;
}
//nothing found
return [];
@ -169,9 +177,9 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
}
computeParentIds(): string[] {
if (!this.formControlForCheck.get('id')) return [];
if (!this.rootForm.get('id')) return [];
const current = this.options.find(opt => opt.id === this.formControlForCheck.get('id').value);
const current = this.options.find(opt => opt.id === this.rootForm.get('id').value);
if (current) {
return current.parentsIds;
}
@ -179,9 +187,9 @@ export class DescriptionTemplateEditorRuleComponent implements OnInit {
}
computeHiddenBy(): string[] {
if (!this.formControlForCheck.get('id')) return [];
if (!this.rootForm.get('id')) return [];
const current = this.options.find(opt => opt.id === this.formControlForCheck.get('id').value);
const current = this.options.find(opt => opt.id === this.rootForm.get('id').value);
if (current) {
return current.hiddenBy;
}

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { DescriptionTemplateType } from '@app/core/model/description-template-type/description-template-type';
import { DescriptionTemplate, DescriptionTemplateExternalSelectData, DescriptionTemplateBaseFieldData, DescriptionTemplateSelectOption, DescriptionTemplateDefinition, DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateMultiplicity, DescriptionTemplatePage, DescriptionTemplateRule, DescriptionTemplateSection, DescriptionTemplateSelectData, DescriptionTemplateExternalDatasetData, DescriptionTemplateExternalSelectSource, DescriptionTemplateExternalSelectAuthData, DescriptionTemplateExternalSelectSourceBinding } from '@app/core/model/description-template/description-template';
import { DescriptionTemplate, DescriptionTemplateExternalSelectData, DescriptionTemplateBaseFieldData, DescriptionTemplateSelectOption, DescriptionTemplateDefinition, DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateMultiplicity, DescriptionTemplatePage, DescriptionTemplateRule, DescriptionTemplateSection, DescriptionTemplateSelectData, DescriptionTemplateExternalDatasetData, DescriptionTemplateExternalSelectSource, DescriptionTemplateExternalSelectAuthData, DescriptionTemplateExternalSelectSourceBinding, DescriptionTemplateUploadData, DescriptionTemplateUploadOption } from '@app/core/model/description-template/description-template';
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditorResolver } from '@common/base/base-editor.resolver';
@ -85,6 +85,9 @@ export class DescriptionTemplateEditorResolver extends BaseEditorResolver {
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateExternalSelectData>(x => x.sources), nameof<DescriptionTemplateExternalSelectSource>(x => x.auth), nameof<DescriptionTemplateExternalSelectAuthData>(x => x.body)].join('.'),
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateExternalSelectData>(x => x.sources), nameof<DescriptionTemplateExternalSelectSource>(x => x.auth), nameof<DescriptionTemplateExternalSelectAuthData>(x => x.path)].join('.'),
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateExternalSelectData>(x => x.sources), nameof<DescriptionTemplateExternalSelectSource>(x => x.auth), nameof<DescriptionTemplateExternalSelectAuthData>(x => x.type)].join('.'),
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateUploadData>(x => x.maxFileSizeInMB)].join('.'),
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateUploadData>(x => x.types), nameof<DescriptionTemplateUploadOption>(x => x.label)].join('.'),
[nameof<DescriptionTemplate>(x => x.definition), nameof<DescriptionTemplateDefinition>(x => x.pages), nameof<DescriptionTemplatePage>(x => x.sections), nameof<DescriptionTemplateSection>(x => x.fieldSets), nameof<DescriptionTemplateFieldSet>(x => x.fields), nameof<DescriptionTemplateField>(x => x.data), nameof<DescriptionTemplateUploadData>(x => x.types), nameof<DescriptionTemplateUploadOption>(x => x.value)].join('.'),