reference type changes

This commit is contained in:
Efstratios Giannopoulos 2024-02-13 15:54:28 +02:00
parent bd436e55b1
commit f826c2297b
28 changed files with 289 additions and 601 deletions

View File

@ -1,9 +1,7 @@
FROM maven:3-openjdk-11 AS MAVEN_BUILD FROM maven:3-openjdk-11 AS MAVEN_BUILD
COPY pom.xml /build/ COPY pom.xml /build/
COPY data /build/data/
COPY elastic /build/elastic/ COPY elastic /build/elastic/
COPY queryable /build/queryable/
COPY web /build/web/ COPY web /build/web/
WORKDIR /build/ WORKDIR /build/

View File

@ -1,44 +0,0 @@
package eu.eudat.commons.types.referencetype;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "property")
@XmlAccessorType(XmlAccessType.FIELD)
public class DependencyPropertyEntity {
@XmlAttribute(name = "code")
private String code;
@XmlAttribute(name = "target")
private String target;
@XmlAttribute(name = "required")
private Boolean required;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}

View File

@ -0,0 +1,66 @@
package eu.eudat.commons.types.referencetype;
import eu.eudat.service.remotefetcher.config.entities.QueryCaseConfig;
import jakarta.xml.bind.annotation.XmlElement;
import java.util.UUID;
public class QueryCaseConfigEntity implements QueryCaseConfig {
private UUID referenceTypeId;
private String referenceTypeSourceKey;
private String likePattern;
private String separator;
private String value;
@Override
public String getReferenceTypeSourceKey() {
return referenceTypeSourceKey;
}
@XmlElement(name = "defaultValue")
public void setReferenceTypeSourceKey(String referenceTypeSourceKey) {
this.referenceTypeSourceKey = referenceTypeSourceKey;
}
@Override
public UUID getReferenceTypeId() {
return referenceTypeId;
}
@XmlElement(name = "referenceTypeSourceKey")
public void setReferenceTypeId(UUID referenceTypeId) {
this.referenceTypeId = referenceTypeId;
}
@Override
public String getLikePattern() {
return likePattern;
}
@XmlElement(name = "likePattern")
public void setLikePattern(String likePattern) {
this.likePattern = likePattern;
}
@Override
public String getSeparator() {
return separator;
}
@XmlElement(name = "separator")
public void setSeparator(String separator) {
this.separator = separator;
}
@Override
public String getValue() {
return value;
}
@XmlElement(name = "value")
public void setValue(String value) {
this.value = value;
}
}

View File

@ -1,49 +1,48 @@
package eu.eudat.commons.types.referencetype; package eu.eudat.commons.types.referencetype;
import eu.eudat.service.remotefetcher.config.entities.QueryCaseConfig;
import eu.eudat.service.remotefetcher.config.entities.QueryConfig; import eu.eudat.service.remotefetcher.config.entities.QueryConfig;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper;
public class QueryConfigEntity implements QueryConfig { import java.util.List;
import java.util.UUID;
private String condition; public class QueryConfigEntity implements QueryConfig<QueryCaseConfigEntity> {
private String separator;
private String value;
private Integer ordinal;
private String name;
private String defaultValue;
List<QueryCaseConfigEntity> cases;
public String getCondition() { @Override
return condition; public String getName() {
return name;
} }
@XmlElement(name = "condition") @XmlElement(name = "name")
public void setCondition(String condition) { public void setName(String name) {
this.condition = condition; this.name = name;
} }
public String getSeparator() { @Override
return separator; public String getDefaultValue() {
return defaultValue;
} }
@XmlElement(name = "separator") @XmlElement(name = "defaultValue")
public void setSeparator(String separator) { public void setDefaultValue(String defaultValue) {
this.separator = separator; this.defaultValue = defaultValue;
} }
public String getValue() { @Override
return value; public List<QueryCaseConfigEntity> getCases() {
return cases;
} }
@XmlElement(name = "value") @XmlElementWrapper
public void setValue(String value) { @XmlElement(name = "case")
this.value = value; public void setCases(List<QueryCaseConfigEntity> cases) {
this.cases = cases;
}
} }
public Integer getOrdinal() {
return ordinal;
}
@XmlElement(name = "ordinal")
public void setOrdinal(Integer ordinal) {
this.ordinal = ordinal;
}
}

View File

@ -6,6 +6,7 @@ import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlElementWrapper;
import java.util.List; import java.util.List;
import java.util.UUID;
public abstract class ReferenceTypeSourceBaseConfigurationEntity implements SourceBaseConfiguration { public abstract class ReferenceTypeSourceBaseConfigurationEntity implements SourceBaseConfiguration {
@ -16,7 +17,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity implements Sour
private Integer ordinal; private Integer ordinal;
private ReferenceTypeSourceType type; private ReferenceTypeSourceType type;
private List<ReferenceTypeSourceBaseDependencyEntity> dependencies; private List<UUID> referenceTypeDependencyIds;
public ReferenceTypeSourceType getType() { public ReferenceTypeSourceType getType() {
return type; return type;
} }
@ -53,13 +54,13 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity implements Sour
this.type = type; this.type = type;
} }
public List<ReferenceTypeSourceBaseDependencyEntity> getDependencies() { public List<UUID> getReferenceTypeDependencyIds() {
return dependencies; return referenceTypeDependencyIds;
} }
@XmlElementWrapper @XmlElementWrapper
@XmlElement(name = "dependency") @XmlElement(name = "referenceTypeDependencyIds")
public void setDependencies(List<ReferenceTypeSourceBaseDependencyEntity> dependencies) { public void setReferenceTypeDependencyIds(List<UUID> referenceTypeDependencyIds) {
this.dependencies = dependencies; this.referenceTypeDependencyIds = referenceTypeDependencyIds;
} }
} }

