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 8eda7d5fd..e03b0e0ce 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 @@ -52,6 +52,7 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; +import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -1018,15 +1019,12 @@ public class DatasetManager { if (!tagNodes.isEmpty()) { tagNodes.forEach(node -> { JsonNode value = node.get("value"); - if (value.isArray()) { - value.elements().forEachRemaining(element -> { - try { - Map data = mapper.readValue(element.asText(), HashMap.class); - this.addTag(tags, wizardModel.getTags(), data.get("id"), data.get("name")); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - + String stringValue = value.asText().replaceAll("=", ":"); + JSONArray values = new JSONArray(stringValue); + if (values != null) { + values.iterator().forEachRemaining(element -> { + Map data = ((JSONObject) element).toMap(); + this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString()); }); } else { this.addTag(tags, wizardModel.getTags(), "", value.asText()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/fetching/RemoteFetcher.java b/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/fetching/RemoteFetcher.java index 27ed3a22e..9b824a81c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/fetching/RemoteFetcher.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/fetching/RemoteFetcher.java @@ -297,7 +297,11 @@ public class RemoteFetcher { } } } else { - mapToMap(id, (Map)obj, item, i == 1); + if (obj instanceof Map) { + mapToMap(id, (Map) obj, item, i == 1); + } else if (obj != null){ + item.put(id, obj.toString()); + } } } } @@ -502,14 +506,16 @@ public class RemoteFetcher { } private void mapToMap(String key, Map source, Map destination, boolean isTitle) { - String content = source.get("content"); - if (isTitle) { - String classId = source.get("classid"); - if (classId.equals("main title")) { + if (source != null) { + String content = source.get("content"); + if (isTitle) { + String classId = source.get("classid"); + if (classId.equals("main title")) { + destination.put(key, content); + } + } else { destination.put(key, content); } - } else { - destination.put(key, content); } } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts index 0a5d5f758..c50f4b40e 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/external-references/dataset-external-references-editor.component.ts @@ -76,7 +76,7 @@ export class DatasetExternalReferencesEditorComponent extends BaseComponent impl initialItems: (type) => this.searchDatasetExternalServices('', type), displayFn: (item) => item ? item.label : null, titleFn: (item) => item ? item.label : null, - subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') + subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE') }; tagsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { 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 bb7741581..bd576ccdb 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 @@ -190,18 +190,7 @@
- - - {{tag.name}} - cancel - - - +
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 e35c8026b..dc3e4b75e 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 @@ -166,12 +166,19 @@ export class FormFieldComponent extends BaseComponent implements OnInit { initialItems: () => this.searchDatasetExternalServices(''), displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, - subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'), + subtitleFn: (item) => item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'), valueAssign: (item) => typeof (item) == 'string' ? item : JSON.stringify(item) }; break; case DatasetProfileFieldViewStyle.Tags: - this.setupTags(); + this.tagsAutoCompleteConfiguration = { + filterFn: this.filterTags.bind(this), + initialItems: (excludedItems: any[]) => this.filterTags('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), + displayFn: (item) => this.showTag(item), + titleFn: (item) => item['name'], + valueAssign: (item) => this.addTag(item) + }; + this.parseTags(); break; case DatasetProfileFieldViewStyle.Researchers: this.researchersAutoCompleteConfiguration = { @@ -337,28 +344,43 @@ export class FormFieldComponent extends BaseComponent implements OnInit { return this.externalSourcesService.searchDatasetTags(requestItem); } - private setupTags() { - this.tags = (this.form.get('value').value as string[]).map(string => JSON.parse(string)); - if (this.tags === null) { - this.tags = []; + parseTags() { + let stringValue = this.form.get('value').value; + stringValue = (stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}'); + stringValue = stringValue.replace(new RegExp('}"', 'g'), '}').replace(new RegExp('"{', 'g'), '{'); + console.log(stringValue); + const tagArray = JSON.parse(stringValue); + console.log(tagArray); + this.form.patchValue({'value': tagArray}); + } + + filterTags(value: string): Observable { + const requestItem: RequestItem = new RequestItem(); + const criteria: TagCriteria = new TagCriteria(); + criteria.like = value; + requestItem.criteria = criteria; + return this.externalSourcesService.searchDatasetTags(requestItem); + } + + showTag(ev: any) { + if (typeof ev === 'string') { + return ev; + } else { + return ev.name; } } - getTags() { - return this.tags; - } - - removeTag(tag: any) { - this.tags.splice(this.tags.indexOf(tag), 1); - this.form.patchValue({ 'value': JSON.stringify(this.tags) }); - } - - addTag(ev: MatChipInputEvent) { - if (ev.value !== '' && isNullOrUndefined((this.tags.find(tag => tag.name === ev.value)))) { - this.tags.push(new ExternalTagEditorModel('', ev.value)); + addTag(ev: any) { + let item: ExternalTagEditorModel; + //this.filteredTags = this.formGroup.get('tags').value; + if (typeof ev === 'string') { + item = new ExternalTagEditorModel('', ev); + } else { + item = ev; + } + if (item.name !== '' ) { + return item; } - this.form.patchValue({ 'value': JSON.stringify(this.tags) }); - ev.input.value = ''; } filterOrganisations(value: string): Observable {