reference type changes
This commit is contained in:
parent
bd436e55b1
commit
f826c2297b
|
@ -1,9 +1,7 @@
|
|||
FROM maven:3-openjdk-11 AS MAVEN_BUILD
|
||||
|
||||
COPY pom.xml /build/
|
||||
COPY data /build/data/
|
||||
COPY elastic /build/elastic/
|
||||
COPY queryable /build/queryable/
|
||||
COPY web /build/web/
|
||||
|
||||
WORKDIR /build/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,49 +1,48 @@
|
|||
package eu.eudat.commons.types.referencetype;
|
||||
|
||||
import eu.eudat.service.remotefetcher.config.entities.QueryCaseConfig;
|
||||
import eu.eudat.service.remotefetcher.config.entities.QueryConfig;
|
||||
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;
|
||||
private String separator;
|
||||
private String value;
|
||||
private Integer ordinal;
|
||||
public class QueryConfigEntity implements QueryConfig<QueryCaseConfigEntity> {
|
||||
|
||||
private String name;
|
||||
private String defaultValue;
|
||||
List<QueryCaseConfigEntity> cases;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@XmlElement(name = "condition")
|
||||
public void setCondition(String condition) {
|
||||
this.condition = condition;
|
||||
@XmlElement(name = "name")
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSeparator() {
|
||||
return separator;
|
||||
@Override
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@XmlElement(name = "separator")
|
||||
public void setSeparator(String separator) {
|
||||
this.separator = separator;
|
||||
@XmlElement(name = "defaultValue")
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
@Override
|
||||
public List<QueryCaseConfigEntity> getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
@XmlElement(name = "value")
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getOrdinal() {
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
@XmlElement(name = "ordinal")
|
||||
public void setOrdinal(Integer ordinal) {
|
||||
this.ordinal = ordinal;
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name = "case")
|
||||
public void setCases(List<QueryCaseConfigEntity> cases) {
|
||||
this.cases = cases;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import jakarta.xml.bind.annotation.XmlElement;
|
|||
import jakarta.xml.bind.annotation.XmlElementWrapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class ReferenceTypeSourceBaseConfigurationEntity implements SourceBaseConfiguration {
|
||||
|
||||
|
@ -16,7 +17,7 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity implements Sour
|
|||
private Integer ordinal;
|
||||
private ReferenceTypeSourceType type;
|
||||
|
||||
private List<ReferenceTypeSourceBaseDependencyEntity> dependencies;
|
||||
private List<UUID> referenceTypeDependencyIds;
|
||||
public ReferenceTypeSourceType getType() {
|
||||
return type;
|
||||
}
|
||||
|
@ -53,13 +54,13 @@ public abstract class ReferenceTypeSourceBaseConfigurationEntity implements Sour
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public List<ReferenceTypeSourceBaseDependencyEntity> getDependencies() {
|
||||
return dependencies;
|
||||
public List<UUID> getReferenceTypeDependencyIds() {
|
||||
return referenceTypeDependencyIds;
|
||||
}
|
||||
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name = "dependency")
|
||||
public void setDependencies(List<ReferenceTypeSourceBaseDependencyEntity> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
@XmlElement(name = "referenceTypeDependencyIds")
|
||||
public void setReferenceTypeDependencyIds(List<UUID> referenceTypeDependencyIds) {
|
||||
this.referenceTypeDependencyIds = referenceTypeDependencyIds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,14 @@
|
|||
package eu.eudat.model.builder.referencetypedefinition;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.types.referencetype.AuthenticationConfigurationEntity;
|
||||
import eu.eudat.commons.types.referencetype.QueryConfigEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.model.builder.BaseBuilder;
|
||||
import eu.eudat.model.referencetypedefinition.AuthenticationConfiguration;
|
||||
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.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
|
@ -24,14 +26,12 @@ import java.util.*;
|
|||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class AuthenticationConfigurationBuilder extends BaseBuilder<AuthenticationConfiguration, AuthenticationConfigurationEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public AuthenticationConfigurationBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
ConventionService conventionService) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(AuthenticationConfigurationBuilder.class)));
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public AuthenticationConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -47,10 +47,10 @@ public class QueryConfigBuilder extends BaseBuilder<QueryConfig, QueryConfigEnti
|
|||
List<QueryConfig> models = new ArrayList<>();
|
||||
for (QueryConfigEntity d : data) {
|
||||
QueryConfig m = new QueryConfig();
|
||||
if (fields.hasField(this.asIndexer(QueryConfig._condition))) m.setCondition(d.getCondition());
|
||||
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._ordinal))) m.setOrdinal(d.getOrdinal());
|
||||
// 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._value))) m.setValue(d.getValue());
|
||||
// if (fields.hasField(this.asIndexer(QueryConfig._ordinal))) m.setOrdinal(d.getOrdinal());
|
||||
|
||||
models.add(m);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,17 @@ package eu.eudat.model.builder.referencetypedefinition;
|
|||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfigurationEntity;
|
||||
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.ReferenceTypeBuilder;
|
||||
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
|
||||
import eu.eudat.query.ReferenceTypeQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.DataLogEntry;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
|
@ -16,6 +23,7 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
|
@ -23,13 +31,15 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
|
|||
|
||||
protected EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
protected final BuilderFactory builderFactory;
|
||||
protected final QueryFactory queryFactory;
|
||||
|
||||
@Autowired
|
||||
public ReferenceTypeSourceBaseConfigurationBuilder(
|
||||
ConventionService conventionService,
|
||||
LoggerService logger, BuilderFactory builderFactory) {
|
||||
ConventionService conventionService,
|
||||
LoggerService logger, BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||
super(conventionService, logger);
|
||||
this.builderFactory = builderFactory;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public ReferenceTypeSourceBaseConfigurationBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
@ -47,7 +57,11 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder<Model extends
|
|||
if (fields == null || data == null || fields.isEmpty())
|
||||
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<>();
|
||||
for (Entity d : data) {
|
||||
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._ordinal))) m.setOrdinal(d.getOrdinal());
|
||||
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);
|
||||
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));
|
||||
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;
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
package eu.eudat.model.builder.referencetypedefinition;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceExternalApiConfigurationEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
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.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -21,12 +24,14 @@ public class ReferenceTypeSourceExternalApiConfigurationBuilder extends Referenc
|
|||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public ReferenceTypeSourceExternalApiConfigurationBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)), builderFactory);
|
||||
ConventionService conventionService, BuilderFactory builderFactory, AuthorizationService authorizationService, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceExternalApiConfigurationBuilder.class)), builderFactory, queryFactory);
|
||||
this.builderFactory = builderFactory;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +45,8 @@ public class ReferenceTypeSourceExternalApiConfigurationBuilder extends Referenc
|
|||
FieldSet resultsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._results));
|
||||
FieldSet authFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceExternalApiConfiguration._auth));
|
||||
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 (!resultsFields.isEmpty() && d.getResults() != null) {
|
||||
m.setResults(this.builderFactory.builder(ResultsConfigurationBuilder.class).authorize(this.authorize).build(resultsFields, d.getResults()));
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package eu.eudat.model.builder.referencetypedefinition;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceStaticOptionConfigurationEntity;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
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.query.QueryFactory;
|
||||
import gr.cite.tools.fieldset.FieldSet;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -21,12 +24,14 @@ public class ReferenceTypeSourceStaticOptionConfigurationBuilder extends Referen
|
|||
|
||||
private final BuilderFactory builderFactory;
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
private final AuthorizationService authorizationService;
|
||||
|
||||
@Autowired
|
||||
public ReferenceTypeSourceStaticOptionConfigurationBuilder(
|
||||
ConventionService conventionService, BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)), builderFactory);
|
||||
ConventionService conventionService, BuilderFactory builderFactory, AuthorizationService authorizationService, QueryFactory queryFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceTypeSourceStaticOptionConfigurationBuilder.class)), builderFactory, queryFactory);
|
||||
this.builderFactory = builderFactory;
|
||||
this.authorizationService = authorizationService;
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,6 +44,8 @@ public class ReferenceTypeSourceStaticOptionConfigurationBuilder extends Referen
|
|||
protected ReferenceTypeSourceStaticOptionConfiguration buildChild(FieldSet fields, ReferenceTypeSourceStaticOptionConfigurationEntity d, ReferenceTypeSourceStaticOptionConfiguration m) {
|
||||
FieldSet optionsFields = fields.extractPrefixed(this.asPrefix(ReferenceTypeSourceStaticOptionConfiguration._options));
|
||||
|
||||
if(!authorizationService.authorize(Permission.EditReferenceType)) return m;
|
||||
|
||||
if (!optionsFields.isEmpty() && d.getOptions() != null) {
|
||||
m.setOptions(this.builderFactory.builder(ReferenceTypeStaticOptionBuilder.class).authorize(this.authorize).build(optionsFields, d.getOptions()));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ 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.censorship.ReferenceTypeCensor;
|
||||
import eu.eudat.model.referencetypedefinition.ReferenceTypeSourceBaseConfiguration;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.censor.CensorFactory;
|
||||
|
@ -38,8 +39,8 @@ public class ReferenceTypeSourceBaseConfigurationCensor extends BaseCensor {
|
|||
return;
|
||||
|
||||
this.authService.authorizeForce(Permission.BrowseReferenceType);
|
||||
FieldSet dependenciesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._dependencies));
|
||||
this.censorFactory.censor(ReferenceTypeSourceBaseDependencyCensor.class).censor(dependenciesFields, userId);
|
||||
FieldSet referenceTypeDependencyFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._referenceTypeDependencies));
|
||||
this.censorFactory.censor(ReferenceTypeCensor.class).censor(referenceTypeDependencyFields, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
|
@ -42,9 +43,9 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
|
|||
|
||||
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() {
|
||||
return key;
|
||||
|
@ -78,12 +79,12 @@ public abstract class ReferenceTypeSourceBaseConfigurationPersist {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public List<ReferenceTypeSourceBaseDependencyPersist> getDependencies() {
|
||||
return dependencies;
|
||||
public List<UUID> getReferenceTypeDependencyIds() {
|
||||
return referenceTypeDependencyIds;
|
||||
}
|
||||
|
||||
public void setDependencies(List<ReferenceTypeSourceBaseDependencyPersist> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
public void setReferenceTypeDependencyIds(List<UUID> referenceTypeDependencyIds) {
|
||||
this.referenceTypeDependencyIds = referenceTypeDependencyIds;
|
||||
}
|
||||
|
||||
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())),
|
||||
this.spec()
|
||||
.must(() -> !this.isNull(item.getType()))
|
||||
.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))
|
||||
.failOn(ReferenceTypeSourceBaseConfigurationPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseConfigurationPersist._type}, LocaleContextHolder.getLocale()))
|
||||
));
|
||||
return specifications;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.model.referencetypedefinition;
|
||||
|
||||
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
||||
import eu.eudat.model.ReferenceType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,8 +20,8 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
|
|||
public final static String _type = "type";
|
||||
private ReferenceTypeSourceType type;
|
||||
|
||||
public final static String _dependencies = "dependencies";
|
||||
private List<ReferenceTypeSourceBaseDependency> dependencies;
|
||||
public final static String _referenceTypeDependencies = "referenceTypeDependencies";
|
||||
private List<ReferenceType> referenceTypeDependencies;
|
||||
|
||||
public ReferenceTypeSourceType getType() {
|
||||
return type;
|
||||
|
@ -54,11 +55,11 @@ public abstract class ReferenceTypeSourceBaseConfiguration {
|
|||
this.ordinal = ordinal;
|
||||
}
|
||||
|
||||
public List<ReferenceTypeSourceBaseDependency> getDependencies() {
|
||||
return dependencies;
|
||||
public List<ReferenceType> getReferenceTypeDependencies() {
|
||||
return referenceTypeDependencies;
|
||||
}
|
||||
|
||||
public void setDependencies(List<ReferenceTypeSourceBaseDependency> dependencies) {
|
||||
this.dependencies = dependencies;
|
||||
public void setReferenceTypeDependencies(List<ReferenceType> referenceTypeDependencies) {
|
||||
this.referenceTypeDependencies = referenceTypeDependencies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -181,13 +181,7 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
|||
data.setKey(persist.getKey());
|
||||
data.setLabel(persist.getLabel());
|
||||
data.setOrdinal(persist.getOrdinal());
|
||||
|
||||
if (!this.conventionService.isListNullOrEmpty(persist.getDependencies())){
|
||||
data.setDependencies(new ArrayList<>());
|
||||
for (ReferenceTypeSourceBaseDependencyPersist dependencyPersist: persist.getDependencies()) {
|
||||
data.getDependencies().add(this.buildDependencyEntity(dependencyPersist));
|
||||
}
|
||||
}
|
||||
data.setReferenceTypeDependencyIds(persist.getReferenceTypeDependencyIds());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -236,10 +230,10 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
|||
QueryConfigEntity data = new QueryConfigEntity();
|
||||
if (persist == null) return data;
|
||||
|
||||
data.setCondition(persist.getCondition());
|
||||
data.setSeparator(persist.getSeparator());
|
||||
data.setValue(persist.getValue());
|
||||
data.setOrdinal(persist.getOrdinal());
|
||||
// data.setCondition(persist.getCondition()); //TODO
|
||||
// data.setSeparator(persist.getSeparator());
|
||||
// data.setValue(persist.getValue());
|
||||
// data.setOrdinal(persist.getOrdinal());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -254,35 +248,6 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService {
|
|||
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 {
|
||||
logger.debug("deleting : {}", id);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.service.remotefetcher;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
|
@ -9,6 +8,8 @@ import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
|||
import eu.eudat.commons.exceptions.HugeResultSetException;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
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.models.ExternalDataResult;
|
||||
import eu.eudat.service.remotefetcher.criteria.ExternalReferenceCriteria;
|
||||
|
@ -82,8 +83,8 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
|
|||
for (SourceBaseConfiguration source : sources) {
|
||||
if (source.getType() == null || source.getType().equals(ReferenceTypeSourceType.API)) {
|
||||
try {
|
||||
SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource = (SourceExternalApiConfiguration)source;
|
||||
this.applyFunderToQuery(apiSource, externalReferenceCriteria);
|
||||
SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource = (SourceExternalApiConfiguration)source;
|
||||
// this.applyFunderToQuery(apiSource, externalReferenceCriteria);
|
||||
|
||||
String auth = 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) {
|
||||
//TODO new reference logic
|
||||
// private void applyFunderToQuery(SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria) {
|
||||
// //TODO new reference logic
|
||||
// if (apiSource.getFunderQuery() != null) {
|
||||
// if (externalReferenceCriteria.getFunderId() != null && !apiSource.getFunderQuery().startsWith("dmp:")) {
|
||||
// apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", apiSource.getFunderQuery()));
|
||||
|
@ -147,74 +148,76 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
|
|||
// apiSource.setUrl(apiSource.getUrl().replace("{funderQuery}", ""));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// }
|
||||
|
||||
private String replaceLookupFieldQuery(ExternalReferenceCriteria externalReferenceCriteria, List<QueryConfig> queryConfigs) {
|
||||
String finalQuery = "";
|
||||
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++) {
|
||||
finalQuery = finalQuery.replaceAll("\\{like" + (i + 1) + "}", likes[i]);
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finalQuery = queryConfig.getValue().replaceAll("\\{like}", externalReferenceCriteria.getLike());
|
||||
|
||||
if (caseConfig.getSeparator() != null) {
|
||||
String[] likes = likeValue.split(caseConfig.getSeparator());
|
||||
for (int i = 0; i < likes.length; i++) {
|
||||
filterValue = filterValue.replaceAll("\\{like" + (i + 1) + "}", likes[i]);
|
||||
}
|
||||
} else {
|
||||
filterValue = filterValue.replaceAll("\\{like}", likeValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
finalQuery = finalQuery.replaceAll("{" + queryConfig.getName() + "}", filterValue);
|
||||
}
|
||||
|
||||
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;
|
||||
String completedPath = path;
|
||||
|
||||
if (externalReferenceCriteria.getLike() != null) {
|
||||
if ((path.contains("openaire") || path.contains("orcid") || path.contains("ror") || path.contains("fairsharing")) && externalReferenceCriteria.getLike().isEmpty()) {
|
||||
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.isListNullOrEmpty(apiSource.getQueries())){
|
||||
this.replaceLookupFieldQuery(completedPath, externalReferenceCriteria, apiSource.getQueries());
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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("{path}", !this.conventionService.isNullOrEmpty(externalReferenceCriteria.getPath()) ? externalReferenceCriteria.getPath() : "");
|
||||
|
||||
|
||||
return completedPath;
|
||||
}
|
||||
|
||||
private ExternalDataResult queryExternalData(FetchStrategy fetchStrategy, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception {
|
||||
String replacedPath = replaceLookupFields(apiSource.getUrl(), externalReferenceCriteria, apiSource.getFirstPage(), apiSource.getQueries());
|
||||
String replacedBody = replaceLookupFields(apiSource.getRequestBody(), externalReferenceCriteria, apiSource.getFirstPage(), apiSource.getQueries());
|
||||
private ExternalDataResult queryExternalData(FetchStrategy fetchStrategy, final SourceExternalApiConfiguration<ResultsConfiguration<ResultFieldsMappingConfiguration>, AuthenticationConfiguration, QueryConfig<QueryCaseConfig>> apiSource, ExternalReferenceCriteria externalReferenceCriteria, String auth) throws Exception {
|
||||
String replacedPath = replaceLookupFields(apiSource.getUrl(), apiSource, externalReferenceCriteria);
|
||||
String replacedBody = replaceLookupFields(apiSource.getRequestBody(), apiSource, externalReferenceCriteria);
|
||||
|
||||
ExternalDataResult externalDataResult = this.getExternalDataResults(replacedPath, apiSource, replacedBody, auth);
|
||||
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 {
|
||||
JsonNode jsonBody = new ObjectMapper().readTree(requestBody);
|
||||
|
@ -291,11 +294,8 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
|
|||
for(Object resultItem : results){
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for(ResultFieldsMappingConfiguration field : resultsConfigurationEntity.getFieldsMapping()) {
|
||||
StringBuilder pathValue = new StringBuilder();
|
||||
for (String pathPart : field.getResponsePath().split("\\.")) {
|
||||
pathValue.append("['").append(pathPart).append("']");
|
||||
}
|
||||
Object value = JsonPath.parse(resultItem).read(pathValue.toString());
|
||||
if (this.conventionService.isNullOrEmpty(field.getResponsePath()) || this.conventionService.isNullOrEmpty(field.getCode())) continue;
|
||||
Object value = JsonPath.parse(resultItem).read(field.getResponsePath());
|
||||
map.put(field.getCode(), normalizeJsonValue(value));
|
||||
}
|
||||
parsedData.add(map);
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
package eu.eudat.service.remotefetcher.config.entities;
|
||||
|
||||
public interface QueryConfig {
|
||||
String getCondition();
|
||||
import java.util.List;
|
||||
|
||||
String getSeparator();
|
||||
public interface QueryConfig<CaseConfig extends QueryCaseConfig> {
|
||||
String getName();
|
||||
|
||||
String getValue();
|
||||
List<CaseConfig> getCases();
|
||||
|
||||
Integer getOrdinal();
|
||||
String getDefaultValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
|||
|
||||
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();
|
||||
|
||||
RsConfig getResults();
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
package eu.eudat.service.remotefetcher.criteria;
|
||||
|
||||
import eu.eudat.model.Reference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExternalReferenceCriteria {
|
||||
private String like;
|
||||
private String page;
|
||||
private String pageSize;
|
||||
private String funderId;
|
||||
private String path;
|
||||
private String host;
|
||||
|
||||
private List<Reference> dependencyReferences;
|
||||
|
||||
public String getLike() {
|
||||
return like;
|
||||
|
@ -29,13 +35,6 @@ public class ExternalReferenceCriteria {
|
|||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getFunderId() {
|
||||
return funderId;
|
||||
}
|
||||
public void setFunderId(String funderId) {
|
||||
this.funderId = funderId;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
@ -59,15 +58,11 @@ public class ExternalReferenceCriteria {
|
|||
public ExternalReferenceCriteria() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" +
|
||||
"like='" + like + '\'' +
|
||||
", page='" + page + '\'' +
|
||||
", pageSize='" + pageSize + '\'' +
|
||||
", funderId='" + funderId + '\'' +
|
||||
", path='" + path + '\'' +
|
||||
", host='" + host + '\'' +
|
||||
'}';
|
||||
public List<Reference> getDependencyReferences() {
|
||||
return dependencyReferences;
|
||||
}
|
||||
|
||||
public void setDependencyReferences(List<Reference> dependencyReferences) {
|
||||
this.dependencyReferences = dependencyReferences;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>queryable</module>
|
||||
<module>web</module>
|
||||
<module>data</module>
|
||||
<module>core</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -21,16 +21,6 @@
|
|||
<artifactId>core</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</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>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
|
|
Loading…
Reference in New Issue