View File

@ -1,55 +0,0 @@
package eu.eudat.commons.types.referencetype;
import jakarta.xml.bind.annotation.*;
import java.util.List;
@XmlRootElement(name = "dependency")
@XmlAccessorType(XmlAccessType.FIELD)
public class ReferenceTypeSourceBaseDependencyEntity {
@XmlAttribute(name = "referenceTypeCode")
private String referenceTypeCode;
@XmlAttribute(name = "key")
private String key;
@XmlAttribute(name = "required")
private Boolean required;
@XmlElementWrapper(name = "properties")
@XmlElement(name = "property")
private List<DependencyPropertyEntity> properties;
public String getReferenceTypeCode() {
return referenceTypeCode;
}
public void setReferenceTypeCode(String referenceTypeCode) {
this.referenceTypeCode = referenceTypeCode;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public List<DependencyPropertyEntity> getProperties() {
return properties;
}
public void setProperties(List<DependencyPropertyEntity> properties) {
this.properties = properties;
}
}

View File

@ -1,12 +1,14 @@
package eu.eudat.model.builder.referencetypedefinition; package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.types.referencetype.AuthenticationConfigurationEntity; import eu.eudat.commons.types.referencetype.AuthenticationConfigurationEntity;
import eu.eudat.commons.types.referencetype.QueryConfigEntity; import eu.eudat.commons.types.referencetype.QueryConfigEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.AuthenticationConfiguration; import eu.eudat.model.referencetypedefinition.AuthenticationConfiguration;
import eu.eudat.model.referencetypedefinition.QueryConfig; import eu.eudat.model.referencetypedefinition.QueryConfig;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
@ -24,14 +26,12 @@ import java.util.*;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class AuthenticationConfigurationBuilder extends BaseBuilder<AuthenticationConfiguration, AuthenticationConfigurationEntity> { public class AuthenticationConfigurationBuilder extends BaseBuilder<AuthenticationConfiguration, AuthenticationConfigurationEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public AuthenticationConfigurationBuilder( public AuthenticationConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(AuthenticationConfigurationBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(AuthenticationConfigurationBuilder.class)));
this.builderFactory = builderFactory;
} }
public AuthenticationConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) { public AuthenticationConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {

View File

@ -1,59 +0,0 @@
package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.referencetype.DependencyPropertyEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.DependencyProperty;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DependencyPropertyBuilder extends BaseBuilder<DependencyProperty, DependencyPropertyEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DependencyPropertyBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DependencyPropertyBuilder.class)));
this.builderFactory = builderFactory;
}
public DependencyPropertyBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<DependencyProperty> build(FieldSet fields, List<DependencyPropertyEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
List<DependencyProperty> models = new ArrayList<>();
for (DependencyPropertyEntity d : data) {
DependencyProperty m = new DependencyProperty();
if (fields.hasField(this.asIndexer(DependencyProperty._code))) m.setCode(d.getCode());
if (fields.hasField(this.asIndexer(DependencyProperty._target))) m.setTarget(d.getTarget());
if (fields.hasField(this.asIndexer(DependencyProperty._required))) m.setRequired(d.getRequired());
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -47,10 +47,10 @@ public class QueryConfigBuilder extends BaseBuilder<QueryConfig, QueryConfigEnti
List<QueryConfig> models = new ArrayList<>(); List<QueryConfig> models = new ArrayList<>();
for (QueryConfigEntity d : data) { for (QueryConfigEntity d : data) {
QueryConfig m = new QueryConfig(); QueryConfig m = new QueryConfig();
if (fields.hasField(this.asIndexer(QueryConfig._condition))) m.setCondition(d.getCondition()); // if (fields.hasField(this.asIndexer(QueryConfig._condition))) m.setCondition(d.getCondition()); //TODO
if (fields.hasField(this.asIndexer(QueryConfig._separator))) m.setSeparator(d.getSeparator()); // if (fields.hasField(this.asIndexer(QueryConfig._separator))) m.setSeparator(d.getSeparator());
if (fields.hasField(this.asIndexer(QueryConfig._value))) m.setValue(d.getValue()); // if (fields.hasField(this.asIndexer(QueryConfig._value))) m.setValue(d.getValue());
if (fields.hasField(this.asIndexer(QueryConfig._ordinal))) m.setOrdinal(d.getOrdinal()); // if (fields.hasField(this.asIndexer(QueryConfig._ordinal))) m.setOrdinal(d.getOrdinal());
models.add(m); models.add(m);
} }

View File

@ -3,10 +3,17 @@ package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfigurationEntity; import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfigurationEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.Reference;
import eu.eudat.model.ReferenceType;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.builder.ReferenceTypeBuilder;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration; import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
import eu.eudat.query.ReferenceTypeQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -16,6 +23,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ -23,13 +31,15 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
protected EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); protected EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
protected final BuilderFactory builderFactory; protected final BuilderFactory builderFactory;
protected final QueryFactory queryFactory;
@Autowired @Autowired
public ReferenceTypeSourceBaseConfigurationBuilder( public ReferenceTypeSourceBaseConfigurationBuilder(
ConventionService conventionService, ConventionService conventionService,
LoggerService logger, BuilderFactory builderFactory) { LoggerService logger, BuilderFactory builderFactory, QueryFactory queryFactory) {
super(conventionService, logger); super(conventionService, logger);
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
} }
public ReferenceTypeSourceBaseConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) { public ReferenceTypeSourceBaseConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
@ -47,7 +57,11 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet dependenciesFields = fields.extractPrefixed(this.asPrefix(Model._dependencies)); // FieldSet dependenciesFields = fields.extractPrefixed(this.asPrefix(Model._dependencies));
FieldSet typeFields = fields.extractPrefixed(this.asPrefix(Model._referenceTypeDependencies));
// Map<UUID, ReferenceType> referenceTypeItemsMap = this.collectReferenceTypes(typeFields, data);
List<Model> models = new ArrayList<>(); List<Model> models = new ArrayList<>();
for (Entity d : data) { for (Entity d : data) {
Model m = this.getInstance(); Model m = this.getInstance();
@ -55,7 +69,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
if (fields.hasField(this.asIndexer(Model._label))) m.setLabel(d.getLabel()); if (fields.hasField(this.asIndexer(Model._label))) m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(Model._ordinal))) m.setOrdinal(d.getOrdinal()); if (fields.hasField(this.asIndexer(Model._ordinal))) m.setOrdinal(d.getOrdinal());
if (fields.hasField(this.asIndexer(Model._type))) m.setType(d.getType()); if (fields.hasField(this.asIndexer(Model._type))) m.setType(d.getType());
if (!dependenciesFields.isEmpty() && d.getDependencies() != null) m.setDependencies(this.builderFactory.builder(ReferenceTypeSourceBaseDependencyBuilder.class).authorize(this.authorize).build(dependenciesFields, d.getDependencies())); // if (!dependenciesFields.isEmpty() && d.getDependencies() != null) m.setReferenceTypeDependencies(this.builderFactory.builder(ReferenceTypeSourceBaseDependencyBuilder.class).authorize(this.authorize).build(dependenciesFields, d.getDependencies()));
this.buildChild(fields, d, m); this.buildChild(fields, d, m);
models.add(m); models.add(m);
@ -63,5 +77,35 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
// private Map<UUID, ReferenceType> collectReferenceTypes(FieldSet fields, List<Entity> data) throws MyApplicationException {
// if (fields.isEmpty() || data.isEmpty())
// return null;
// this.logger.debug("checking related - {}", ReferenceType.class.getSimpleName());
//
// Map<UUID, ReferenceType> itemMap;
// if (!fields.hasOtherField(this.asIndexer(ReferenceType._id))) {
// itemMap = this.asEmpty(
// data.stream().filter(x-> x.getReferenceTypeDependencyIds() != null).map(x-> x.getReferenceTypeDependencyIds())..distinct().collect(Collectors.toList()),
// x -> {
// ReferenceType item = new ReferenceType();
// item.setId(x);
// return item;
// },
// ReferenceType::getId);
// } else {
// FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(ReferenceType._id);
// ReferenceTypeQuery q = this.queryFactory.query(ReferenceTypeQuery.class).authorize(this.authorize).ids(data.stream().map(ReferenceEntity::getTypeId).distinct().collect(Collectors.toList()));
// itemMap = this.builderFactory.builder(ReferenceTypeBuilder.class).authorize(this.authorize).asForeignKey(q, clone, ReferenceType::getId);
// }
// if (!fields.hasField(ReferenceType._id)) {
// itemMap.forEach((id, item) -> {
// if (item != null)
// item.setId(null);
// });
// }
//
// return itemMap;
// }
} }

