Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-01 14:28:28 +03:00
commit f6ea1e2b04
10 changed files with 126 additions and 122 deletions

View File

@ -1,14 +1,14 @@
package org.opencdmp.commons.types.externalfetcher; package org.opencdmp.commons.types.externalfetcher;
import org.opencdmp.service.externalfetcher.config.entities.ResultFieldsMappingConfiguration;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import org.opencdmp.service.externalfetcher.config.entities.ResultFieldsMappingConfiguration;
public class ResultFieldsMappingConfigurationEntity implements ResultFieldsMappingConfiguration { public class ResultFieldsMappingConfigurationEntity implements ResultFieldsMappingConfiguration {
private String code; private String code;
private String responsePath; private String responsePath;
public String getCode() { public String getCode() {
return code; return this.code;
} }
@XmlElement(name = "code") @XmlElement(name = "code")
@ -17,7 +17,7 @@ public class ResultFieldsMappingConfigurationEntity implements ResultFieldsMappi
} }
public String getResponsePath() { public String getResponsePath() {
return responsePath; return this.responsePath;
} }
@XmlElement(name = "responsePath") @XmlElement(name = "responsePath")

View File

@ -38,7 +38,7 @@ public class FieldSet {
private List<Field> fields; private List<Field> fields;
public String getId() { public String getId() {
return id; return this.id;
} }
public void setId(String id) { public void setId(String id) {
@ -46,7 +46,7 @@ public class FieldSet {
} }
public Integer getOrdinal() { public Integer getOrdinal() {
return ordinal; return this.ordinal;
} }
public void setOrdinal(Integer ordinal) { public void setOrdinal(Integer ordinal) {
@ -54,7 +54,7 @@ public class FieldSet {
} }
public String getNumbering() { public String getNumbering() {
return numbering; return this.numbering;
} }
public void setNumbering(String numbering) { public void setNumbering(String numbering) {
@ -62,7 +62,7 @@ public class FieldSet {
} }
public String getTitle() { public String getTitle() {
return title; return this.title;
} }
public void setTitle(String title) { public void setTitle(String title) {
@ -70,7 +70,7 @@ public class FieldSet {
} }
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
public void setDescription(String description) { public void setDescription(String description) {
@ -78,7 +78,7 @@ public class FieldSet {
} }
public String getExtendedDescription() { public String getExtendedDescription() {
return extendedDescription; return this.extendedDescription;
} }
public void setExtendedDescription(String extendedDescription) { public void setExtendedDescription(String extendedDescription) {
@ -86,7 +86,7 @@ public class FieldSet {
} }
public String getAdditionalInformation() { public String getAdditionalInformation() {
return additionalInformation; return this.additionalInformation;
} }
public void setAdditionalInformation(String additionalInformation) { public void setAdditionalInformation(String additionalInformation) {
@ -94,7 +94,7 @@ public class FieldSet {
} }
public Multiplicity getMultiplicity() { public Multiplicity getMultiplicity() {
return multiplicity; return this.multiplicity;
} }
public void setMultiplicity(Multiplicity multiplicity) { public void setMultiplicity(Multiplicity multiplicity) {
@ -102,7 +102,7 @@ public class FieldSet {
} }
public Boolean getHasMultiplicity() { public Boolean getHasMultiplicity() {
return hasMultiplicity; return this.hasMultiplicity;
} }
public void setHasMultiplicity(Boolean hasMultiplicity) { public void setHasMultiplicity(Boolean hasMultiplicity) {
@ -110,7 +110,7 @@ public class FieldSet {
} }
public Boolean getHasCommentField() { public Boolean getHasCommentField() {
return hasCommentField; return this.hasCommentField;
} }
public void setHasCommentField(Boolean hasCommentField) { public void setHasCommentField(Boolean hasCommentField) {
@ -118,7 +118,7 @@ public class FieldSet {
} }
public List<Field> getFields() { public List<Field> getFields() {
return fields; return this.fields;
} }
public void setFields(List<Field> fields) { public void setFields(List<Field> fields) {

View File

@ -182,9 +182,6 @@ public class NewVersionDescriptionTemplatePersist {
.on(NewVersionDescriptionTemplatePersist._definition) .on(NewVersionDescriptionTemplatePersist._definition)
.over(item.getDefinition()) .over(item.getDefinition())
.using(() -> this.validatorFactory.validator(DefinitionPersist.DefinitionPersistValidator.class)), .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() this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getUsers())) .iff(() -> !this.isListNullOrEmpty(item.getUsers()))
.on(NewVersionDescriptionTemplatePersist._users) .on(NewVersionDescriptionTemplatePersist._users)

View File

@ -1,8 +1,8 @@
package org.opencdmp.model.persist.descriptiontemplatedefinition; package org.opencdmp.model.persist.descriptiontemplatedefinition;
import org.opencdmp.commons.validation.BaseValidator;
import gr.cite.tools.validation.ValidatorFactory; import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification; import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.validation.BaseValidator;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -16,47 +16,47 @@ import java.util.List;
public class FieldSetPersist { public class FieldSetPersist {
private String id = null; private String id;
public static final String _id = "id"; public static final String _id = "id";
private Integer ordinal = null; private Integer ordinal;
public static final String _ordinal = "ordinal"; public static final String _ordinal = "ordinal";
private String numbering = null; private String numbering;
public static final String _numbering = "numbering"; public static final String _numbering = "numbering";
private String title = null; private String title;
public static final String _title = "title"; public static final String _title = "title";
private String description = null; private String description;
public static final String _description = "description"; public static final String _description = "description";
private String extendedDescription = null; private String extendedDescription;
public static final String _extendedDescription = "extendedDescription"; public static final String _extendedDescription = "extendedDescription";
private String additionalInformation = null; private String additionalInformation;
public static final String _additionalInformation = "additionalInformation"; public static final String _additionalInformation = "additionalInformation";
private MultiplicityPersist multiplicity = null; private MultiplicityPersist multiplicity;
public static final String _multiplicity = "multiplicity"; public static final String _multiplicity = "multiplicity";
private Boolean hasMultiplicity; private Boolean hasMultiplicity;
public static final String _hasMultiplicity = "hasMultiplicity"; public static final String _hasMultiplicity = "hasMultiplicity";
private Boolean hasCommentField = null; private Boolean hasCommentField;
private List<FieldPersist> fields = null; private List<FieldPersist> fields;
public static final String _fields = "fields"; public static final String _fields = "fields";
public String getId() { public String getId() {
return id; return this.id;
} }
public void setId(String id) { public void setId(String id) {
@ -64,7 +64,7 @@ public class FieldSetPersist {
} }
public Integer getOrdinal() { public Integer getOrdinal() {
return ordinal; return this.ordinal;
} }
public void setOrdinal(Integer ordinal) { public void setOrdinal(Integer ordinal) {
@ -72,7 +72,7 @@ public class FieldSetPersist {
} }
public String getNumbering() { public String getNumbering() {
return numbering; return this.numbering;
} }
public void setNumbering(String numbering) { public void setNumbering(String numbering) {
@ -80,7 +80,7 @@ public class FieldSetPersist {
} }
public String getTitle() { public String getTitle() {
return title; return this.title;
} }
public void setTitle(String title) { public void setTitle(String title) {
@ -88,7 +88,7 @@ public class FieldSetPersist {
} }
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
public void setDescription(String description) { public void setDescription(String description) {
@ -96,7 +96,7 @@ public class FieldSetPersist {
} }
public String getExtendedDescription() { public String getExtendedDescription() {
return extendedDescription; return this.extendedDescription;
} }
public void setExtendedDescription(String extendedDescription) { public void setExtendedDescription(String extendedDescription) {
@ -104,7 +104,7 @@ public class FieldSetPersist {
} }
public String getAdditionalInformation() { public String getAdditionalInformation() {
return additionalInformation; return this.additionalInformation;
} }
public void setAdditionalInformation(String additionalInformation) { public void setAdditionalInformation(String additionalInformation) {
@ -112,7 +112,7 @@ public class FieldSetPersist {
} }
public MultiplicityPersist getMultiplicity() { public MultiplicityPersist getMultiplicity() {
return multiplicity; return this.multiplicity;
} }
public void setMultiplicity(MultiplicityPersist multiplicity) { public void setMultiplicity(MultiplicityPersist multiplicity) {
@ -120,7 +120,7 @@ public class FieldSetPersist {
} }
public Boolean getHasCommentField() { public Boolean getHasCommentField() {
return hasCommentField; return this.hasCommentField;
} }
public void setHasCommentField(Boolean hasCommentField) { public void setHasCommentField(Boolean hasCommentField) {
@ -128,7 +128,7 @@ public class FieldSetPersist {
} }
public List<FieldPersist> getFields() { public List<FieldPersist> getFields() {
return fields; return this.fields;
} }
public void setFields(List<FieldPersist> fields) { public void setFields(List<FieldPersist> fields) {
@ -136,7 +136,7 @@ public class FieldSetPersist {
} }
public Boolean getHasMultiplicity() { public Boolean getHasMultiplicity() {
return hasMultiplicity; return this.hasMultiplicity;
} }
public void setHasMultiplicity(Boolean hasMultiplicity) { public void setHasMultiplicity(Boolean hasMultiplicity) {
@ -169,19 +169,19 @@ public class FieldSetPersist {
return Arrays.asList( return Arrays.asList(
this.spec() this.spec()
.must(() -> !this.isEmpty(item.getId())) .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() this.spec()
.must(() -> !this.isNull(item.getOrdinal())) .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() this.spec()
.must(() -> !this.isEmpty(item.getNumbering())) .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() this.spec()
.must(() -> !this.isNull(item.getHasMultiplicity())) .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() this.spec()
.must(() -> !this.isEmpty(item.getTitle())) .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() this.refSpec()
.iff(() -> !this.isNull(item.getMultiplicity())) .iff(() -> !this.isNull(item.getMultiplicity()))
.on(FieldSetPersist._multiplicity) .on(FieldSetPersist._multiplicity)

View File

@ -2,9 +2,9 @@ package org.opencdmp.model.persist.descriptiontemplatedefinition.fielddata;
import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.commons.enums.FieldType; import org.opencdmp.commons.enums.FieldType;
import org.opencdmp.commons.validation.BaseValidator; import org.opencdmp.commons.validation.BaseValidator;
import gr.cite.tools.validation.specification.Specification;
import org.opencdmp.convention.ConventionService; import org.opencdmp.convention.ConventionService;
import org.opencdmp.errorcode.ErrorThesaurusProperties; import org.opencdmp.errorcode.ErrorThesaurusProperties;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -39,7 +39,7 @@ import java.util.List;
}) })
public abstract class BaseFieldDataPersist { public abstract class BaseFieldDataPersist {
private String label = null; private String label;
public static final String _label = "label"; public static final String _label = "label";
@ -48,7 +48,7 @@ public abstract class BaseFieldDataPersist {
public static final String _fieldType = "fieldType"; public static final String _fieldType = "fieldType";
public String getLabel() { public String getLabel() {
return label; return this.label;
} }
public void setLabel(String label) { public void setLabel(String label) {
@ -56,7 +56,7 @@ public abstract class BaseFieldDataPersist {
} }
public FieldType getFieldType() { public FieldType getFieldType() {
return fieldType; return this.fieldType;
} }
public void setFieldType(FieldType fieldType) { public void setFieldType(FieldType fieldType) {
@ -73,13 +73,11 @@ public abstract class BaseFieldDataPersist {
} }
protected List<Specification> getBaseSpecifications(T item) { protected List<Specification> getBaseSpecifications(T item) {
List<Specification> specifications = new ArrayList<>(); return new ArrayList<>(Arrays.asList(
specifications.addAll(Arrays.asList(
this.spec() this.spec()
.must(() -> !this.isNull(item.getFieldType())) .must(() -> !this.isNull(item.getFieldType()))
.failOn(BaseFieldDataPersist._fieldType).failWith(messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale())) .failOn(BaseFieldDataPersist._fieldType).failWith(this.messageSource.getMessage("Validation_Required", new Object[]{BaseFieldDataPersist._fieldType}, LocaleContextHolder.getLocale()))
)); ));
return specifications;
} }
} }

View File

@ -188,8 +188,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.entityManager.persist(data); this.entityManager.persist(data);
this.persistUsers(data.getId(), model.getUsers()); this.persistUsers(data.getId(), model.getUsers());
if (this.conventionService.isListNullOrEmpty(model.getUsers()))
this.addOwner(data);
this.entityManager.flush(); this.entityManager.flush();
@ -284,18 +282,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
this.eventHandler.handle(event); 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 { private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist) throws InvalidApplicationException {
DefinitionEntity data = new DefinitionEntity(); DefinitionEntity data = new DefinitionEntity();
if (persist == null) if (persist == null)

View File

@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException; 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.JsonHandlingService;
import org.opencdmp.commons.enums.ExternalFetcherSourceType; import org.opencdmp.commons.enums.ExternalFetcherSourceType;
import org.opencdmp.commons.types.externalfetcher.StaticOptionEntity; 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.Reference;
import org.opencdmp.model.referencedefinition.Field; import org.opencdmp.model.referencedefinition.Field;
import org.opencdmp.service.externalfetcher.config.entities.*; import org.opencdmp.service.externalfetcher.config.entities.*;
import org.opencdmp.service.externalfetcher.models.ExternalDataResult;
import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria; import org.opencdmp.service.externalfetcher.criteria.ExternalReferenceCriteria;
import gr.cite.tools.exception.MyApplicationException; import org.opencdmp.service.externalfetcher.models.ExternalDataResult;
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.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference; 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.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClient;
import javax.net.ssl.SSLException;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -58,7 +57,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
} }
).clientConnector(new ReactorClientHttpConnector(HttpClient.create().followRedirect(true))).build(); ).clientConnector(new ReactorClientHttpConnector(HttpClient.create().followRedirect(true))).build();
} }
return webClient; return this.webClient;
} }
@ -78,7 +77,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
@Override @Override
public Integer countExternalData(List<SourceBaseConfiguration> sources, ExternalReferenceCriteria externalReferenceCriteria, String key) { public Integer countExternalData(List<SourceBaseConfiguration> sources, ExternalReferenceCriteria externalReferenceCriteria, String key) {
return getExternalData(sources, externalReferenceCriteria, key).getResults().size(); return this.getExternalData(sources, externalReferenceCriteria, key).getResults().size();
} }
private ExternalDataResult queryExternalData(List<SourceBaseConfiguration> sources, ExternalReferenceCriteria externalReferenceCriteria) { private ExternalDataResult queryExternalData(List<SourceBaseConfiguration> sources, ExternalReferenceCriteria externalReferenceCriteria) {
@ -103,7 +102,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
} }
} else if (source.getType() != null && source.getType().equals(ExternalFetcherSourceType.STATIC)) { } else if (source.getType() != null && source.getType().equals(ExternalFetcherSourceType.STATIC)) {
SourceStaticOptionConfiguration<Static> staticSource = (SourceStaticOptionConfiguration)source; SourceStaticOptionConfiguration<Static> staticSource = (SourceStaticOptionConfiguration)source;
results.addAll(queryStaticData(staticSource, externalReferenceCriteria)); results.addAll(this.queryStaticData(staticSource, externalReferenceCriteria));
} }
} }
return results; return results;
@ -232,12 +231,12 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
} }
private ExternalDataResult queryExternalData(final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception { private ExternalDataResult queryExternalData(final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception {
String replacedPath = replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria); String replacedPath = this.replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria);
String replacedBody = replaceLookupFields(apiSource.getRequestBody(), apiSource, externalReferenceCriteria); String replacedBody = this.replaceLookupFields(apiSource.getRequestBody(), apiSource, externalReferenceCriteria);
ExternalDataResult externalDataResult = this.getExternalDataResults(replacedPath, apiSource, replacedBody, auth); ExternalDataResult externalDataResult = this.getExternalDataResults(replacedPath, apiSource, replacedBody, auth);
if(externalDataResult != null) { 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() externalDataResult.setResults(externalDataResult.getResults().stream()
.filter(r -> r.get(ReferenceEntity.KnownFields.Label).toLowerCase().contains(externalReferenceCriteria.getLike().toLowerCase())) .filter(r -> r.get(ReferenceEntity.KnownFields.Label).toLowerCase().contains(externalReferenceCriteria.getLike().toLowerCase()))
.collect(Collectors.toList())); .collect(Collectors.toList()));
@ -310,28 +309,30 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
boolean isValid = true; boolean isValid = true;
for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) { for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) {
if (this.conventionService.isNullOrEmpty(field.getResponsePath()) || this.conventionService.isNullOrEmpty(field.getCode())) continue; 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 { try {
if (field.getResponsePath().contains("@{{")){ if (responsePath.contains("@{{")){
String rePattern = "@\\{\\{(.*?)}}"; String rePattern = "@\\{\\{(.*?)}}";
Pattern p = Pattern.compile(rePattern); Pattern p = Pattern.compile(rePattern);
Matcher m = p.matcher(field.getResponsePath()); Matcher m = p.matcher(responsePath);
String value = field.getResponsePath(); String value = responsePath;
while (m.find()) { while (m.find()) {
if (m.groupCount() < 1) continue; if (m.groupCount() < 1) continue;
Object partValue = JsonPath.parse(resultItem).read(m.group(1)); 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); if (normalizedValue != null) value = value.replace("@{{" + m.group(1) + "}}", normalizedValue);
else value = value.replace("@{{" + m.group(1) + "}}",""); else value = value.replace("@{{" + m.group(1) + "}}","");
} }
map.put(field.getCode(), normalizeJsonValue(value)); map.put(field.getCode(), normalizeJsonValue(value, getFirst));
} else { } else {
Object value = JsonPath.parse(resultItem).read(field.getResponsePath()); Object value = JsonPath.parse(resultItem).read(responsePath);
map.put(field.getCode(), normalizeJsonValue(value)); map.put(field.getCode(), normalizeJsonValue(value, getFirst));
} }
}catch (PathNotFoundException e){ }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())) { if (ReferenceEntity.KnownFields.ReferenceId.equals(field.getCode())) {
isValid = false; isValid = false;
break; break;
@ -339,7 +340,7 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
} }
} }
if (this.conventionService.isNullOrEmpty(map.getOrDefault(ReferenceEntity.KnownFields.ReferenceId, null))){ 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); if (isValid) parsedData.add(map);
} }
@ -348,29 +349,13 @@ public class ExternalFetcherServiceImpl implements ExternalFetcherService {
return result; return result;
} }
private static String normalizeJsonValue(Object value) { private static String normalizeJsonValue(Object value, boolean getfirst) {
if (value instanceof JSONArray jsonArray) { if (value instanceof JSONArray jsonArray) {
if (getfirst) {
if (!jsonArray.isEmpty() && jsonArray.getFirst() instanceof String) {
return jsonArray.getFirst().toString(); return jsonArray.getFirst().toString();
} else { } else {
for (Object o : jsonArray) { return value.toString();
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;
}
}
}
}
} else if (value instanceof Map) {
String key = ((Map<?, ?>)value).containsKey("$") ? "$" : "content";
return String.valueOf(((Map<?, ?>)value).get(key));
} }
return value != null ? value.toString() : null; return value != null ? value.toString() : null;
} }

View File

@ -1,17 +1,27 @@
import { DatePipe } from "@angular/common"; import { DatePipe } from "@angular/common";
import { Pipe, PipeTransform } from "@angular/core"; import { Pipe, PipeTransform } from "@angular/core";
import { DescriptionTemplateFieldType } from "../common/enum/description-template-field-type"; import { DescriptionTemplateFieldType } from "../common/enum/description-template-field-type";
import { Reference } from "../model/reference/reference"; import { DescriptionTemplateField, DescriptionTemplateLabelAndMultiplicityData, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template";
import { DescriptionTemplateField, DescriptionTemplateRadioBoxData, DescriptionTemplateReferenceTypeData, DescriptionTemplateSelectData } from "../model/description-template/description-template";
import { DescriptionFieldPersist } from "../model/description/description"; 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({ @Pipe({
name: 'fieldValue' name: 'fieldValue'
}) })
export class FieldValuePipe implements PipeTransform { 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<string> { transform(controlValue: DescriptionFieldPersist, field: DescriptionTemplateField): Observable<string> {
@ -57,11 +67,37 @@ export class FieldValuePipe implements PipeTransform {
} }
break; break;
} }
// case DescriptionTemplateFieldType.TAGS: case DescriptionTemplateFieldType.TAGS: {
// return this.parseJson(value); if (controlValue.textListValue && controlValue.textListValue.length > 0) {
// case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: 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(',')));
// case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DESCRIPTIONS: }
// return this.parseJson(value, 'label'); break;
}
case DescriptionTemplateFieldType.INTERNAL_ENTRIES_DMPS: {
const data = <DescriptionTemplateLabelAndMultiplicityData>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 = <DescriptionTemplateLabelAndMultiplicityData>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<StorageFile>(x => x.name)
]).pipe(map(x => x.name));
}
break;
}
case DescriptionTemplateFieldType.DATASET_IDENTIFIER: case DescriptionTemplateFieldType.DATASET_IDENTIFIER:
case DescriptionTemplateFieldType.VALIDATION: case DescriptionTemplateFieldType.VALIDATION:
if (controlValue.externalIdentifier?.identifier) { if (controlValue.externalIdentifier?.identifier) {
@ -72,7 +108,7 @@ export class FieldValuePipe implements PipeTransform {
return of(null); return of(null);
} }
} }
return null; return of(null);
} }
public parseJson(value: any, field: string = 'name') { public parseJson(value: any, field: string = 'name') {

View File

@ -65,6 +65,8 @@ public class TagMigrationService {
boolean tagAlreadyExists; boolean tagAlreadyExists;
if (elasticDataset.getTags() != null && !elasticDataset.getTags().isEmpty()) { if (elasticDataset.getTags() != null && !elasticDataset.getTags().isEmpty()) {
for (Tag tag : elasticDataset.getTags()) { 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 ? tagAlreadyExists = savedTagIdsByName.containsKey(new TagKey(item, tag)); //TODO we want owner logic ?
if (!tagAlreadyExists) { if (!tagAlreadyExists) {
TagEntity tagEntity = new TagEntity(); TagEntity tagEntity = new TagEntity();