diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index 1c735e1a9..867c0b3a9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -1,5 +1,7 @@ package eu.eudat.models.data.user.components.datasetprofile; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.models.data.components.commons.DefaultValue; import eu.eudat.models.data.components.commons.Multiplicity; import eu.eudat.models.data.components.commons.ViewStyle; @@ -11,6 +13,9 @@ import eu.eudat.logic.utilities.builders.ModelBuilder; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.LinkedList; import java.util.List; @@ -18,6 +23,7 @@ import java.util.Map; import java.util.stream.Collectors; public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefinition, PropertiesGenerator { + private static final Logger logger = LoggerFactory.getLogger(Field.class); private String id; private Integer ordinal; private Object value; @@ -224,7 +230,18 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin @Override public void toMap(Map fieldValues) { if (this.value != null) { - fieldValues.put(this.id, this.value.toString()); + if (this.viewStyle.getRenderStyle().equals("datasetIdentifier")) { + ObjectMapper mapper = new ObjectMapper(); + String valueString = null; + try { + valueString = mapper.writeValueAsString(this.value); + fieldValues.put(this.id, valueString); + } catch (JsonProcessingException e) { + logger.error(e.getMessage(), e); + } + } else { + fieldValues.put(this.id, this.value.toString()); + } } else { fieldValues.put(this.id, ""); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetIdRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetIdRDAMapper.java index 785a92d58..0f3cf01ca 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetIdRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetIdRDAMapper.java @@ -4,13 +4,17 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.models.rda.DatasetId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; public class DatasetIdRDAMapper { + private static final Logger logger = LoggerFactory.getLogger(DatasetIdRDAMapper.class); /*public static DatasetId toRDA(UUID id) { DatasetId rda = new DatasetId(); @@ -26,18 +30,19 @@ public class DatasetIdRDAMapper { String rdaProperty = node.get("rdaProperty").asText(); String rdaValue = node.get("value").asText(); - for (DatasetIdProperties datasetIdProperties : DatasetIdProperties.values()) { - if (rdaProperty.contains(datasetIdProperties.getName())) { - switch (datasetIdProperties) { - case IDENTIFIER: - data.setIdentifier(rdaValue); - break; - case TYPE: - data.setType(DatasetId.Type.fromValue(rdaValue)); - break; - } + ObjectMapper mapper = new ObjectMapper(); + try { + Map values = mapper.readValue(rdaValue, HashMap.class); + if (!values.isEmpty()) { + values.entrySet().forEach(entry -> finalRDAMap(data, entry.getKey(), (String) entry.getValue())); + } else { + finalRDAMap(data, rdaProperty, rdaValue); } + } catch (IOException e) { + finalRDAMap(data, rdaProperty, rdaValue); + logger.error(e.getMessage(), e); } + } if (data.getIdentifier() != null && data.getType() != null) { @@ -46,6 +51,23 @@ public class DatasetIdRDAMapper { return null; } + private static void finalRDAMap(DatasetId rda, String property, String value) { + for (DatasetIdProperties datasetIdProperties : DatasetIdProperties.values()) { + if (property.contains(datasetIdProperties.getName())) { + switch (datasetIdProperties) { + case IDENTIFIER: + rda.setIdentifier(value); + break; + case TYPE: + rda.setType(DatasetId.Type.fromValue(value)); + break; + } + } + } + + + } + public static Map toProperties(DatasetId rda, JsonNode node) { Map properties = new HashMap<>(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 255e344bc..2559535d3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java @@ -20,6 +20,7 @@ import javax.transaction.Transactional; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.stream.StreamSupport; @Component public class DatasetRDAMapper { @@ -87,7 +88,14 @@ public class DatasetRDAMapper { } List keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword"); if (!keywordNodes.isEmpty()) { - rda.setKeyword(keywordNodes.stream().map(keywordNode -> keywordNode.get("value").asText()).collect(Collectors.toList())); + rda.setKeyword(keywordNodes.stream().map(keywordNode -> { + JsonNode value = keywordNode.get("value"); + if (value.isArray()) { + return StreamSupport.stream(value.spliterator(), false).map(node -> KeywordRDAMapper.toRDA(node.asText())).collect(Collectors.joining("\", \"")).replaceAll("\"", "\""); + } else { + return KeywordRDAMapper.toRDA(keywordNode.get("value").asText()); + } + }).collect(Collectors.toList())); for (int i = 0; i < keywordNodes.size(); i++) { rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText()); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/KeywordRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/KeywordRDAMapper.java new file mode 100644 index 000000000..4fd4771db --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/KeywordRDAMapper.java @@ -0,0 +1,25 @@ +package eu.eudat.models.rda.mapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class KeywordRDAMapper { + private static final Logger logger = LoggerFactory.getLogger(KeywordRDAMapper.class); + + public static String toRDA(String value) { + ObjectMapper mapper = new ObjectMapper(); + try { + Map map = mapper.readValue(value, HashMap.class); + return (String) map.get("name"); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + + return value; + } +} diff --git a/dmp-frontend/src/app/core/model/dataset/dataset-id.model.ts b/dmp-frontend/src/app/core/model/dataset/dataset-id.model.ts new file mode 100644 index 000000000..5020bbbcb --- /dev/null +++ b/dmp-frontend/src/app/core/model/dataset/dataset-id.model.ts @@ -0,0 +1,22 @@ +import { FormGroup, FormBuilder } from '@angular/forms'; +import { isNullOrUndefined } from 'util'; + +export class DatasetIdModel { + identifier: string; + type: string; + + constructor(data: any) { + const parsed = JSON.parse(data); + if (!isNullOrUndefined(parsed)) { + this.identifier = parsed.identifier; + this.type = parsed.type; + } + } + + buildForm(): FormGroup { + return new FormBuilder().group({ + identifier: [this.identifier], + type: [this.type] + }); + } +} 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 6f265f232..0e064a31e 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 @@ -227,14 +227,20 @@
-
+
- - + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + + + + + + {{ type.name }} + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} - {{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.EXTERNAL-SOURCE-HINT" | translate }}
diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts index 89743d093..076dc1156 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/components/form-field/form-field.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core'; -import { FormGroup, FormArray } from '@angular/forms'; +import { FormGroup, FormArray, FormControl } from '@angular/forms'; import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type'; import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style'; import { DatasetProfileInternalDmpEntitiesType } from '@app/core/common/enum/dataset-profile-internal-dmp-entities-type'; @@ -31,6 +31,7 @@ import { isNullOrUndefined } from 'util'; import { ExternalTagEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model'; import { MatChipInputEvent } from '@angular/material'; import { ENTER, COMMA } from '@angular/cdk/keycodes'; +import { DatasetIdModel } from '@app/core/model/dataset/dataset-id.model'; @Component({ selector: 'app-form-field', @@ -64,6 +65,16 @@ export class FormFieldComponent extends BaseComponent implements OnInit { tags: ExternalTagEditorModel[] = []; + datasetIdInitialized: boolean = false; + + readonly datasetIdTypes: any[] = [ + { name: 'Handle', value: 'handle' }, + { name: 'DOI', value: 'doi' }, + { name: 'Ark', value: 'ark' }, + { name: 'Url', value: 'url' }, + { name: 'Other', value: 'other' } + ]; + constructor( public visibilityRulesService: VisibilityRulesService, private datasetExternalAutocompleteService: DatasetExternalAutocompleteService, @@ -166,6 +177,12 @@ export class FormFieldComponent extends BaseComponent implements OnInit { valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item) }; break; + case DatasetProfileFieldViewStyle.DatasetIdentifier: + const value = this.form.get('value').value; + this.form.removeControl('value'); + this.form.addControl('value', new DatasetIdModel(value).buildForm()); + this.datasetIdInitialized = true; + break; } if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.InternalDmpEntities) { @@ -326,4 +343,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit { filterResearchers(value: string): Observable { return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } }); } + + getDatasetIdControl(name: string): FormControl { + return this.form.get('value').get(name) as FormControl; + } }