View File

@ -1,62 +0,0 @@
package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseDependencyEntity;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseDependency;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeSourceBaseDependencyBuilder extends BaseBuilder<ReferenceTypeSourceBaseDependency, ReferenceTypeSourceBaseDependencyEntity> {
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public ReferenceTypeSourceBaseDependencyBuilder(
ConventionService conventionService, BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseDependencyBuilder.class)));
this.builderFactory = builderFactory;
}
public ReferenceTypeSourceBaseDependencyBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<ReferenceTypeSourceBaseDependency> build(FieldSet fields, List<ReferenceTypeSourceBaseDependencyEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet propertiesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceBaseDependency._properties));
List<ReferenceTypeSourceBaseDependency> models = new ArrayList<>();
for (ReferenceTypeSourceBaseDependencyEntity d : data) {
ReferenceTypeSourceBaseDependency m = new ReferenceTypeSourceBaseDependency();
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._referenceTypeCode))) m.setReferenceTypeCode(d.getReferenceTypeCode());
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._key))) m.setKey(d.getKey());
if (fields.hasField(this.asIndexer(ReferenceTypeSourceBaseDependency._required))) m.setRequired(d.getRequired());
if (!propertiesFields.isEmpty() && d.getProperties() != null) m.setProperties(this.builderFactory.builder(DependencyPropertyBuilder.class).authorize(this.authorize).build(propertiesFields, d.getProperties()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
}

View File

@ -1,10 +1,13 @@
package eu.eudat.model.builder.referencetypedefinition; package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceExternalApiConfigurationEntity; import eu.eudat.commons.types.referencetype.ReferenceTypeSourceExternalApiConfigurationEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceExternalApiConfiguration; import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceExternalApiConfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,12 +24,14 @@ public class ReferenceTypeSourceExternalApiConfigurationBuilder extends Referenc
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final AuthorizationService authorizationService;
@Autowired @Autowired
public ReferenceTypeSourceExternalApiConfigurationBuilder( public ReferenceTypeSourceExternalApiConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService, BuilderFactory builderFactory, AuthorizationService authorizationService, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)), builderFactory); super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)), builderFactory, queryFactory);
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.authorizationService = authorizationService;
} }
@ -40,6 +45,7 @@ public class ReferenceTypeSourceExternalApiConfigurationBuilder extends Referenc
FieldSet resultsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._results)); FieldSet resultsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._results));
FieldSet authFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._auth)); FieldSet authFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._auth));
FieldSet queriesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._queries)); FieldSet queriesFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._queries));
if(!authorizationService.authorize(Permission.EditReferenceType)) return m;
if (fields.hasField(this.asIndexer(ReferenceTypeSourceExternalApiConfiguration._url))) m.setUrl(d.getUrl()); if (fields.hasField(this.asIndexer(ReferenceTypeSourceExternalApiConfiguration._url))) m.setUrl(d.getUrl());
if (!resultsFields.isEmpty() && d.getResults() != null) { if (!resultsFields.isEmpty() && d.getResults() != null) {

View File

@ -1,10 +1,13 @@
package eu.eudat.model.builder.referencetypedefinition; package eu.eudat.model.builder.referencetypedefinition;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceStaticOptionConfigurationEntity; import eu.eudat.commons.types.referencetype.ReferenceTypeSourceStaticOptionConfigurationEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceStaticOptionConfiguration; import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceStaticOptionConfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,12 +24,14 @@ public class ReferenceTypeSourceStaticOptionConfigurationBuilder extends Referen
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final AuthorizationService authorizationService;
@Autowired @Autowired
public ReferenceTypeSourceStaticOptionConfigurationBuilder( public ReferenceTypeSourceStaticOptionConfigurationBuilder(
ConventionService conventionService, BuilderFactory builderFactory) { ConventionService conventionService, BuilderFactory builderFactory, AuthorizationService authorizationService, QueryFactory queryFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)), builderFactory); super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)), builderFactory, queryFactory);
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.authorizationService = authorizationService;
} }
@ -39,6 +44,8 @@ public class ReferenceTypeSourceStaticOptionConfigurationBuilder extends Referen
protected ReferenceTypeSourceStaticOptionConfiguration buildChild(FieldSet fields, ReferenceTypeSourceStaticOptionConfigurationEntity d, ReferenceTypeSourceStaticOptionConfiguration m) { protected ReferenceTypeSourceStaticOptionConfiguration buildChild(FieldSet fields, ReferenceTypeSourceStaticOptionConfigurationEntity d, ReferenceTypeSourceStaticOptionConfiguration m) {
FieldSet optionsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceStaticOptionConfiguration._options)); FieldSet optionsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceStaticOptionConfiguration._options));
if(!authorizationService.authorize(Permission.EditReferenceType)) return m;
if (!optionsFields.isEmpty() && d.getOptions() != null) { if (!optionsFields.isEmpty() && d.getOptions() != null) {
m.setOptions(this.builderFactory.builder(ReferenceTypeStaticOptionBuilder.class).authorize(this.authorize).build(optionsFields, d.getOptions())); m.setOptions(this.builderFactory.builder(ReferenceTypeStaticOptionBuilder.class).authorize(this.authorize).build(optionsFields, d.getOptions()));
} }

