Finished the implementation of the dataset Identifier field and added mapping support for the RDA (alongside the tags field)
This commit is contained in:
parent
64ff9d749c
commit
89fb26a693
|
@ -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<eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field>, 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<String, Object> fieldValues) {
|
||||
if (this.value != null) {
|
||||
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, "");
|
||||
}
|
||||
|
|
|
@ -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<String, Object> 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<String, String> toProperties(DatasetId rda, JsonNode node) {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
|
||||
|
|
|
@ -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<JsonNode> 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());
|
||||
}
|
||||
|
|
|
@ -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<String, Object> map = mapper.readValue(value, HashMap.class);
|
||||
return (String) map.get("name");
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -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]
|
||||
});
|
||||
}
|
||||
}
|
|
@ -227,14 +227,20 @@
|
|||
</div>
|
||||
|
||||
<div *ngSwitchCase="datasetProfileFieldViewStyleEnum.DatasetIdentifier" class="col-12">
|
||||
<div class="row">
|
||||
<div class="row" *ngIf="datasetIdInitialized">
|
||||
<mat-form-field class="col-md-12">
|
||||
<app-single-auto-complete placeholder="{{ form.get('data').value.label | translate }}" [formControl]="form.get('value')"
|
||||
[configuration]="servicesAutoCompleteConfiguration" [required]="form.get('validationRequired').value">
|
||||
</app-single-auto-complete>
|
||||
<input matInput class="col-md-12" [formControl]="getDatasetIdControl('identifier')" placeholder="{{form.get('data').value.label}}" [required]="form.get('validationRequired').value">
|
||||
<mat-error *ngIf="form.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="col-md-12">
|
||||
<mat-select class="col-md-12" [formControl]="getDatasetIdControl('type')">
|
||||
<mat-option *ngFor="let type of datasetIdTypes" [value]="type.value">
|
||||
{{ type.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="form.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
|
||||
</mat-error>
|
||||
<mat-hint>{{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.EXTERNAL-SOURCE-HINT" | translate }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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<ExternalSourceItemModel[]> {
|
||||
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
|
||||
}
|
||||
|
||||
getDatasetIdControl(name: string): FormControl {
|
||||
return this.form.get('value').get(name) as FormControl;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue