diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/externalfetcher/ResultFieldsMappingConfigurationEntity.java b/backend/core/src/main/java/org/opencdmp/commons/types/externalfetcher/ResultFieldsMappingConfigurationEntity.java index e99cb0837..83c5fd366 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/externalfetcher/ResultFieldsMappingConfigurationEntity.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/externalfetcher/ResultFieldsMappingConfigurationEntity.java @@ -1,14 +1,14 @@ package org.opencdmp.commons.types.externalfetcher; -import org.opencdmp.service.externalfetcher.config.entities.ResultFieldsMappingConfiguration; import jakarta.xml.bind.annotation.XmlElement; +import org.opencdmp.service.externalfetcher.config.entities.ResultFieldsMappingConfiguration; public class ResultFieldsMappingConfigurationEntity implements ResultFieldsMappingConfiguration { private String code; private String responsePath; public String getCode() { - return code; + return this.code; } @XmlElement(name = "code") @@ -17,7 +17,7 @@ public class ResultFieldsMappingConfigurationEntity implements ResultFieldsMappi } public String getResponsePath() { - return responsePath; + return this.responsePath; } @XmlElement(name = "responsePath") diff --git a/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/FieldSet.java b/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/FieldSet.java index c834f1546..da4b79be6 100644 --- a/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/FieldSet.java +++ b/backend/core/src/main/java/org/opencdmp/model/descriptiontemplatedefinition/FieldSet.java @@ -38,7 +38,7 @@ public class FieldSet { private List fields; public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -46,7 +46,7 @@ public class FieldSet { } public Integer getOrdinal() { - return ordinal; + return this.ordinal; } public void setOrdinal(Integer ordinal) { @@ -54,7 +54,7 @@ public class FieldSet { } public String getNumbering() { - return numbering; + return this.numbering; } public void setNumbering(String numbering) { @@ -62,7 +62,7 @@ public class FieldSet { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -70,7 +70,7 @@ public class FieldSet { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { @@ -78,7 +78,7 @@ public class FieldSet { } public String getExtendedDescription() { - return extendedDescription; + return this.extendedDescription; } public void setExtendedDescription(String extendedDescription) { @@ -86,7 +86,7 @@ public class FieldSet { } public String getAdditionalInformation() { - return additionalInformation; + return this.additionalInformation; } public void setAdditionalInformation(String additionalInformation) { @@ -94,7 +94,7 @@ public class FieldSet { } public Multiplicity getMultiplicity() { - return multiplicity; + return this.multiplicity; } public void setMultiplicity(Multiplicity multiplicity) { @@ -102,7 +102,7 @@ public class FieldSet { } public Boolean getHasMultiplicity() { - return hasMultiplicity; + return this.hasMultiplicity; } public void setHasMultiplicity(Boolean hasMultiplicity) { @@ -110,7 +110,7 @@ public class FieldSet { } public Boolean getHasCommentField() { - return hasCommentField; + return this.hasCommentField; } public void setHasCommentField(Boolean hasCommentField) { @@ -118,7 +118,7 @@ public class FieldSet { } public List getFields() { - return fields; + return this.fields; } public void setFields(List fields) { diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/NewVersionDescriptionTemplatePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/NewVersionDescriptionTemplatePersist.java index 6a57738bc..2b492c132 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/NewVersionDescriptionTemplatePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/NewVersionDescriptionTemplatePersist.java @@ -182,9 +182,6 @@ public class NewVersionDescriptionTemplatePersist { .on(NewVersionDescriptionTemplatePersist._definition) .over(item.getDefinition()) .using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)), - this.spec() - .must(() -> !this.isListNullOrEmpty(item.getUsers())) - .failOn(NewVersionDescriptionTemplatePersist._users).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._users}, LocaleContextHolder.getLocale())), this.navSpec() .iff(() -> !this.isListNullOrEmpty(item.getUsers())) .on(NewVersionDescriptionTemplatePersist._users) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java index c8f2bd4b9..51f84f7ba 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/FieldSetPersist.java @@ -1,8 +1,8 @@ package org.opencdmp.model.persist.descriptiontemplatedefinition; -import org.opencdmp.commons.validation.BaseValidator; import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.specification.Specification; +import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -16,47 +16,47 @@ import java.util.List; public class FieldSetPersist { - private String id = null; + private String id; public static final String _id = "id"; - private Integer ordinal = null; + private Integer ordinal; public static final String _ordinal = "ordinal"; - private String numbering = null; + private String numbering; public static final String _numbering = "numbering"; - private String title = null; + private String title; public static final String _title = "title"; - private String description = null; + private String description; public static final String _description = "description"; - private String extendedDescription = null; + private String extendedDescription; public static final String _extendedDescription = "extendedDescription"; - private String additionalInformation = null; + private String additionalInformation; public static final String _additionalInformation = "additionalInformation"; - private MultiplicityPersist multiplicity = null; + private MultiplicityPersist multiplicity; public static final String _multiplicity = "multiplicity"; private Boolean hasMultiplicity; public static final String _hasMultiplicity = "hasMultiplicity"; - private Boolean hasCommentField = null; + private Boolean hasCommentField; - private List fields = null; + private List fields; public static final String _fields = "fields"; public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -64,7 +64,7 @@ public class FieldSetPersist { } public Integer getOrdinal() { - return ordinal; + return this.ordinal; } public void setOrdinal(Integer ordinal) { @@ -72,7 +72,7 @@ public class FieldSetPersist { } public String getNumbering() { - return numbering; + return this.numbering; } public void setNumbering(String numbering) { @@ -80,7 +80,7 @@ public class FieldSetPersist { } public String getTitle() { - return title; + return this.title; } public void setTitle(String title) { @@ -88,7 +88,7 @@ public class FieldSetPersist { } public String getDescription() { - return description; + return this.description; } public void setDescription(String description) { @@ -96,7 +96,7 @@ public class FieldSetPersist { } public String getExtendedDescription() { - return extendedDescription; + return this.extendedDescription; } public void setExtendedDescription(String extendedDescription) { @@ -104,7 +104,7 @@ public class FieldSetPersist { } public String getAdditionalInformation() { - return additionalInformation; + return this.additionalInformation; } public void setAdditionalInformation(String additionalInformation) { @@ -112,7 +112,7 @@ public class FieldSetPersist { } public MultiplicityPersist getMultiplicity() { - return multiplicity; + return this.multiplicity; } public void setMultiplicity(MultiplicityPersist multiplicity) { @@ -120,7 +120,7 @@ public class FieldSetPersist { } public Boolean getHasCommentField() { - return hasCommentField; + return this.hasCommentField; } public void setHasCommentField(Boolean hasCommentField) { @@ -128,7 +128,7 @@ public class FieldSetPersist { } public List getFields() { - return fields; + return this.fields; } public void setFields(List fields) { @@ -136,7 +136,7 @@ public class FieldSetPersist { } public Boolean getHasMultiplicity() { - return hasMultiplicity; + return this.hasMultiplicity; } public void setHasMultiplicity(Boolean hasMultiplicity) { @@ -169,19 +169,19 @@ public class FieldSetPersist { return Arrays.asList( this.spec() .must(() -> !this.isEmpty(item.getId())) - .failOn(FieldSetPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._id}, LocaleContextHolder.getLocale())), + .failOn(FieldSetPersist._id).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._id}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getOrdinal())) - .failOn(FieldSetPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._ordinal}, LocaleContextHolder.getLocale())), + .failOn(FieldSetPersist._ordinal).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._ordinal}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getNumbering())) - .failOn(FieldSetPersist._numbering).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._numbering}, LocaleContextHolder.getLocale())), + .failOn(FieldSetPersist._numbering).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._numbering}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isNull(item.getHasMultiplicity())) - .failOn(FieldSetPersist._hasMultiplicity).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._hasMultiplicity}, LocaleContextHolder.getLocale())), + .failOn(FieldSetPersist._hasMultiplicity).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._hasMultiplicity}, LocaleContextHolder.getLocale())), this.spec() .must(() -> !this.isEmpty(item.getTitle())) - .failOn(FieldSetPersist._title).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._title}, LocaleContextHolder.getLocale())), + .failOn(FieldSetPersist._title).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{FieldSetPersist._title}, LocaleContextHolder.getLocale())), this.refSpec() .iff(() -> !this.isNull(item.getMultiplicity())) .on(FieldSetPersist._multiplicity) diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java index 4de14ce1e..7264e1f41 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/descriptiontemplatedefinition/fielddata/BaseFieldDataPersist.java @@ -2,9 +2,9 @@ package org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import gr.cite.tools.validation.specification.Specification; import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.validation.BaseValidator; -import gr.cite.tools.validation.specification.Specification; import org.opencdmp.convention.ConventionService; import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.springframework.context.MessageSource; @@ -39,7 +39,7 @@ import java.util.List; }) public abstract class BaseFieldDataPersist { - private String label = null; + private String label; public static final String _label = "label"; @@ -48,7 +48,7 @@ public abstract class BaseFieldDataPersist { public static final String _fieldType = "fieldType"; public String getLabel() { - return label; + return this.label; } public void setLabel(String label) { @@ -56,7 +56,7 @@ public abstract class BaseFieldDataPersist { } public FieldType getFieldType() { - return fieldType; + return this.fieldType; } public void setFieldType(FieldType fieldType) { @@ -73,13 +73,11 @@ public abstract class BaseFieldDataPersist { } protected List getBaseSpecifications(T item) { - List specifications = new ArrayList<>(); - specifications.addAll(Arrays.asList( - this.spec() - .must(() -> !this.isNull(item.getFieldType())) - .failOn(BaseFieldDataPersist._fieldType).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale())) + return new ArrayList<>(Arrays.asList( + this.spec() + .must(() -> !this.isNull(item.getFieldType())) + .failOn(BaseFieldDataPersist._fieldType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale())) )); - return specifications; } } diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 214a80dd8..b09fbeb73 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -188,8 +188,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.entityManager.persist(data); this.persistUsers(data.getId(), model.getUsers()); - if (this.conventionService.isListNullOrEmpty(model.getUsers())) - this.addOwner(data); this.entityManager.flush(); @@ -284,18 +282,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.eventHandler.handle(event); } - private void addOwner(DescriptionTemplateEntity descriptionTemplateEntity) throws InvalidApplicationException { - UserDescriptionTemplateEntity data = new UserDescriptionTemplateEntity(); - data.setId(UUID.randomUUID()); - data.setIsActive(IsActive.Active); - data.setCreatedAt(Instant.now()); - data.setUpdatedAt(Instant.now()); - data.setRole(UserDescriptionTemplateRole.Owner); - data.setUserId(this.userScope.getUserId()); - data.setDescriptionTemplateId(descriptionTemplateEntity.getId()); - this.entityManager.persist(data); - } - private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist) throws InvalidApplicationException { DefinitionEntity data = new DefinitionEntity(); if (persist == null) diff --git a/backend/core/src/main/java/org/opencdmp/service/externalfetcher/ExternalFetcherServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/externalfetcher/ExternalFetcherServiceImpl.java index 8dfaa9a82..63796c20c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/externalfetcher/ExternalFetcherServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/externalfetcher/ExternalFetcherServiceImpl.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.PathNotFoundException; +import gr.cite.tools.exception.MyApplicationException; +import net.minidev.json.JSONArray; import org.opencdmp.commons.JsonHandlingService; import org.opencdmp.commons.enums.ExternalFetcherSourceType; import org.opencdmp.commons.types.externalfetcher.StaticOptionEntity; @@ -13,25 +15,22 @@ import org.opencdmp.data.ReferenceEntity; import org.opencdmp.model.Reference; import org.opencdmp.model.referencedefinition.Field; import org.opencdmp.service.externalfetcher.config.entities.*; -import org.opencdmp.service.externalfetcher.models.ExternalDataResult; import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria; -import gr.cite.tools.exception.MyApplicationException; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import net.minidev.json.JSONArray; +import org.opencdmp.service.externalfetcher.models.ExternalDataResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.*; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; import reactor.netty.http.client.HttpClient; -import javax.net.ssl.SSLException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,7 +57,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { } ).clientConnector(new ReactorClientHttpConnector(HttpClient.create().followRedirect(true))).build(); } - return webClient; + return this.webClient; } @@ -78,7 +77,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { @Override public Integer countExternalData(List sources, ExternalReferenceCriteria externalReferenceCriteria, String key) { - return getExternalData(sources, externalReferenceCriteria, key).getResults().size(); + return this.getExternalData(sources, externalReferenceCriteria, key).getResults().size(); } private ExternalDataResult queryExternalData(List sources, ExternalReferenceCriteria externalReferenceCriteria) { @@ -103,7 +102,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { } } else if (source.getType() != null && source.getType().equals(ExternalFetcherSourceType.STATIC)) { SourceStaticOptionConfiguration staticSource = (SourceStaticOptionConfiguration)source; - results.addAll(queryStaticData(staticSource, externalReferenceCriteria)); + results.addAll(this.queryStaticData(staticSource, externalReferenceCriteria)); } } return results; @@ -232,12 +231,12 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { } private ExternalDataResult queryExternalData(final SourceExternalApiConfiguration, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception { - String replacedPath = replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria); - String replacedBody = replaceLookupFields(apiSource.getRequestBody(), apiSource, externalReferenceCriteria); + String replacedPath = this.replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria); + String replacedBody = this.replaceLookupFields(apiSource.getRequestBody(), apiSource, externalReferenceCriteria); ExternalDataResult externalDataResult = this.getExternalDataResults(replacedPath, apiSource, replacedBody, auth); if(externalDataResult != null) { - if (apiSource.getFilterType() != null && apiSource.getFilterType().equals("local") && (externalReferenceCriteria.getLike() != null && !externalReferenceCriteria.getLike().isEmpty())) { + if (apiSource.getFilterType() != null && "local".equals(apiSource.getFilterType()) && (externalReferenceCriteria.getLike() != null && !externalReferenceCriteria.getLike().isEmpty())) { externalDataResult.setResults(externalDataResult.getResults().stream() .filter(r -> r.get(ReferenceEntity.KnownFields.Label).toLowerCase().contains(externalReferenceCriteria.getLike().toLowerCase())) .collect(Collectors.toList())); @@ -310,28 +309,30 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { boolean isValid = true; for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) { if (this.conventionService.isNullOrEmpty(field.getResponsePath()) || this.conventionService.isNullOrEmpty(field.getCode())) continue; - + boolean getFirst = field.getResponsePath().endsWith(".first()"); + String responsePath = new String(field.getResponsePath()); + if (getFirst) responsePath = responsePath.substring(0, responsePath.length() - ".first()".length()); try { - if (field.getResponsePath().contains("@{{")){ + if (responsePath.contains("@{{")){ String rePattern = "@\\{\\{(.*?)}}"; Pattern p = Pattern.compile(rePattern); - Matcher m = p.matcher(field.getResponsePath()); - String value = field.getResponsePath(); + Matcher m = p.matcher(responsePath); + String value = responsePath; while (m.find()) { if (m.groupCount() < 1) continue; Object partValue = JsonPath.parse(resultItem).read(m.group(1)); - String normalizedValue = normalizeJsonValue(partValue); + String normalizedValue = normalizeJsonValue(partValue, getFirst); if (normalizedValue != null) value = value.replace("@{{" + m.group(1) + "}}", normalizedValue); else value = value.replace("@{{" + m.group(1) + "}}",""); } - map.put(field.getCode(), normalizeJsonValue(value)); + map.put(field.getCode(), normalizeJsonValue(value, getFirst)); } else { - Object value = JsonPath.parse(resultItem).read(field.getResponsePath()); - map.put(field.getCode(), normalizeJsonValue(value)); + Object value = JsonPath.parse(resultItem).read(responsePath); + map.put(field.getCode(), normalizeJsonValue(value, getFirst)); } }catch (PathNotFoundException e){ - logger.debug("Json Path Error: " + e.getMessage() + " on source " + jsonHandlingService.toJsonSafe(resultItem)); + logger.debug("Json Path Error: " + e.getMessage() + " on source " + this.jsonHandlingService.toJsonSafe(resultItem)); if (ReferenceEntity.KnownFields.ReferenceId.equals(field.getCode())) { isValid = false; break; @@ -339,7 +340,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { } } if (this.conventionService.isNullOrEmpty(map.getOrDefault(ReferenceEntity.KnownFields.ReferenceId, null))){ - logger.warn("Invalid reference on source " + jsonHandlingService.toJsonSafe(resultItem)); + logger.warn("Invalid reference on source " + this.jsonHandlingService.toJsonSafe(resultItem)); } if (isValid) parsedData.add(map); } @@ -348,29 +349,13 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService { return result; } - private static String normalizeJsonValue(Object value) { + private static String normalizeJsonValue(Object value, boolean getfirst) { if (value instanceof JSONArray jsonArray) { - - if (!jsonArray.isEmpty() && jsonArray.getFirst() instanceof String) { + if (getfirst) { return jsonArray.getFirst().toString(); } else { - for (Object o : jsonArray) { - if ((o instanceof Map) && ((Map) o).containsKey("content")) { - try { - return String.valueOf(((Map) o).get("content")); - } - catch (ClassCastException e){ - if(((Map) o).get("content") instanceof Integer) { - return String.valueOf(((Map) o).get("content")); - } - return null; - } - } - } + return value.toString(); } - } else if (value instanceof Map) { - String key = ((Map)value).containsKey("$") ? "$" : "content"; - return String.valueOf(((Map)value).get(key)); } return value != null ? value.toString() : null; } diff --git a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts index ef9777c0c..68e3e2c67 100644 --- a/dmp-frontend/src/app/core/pipes/field-value.pipe.ts +++ b/dmp-frontend/src/app/core/pipes/field-value.pipe.ts @@ -1,17 +1,27 @@ import { DatePipe } from "@angular/common"; import { Pipe, PipeTransform } from "@angular/core"; import { DescriptionTemplateFieldType } from "../common/enum/description-template-field-type"; -import { Reference } from "../model/reference/reference"; -import { DescriptionTemplateField, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template"; +import { DescriptionTemplateField, DescriptionTemplateLabelAndMultiplicityData, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template"; import { DescriptionFieldPersist } from "../model/description/description"; -import { Observable, of } from "rxjs"; +import { Observable, map, of } from "rxjs"; +import { TagService } from "../services/tag/tag.service"; +import { Guid } from "@common/types/guid"; +import { DmpService } from "../services/dmp/dmp.service"; +import { DescriptionService } from "../services/description/description.service"; +import { StorageFileService } from "../services/storage-file/storage-file.service"; +import { nameof } from "ts-simple-nameof"; +import { StorageFile } from "../model/storage-file/storage-file"; @Pipe({ name: 'fieldValue' }) export class FieldValuePipe implements PipeTransform { - constructor(private date: DatePipe) { + constructor(private date: DatePipe, + private tagService: TagService, + private dmpService: DmpService, + private storageFileService: StorageFileService, + private descriptionService: DescriptionService) { } transform(controlValue: DescriptionFieldPersist, field: DescriptionTemplateField): Observable { @@ -57,11 +67,37 @@ export class FieldValuePipe implements PipeTransform { } break; } - // case DescriptionTemplateFieldType.TAGS: - // return this.parseJson(value); - // case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: - // case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: - // return this.parseJson(value, 'label'); + case DescriptionTemplateFieldType.TAGS: { + if (controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.tagService.query(this.tagService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + } + case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: { + const data = field.data; + if (!data?.multipleSelect && controlValue.textValue && controlValue.textValue.length > 0) { + return this.dmpService.query(this.dmpService.buildAutocompleteLookup(null, null, [Guid.parse(controlValue.textValue)])).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } else if (data?.multipleSelect && controlValue.references && controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.dmpService.query(this.dmpService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + } + case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: + const data = field.data; + if (!data?.multipleSelect && controlValue.textValue && controlValue.textValue.length > 0) { + return this.descriptionService.query(this.descriptionService.buildAutocompleteLookup(null, null, [Guid.parse(controlValue.textValue)])).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } else if (data?.multipleSelect && controlValue.references && controlValue.textListValue && controlValue.textListValue.length > 0) { + return this.descriptionService.query(this.descriptionService.buildAutocompleteLookup(null, null, controlValue.textListValue.map(x => Guid.parse(x)))).pipe(map(x => x.items?.map(y=> y.label).join(','))); + } + break; + case DescriptionTemplateFieldType.UPLOAD: { + if (controlValue.textValue && controlValue.textValue.length > 0) { + return this.storageFileService.getSingle(Guid.parse(controlValue.textValue), [ + nameof(x => x.name) + ]).pipe(map(x => x.name)); + } + break; + } case DescriptionTemplateFieldType.DATASET_IDENTIFIER: case DescriptionTemplateFieldType.VALIDATION: if (controlValue.externalIdentifier?.identifier) { @@ -72,7 +108,7 @@ export class FieldValuePipe implements PipeTransform { return of(null); } } - return null; + return of(null); } public parseJson(value: any, field: string = 'name') { diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html index f5704cbd6..a92f6aea1 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-datasets/description-template-editor-external-datasets-field.component.html @@ -23,4 +23,4 @@ {{form.get('data').get('type').getError('backendError').message}} - \ No newline at end of file + diff --git a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/TagMigrationService.java b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/TagMigrationService.java index 3005c4290..520fa51f0 100644 --- a/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/TagMigrationService.java +++ b/dmp-migration-tool/web/src/main/java/eu/old/eudat/migration/TagMigrationService.java @@ -65,6 +65,8 @@ public class TagMigrationService { boolean tagAlreadyExists; if (elasticDataset.getTags() != null && !elasticDataset.getTags().isEmpty()) { for (Tag tag : elasticDataset.getTags()) { + if (tag.getName() == null || tag.getName().isBlank()) continue; + tagAlreadyExists = savedTagIdsByName.containsKey(new TagKey(item, tag)); //TODO we want owner logic ? if (!tagAlreadyExists) { TagEntity tagEntity = new TagEntity();