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;
|
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.DefaultValue;
|
||||||
import eu.eudat.models.data.components.commons.Multiplicity;
|
import eu.eudat.models.data.components.commons.Multiplicity;
|
||||||
import eu.eudat.models.data.components.commons.ViewStyle;
|
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.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -18,6 +23,7 @@ import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefinition<eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field>, PropertiesGenerator {
|
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 String id;
|
||||||
private Integer ordinal;
|
private Integer ordinal;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
@ -224,7 +230,18 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin
|
||||||
@Override
|
@Override
|
||||||
public void toMap(Map<String, Object> fieldValues) {
|
public void toMap(Map<String, Object> fieldValues) {
|
||||||
if (this.value != null) {
|
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());
|
fieldValues.put(this.id, this.value.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fieldValues.put(this.id, "");
|
fieldValues.put(this.id, "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,17 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.logic.utilities.json.JsonSearcher;
|
import eu.eudat.logic.utilities.json.JsonSearcher;
|
||||||
import eu.eudat.models.rda.DatasetId;
|
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.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DatasetIdRDAMapper {
|
public class DatasetIdRDAMapper {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(DatasetIdRDAMapper.class);
|
||||||
|
|
||||||
/*public static DatasetId toRDA(UUID id) {
|
/*public static DatasetId toRDA(UUID id) {
|
||||||
DatasetId rda = new DatasetId();
|
DatasetId rda = new DatasetId();
|
||||||
|
@ -26,18 +30,19 @@ public class DatasetIdRDAMapper {
|
||||||
String rdaProperty = node.get("rdaProperty").asText();
|
String rdaProperty = node.get("rdaProperty").asText();
|
||||||
String rdaValue = node.get("value").asText();
|
String rdaValue = node.get("value").asText();
|
||||||
|
|
||||||
for (DatasetIdProperties datasetIdProperties : DatasetIdProperties.values()) {
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
if (rdaProperty.contains(datasetIdProperties.getName())) {
|
try {
|
||||||
switch (datasetIdProperties) {
|
Map<String, Object> values = mapper.readValue(rdaValue, HashMap.class);
|
||||||
case IDENTIFIER:
|
if (!values.isEmpty()) {
|
||||||
data.setIdentifier(rdaValue);
|
values.entrySet().forEach(entry -> finalRDAMap(data, entry.getKey(), (String) entry.getValue()));
|
||||||
break;
|
} else {
|
||||||
case TYPE:
|
finalRDAMap(data, rdaProperty, rdaValue);
|
||||||
data.setType(DatasetId.Type.fromValue(rdaValue));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
finalRDAMap(data, rdaProperty, rdaValue);
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.getIdentifier() != null && data.getType() != null) {
|
if (data.getIdentifier() != null && data.getType() != null) {
|
||||||
|
@ -46,6 +51,23 @@ public class DatasetIdRDAMapper {
|
||||||
return null;
|
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) {
|
public static Map<String, String> toProperties(DatasetId rda, JsonNode node) {
|
||||||
Map<String, String> properties = new HashMap<>();
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import javax.transaction.Transactional;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DatasetRDAMapper {
|
public class DatasetRDAMapper {
|
||||||
|
@ -87,7 +88,14 @@ public class DatasetRDAMapper {
|
||||||
}
|
}
|
||||||
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
|
List<JsonNode> keywordNodes = JsonSearcher.findNodes(datasetDescriptionObj, "rdaProperty", "dataset.keyword");
|
||||||
if (!keywordNodes.isEmpty()) {
|
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++) {
|
for (int i = 0; i < keywordNodes.size(); i++) {
|
||||||
rda.setAdditionalProperty("keyword" + (i + 1), keywordNodes.get(i).get("id").asText());
|
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>
|
||||||
|
|
||||||
<div *ngSwitchCase="datasetProfileFieldViewStyleEnum.DatasetIdentifier" class="col-12">
|
<div *ngSwitchCase="datasetProfileFieldViewStyleEnum.DatasetIdentifier" class="col-12">
|
||||||
<div class="row">
|
<div class="row" *ngIf="datasetIdInitialized">
|
||||||
<mat-form-field class="col-md-12">
|
<mat-form-field class="col-md-12">
|
||||||
<app-single-auto-complete placeholder="{{ form.get('data').value.label | translate }}" [formControl]="form.get('value')"
|
<input matInput class="col-md-12" [formControl]="getDatasetIdControl('identifier')" placeholder="{{form.get('data').value.label}}" [required]="form.get('validationRequired').value">
|
||||||
[configuration]="servicesAutoCompleteConfiguration" [required]="form.get('validationRequired').value">
|
<mat-error *ngIf="form.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
|
||||||
</app-single-auto-complete>
|
</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 *ngIf="form.get('value').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
<mat-hint>{{ "TYPES.DATASET-PROFILE-COMBO-BOX-TYPE.EXTERNAL-SOURCE-HINT" | translate }}</mat-hint>
|
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
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 { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
|
||||||
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
|
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';
|
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 { ExternalTagEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
||||||
import { MatChipInputEvent } from '@angular/material';
|
import { MatChipInputEvent } from '@angular/material';
|
||||||
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
||||||
|
import { DatasetIdModel } from '@app/core/model/dataset/dataset-id.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-form-field',
|
selector: 'app-form-field',
|
||||||
|
@ -64,6 +65,16 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
tags: ExternalTagEditorModel[] = [];
|
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(
|
constructor(
|
||||||
public visibilityRulesService: VisibilityRulesService,
|
public visibilityRulesService: VisibilityRulesService,
|
||||||
private datasetExternalAutocompleteService: DatasetExternalAutocompleteService,
|
private datasetExternalAutocompleteService: DatasetExternalAutocompleteService,
|
||||||
|
@ -166,6 +177,12 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
|
||||||
valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item)
|
valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item)
|
||||||
};
|
};
|
||||||
break;
|
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) {
|
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[]> {
|
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> {
|
||||||
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
|
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