View File

@ -1,39 +0,0 @@
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DependencyPropertyCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DependencyPropertyCensor.class));
protected final AuthorizationService authService;
public DependencyPropertyCensor(ConventionService conventionService,
AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseReferenceType);
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor; import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.censorship.ReferenceTypeCensor;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration; import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.data.censor.CensorFactory;
@ -38,8 +39,8 @@ public class ReferenceTypeSourceBaseConfigurationCensor extends BaseCensor {
return; return;
this.authService.authorizeForce(Permission.BrowseReferenceType); this.authService.authorizeForce(Permission.BrowseReferenceType);
FieldSet dependenciesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._dependencies)); FieldSet referenceTypeDependencyFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._referenceTypeDependencies));
this.censorFactory.censor(ReferenceTypeSourceBaseDependencyCensor.class).censor(dependenciesFields, userId); this.censorFactory.censor(ReferenceTypeCensor.class).censor(referenceTypeDependencyFields, userId);
} }
} }

View File

@ -1,45 +0,0 @@
package eu.eudat.model.censorship.referencetypedefinition;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.censorship.BaseCensor;
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseDependency;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ReferenceTypeSourceBaseDependencyCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceBaseDependencyCensor.class));
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public ReferenceTypeSourceBaseDependencyCensor(ConventionService conventionService,
AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseReferenceType);
FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix( ReferenceTypeSourceBaseDependency._properties));
this.censorFactory.censor(DependencyPropertyCensor.class).censor(propertiesFields, userId);
}
}

View File

