From e9b0bcf1024797c9253b46786a18dff98ddc684d Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Fri, 4 Feb 2022 16:08:22 +0200 Subject: [PATCH 01/12] dataset description section id fix --- .../dataset-description-form/dataset-description-form.model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts index 21c3b2ad1..0ea6ca7a0 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts @@ -115,7 +115,7 @@ export class DatasetDescriptionSectionEditorModel extends BaseFormModel { formGroup.addControl('description', new FormControl({ value: this.description, disabled: true })); formGroup.addControl('numbering', new FormControl({ value: this.numbering, disabled: true })); formGroup.addControl('title', new FormControl({ value: this.title, disabled: true })); - formGroup.addControl('id', new FormControl({ value: this.title, disabled: false })); + formGroup.addControl('id', new FormControl({ value: this.id, disabled: false })); formGroup.addControl('ordinal', new FormControl({ value: this.ordinal, disabled: true })); return formGroup; } From 2b71cddc39d74729ef4c18c73215bca7ac89a5e3 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Fri, 4 Feb 2022 16:38:05 +0200 Subject: [PATCH 02/12] Fix for word generator not merging multiple visibility rule results --- .../logic/services/forms/VisibilityRuleServiceImpl.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java index d46e138de..815ba24dd 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java @@ -44,7 +44,11 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { if (properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) && (isContained(properties.get(sources.get(i).getVisibilityRuleSourceId()), sources.get(i).getVisibilityRuleSourceValue()) || properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue()))) { this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true); }else{ - this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false); + if (this.elementVisibility.containsKey(rule.getVisibilityRuleTargetId())) { + this.elementVisibility.put(rule.getVisibilityRuleTargetId(), this.elementVisibility.get(rule.getVisibilityRuleTargetId()) || false); + } else { + this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false); + } return; } } From 14550e0536f4046d594c227d21e8930a110f9aad Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Fri, 4 Feb 2022 18:17:51 +0200 Subject: [PATCH 03/12] visibility rule fix on word builder --- .../eudat/logic/services/forms/VisibilityRuleServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java index 815ba24dd..439496588 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java @@ -43,13 +43,12 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { for(int i = 0; i < sources.size(); i++){ if (properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) && (isContained(properties.get(sources.get(i).getVisibilityRuleSourceId()), sources.get(i).getVisibilityRuleSourceValue()) || properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue()))) { this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true); - }else{ + } else { if (this.elementVisibility.containsKey(rule.getVisibilityRuleTargetId())) { this.elementVisibility.put(rule.getVisibilityRuleTargetId(), this.elementVisibility.get(rule.getVisibilityRuleTargetId()) || false); } else { this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false); } - return; } } } From 815fc05af6301e25b2b9eecff6250f489e088f59 Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Tue, 8 Feb 2022 09:44:55 +0200 Subject: [PATCH 04/12] fix missing section titles from word export --- .../logic/utilities/documents/word/WordBuilder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index a7d1f9d0d..e491b3b9f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -191,6 +191,7 @@ public class WordBuilder { private Boolean createCompositeFields(List
compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService, Integer page, String section) { if (createListing) this.addListing(mainDocumentPart, indent, true, true); boolean hasValue = false; + boolean returnedValue = false; for (FieldSet compositeField: compositeFields) { if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) { char c = 'a'; @@ -205,6 +206,9 @@ public class WordBuilder { } } hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); + if(hasValue){ + returnedValue = true; + } if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) { List
list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList()); for (FieldSet multiplicityFieldset : list) { @@ -213,6 +217,9 @@ public class WordBuilder { addParagraphContent(c + ".\n", mainDocumentPart, ParagraphStyle.HEADER6, numId); } hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService); + if(hasValue){ + returnedValue = true; + } } } if (hasValue && compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) { @@ -225,7 +232,7 @@ public class WordBuilder { } } } - return hasValue; + return returnedValue; } private Boolean createFields(List fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) { From 80e5e12f29d95cd161162fb21886e4daed496b60 Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Tue, 8 Feb 2022 14:04:26 +0200 Subject: [PATCH 05/12] fix export-import dataset missing rda mappings --- .../ExportXmlBuilderDatasetProfile.java | 5 +++++ .../datasetProfileModel/Fields/Field.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java index 97cc158aa..f818ee50b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java @@ -163,6 +163,11 @@ public class ExportXmlBuilderDatasetProfile { numbering.setTextContent(field.getNumbering()); elementField.appendChild(numbering); } + if (field.getRdaProperty() != null) { + Element rdaProperty = element.createElement("rdaProperty"); + rdaProperty.setTextContent(field.getRdaProperty()); + elementField.appendChild(rdaProperty); + } if (field.getValidations() != null) { Element validations = element.createElement("validations"); field.getValidations().forEach(validation -> { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/Fields/Field.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/Fields/Field.java index a4cce3d02..89e66e869 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/Fields/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/Fields/Field.java @@ -29,6 +29,8 @@ public class Field { private Object data; + private String rdaProperty; + @XmlAttribute(name = "id") public String getId() { return id; @@ -101,6 +103,15 @@ public class Field { this.data = data; } + @XmlElement(name = "rdaProperty") + public String getRdaProperty() { + return rdaProperty; + } + + public void setRdaProperty(String rdaProperty) { + this.rdaProperty = rdaProperty; + } + public eu.eudat.models.data.admin.components.datasetprofile.Field toAdminCompositeModelSection() { eu.eudat.models.data.admin.components.datasetprofile.Field fieldEntity =new eu.eudat.models.data.admin.components.datasetprofile.Field(); @@ -120,6 +131,7 @@ public class Field { if (data != null) { fieldEntity.setData(data.toMap((Element) this.data)); } + fieldEntity.setRdaCommonStandard(this.rdaProperty); return fieldEntity; } } From 26e10b129943659d0ea18e76240fe1bbb5fac303 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 8 Feb 2022 14:31:36 +0200 Subject: [PATCH 06/12] Add URL Validator type in validators. Free Text can have URL validator. --- .../components/datasetprofile/Field.java | 4 +- .../app/core/common/enum/validation-type.ts | 16 +++- .../model/dataset-profile-definition/field.ts | 3 +- ...ataset-profile-editor-field.component.html | 7 +- .../dataset-profile-editor-field.component.ts | 87 +++++++++++++------ .../form-field/form-field.component.html | 9 +- .../form-progress-indication.component.ts | 6 +- .../dataset-description-form.model.ts | 48 ++++++---- dmp-frontend/src/assets/i18n/de.json | 8 +- dmp-frontend/src/assets/i18n/en.json | 8 +- dmp-frontend/src/assets/i18n/es.json | 9 +- dmp-frontend/src/assets/i18n/gr.json | 8 +- dmp-frontend/src/assets/i18n/pt.json | 9 +- dmp-frontend/src/assets/i18n/sk.json | 8 +- dmp-frontend/src/assets/i18n/sr.json | 8 +- dmp-frontend/src/assets/i18n/tr.json | 8 +- 16 files changed, 171 insertions(+), 75 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/Field.java index 7903a4ddc..8847c8692 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/Field.java @@ -13,7 +13,7 @@ import java.util.stream.Collectors; public class Field implements ViewStyleDefinition, Comparable { public enum ValidationType { - NONE((short) 0), REQUIRED((short) 1); + NONE((short) 0), REQUIRED((short) 1), URL((short) 2); private short value; private ValidationType(short value) { @@ -30,6 +30,8 @@ public class Field implements ViewStyleDefinition; validationRequired; -} \ No newline at end of file + validationURL; +} diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.html b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.html index 493589d62..1f9e1f78f 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.html +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.html @@ -5,11 +5,16 @@
    -
  • +
  • {{'GENERAL.VALIDATION.REQUIRED' | translate}}
  • +
  • + + {{'GENERAL.VALIDATION.URL.LABEL' | translate}} + +
  • diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts index 2486aea7e..53d195c32 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts @@ -1,22 +1,43 @@ - -import { Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; +import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {FormArray, FormControl, FormGroup, FormGroupDirective, NgForm,} from '@angular/forms'; -import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style'; -import { ValidationType } from '@app/core/common/enum/validation-type'; -import { DatasetProfileService } from '@app/core/services/dataset-profile/dataset-profile.service'; -import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; -import { RuleEditorModel } from '@app/ui/admin/dataset-profile/admin/rule-editor-model'; -import { BaseComponent } from '@common/base/base.component'; -import { Subscription } from 'rxjs'; -import { ViewStyleType } from './view-style-enum'; -import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type'; -import { ErrorStateMatcher } from '@angular/material/core'; -import { MatDialog } from '@angular/material/dialog'; -import { MatSlideToggleChange } from '@angular/material/slide-toggle'; -import { Field } from '@app/core/model/admin/dataset-profile/dataset-profile'; -import { DatasetProfileInternalDmpEntitiesType } from '@app/core/common/enum/dataset-profile-internal-dmp-entities-type'; -import { FieldEditorModel } from '../../../admin/field-editor-model'; -import { AutoCompleteFieldData, BooleanDecisionFieldData, CheckBoxFieldData, CurrencyFieldData, DataRepositoriesFieldData, DatasetIdentifierFieldData, DatePickerFieldData, DmpsAutoCompleteFieldData, ExternalDatasetsFieldData, FieldDataOption, FreeTextFieldData, OrganizationsFieldData, RadioBoxFieldData, RegistriesFieldData, ResearchersAutoCompleteFieldData, ServicesFieldData, TagsFieldData, TextAreaFieldData, RichTextAreaFieldData, ValidationFieldData, WordListFieldData } from '@app/core/model/dataset-profile-definition/field-data/field-data'; +import {DatasetProfileFieldViewStyle} from '@app/core/common/enum/dataset-profile-field-view-style'; +import {ValidationType} from '@app/core/common/enum/validation-type'; +import {DatasetProfileService} from '@app/core/services/dataset-profile/dataset-profile.service'; +import {EnumUtils} from '@app/core/services/utilities/enum-utils.service'; +import {RuleEditorModel} from '@app/ui/admin/dataset-profile/admin/rule-editor-model'; +import {BaseComponent} from '@common/base/base.component'; +import {Subscription} from 'rxjs'; +import {ViewStyleType} from './view-style-enum'; +import {DatasetProfileComboBoxType} from '@app/core/common/enum/dataset-profile-combo-box-type'; +import {ErrorStateMatcher} from '@angular/material/core'; +import {MatDialog} from '@angular/material/dialog'; +import {MatSlideToggleChange} from '@angular/material/slide-toggle'; +import {Field} from '@app/core/model/admin/dataset-profile/dataset-profile'; +import {DatasetProfileInternalDmpEntitiesType} from '@app/core/common/enum/dataset-profile-internal-dmp-entities-type'; +import {FieldEditorModel} from '../../../admin/field-editor-model'; +import { + AutoCompleteFieldData, + BooleanDecisionFieldData, + CheckBoxFieldData, + CurrencyFieldData, + DataRepositoriesFieldData, + DatasetIdentifierFieldData, + DatePickerFieldData, + DmpsAutoCompleteFieldData, + ExternalDatasetsFieldData, + FieldDataOption, + FreeTextFieldData, + OrganizationsFieldData, + RadioBoxFieldData, + RegistriesFieldData, + ResearchersAutoCompleteFieldData, + RichTextAreaFieldData, + ServicesFieldData, + TagsFieldData, + TextAreaFieldData, + ValidationFieldData, + WordListFieldData +} from '@app/core/model/dataset-profile-definition/field-data/field-data'; @Component({ selector: 'app-dataset-profile-editor-field-component', @@ -147,7 +168,9 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements this.viewType = this.viewTypeEnum.Validation; break; } - + if(this.viewType !== this.viewTypeEnum.FreeText) { + this.setValidator(ValidationType.URL, false); + } } // this.showPreview = true; @@ -793,20 +816,24 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements toggleRequired(event:MatSlideToggleChange){ + this.setValidator(ValidationType.Required, event.checked); + } + toggleURL(event:MatSlideToggleChange){ + this.setValidator(ValidationType.URL, event.checked); + } + + private setValidator(validationType: ValidationType, add: boolean) { let validationsControl = this.form.get('validations') as FormControl; let validations: Array = validationsControl.value; - if(event.checked){ - if(!validations.includes(ValidationType.Required)){//IS ALREADY REQUIRED - // validationsControl.setValue(validations.filter(validator=> validator != ValidationType.Required)); - // validationsControl.updateValueAndValidity(); - validations.push(ValidationType.Required); - // validationsControl.setValue(validations); + if(add){ + if(!validations.includes(validationType)){ + validations.push(validationType); validationsControl.updateValueAndValidity(); } - }else{ - validationsControl.setValue(validations.filter(validator=> validator != ValidationType.Required)); + } else{ + validationsControl.setValue(validations.filter(validator=> validator != validationType)); validationsControl.updateValueAndValidity(); } this.form.markAsDirty();//deactivate guard @@ -818,6 +845,12 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements return validations.includes(ValidationType.Required); } + get isURL(){ + let validationsControl = this.form.get('validations') as FormControl; + let validations: Array = validationsControl.value; + return validations.includes(ValidationType.URL); + } + onDelete(){ this.delete.emit(); diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.html b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.html index f66811504..977e31f46 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.html +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.html @@ -11,7 +11,8 @@ - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{'GENERAL.VALIDATION.URL.MESSAGE' | translate}}
    @@ -105,7 +106,7 @@ - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} -
    - {{'GENERAL.VALIDATION.REQUIRED' | translate}} +
    + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
    diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts index 6a48092e5..25691b74f 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-progress-indication/form-progress-indication.component.ts @@ -91,10 +91,8 @@ export class FormProgressIndicationComponent extends BaseComponent implements On } private checkIfIsRequired(formControl: FormGroup): boolean { - if (formControl.get('validationRequired') && formControl.get('validationRequired').value) { - return true; - } - return false; + return !!(formControl.get('validationRequired') && formControl.get('validationRequired').value); + } private checkFormsIfIsFieldsAndVisible(formControl: FormGroup): boolean { diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts index 0ea6ca7a0..fdd38822c 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/dataset-description-form.model.ts @@ -1,18 +1,18 @@ -import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms"; -import { Guid } from '@common/types/guid'; -import { ValidationType } from "../../../core/common/enum/validation-type"; -import { BaseFormModel } from "../../../core/model/base-form-model"; -import { CompositeField } from "../../../core/model/dataset-profile-definition/composite-field"; -import { DatasetProfileDefinitionModel } from "../../../core/model/dataset-profile-definition/dataset-profile-definition"; -import { DefaultValue } from "../../../core/model/dataset-profile-definition/default-value"; -import { Field } from "../../../core/model/dataset-profile-definition/field"; -import { Multiplicity } from "../../../core/model/dataset-profile-definition/multiplicity"; -import { Page } from "../../../core/model/dataset-profile-definition/page"; -import { Rule } from "../../../core/model/dataset-profile-definition/rule"; -import { Section } from "../../../core/model/dataset-profile-definition/section"; -import { ViewStyle } from "../../../core/model/dataset-profile-definition/view-style"; -import { BackendErrorValidator } from '@common/forms/validation/custom-validator'; -import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import {FormBuilder, FormControl, FormGroup, ValidatorFn, Validators} from "@angular/forms"; +import {Guid} from '@common/types/guid'; +import {ValidationType, ValidatorURL} from "../../../core/common/enum/validation-type"; +import {BaseFormModel} from "../../../core/model/base-form-model"; +import {CompositeField} from "../../../core/model/dataset-profile-definition/composite-field"; +import {DatasetProfileDefinitionModel} from "../../../core/model/dataset-profile-definition/dataset-profile-definition"; +import {DefaultValue} from "../../../core/model/dataset-profile-definition/default-value"; +import {Field} from "../../../core/model/dataset-profile-definition/field"; +import {Multiplicity} from "../../../core/model/dataset-profile-definition/multiplicity"; +import {Page} from "../../../core/model/dataset-profile-definition/page"; +import {Rule} from "../../../core/model/dataset-profile-definition/rule"; +import {Section} from "../../../core/model/dataset-profile-definition/section"; +import {ViewStyle} from "../../../core/model/dataset-profile-definition/view-style"; +import {BackendErrorValidator} from '@common/forms/validation/custom-validator'; +import {ValidationErrorModel} from '@common/forms/validation/error-model/validation-error-model'; export class DatasetDescriptionFormEditorModel extends BaseFormModel { @@ -229,6 +229,7 @@ export class DatasetDescriptionFieldEditorModel extends BaseFormModel { public data: any; public validations: Array; public validationRequired = false; + public validationURL = false; fromModel(item: Field): DatasetDescriptionFieldEditorModel { this.id = item.id; @@ -253,16 +254,27 @@ export class DatasetDescriptionFieldEditorModel extends BaseFormModel { buildForm(): FormGroup { if (this.validations) { this.validations.forEach(validation => { - if (validation === ValidationType.Required) { this.validationRequired = true; } + if (validation === ValidationType.Required) { + this.validationRequired = true; + } else if(validation === ValidationType.URL) { + this.validationURL = true; + } }); } - + let validators: any[] = []; + if(this.validationRequired) { + validators.push(Validators.required) + } + if(this.validationURL) { + validators.push(ValidatorURL.validator); + } const formGroup = this.formBuilder.group({ - value: [this.value, this.validationRequired === true ? Validators.required : null], + value: [this.value, validators], id: [{ value: this.id, disabled: false }], viewStyle: [{ value: this.viewStyle, disabled: true }], data: [{ value: this.data, disabled: true }], validationRequired: [{ value: this.validationRequired, disabled: true }], + validationURL: [{ value: this.validationURL, disabled: true }], description: [{ value: this.description, disabled: true }], extendedDescription: [{ value: this.extendedDescription, disabled: true }], additionalInformation: [{ value: this.additionalInformation, disabled: true }], diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index 0bea1b395..78ba43a61 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Pflichtfeld", "GRANT-START-AFTER-END": "Anfangsdatum der Förderung kann nicht nach dem Laufzeitende liegen", - "PATTERN-_": "Schriftzeichen \"_\" ist nicht erlaubt" + "PATTERN-_": "Schriftzeichen \"_\" ist nicht erlaubt", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Warnung", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Datensatzbeschreibung ist nicht vorhanden", "DATASET-NOT-ALLOWED": "Sie haben keinen Zugriff auf diese Datensatzbeschreibung", "SUCCESS-UPDATE-DATASET-PROFILE": "Vorlage der Datensatzbeschreibung erfolgreich aktualisiert", - "MISSING-FIELDS": "There are some required fields left unfilled. Please check the form and make sure that all required fields are filled. (Missing fields are marked in red color)" + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color)" }, "UPLOAD": { "UPLOAD-XML": "Importieren", diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 723f0cea9..bc17a486b 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Required", "GRANT-START-AFTER-END": "Grant start date cannot be after the end date", - "PATTERN-_": "Character \"_\" is not allowed" + "PATTERN-_": "Character \"_\" is not allowed", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Warning", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Dataset does not exist", "DATASET-NOT-ALLOWED": "You have no access to this Dataset", "SUCCESS-UPDATE-DATASET-PROFILE": "Dataset Template updated successfully", - "MISSING-FIELDS": "There are some required fields left unfilled. Please check the form and make sure that all required fields are filled. (Missing fields are marked in red color)" + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color)" }, "UPLOAD": { "UPLOAD-XML": "Import", diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index dfb9137a7..bb849fb8e 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Obligatorio", "GRANT-START-AFTER-END": "La fecha de incio de la subvención no puede ser posterior a la fecha de fin", - "PATTERN-_": "Carácter \"_\" no permitido" + "PATTERN-_": "Carácter \"_\" no permitido", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Aviso", @@ -721,8 +725,7 @@ "DATASET-NOT-FOUND": "No existe la descripción del dataset", "DATASET-NOT-ALLOWED": "No tiene acceso a la descricipción de este dataset", "SUCCESS-UPDATE-DATASET-PROFILE": "Plantilla de descripción del dataset actualizada correctamente", - "MISSING-FIELDS": "Hay campos requeridos sin rellenar. Por favor, compruebe el formulario y rellene los campos obligatorios (Los campos sin rellenar se marcan en color rojo)" - }, + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color)" }, "UPLOAD": { "UPLOAD-XML": "Importar", "UPLOAD-XML-FILE-TITLE": "Importar la plantilla de descripción del dataset", diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index 2abf969f3..eab84d238 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Προαπαιτούμενο", "GRANT-START-AFTER-END": "Η ημερομηνία έναρξης της επιχορήγησης δεν μπορεί να είναι μεταγενέστερη της ημερομηνίας λήξης", - "PATTERN-_": "Ο χαρακτήρας \"_\" δεν υποστηρίζεται" + "PATTERN-_": "Ο χαρακτήρας \"_\" δεν υποστηρίζεται", + "URL": { + "LABEL": "URL", + "MESSAGE": "Παρακαλώ εισάγεται ένα έγκυρο URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Προσοχή", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Η Περιγραφή Συνόλου Δεδομένων δεν υπάρχει", "DATASET-NOT-ALLOWED": "Δεν έχετε πρόσβαση σε αυτή την Περιγραφή Συνόλου Δεδομένων", "SUCCESS-UPDATE-DATASET-PROFILE": "Επιτυχία ενημέρωσης της Περιγραφής Συνόλου Δεδομένων", - "MISSING-FIELDS": "Υπάρχουν ορισμένα υποχρεωτικά πεδία που δεν έχουν συμπληρωθεί. Ελέγξτε τη φόρμα και βεβαιωθείτε ότι έχουν συμπληρωθεί όλα τα απαιτούμενα πεδία. (Τα πεδία που λείπουν επισημαίνονται με κόκκινο χρώμα)" + "MISSING-FIELDS": "Υπάρχουν ορισμένα υποχρεωτικά πεδία που δεν έχουν συμπληρωθεί. Ελέγξτε το DMP και βεβαιωθείτε ότι έχουν συμπληρωθεί όλα τα απαιτούμενα πεδία και τα URL είναι έγκυρα. (Τα πεδία που λείπουν επισημαίνονται με κόκκινο χρώμα)" }, "UPLOAD": { "UPLOAD-XML": "Εισαγωγή", diff --git a/dmp-frontend/src/assets/i18n/pt.json b/dmp-frontend/src/assets/i18n/pt.json index 606bb934c..17be1de02 100644 --- a/dmp-frontend/src/assets/i18n/pt.json +++ b/dmp-frontend/src/assets/i18n/pt.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Obrigatório", "GRANT-START-AFTER-END": "A data de início do financiamento não pode ser posterior à data de término", - "PATTERN-_": "O caracter \"_\" não é permitido" + "PATTERN-_": "O caracter \"_\" não é permitido", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Atenção", @@ -721,8 +725,7 @@ "DATASET-NOT-FOUND": "O Dataset não existe", "DATASET-NOT-ALLOWED": "Não tem acesso a este Dataset", "SUCCESS-UPDATE-DATASET-PROFILE": "O Dataset foi atualizado com sucesso", - "MISSING-FIELDS": "Alguns campos obrigatórios não foram preenchidos. Por favor, verifique o formulário e certifique-se de que todos os campos obrigatórios foram preenchidos. (Os campos ausentes são marcados em vermelho)" - }, + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color)" }, "UPLOAD": { "UPLOAD-XML": "Importar", "UPLOAD-XML-FILE-TITLE": "Importar o Dataset", diff --git a/dmp-frontend/src/assets/i18n/sk.json b/dmp-frontend/src/assets/i18n/sk.json index 0410d0be4..420f481c0 100644 --- a/dmp-frontend/src/assets/i18n/sk.json +++ b/dmp-frontend/src/assets/i18n/sk.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Povinné", "GRANT-START-AFTER-END": "Dátum začatia poskytovania grantu nesmie byť po dátume ukončenia", - "PATTERN-_": "Znak \"_\" nie je povolený" + "PATTERN-_": "Znak \"_\" nie je povolený", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Upozornenie", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Súbor dát neexistuje", "DATASET-NOT-ALLOWED": "K tomuto súboru dát nemáte prístup", "SUCCESS-UPDATE-DATASET-PROFILE": "Šablóna súboru dát bola úspešne aktualizovaná", - "MISSING-FIELDS": "There are some required fields left unfilled. Please check the form and make sure that all required fields are filled. (Missing fields are marked in red color)" + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color.)" }, "UPLOAD": { "UPLOAD-XML": "Importovať", diff --git a/dmp-frontend/src/assets/i18n/sr.json b/dmp-frontend/src/assets/i18n/sr.json index bcaedf458..b37320c19 100644 --- a/dmp-frontend/src/assets/i18n/sr.json +++ b/dmp-frontend/src/assets/i18n/sr.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Obavezno", "GRANT-START-AFTER-END": "Datum početka ne može biti kasniji od datuma završetka granta.", - "PATTERN-_": "Karakter \"_\" nije dozvoljen" + "PATTERN-_": "Karakter \"_\" nije dozvoljen", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Oprez", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Skup podataka ne postoji", "DATASET-NOT-ALLOWED": "Nemate pristup ovom skupu podataka", "SUCCESS-UPDATE-DATASET-PROFILE": "Obrazac skupa podataka je ažuriran uspešno", - "MISSING-FIELDS": "There are some required fields left unfilled. Please check the form and make sure that all required fields are filled. (Missing fields are marked in red color)" + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color.)" }, "UPLOAD": { "UPLOAD-XML": "Uvezite", diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index 27189fd8f..845002e8f 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -3,7 +3,11 @@ "VALIDATION": { "REQUIRED": "Gerekli", "GRANT-START-AFTER-END": "Hibe başlangıç tarihi bitiş tarihinden sonra olamaz", - "PATTERN-_": "\"_\" Karakterine izin verilmiyor" + "PATTERN-_": "\"_\" Karakterine izin verilmiyor", + "URL": { + "LABEL": "URL", + "MESSAGE": "Please provide a valid URL" + } }, "DELETE-CONFIRMATION": { "TITLE": "Uyarı", @@ -721,7 +725,7 @@ "DATASET-NOT-FOUND": "Veri Seti mevcut değildir", "DATASET-NOT-ALLOWED": "Bu Veri Setine erişiminiz yok", "SUCCESS-UPDATE-DATASET-PROFILE": "Veri Seti Tanımı başarılı olarak güncellendi", - "MISSING-FIELDS": "There are some required fields left unfilled. Please check the form and make sure that all required fields are filled. (Missing fields are marked in red color)" + "MISSING-FIELDS": "There are some required fields left unfilled. Please check the DMP and make sure that all required questions are answered and URLs are provided with valid input. (Missing fields are marked in red color.)" }, "UPLOAD": { "UPLOAD-XML": "İçeri Aktar", From 6cdf56071315ef382f95efaf9e465b45b8033f37 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 8 Feb 2022 20:51:40 +0200 Subject: [PATCH 07/12] Add clear input in rich text editor --- .../rich-text-editor/rich-text-editor.component.scss | 9 +++++++++ .../rich-text-editor/rich-text-editor.component.ts | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.scss b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.scss index 721812d6a..f33c65603 100644 --- a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.scss +++ b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.scss @@ -9,6 +9,7 @@ //} .editor-wrapper { + position: relative; border: 1px solid transparent !important; border-radius: 5px; } @@ -40,6 +41,14 @@ border: 1px solid #f44336 !important; } +.clear { + position: absolute; + right: 5px; + bottom: 5px; + transform: translate(-50%, -50%); + cursor: pointer; +} + .full-width { width: 100%; } diff --git a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts index 0a820532b..18a325348 100644 --- a/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts +++ b/dmp-frontend/src/app/library/rich-text-editor/rich-text-editor.component.ts @@ -1,5 +1,6 @@ import {Component, Input} from "@angular/core"; import {AngularEditorConfig} from "@kolkov/angular-editor"; +import {FormControl} from "@angular/forms"; @Component({ selector: 'rich-text-editor-component', @@ -7,6 +8,7 @@ import {AngularEditorConfig} from "@kolkov/angular-editor";
    + close
    `, styleUrls: ['./rich-text-editor.component.scss'] @@ -53,6 +55,7 @@ export class RichTextEditorComponent { ] }; - constructor() { + get formInput(): FormControl { + return this.parentFormGroup.get(this.controlName); } } From 4740fbe8e0a18521b921fceab2e12355cd731d74 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Wed, 9 Feb 2022 15:23:16 +0200 Subject: [PATCH 08/12] Refactor visibilityRuleService --- .../java/eu/eudat/controllers/Datasets.java | 7 ++-- .../managers/DataManagementPlanManager.java | 9 ++--- .../eudat/logic/managers/DatasetManager.java | 16 ++++----- .../forms/VisibilityRuleServiceImpl.java | 35 ++++++++----------- .../services/utilities/UtilitiesService.java | 2 -- .../utilities/UtilitiesServiceImpl.java | 10 ++---- 6 files changed, 31 insertions(+), 48 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java index c1ffd67f1..68a3e32c8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java @@ -15,6 +15,7 @@ import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.pdf.PDFUtils; import eu.eudat.models.data.dataset.DatasetOverviewModel; @@ -126,11 +127,11 @@ public class Datasets extends BaseController { public @ResponseBody ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException { try { + VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); if (contentType.equals("application/xml")) { - VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService(); return this.datasetManager.getDocument(id, visibilityRuleService, contentType, principal); } else if (contentType.equals("application/msword")) { - FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService(), principal); + FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, visibilityRuleService, principal); InputStream resource = new FileInputStream(file.getFile()); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.setContentLength(file.getFile().length()); @@ -218,7 +219,7 @@ public class Datasets extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) public @ResponseBody ResponseEntity getPDFDocument(@PathVariable String id, @ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { - FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService(), principal); + FileEnvelope file = datasetManager.getWordDocumentFile(this.configLoader, id, new VisibilityRuleServiceImpl(), principal); String fileName = file.getFilename().replace(" ", "_").replace(",", "_"); if (fileName.endsWith(".docx")){ fileName = fileName.substring(0, fileName.length() - 5); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index b8c4ccf0d..6b13dc058 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1,7 +1,5 @@ package eu.eudat.logic.managers; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration; import eu.eudat.configurations.dynamicgrant.entities.Property; @@ -33,6 +31,7 @@ import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.services.utilities.UtilitiesService; import eu.eudat.logic.utilities.builders.XmlBuilder; @@ -106,7 +105,6 @@ public class DataManagementPlanManager { private ApiContext apiContext; private DatasetManager datasetManager; - private UtilitiesService utilitiesService; private DatabaseRepository databaseRepository; private Environment environment; private RDAManager rdaManager; @@ -117,7 +115,6 @@ public class DataManagementPlanManager { public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager, MetricsManager metricsManager) { this.apiContext = apiContext; this.datasetManager = datasetManager; - this.utilitiesService = apiContext.getUtilitiesService(); this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); this.environment = environment; this.rdaManager = rdaManager; @@ -1172,7 +1169,7 @@ public class DataManagementPlanManager { public FileEnvelope getWordDocument(String id, Principal principal, ConfigLoader configLoader, Boolean versioned) throws IOException { WordBuilder wordBuilder = new WordBuilder(); - VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService(); + VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); DatasetWizardModel dataset = new DatasetWizardModel(); XWPFDocument document = configLoader.getDocument(); @@ -1341,7 +1338,7 @@ public class DataManagementPlanManager { private FileEnvelope getXmlDocument(String id, Principal principal) throws InstantiationException, IllegalAccessException, IOException { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); - VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService(); + VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); if (!dmp.isPublic() && dmp.getUsers().stream().filter(userInfo -> userInfo.getUser().getId() == principal.getId()).collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 92b7d11c0..fdcd3d4b9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -26,6 +26,7 @@ import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.types.ParagraphStyle; @@ -49,7 +50,6 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; import eu.eudat.types.Authorities; import eu.eudat.types.MetricNames; -import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; @@ -60,11 +60,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -91,8 +91,6 @@ import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; @Component public class DatasetManager { @@ -527,7 +525,7 @@ public class DatasetManager { public String getWordDocumentText (Dataset datasetEntity) throws Exception { DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(datasetEntity); datasetWizardModel.setDatasetProfileDefinition(this.getPagedProfile(datasetWizardModel, datasetEntity)); - XWPFDocument document = getLightWordDocument(this.configLoader, datasetWizardModel, this.apiContext.getUtilitiesService().getVisibilityRuleService()); + XWPFDocument document = getLightWordDocument(this.configLoader, datasetWizardModel, new VisibilityRuleServiceImpl()); XWPFWordExtractor extractor = new XWPFWordExtractor(document); return extractor.getText();/*.replaceAll("\n\\s*", " ");*/ } @@ -657,7 +655,7 @@ public class DatasetManager { JSONObject obj = new JSONObject(dataset.getProperties()); - VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService(); + VisibilityRuleService visibilityRuleService = new VisibilityRuleServiceImpl(); visibilityRuleService.setProperties(obj.toMap()); dataset.setProfile(profile); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java index 439496588..c5ce592f1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/forms/VisibilityRuleServiceImpl.java @@ -1,30 +1,26 @@ package eu.eudat.logic.services.forms; import eu.eudat.models.data.user.components.commons.Rule; -import org.springframework.stereotype.Service; import java.util.*; /** * Created by ikalyvas on 3/5/2018. */ -@Service("visibilityRuleService") public class VisibilityRuleServiceImpl implements VisibilityRuleService { - private Map elementVisibility = new HashMap<>(); - private VisibilityContext visibilityContext; + private final Map elementVisibility = new HashMap<>(); private Map properties; public boolean isElementVisible(String id) { - if (!this.elementVisibility.containsKey(id) || this.elementVisibility.get(id)) return true; - return false; + return !this.elementVisibility.containsKey(id) || this.elementVisibility.get(id); } public void setProperties(Map properties) { this.properties = properties; this.properties.entrySet().stream() - .filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[") && ((String) stringObjectEntry.getValue()).endsWith("]")).forEach(stringObjectEntry -> { - stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue())); - }); + .filter(stringObjectEntry -> stringObjectEntry.getValue() instanceof String && ((String) stringObjectEntry.getValue()).startsWith("[") + && ((String) stringObjectEntry.getValue()).endsWith("]")) + .forEach(stringObjectEntry -> stringObjectEntry.setValue(parseArray((String) stringObjectEntry.getValue()))); } private List parseArray(String original) { @@ -33,22 +29,20 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { } public void buildVisibilityContext(List sources) { - this.visibilityContext = new VisibilityContext(); - this.visibilityContext.buildVisibilityContext(sources); - this.visibilityContext.getVisibilityRules().forEach(item-> this.evaluateVisibility(item)); + VisibilityContext visibilityContext = new VisibilityContext(); + visibilityContext.buildVisibilityContext(sources); + visibilityContext.getVisibilityRules().forEach(this::evaluateVisibility); } private void evaluateVisibility(VisibilityRule rule) { List sources = rule.getVisibilityRuleSources(); - for(int i = 0; i < sources.size(); i++){ - if (properties.containsKey(sources.get(i).getVisibilityRuleSourceId()) && (isContained(properties.get(sources.get(i).getVisibilityRuleSourceId()), sources.get(i).getVisibilityRuleSourceValue()) || properties.get(sources.get(i).getVisibilityRuleSourceId()).equals(sources.get(i).getVisibilityRuleSourceValue()))) { + for(VisibilityRuleSource source: sources){ + if (properties.containsKey(source.getVisibilityRuleSourceId()) + && isContained(properties.get(source.getVisibilityRuleSourceId()), source.getVisibilityRuleSourceValue())) { this.elementVisibility.put(rule.getVisibilityRuleTargetId(), true); } else { - if (this.elementVisibility.containsKey(rule.getVisibilityRuleTargetId())) { - this.elementVisibility.put(rule.getVisibilityRuleTargetId(), this.elementVisibility.get(rule.getVisibilityRuleTargetId()) || false); - } else { - this.elementVisibility.put(rule.getVisibilityRuleTargetId(), false); - } + this.elementVisibility.put(rule.getVisibilityRuleTargetId(), + this.elementVisibility.getOrDefault(rule.getVisibilityRuleTargetId(), false)); } } } @@ -56,7 +50,8 @@ public class VisibilityRuleServiceImpl implements VisibilityRuleService { private Boolean isContained(Object values, String source) { if (values instanceof List) { return ((Collection) values).contains(source); + } else { + return values.equals(source); } - return false; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesService.java index 3a6a25c4f..58e9c499b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesService.java @@ -11,7 +11,5 @@ public interface UtilitiesService { MailService getMailService(); - VisibilityRuleService getVisibilityRuleService(); - ConfirmationEmailService getConfirmationEmailService(); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesServiceImpl.java index 9838a8b99..9bc943280 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesServiceImpl.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/UtilitiesServiceImpl.java @@ -1,6 +1,7 @@ package eu.eudat.logic.services.utilities; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -12,22 +13,15 @@ public class UtilitiesServiceImpl implements UtilitiesService { private InvitationService invitationService; private MailService mailService; - private VisibilityRuleService visibilityRuleService; private ConfirmationEmailService confirmationEmailService; @Autowired - public UtilitiesServiceImpl(InvitationService invitationService, MailService mailService, VisibilityRuleService visibilityRuleService, ConfirmationEmailService confirmationEmailService) { + public UtilitiesServiceImpl(InvitationService invitationService, MailService mailService, ConfirmationEmailService confirmationEmailService) { this.invitationService = invitationService; this.mailService = mailService; - this.visibilityRuleService = visibilityRuleService; this.confirmationEmailService = confirmationEmailService; } - @Override - public VisibilityRuleService getVisibilityRuleService() { - return visibilityRuleService; - } - @Override public ConfirmationEmailService getConfirmationEmailService() { return confirmationEmailService; From fac6a93c0aad5c277f65bb1adae4bdd58820b97b Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Thu, 10 Feb 2022 13:21:21 +0200 Subject: [PATCH 09/12] Fix minor worldBuilder issue and a minor refactor --- .../main/java/eu/eudat/logic/managers/DatasetManager.java | 6 +++++- .../eudat/logic/utilities/documents/word/WordBuilder.java | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index fdcd3d4b9..9ea5fabb3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -664,12 +664,16 @@ public class DatasetManager { for (String validator : datasetProfileValidators) { - if ((obj.has(validator) && (obj.getString(validator) == null || obj.getString(validator).trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) { + if (obj.has(validator) && isNullOrEmpty(obj.getString(validator)) && isElementVisible(nodeList, validator, visibilityRuleService)) { throw new Exception("Field value of " + validator + " must be filled."); } } } + private boolean isNullOrEmpty(String value) { + return value == null || value.trim().isEmpty(); + } + private boolean isElementVisible(NodeList nodeList, String id, VisibilityRuleService visibilityRuleService) { Element fieldSet = null; for (int i = 0; i < nodeList.getLength(); i++) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index e491b3b9f..a5cb7d4a3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -27,7 +27,9 @@ import java.io.IOException; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.LocalDate; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAccessor; @@ -397,7 +399,7 @@ public class WordBuilder { try { instant = Instant.parse((String) field.getValue()); } catch (DateTimeParseException ex) { - instant = Instant.from(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).parse((String) field.getValue())); + instant = LocalDate.parse((String) field.getValue()).atStartOfDay().toInstant(ZoneOffset.UTC); } return field.getValue() != null ? DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant) : ""; } From eedcf0dfb0b86a10082a4c038158e67e27a91dbb Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Fri, 11 Feb 2022 13:09:29 +0200 Subject: [PATCH 10/12] fix freetext-format bug in prefilling temporarily --- .../datasetwizard/DatasetWizardModel.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java index e9611870c..7a259b315 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java @@ -390,6 +390,7 @@ public class DatasetWizardModel implements DataModel standardFormats = new ArrayList<>(); + StringBuilder freeTextFormat = new StringBuilder(); for(String format: formats) { RestTemplate restTemplate = new RestTemplate(); String parsedUrl = "https://eestore.paas2.uninett.no/api/fileformat/?search=" + format; @@ -398,28 +399,42 @@ public class DatasetWizardModel implements DataModel entity = new HttpEntity("", headers); Map data = restTemplate.exchange(parsedUrl, HttpMethod.GET, entity, LinkedHashMap.class).getBody(); jsonArr = new JSONArray(new ObjectMapper().writeValueAsString(data.get("data"))); - for(int i = 0; i < jsonArr.length(); i++){ - JSONObject jsonObj = jsonArr.getJSONObject(i); - jsonObj = jsonObj.getJSONObject("attributes"); - JSONArray extensions = jsonObj.getJSONArray("extensions"); - Object formatName = jsonObj.get("name"); - boolean found = false; - for(int j = 0; j < extensions.length(); j++){ - if(extensions.getString(j).equals(format)){ - JSONObject cur = new JSONObject(); - cur.put("label", formatName.toString()); - standardFormats.add(cur.toString()); - found = true; + if(jsonArr.length() > 0) { + for (int i = 0; i < jsonArr.length(); i++) { + JSONObject jsonObj = jsonArr.getJSONObject(i); + jsonObj = jsonObj.getJSONObject("attributes"); + JSONArray extensions = jsonObj.getJSONArray("extensions"); + Object formatName = jsonObj.get("name"); + boolean found = false; + for (int j = 0; j < extensions.length(); j++) { + if (extensions.getString(j).equals(format)) { + JSONObject cur = new JSONObject(); + cur.put("label", formatName.toString()); + standardFormats.add(cur.toString()); + found = true; + break; + } + } + if (found) { break; } } - if(found){ - break; - } + } + else{ + freeTextFormat.append(format).append(", "); } } - properties.put(id, standardFormats); + String renderStyle = node.get(0) != null ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText(); + if(renderStyle.equals("freetext")){ + if (freeTextFormat.length() > 0) { + freeTextFormat.setLength(freeTextFormat.length() - 2); + } + properties.put(id, freeTextFormat.toString()); + } + else{ + properties.put(id, standardFormats); + } } else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){ value = value.replace("\"", ""); From da5ba952e1a5364fa8bacc9b8652441a45a8bf82 Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Thu, 17 Feb 2022 10:11:34 +0200 Subject: [PATCH 11/12] rda export import tag bug, format preffiling fixed --- .../DataManagementProfileManager.java | 31 ++++---- .../eudat/logic/managers/DatasetManager.java | 5 +- .../datasetwizard/DatasetWizardModel.java | 77 +++++++++---------- .../rda/mapper/DistributionRDAMapper.java | 43 +++++++---- 4 files changed, 86 insertions(+), 70 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java index 6f1797776..031bab7e7 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java @@ -164,18 +164,23 @@ public class DataManagementProfileManager { } private List> externalAutocompleteRequest(DmpProfileExternalAutoComplete data, String like) { - List> result = new LinkedList<>(); - RestTemplate restTemplate = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(MediaType.valueOf("application/vnd.api+json; charset=utf-8"))); - headers.setContentType(MediaType.APPLICATION_JSON); - HttpEntity entity = new HttpEntity<>("parameters", headers); - - ResponseEntity response = restTemplate.exchange(data.getUrl() + "?search=" + like, HttpMethod.GET, entity, Object.class); - DocumentContext jsonContext = JsonPath.parse(response.getBody()); - - List> jsonItems = jsonContext.read(data.getOptionsRoot() + "['" + data.getLabel() + "','" + data.getValue() + "']"); - jsonItems.forEach(item -> result.add(new Tuple<>(item.get(data.getValue()), item.get(data.getLabel())))); - return result; + return externalAutocompleteRequest(data.getUrl(), data.getOptionsRoot(), data.getLabel(), data.getValue(), like); } + + public static List> externalAutocompleteRequest(String url, String optionsRoot, String label, String value, String like) { + List> result = new LinkedList<>(); + RestTemplate restTemplate = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.valueOf("application/vnd.api+json; charset=utf-8"))); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>("parameters", headers); + + ResponseEntity response = restTemplate.exchange(url + "?search=" + like, HttpMethod.GET, entity, Object.class); + DocumentContext jsonContext = JsonPath.parse(response.getBody()); + + List> jsonItems = jsonContext.read(optionsRoot + "['" + label + "','" + value + "']"); + jsonItems.forEach(item -> result.add(new Tuple<>(item.get(value), item.get(label)))); + return result; + + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 9ea5fabb3..5d3c35c98 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -1050,10 +1050,13 @@ public class DatasetManager { Set tagNodes = new HashSet<>(); tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "renderStyle", "tags", true)); tagNodes.addAll(JsonSearcher.findNodes(propertiesJson, "rdaProperty", "dataset.keyword")); + if(wizardModel.getTags() == null){ + wizardModel.setTags(new ArrayList<>()); + } if (!tagNodes.isEmpty()) { tagNodes.forEach(node -> { JsonNode value = node.get("value"); - if (!value.toString().equals("\"\"")) { + if (!value.toString().equals("\"\"") && !value.toString().equals("null")) { String stringValue = value.toString().replaceAll("=", ":"); JSONArray values = new JSONArray(stringValue); values.iterator().forEachRemaining(element -> { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java index 7a259b315..79bfe4723 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/datasetwizard/DatasetWizardModel.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.entities.*; import eu.eudat.elastic.entities.Tag; +import eu.eudat.logic.managers.DataManagementProfileManager; import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.proxy.config.entities.PrefillingFixedMapping; import eu.eudat.logic.proxy.config.entities.PrefillingGet; @@ -18,15 +19,11 @@ import eu.eudat.models.data.dataset.Service; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel; +import eu.eudat.models.data.helpermodels.Tuple; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import net.minidev.json.JSONValue; import org.json.JSONArray; import org.json.JSONObject; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.web.client.RestTemplate; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -34,7 +31,6 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; public class DatasetWizardModel implements DataModel { @@ -361,6 +357,11 @@ public class DatasetWizardModel implements DataModel parsedTags = rawTags.stream().map(rawTag -> new Tag((String) rawTag, (String) rawTag)).collect(Collectors.toList()); value = mapper.writeValueAsString(parsedTags); + List nodes = JsonSearcher.findNodes(parentNode, "rdaProperty", "dataset.keyword"); + for (JsonNode node: nodes) { + String id = node.get(0) != null ? node.get(0).get("id").asText() : node.get("id").asText(); + properties.put(id, value); + } } } setterMethod.invoke(datasetWizardModel, mapper.readValue(value, params[0])); @@ -375,9 +376,10 @@ public class DatasetWizardModel implements DataModel formats = new ArrayList<>(); String extension; @@ -389,52 +391,45 @@ public class DatasetWizardModel implements DataModel standardFormats = new ArrayList<>(); - StringBuilder freeTextFormat = new StringBuilder(); - for(String format: formats) { - RestTemplate restTemplate = new RestTemplate(); - String parsedUrl = "https://eestore.paas2.uninett.no/api/fileformat/?search=" + format; - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(new MediaType("application", "vnd.api+json"))); - HttpEntity entity = new HttpEntity("", headers); - Map data = restTemplate.exchange(parsedUrl, HttpMethod.GET, entity, LinkedHashMap.class).getBody(); - jsonArr = new JSONArray(new ObjectMapper().writeValueAsString(data.get("data"))); - if(jsonArr.length() > 0) { - for (int i = 0; i < jsonArr.length(); i++) { - JSONObject jsonObj = jsonArr.getJSONObject(i); - jsonObj = jsonObj.getJSONObject("attributes"); - JSONArray extensions = jsonObj.getJSONArray("extensions"); - Object formatName = jsonObj.get("name"); - boolean found = false; - for (int j = 0; j < extensions.length(); j++) { - if (extensions.getString(j).equals(format)) { + + String renderStyle = node.get(0) != null ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText(); + if(renderStyle.equals("combobox")){ + String autocomplete = node.get(0) != null ? node.get(0).get("data").get("type").asText() : node.get("data").get("type").asText(); + if(autocomplete.equals("autocomplete")) { + JsonNode urlNode = node.get(0) != null ? node.get(0).get("data").get("autoCompleteSingleDataList") : node.get("data").get("autoCompleteSingleDataList"); + String url = urlNode.get(0).get("url").asText(); + String optionsRoot = urlNode.get(0).get("optionsRoot").asText(); + String label = urlNode.get(0).get("autoCompleteOptions").get("label").asText(); + String val = urlNode.get(0).get("autoCompleteOptions").get("value").asText(); + for (String format : formats) { + List> result = DataManagementProfileManager.externalAutocompleteRequest(url, optionsRoot, label, val, format); + result = result.stream().distinct().collect(Collectors.toList()); + if(!result.isEmpty()){ + for (Tuple f : result) { JSONObject cur = new JSONObject(); - cur.put("label", formatName.toString()); + cur.put("label", f.getLabel()); standardFormats.add(cur.toString()); - found = true; - break; + freeTextFormat.append(f.getLabel()).append(", "); } } - if (found) { - break; + else{ + freeTextFormat.append(format).append(", "); } } + properties.put(id, standardFormats); } - else{ - freeTextFormat.append(format).append(", "); - } - } - String renderStyle = node.get(0) != null ? node.get(0).get("viewStyle").get("renderStyle").asText() : node.get("viewStyle").get("renderStyle").asText(); - if(renderStyle.equals("freetext")){ - if (freeTextFormat.length() > 0) { - freeTextFormat.setLength(freeTextFormat.length() - 2); + else if(renderStyle.equals("freetext")){ + if (freeTextFormat.length() == 0) { + for (String format : formats) { + freeTextFormat.append(format).append(", "); + } } + freeTextFormat.setLength(freeTextFormat.length() - 2); properties.put(id, freeTextFormat.toString()); } - else{ - properties.put(id, standardFormats); - } } else if(prefillingMapping.getMaDmpTarget().equals("dataset.distribution.data_access")){ value = value.replace("\"", ""); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DistributionRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DistributionRDAMapper.java index 00eae64b7..c9bd007dc 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DistributionRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DistributionRDAMapper.java @@ -89,12 +89,12 @@ public class DistributionRDAMapper { int i = 1; while(iter.hasNext()) { JsonNode current = iter.next(); - String format = JavaToJson.objectStringToJson(current.asText()); + String format = JavaToJson.objectStringToJson(current.toString()); try { Map result = new ObjectMapper().readValue(format, HashMap.class); format = result.get("label"); formats.add(format); - rda.setAdditionalProperty("format" + i++, new ObjectMapper().readTree(current.asText())); + rda.setAdditionalProperty("format" + i++, new ObjectMapper().readTree(current.toString())); } catch(JsonProcessingException e){ logger.warn(e.getMessage()); @@ -103,7 +103,12 @@ public class DistributionRDAMapper { rda.setFormat(formats); } else{ - rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(",")))); + if(rda.getFormat() == null || rda.getFormat().isEmpty()){ + rda.setFormat(new ArrayList<>(Arrays.asList(rdaValue.replace(" ", "").split(",")))); + } + else{ + rda.getFormat().addAll(Arrays.asList(rdaValue.replace(" ", "").split(","))); + } } rda.setAdditionalProperty(ImportPropertyName.FORMAT.getName(), node.get("id").asText()); break; @@ -209,19 +214,27 @@ public class DistributionRDAMapper { break; case FORMAT: if (rda.getFormat() != null && !rda.getFormat().isEmpty()) { - Map additionalProperties = rda.getAdditionalProperties(); - List standardFormats = new ArrayList<>(); - ObjectMapper mapper = new ObjectMapper(); - rda.getAdditionalProperties().forEach((key, value) -> { - try { - if (key.matches("format\\d+")) { - standardFormats.add(additionalProperties.get(key)); - properties.put(distributionNode.get("id").asText(), mapper.writeValueAsString(standardFormats)); - } - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); + String style = distributionNode.get("viewStyle").get("renderStyle").asText(); + if(style.equals("combobox")) { + if (distributionNode.get("data").get("type").asText().equals("autocomplete")) { + Map additionalProperties = rda.getAdditionalProperties(); + List standardFormats = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + rda.getAdditionalProperties().forEach((key, value) -> { + try { + if (key.matches("format\\d+")) { + standardFormats.add(additionalProperties.get(key)); + properties.put(distributionNode.get("id").asText(), mapper.writeValueAsString(standardFormats)); + } + } catch (JsonProcessingException e) { + logger.error(e.getMessage(), e); + } + }); } - }); + } + else if(style.equals("freetext")){ + properties.put(distributionNode.get("id").asText(), String.join(", ", rda.getFormat())); + } } break; case LICENSE: From e4e009f5b138c7146d73b6f1c04cbc2d36e9cfa2 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 18 Feb 2022 15:57:17 +0200 Subject: [PATCH 12/12] Fix after prefill datase editor behaviour - 7545 --- .../dataset-wizard/dataset-wizard.component.html | 4 ++-- .../dataset-wizard/dataset-wizard.component.ts | 3 +++ .../src/app/ui/dmp/editor/dmp-editor.component.ts | 15 ++------------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index 9a0a489c8..ec1cb77f6 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -89,7 +89,7 @@ chevron_right
    {{'DMP-EDITOR.STEPPER.NEXT' | translate}}
    -
    +
    {{ 'DATASET-WIZARD.ACTIONS.SAVE-AND-ADD' | translate }}
    @@ -107,7 +107,7 @@