@ -14,6 +14,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID;
@JsonTypeInfo( @JsonTypeInfo(
use = JsonTypeInfo.Id.NAME, use = JsonTypeInfo.Id.NAME,
@ -42,9 +43,9 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
public static final String _type = "type"; public static final String _type = "type";
private List<ReferenceTypeSourceBaseDependencyPersist> dependencies; private List<UUID> referenceTypeDependencyIds;
public static final String _dependencies = "dependencies"; public static final String _referenceTypeDependencyIds = "referenceTypeDependencyIds";
public String getKey() { public String getKey() {
return key; return key;
@ -78,12 +79,12 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
this.type = type; this.type = type;
} }
public List<ReferenceTypeSourceBaseDependencyPersist> getDependencies() { public List<UUID> getReferenceTypeDependencyIds() {
return dependencies; return referenceTypeDependencyIds;
} }
public void setDependencies(List<ReferenceTypeSourceBaseDependencyPersist> dependencies) { public void setReferenceTypeDependencyIds(List<UUID> referenceTypeDependencyIds) {
this.dependencies = dependencies; this.referenceTypeDependencyIds = referenceTypeDependencyIds;
} }
public static abstract class ReferenceTypeSourceBaseConfigurationPersistValidator<T extends ReferenceTypeSourceBaseConfigurationPersist> extends BaseValidator<T> { public static abstract class ReferenceTypeSourceBaseConfigurationPersistValidator<T extends ReferenceTypeSourceBaseConfigurationPersist> extends BaseValidator<T> {
@ -112,13 +113,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
.failOn(ReferenceTypeSourceBaseConfigurationPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._ordinal}, LocaleContextHolder.getLocale())), .failOn(ReferenceTypeSourceBaseConfigurationPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._ordinal}, LocaleContextHolder.getLocale())),
this.spec() this.spec()
.must(() -> !this.isNull(item.getType())) .must(() -> !this.isNull(item.getType()))
.failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._type}, LocaleContextHolder.getLocale())), .failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._type}, LocaleContextHolder.getLocale()))
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getDependencies()))
.on(ReferenceTypeSourceBaseConfigurationPersist._dependencies)
.over(item.getDependencies())
.using((itm) -> this.validatorFactory.validator(ReferenceTypeSourceBaseDependencyPersist.ReferenceTypeSourceBaseDependencyPersistValidator.class))
)); ));
return specifications; return specifications;
} }

View File

@ -1,38 +0,0 @@
package eu.eudat.model.referencetypedefinition;
public class DependencyProperty {
public final static String _code = "code";
private String code;
public final static String _target = "target";
private String target;
public final static String _required = "required";
private Boolean required;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.model.referencetypedefinition; package eu.eudat.model.referencetypedefinition;
import eu.eudat.commons.enums.ReferenceTypeSourceType; import eu.eudat.commons.enums.ReferenceTypeSourceType;
import eu.eudat.model.ReferenceType;
import java.util.List; import java.util.List;
@ -19,8 +20,8 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
public final static String _type = "type"; public final static String _type = "type";
private ReferenceTypeSourceType type; private ReferenceTypeSourceType type;
public final static String _dependencies = "dependencies"; public final static String _referenceTypeDependencies = "referenceTypeDependencies";
private List<ReferenceTypeSourceBaseDependency> dependencies; private List<ReferenceType> referenceTypeDependencies;
public ReferenceTypeSourceType getType() { public ReferenceTypeSourceType getType() {
return type; return type;
@ -54,11 +55,11 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
this.ordinal = ordinal; this.ordinal = ordinal;
} }
public List<ReferenceTypeSourceBaseDependency> getDependencies() { public List<ReferenceType> getReferenceTypeDependencies() {
return dependencies; return referenceTypeDependencies;
} }
public void setDependencies(List<ReferenceTypeSourceBaseDependency> dependencies) { public void setReferenceTypeDependencies(List<ReferenceType> referenceTypeDependencies) {
this.dependencies = dependencies; this.referenceTypeDependencies = referenceTypeDependencies;
} }
} }

View File

@ -1,52 +0,0 @@
package eu.eudat.model.referencetypedefinition;
import java.util.List;
public class ReferenceTypeSourceBaseDependency {
public final static String _referenceTypeCode = "referenceTypeCode";
private String referenceTypeCode;
public final static String _key = "key";
private String key;
public final static String _required = "required";
private Boolean required;
public final static String _properties = "properties";
private List<DependencyProperty> properties;
public String getReferenceTypeCode() {
return referenceTypeCode;
}
public void setReferenceTypeCode(String referenceTypeCode) {
this.referenceTypeCode = referenceTypeCode;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public List<DependencyProperty> getProperties() {
return properties;
}
public void setProperties(List<DependencyProperty> properties) {
this.properties = properties;
}
}

View File

@ -181,13 +181,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
data.setKey(persist.getKey()); data.setKey(persist.getKey());
data.setLabel(persist.getLabel()); data.setLabel(persist.getLabel());
data.setOrdinal(persist.getOrdinal()); data.setOrdinal(persist.getOrdinal());
data.setReferenceTypeDependencyIds(persist.getReferenceTypeDependencyIds());
if (!this.conventionService.isListNullOrEmpty(persist.getDependencies())){
data.setDependencies(new ArrayList<>());
for (ReferenceTypeSourceBaseDependencyPersist dependencyPersist: persist.getDependencies()) {
data.getDependencies().add(this.buildDependencyEntity(dependencyPersist));
}
}
return data; return data;
} }
@ -236,10 +230,10 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
QueryConfigEntity data = new QueryConfigEntity(); QueryConfigEntity data = new QueryConfigEntity();
if (persist == null) return data; if (persist == null) return data;
data.setCondition(persist.getCondition()); // data.setCondition(persist.getCondition()); //TODO
data.setSeparator(persist.getSeparator()); // data.setSeparator(persist.getSeparator());
data.setValue(persist.getValue()); // data.setValue(persist.getValue());
data.setOrdinal(persist.getOrdinal()); // data.setOrdinal(persist.getOrdinal());
return data; return data;
} }
@ -254,35 +248,6 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
return data; return data;
} }
private @NotNull ReferenceTypeSourceBaseDependencyEntity buildDependencyEntity(ReferenceTypeSourceBaseDependencyPersist persist){
ReferenceTypeSourceBaseDependencyEntity data = new ReferenceTypeSourceBaseDependencyEntity();
if (persist == null) return data;
data.setReferenceTypeCode(persist.getReferenceTypeCode());
data.setKey(persist.getKey());
data.setRequired(persist.getRequired());
if (!this.conventionService.isListNullOrEmpty(persist.getProperties())){
data.setProperties(new ArrayList<>());
for (DependencyPropertyPersist propertyPersist: persist.getProperties()) {
data.getProperties().add(this.buildPropertyEntity(propertyPersist));
}
}
return data;
}
private @NotNull DependencyPropertyEntity buildPropertyEntity(DependencyPropertyPersist persist){
DependencyPropertyEntity data = new DependencyPropertyEntity();
if (persist == null) return data;
data.setCode(persist.getCode());
data.setTarget(persist.getTarget());
data.setRequired(persist.getRequired());
return data;
}
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting : {}", id); logger.debug("deleting : {}", id);

View File

@ -1,6 +1,5 @@
package eu.eudat.service.remotefetcher; package eu.eudat.service.remotefetcher;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.DocumentContext;
@ -9,6 +8,8 @@ import eu.eudat.commons.enums.ReferenceTypeSourceType;
import eu.eudat.commons.exceptions.HugeResultSetException; import eu.eudat.commons.exceptions.HugeResultSetException;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.Reference;
import eu.eudat.model.referencedefinition.Field;
import eu.eudat.service.remotefetcher.config.entities.*; import eu.eudat.service.remotefetcher.config.entities.*;
import eu.eudat.service.remotefetcher.models.ExternalDataResult; import eu.eudat.service.remotefetcher.models.ExternalDataResult;
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria; import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
@ -82,8 +83,8 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
for (SourceBaseConfiguration source : sources) { for (SourceBaseConfiguration source : sources) {
if (source.getType() == null || source.getType().equals(ReferenceTypeSourceType.API)) { if (source.getType() == null || source.getType().equals(ReferenceTypeSourceType.API)) {
try { try {
SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource = (SourceExternalApiConfiguration)source; SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource = (SourceExternalApiConfiguration)source;
this.applyFunderToQuery(apiSource, externalReferenceCriteria); // this.applyFunderToQuery(apiSource, externalReferenceCriteria);
String auth = null; String auth = null;
if (apiSource.getAuth() != null) { if (apiSource.getAuth() != null) {
@ -137,8 +138,8 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
} }
private void applyFunderToQuery(SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria) { // private void applyFunderToQuery(SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria) {
//TODO new reference logic // //TODO new reference logic
// if (apiSource.getFunderQuery() != null) { // if (apiSource.getFunderQuery() != null) {
// if (externalReferenceCriteria.getFunderId() != null && !apiSource.getFunderQuery().startsWith("dmp:")) { // if (externalReferenceCriteria.getFunderId() != null && !apiSource.getFunderQuery().startsWith("dmp:")) {
// apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", apiSource.getFunderQuery())); // apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", apiSource.getFunderQuery()));
@ -147,74 +148,76 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
// apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", "")); // apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", ""));
// } // }
// } // }
// }
private String replaceLookupFieldQuery(String query, ExternalReferenceCriteria externalReferenceCriteria, List<QueryConfig<QueryCaseConfig>> queryConfigs) {
String finalQuery = query;
String likeValue = this.conventionService.isNullOrEmpty(externalReferenceCriteria.getLike()) ? "" : externalReferenceCriteria.getLike();
List<Reference> referenceList = this.conventionService.isListNullOrEmpty(externalReferenceCriteria.getDependencyReferences()) ? new ArrayList<>() : externalReferenceCriteria.getDependencyReferences().stream()
.filter(x-> x.getDefinition() != null && x.getType() != null && !this.conventionService.isListNullOrEmpty(x.getDefinition().getFields())).toList();
if (this.conventionService.isListNullOrEmpty(queryConfigs)) return query;
for (QueryConfig<?> queryConfig : queryConfigs){
QueryCaseConfig caseConfig = this.conventionService.isListNullOrEmpty(queryConfig.getCases()) ? null : queryConfig.getCases().stream().filter(x->
(this.conventionService.isNullOrEmpty(x.getLikePattern()) || likeValue.matches(x.getLikePattern()))
&& ((x.getReferenceTypeId() == null && this.conventionService.isNullOrEmpty(x.getReferenceTypeSourceKey())) || referenceList.stream().anyMatch(y-> Objects.equals(y.getType().getId(), x.getReferenceTypeId()) && Objects.equals(y.getSource() ,x.getReferenceTypeSourceKey())))
).findFirst().orElse(null);
String filterValue = queryConfig.getDefaultValue();
if (caseConfig != null){
filterValue = caseConfig.getValue();
if (caseConfig.getReferenceTypeId() != null && !this.conventionService.isNullOrEmpty(caseConfig.getReferenceTypeSourceKey()) ){
Reference dependencyReference = referenceList.stream()
.filter(x-> Objects.equals(x.getType().getId(), caseConfig.getReferenceTypeId()) && Objects.equals(x.getSource() ,caseConfig.getReferenceTypeSourceKey())).findFirst().orElse(null);
if (dependencyReference != null){
for (Field field : dependencyReference.getDefinition().getFields()){
filterValue = filterValue.replaceAll("{" + field.getCode() + "}", field.getValue());
}
}
} }
private String replaceLookupFieldQuery(ExternalReferenceCriteria externalReferenceCriteria, List<QueryConfig> queryConfigs) { if (caseConfig.getSeparator() != null) {
String finalQuery = ""; String[] likes = likeValue.split(caseConfig.getSeparator());
if (this.conventionService.isNullOrEmpty(externalReferenceCriteria.getLike())) return finalQuery;
QueryConfig queryConfig = queryConfigs.stream().filter(x -> !this.conventionService.isNullOrEmpty(x.getCondition()) && externalReferenceCriteria.getLike().matches(x.getCondition()))
.min((Comparator.comparing(QueryConfig::getOrdinal))).orElse(null);
if (queryConfig != null) {
if (queryConfig.getSeparator() != null) {
String[] likes = externalReferenceCriteria.getLike().split(queryConfig.getSeparator());
finalQuery = queryConfig.getValue();
for (int i = 0; i < likes.length; i++) { for (int i = 0; i < likes.length; i++) {
finalQuery = finalQuery.replaceAll("\\{like" + (i + 1) + "}", likes[i]); filterValue = filterValue.replaceAll("\\{like" + (i + 1) + "}", likes[i]);
} }
} else { } else {
finalQuery = queryConfig.getValue().replaceAll("\\{like}", externalReferenceCriteria.getLike()); filterValue = filterValue.replaceAll("\\{like}", likeValue);
} }
} }
finalQuery = finalQuery.replaceAll("{" + queryConfig.getName() + "}", filterValue);
}
return finalQuery; return finalQuery;
} }
protected String replaceLookupFields(String path, ExternalReferenceCriteria externalReferenceCriteria, String firstPage, List<QueryConfig> queries) { protected String replaceLookupFields(String path, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, ExternalReferenceCriteria externalReferenceCriteria) {
if (!this.conventionService.isNullOrEmpty(path)) return path; if (!this.conventionService.isNullOrEmpty(path)) return path;
String completedPath = path; String completedPath = path;
if (externalReferenceCriteria.getLike() != null) { if (this.conventionService.isListNullOrEmpty(apiSource.getQueries())){
if ((path.contains("openaire") || path.contains("orcid") || path.contains("ror") || path.contains("fairsharing")) && externalReferenceCriteria.getLike().isEmpty()) { this.replaceLookupFieldQuery(completedPath, externalReferenceCriteria, apiSource.getQueries());
completedPath = completedPath.replaceAll("\\{like}", "*");
completedPath = completedPath.replaceAll("\\{query}", "*");
} else {
if (completedPath.contains("{query}")) {
completedPath = completedPath.replaceAll("\\{query}", this.replaceLookupFieldQuery(externalReferenceCriteria, queries));
} else {
completedPath = completedPath.replaceAll("\\{like}", externalReferenceCriteria.getLike());
}
}
} else {
completedPath = completedPath.replace("{like}", "");
}
if (!this.conventionService.isNullOrEmpty(externalReferenceCriteria.getFunderId())) {
String[] founderParts = externalReferenceCriteria.getFunderId().split(":");
String funderPrefix = founderParts.length > 0 ? founderParts[0] : "";
String funderId = externalReferenceCriteria.getFunderId().replace(funderPrefix + ":", "");
if (!funderId.isEmpty() && funderId.toCharArray()[0] == ':') {
funderId = externalReferenceCriteria.getFunderId();
}
completedPath = completedPath.replace("{funderId}", funderId);
} else if(completedPath.contains("{funderId}")){
logger.warn("FunderId is null.");
completedPath = completedPath.replace("{funderId}", " ");
} }
if (!this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPage())) completedPath = completedPath.replace("{page}", externalReferenceCriteria.getPage()); if (!this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPage())) completedPath = completedPath.replace("{page}", externalReferenceCriteria.getPage());
else if (!this.conventionService.isNullOrEmpty(firstPage)) completedPath = completedPath.replace("{page}", firstPage); else if (!this.conventionService.isNullOrEmpty(apiSource.getFirstPage())) completedPath = completedPath.replace("{page}", apiSource.getFirstPage());
else completedPath = completedPath.replace("{page}", "1"); else completedPath = completedPath.replace("{page}", "1");
completedPath = completedPath.replace("{pageSize}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPageSize()) ? externalReferenceCriteria.getPageSize() : "60"); completedPath = completedPath.replace("{pageSize}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPageSize()) ? externalReferenceCriteria.getPageSize() : "60");
completedPath = completedPath.replace("{host}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getHost()) ? externalReferenceCriteria.getHost() : ""); completedPath = completedPath.replace("{host}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getHost()) ? externalReferenceCriteria.getHost() : "");
completedPath = completedPath.replace("{path}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPath()) ? externalReferenceCriteria.getPath() : ""); completedPath = completedPath.replace("{path}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPath()) ? externalReferenceCriteria.getPath() : "");
return completedPath; return completedPath;
} }
private ExternalDataResult queryExternalData(FetchStrategy fetchStrategy, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception { private ExternalDataResult queryExternalData(FetchStrategy fetchStrategy, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception {
String replacedPath = replaceLookupFields(apiSource.getUrl(), externalReferenceCriteria, apiSource.getFirstPage(), apiSource.getQueries()); String replacedPath = replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria);
String replacedBody = replaceLookupFields(apiSource.getRequestBody(), externalReferenceCriteria, apiSource.getFirstPage(), apiSource.getQueries()); String replacedBody = 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) {
@ -237,7 +240,7 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
} }
} }
protected ExternalDataResult getExternalDataResults(String urlString, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, String requestBody, String auth) { protected ExternalDataResult getExternalDataResults(String urlString, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, String requestBody, String auth) {
try { try {
JsonNode jsonBody = new ObjectMapper().readTree(requestBody); JsonNode jsonBody = new ObjectMapper().readTree(requestBody);
@ -291,11 +294,8 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
for(Object resultItem : results){ for(Object resultItem : results){
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) { for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) {
StringBuilder pathValue = new StringBuilder(); if (this.conventionService.isNullOrEmpty(field.getResponsePath()) || this.conventionService.isNullOrEmpty(field.getCode())) continue;
for (String pathPart : field.getResponsePath().split("\\.")) { Object value = JsonPath.parse(resultItem).read(field.getResponsePath());
pathValue.append("['").append(pathPart).append("']");
}
Object value = JsonPath.parse(resultItem).read(pathValue.toString());
map.put(field.getCode(), normalizeJsonValue(value)); map.put(field.getCode(), normalizeJsonValue(value));
} }
parsedData.add(map); parsedData.add(map);

View File

@ -0,0 +1,15 @@
package eu.eudat.service.remotefetcher.config.entities;
import java.util.UUID;
public interface QueryCaseConfig {
UUID getReferenceTypeId();
String getReferenceTypeSourceKey();
String getLikePattern();
String getSeparator();
String getValue();
}

View File

@ -1,11 +1,12 @@
package eu.eudat.service.remotefetcher.config.entities; package eu.eudat.service.remotefetcher.config.entities;
public interface QueryConfig { import java.util.List;
String getCondition();
String getSeparator(); public interface QueryConfig<CaseConfig extends QueryCaseConfig> {
String getName();
String getValue(); List<CaseConfig> getCases();
Integer getOrdinal(); String getDefaultValue();
} }

View File

@ -4,7 +4,7 @@ import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
import java.util.List; import java.util.List;
public interface SourceExternalApiConfiguration<RsConfig extends ResultsConfiguration<? extends ResultFieldsMappingConfiguration>, AuthConfig extends AuthenticationConfiguration, QConfig extends QueryConfig> extends SourceBaseConfiguration { public interface SourceExternalApiConfiguration<RsConfig extends ResultsConfiguration<? extends ResultFieldsMappingConfiguration>, AuthConfig extends AuthenticationConfiguration, QConfig extends QueryConfig<? extends QueryCaseConfig>> extends SourceBaseConfiguration {
String getUrl(); String getUrl();
RsConfig getResults(); RsConfig getResults();

View File

@ -1,13 +1,19 @@
package eu.eudat.service.remotefetcher.criteria; package eu.eudat.service.remotefetcher.criteria;
import eu.eudat.model.Reference;
import java.util.List;
import java.util.Map;
public class ExternalReferenceCriteria { public class ExternalReferenceCriteria {
private String like; private String like;
private String page; private String page;
private String pageSize; private String pageSize;
private String funderId;
private String path; private String path;
private String host; private String host;
private List<Reference> dependencyReferences;
public String getLike() { public String getLike() {
return like; return like;
} }
@ -29,13 +35,6 @@ public class ExternalReferenceCriteria {
this.pageSize = pageSize; this.pageSize = pageSize;
} }
public String getFunderId() {
return funderId;
}
public void setFunderId(String funderId) {
this.funderId = funderId;
}
public String getPath() { public String getPath() {
return path; return path;
} }
@ -59,15 +58,11 @@ public class ExternalReferenceCriteria {
public ExternalReferenceCriteria() { public ExternalReferenceCriteria() {
} }
@Override public List<Reference> getDependencyReferences() {
public String toString() { return dependencyReferences;
return "{" + }
"like='" + like + '\'' +
", page='" + page + '\'' + public void setDependencyReferences(List<Reference> dependencyReferences) {
", pageSize='" + pageSize + '\'' + this.dependencyReferences = dependencyReferences;
", funderId='" + funderId + '\'' +
", path='" + path + '\'' +
", host='" + host + '\'' +
'}';
} }
} }

View File

@ -14,9 +14,7 @@
</parent> </parent>
<modules> <modules>
<module>queryable</module>
<module>web</module> <module>web</module>
<module>data</module>
<module>core</module> <module>core</module>
</modules> </modules>

View File

@ -21,16 +21,6 @@
<artifactId>core</artifactId> <artifactId>core</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>eu.eudat</groupId>
<artifactId>data</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>dmp-backend</groupId>
<artifactId>queryable</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>repositorydepositbase</artifactId> <artifactId>repositorydepositbase</artifactId>