diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryCaseConfigBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryCaseConfigBuilder.java new file mode 100644 index 000000000..a661580c7 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryCaseConfigBuilder.java @@ -0,0 +1,102 @@ +package eu.eudat.model.builder.referencetypedefinition; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.commons.types.referencetype.QueryCaseConfigEntity; +import eu.eudat.convention.ConventionService; +import eu.eudat.model.ReferenceType; +import eu.eudat.model.builder.BaseBuilder; +import eu.eudat.model.builder.ReferenceTypeBuilder; +import eu.eudat.model.referencetypedefinition.QueryCaseConfig; +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; +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.*; +import java.util.stream.Collectors; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class QueryCaseConfigBuilder extends BaseBuilder { + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public QueryCaseConfigBuilder( + ConventionService conventionService, BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(QueryCaseConfigBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public QueryCaseConfigBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List 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 referenceTypeFields = fields.extractPrefixed(this.asPrefix(QueryCaseConfig._referenceType)); + Map referenceTypeItemsMap = this.collectReferenceTypes(referenceTypeFields, data); + + List models = new ArrayList<>(); + for (QueryCaseConfigEntity d : data) { + QueryCaseConfig m = new QueryCaseConfig(); + if (fields.hasField(this.asIndexer(QueryCaseConfig._separator))) m.setSeparator(d.getSeparator()); + if (fields.hasField(this.asIndexer(QueryCaseConfig._value))) m.setValue(d.getValue()); + if (fields.hasField(this.asIndexer(QueryCaseConfig._likePattern))) m.setLikePattern(d.getLikePattern()); + if (fields.hasField(this.asIndexer(QueryCaseConfig._referenceTypeSourceKey))) m.setReferenceTypeSourceKey(d.getReferenceTypeSourceKey()); + if (!referenceTypeFields.isEmpty() && referenceTypeItemsMap != null && referenceTypeItemsMap.containsKey(d.getReferenceTypeId())) m.setReferenceType(referenceTypeItemsMap.get(d.getReferenceTypeId())); + + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private Map collectReferenceTypes(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", ReferenceType.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(ReferenceType._id))) { + itemMap = this.asEmpty( + data.stream().filter(x-> x.getReferenceTypeId() != null).map(QueryCaseConfigEntity::getReferenceTypeId).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().filter(x-> x.getReferenceTypeId() != null).map(QueryCaseConfigEntity::getReferenceTypeId).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; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryConfigBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryConfigBuilder.java index 4f9275a02..bf3638cc4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryConfigBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/QueryConfigBuilder.java @@ -27,7 +27,7 @@ public class QueryConfigBuilder extends BaseBuilder(); + FieldSet casesFields = fields.extractPrefixed(this.asPrefix(QueryConfig._cases)); + List models = new ArrayList<>(); for (QueryConfigEntity d : data) { QueryConfig m = new QueryConfig(); -// 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()); - + if (fields.hasField(this.asIndexer(QueryConfig._defaultValue))) m.setDefaultValue(d.getDefaultValue()); + if (fields.hasField(this.asIndexer(QueryConfig._name))) m.setName(d.getName()); + if (!casesFields.isEmpty() && !this.conventionService.isListNullOrEmpty(d.getCases())){ + m.setCases(this.builderFactory.builder(QueryCaseConfigBuilder.class).authorize(this.authorize).build(casesFields, d.getCases())); + } models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); return models; } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeSourceBaseConfigurationBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeSourceBaseConfigurationBuilder.java index b7a5f2a14..6b16b4dca 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeSourceBaseConfigurationBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/referencetypedefinition/ReferenceTypeSourceBaseConfigurationBuilder.java @@ -57,10 +57,8 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder(); -// FieldSet dependenciesFields = fields.extractPrefixed(this.asPrefix(Model._dependencies)); - - FieldSet typeFields = fields.extractPrefixed(this.asPrefix(Model._referenceTypeDependencies)); -// Map referenceTypeItemsMap = this.collectReferenceTypes(typeFields, data); + FieldSet referenceTypeDependenciesFields = fields.extractPrefixed(this.asPrefix(Model._referenceTypeDependencies)); + Map referenceTypeItemsMap = this.collectReferenceTypes(referenceTypeDependenciesFields, data); List models = new ArrayList<>(); for (Entity d : data) { @@ -69,7 +67,13 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder referenceTypes = new ArrayList<>(); + for (UUID referenceTypeId : d.getReferenceTypeDependencyIds()){ + if (referenceTypeItemsMap.containsKey(referenceTypeId)) referenceTypes.add(referenceTypeItemsMap.get(referenceTypeId)); + } + if (!referenceTypes.isEmpty()) m.setReferenceTypeDependencies(referenceTypes); + } this.buildChild(fields, d, m); models.add(m); @@ -78,34 +82,34 @@ public abstract class ReferenceTypeSourceBaseConfigurationBuilder collectReferenceTypes(FieldSet fields, List data) throws MyApplicationException { -// if (fields.isEmpty() || data.isEmpty()) -// return null; -// this.logger.debug("checking related - {}", ReferenceType.class.getSimpleName()); -// -// Map 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; -// } + private Map collectReferenceTypes(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", ReferenceType.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(ReferenceType._id))) { + itemMap = this.asEmpty( + data.stream().filter(x-> x.getReferenceTypeDependencyIds() != null).map(ReferenceTypeSourceBaseConfigurationEntity::getReferenceTypeDependencyIds).flatMap(List::stream).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().filter(x-> x.getReferenceTypeDependencyIds() != null).map(ReferenceTypeSourceBaseConfigurationEntity::getReferenceTypeDependencyIds).flatMap(List::stream).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; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/AuthenticationConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/AuthenticationConfigurationCensor.java new file mode 100644 index 000000000..c7b49534b --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/AuthenticationConfigurationCensor.java @@ -0,0 +1,39 @@ +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 AuthenticationConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(AuthenticationConfigurationCensor.class)); + + protected final AuthorizationService authService; + + public AuthenticationConfigurationCensor(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); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryCaseConfigCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryCaseConfigCensor.java new file mode 100644 index 000000000..c9055d10d --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryCaseConfigCensor.java @@ -0,0 +1,46 @@ +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.QueryCaseConfig; +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 QueryCaseConfigCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(QueryCaseConfigCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public QueryCaseConfigCensor(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 referenceTypeFields = fields.extractPrefixed(this.asIndexerPrefix(QueryCaseConfig._referenceType)); + this.censorFactory.censor(ReferenceTypeCensor.class).censor(referenceTypeFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryConfigCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryConfigCensor.java new file mode 100644 index 000000000..ccff583c8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/QueryConfigCensor.java @@ -0,0 +1,45 @@ +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.QueryConfig; +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 QueryConfigCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(QueryConfigCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public QueryConfigCensor(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 casesFields = fields.extractPrefixed(this.asIndexerPrefix(QueryConfig._cases)); + this.censorFactory.censor(QueryCaseConfigCensor.class).censor(casesFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeSourceBaseConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeSourceBaseConfigurationCensor.java index fa5ccaf65..d06001c56 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeSourceBaseConfigurationCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeSourceBaseConfigurationCensor.java @@ -4,7 +4,7 @@ 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 eu.eudat.model.referencetypedefinition.*; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -41,6 +41,20 @@ public class ReferenceTypeSourceBaseConfigurationCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseReferenceType); FieldSet referenceTypeDependencyFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceBaseConfiguration._referenceTypeDependencies)); this.censorFactory.censor(ReferenceTypeCensor.class).censor(referenceTypeDependencyFields, userId); + + FieldSet optionsFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceStaticOptionConfiguration._options)); + this.censorFactory.censor(ReferenceTypeStaticOptionCensor.class).censor(optionsFields, userId); + + FieldSet authFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceExternalApiConfiguration._auth)); + this.censorFactory.censor(AuthenticationConfigurationCensor.class).censor(authFields, userId); + + FieldSet resultsFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceExternalApiConfiguration._results)); + this.censorFactory.censor(ResultsConfigurationCensor.class).censor(resultsFields, userId); + + FieldSet queriesFields = fields.extractPrefixed(this.asIndexerPrefix(ReferenceTypeSourceExternalApiConfiguration._queries)); + this.censorFactory.censor(QueryConfigCensor.class).censor(queriesFields, userId); } } + + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeStaticOptionCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeStaticOptionCensor.java new file mode 100644 index 000000000..ad9d2de61 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ReferenceTypeStaticOptionCensor.java @@ -0,0 +1,40 @@ +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.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 ReferenceTypeStaticOptionCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeStaticOptionCensor.class)); + + protected final AuthorizationService authService; + + public ReferenceTypeStaticOptionCensor(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); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultFieldsMappingConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultFieldsMappingConfigurationCensor.java new file mode 100644 index 000000000..adce33a6a --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultFieldsMappingConfigurationCensor.java @@ -0,0 +1,39 @@ +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 ResultFieldsMappingConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ResultFieldsMappingConfigurationCensor.class)); + + protected final AuthorizationService authService; + + public ResultFieldsMappingConfigurationCensor(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); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultsConfigurationCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultsConfigurationCensor.java new file mode 100644 index 000000000..4f37b6fc0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/referencetypedefinition/ResultsConfigurationCensor.java @@ -0,0 +1,45 @@ +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.ResultsConfiguration; +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 ResultsConfigurationCensor extends BaseCensor { + + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ResultsConfigurationCensor.class)); + + protected final AuthorizationService authService; + protected final CensorFactory censorFactory; + + public ResultsConfigurationCensor(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 fieldsMappingFields = fields.extractPrefixed(this.asIndexerPrefix(ResultsConfiguration._fieldsMapping)); + this.censorFactory.censor(ResultFieldsMappingConfigurationCensor.class).censor(fieldsMappingFields, userId); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DependencyPropertyPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DependencyPropertyPersist.java deleted file mode 100644 index 694958760..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/DependencyPropertyPersist.java +++ /dev/null @@ -1,88 +0,0 @@ -package eu.eudat.model.persist.referencetypedefinition; - -import eu.eudat.commons.validation.BaseValidator; -import gr.cite.tools.validation.specification.Specification; -import eu.eudat.convention.ConventionService; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; - -public class DependencyPropertyPersist { - - private String code; - - public static final String _code = "code"; - - private String target; - - public static final String _target = "target"; - - private Boolean required; - - public static final String _required = "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; - } - - @Component(DependencyPropertyPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class DependencyPropertyPersistValidator extends BaseValidator { - - public static final String ValidatorName = "DependencyPropertyPersistValidator"; - - private final MessageSource messageSource; - - protected DependencyPropertyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { - super(conventionService, errors); - this.messageSource = messageSource; - } - - @Override - protected Class modelClass() { - return DependencyPropertyPersist.class; - } - - @Override - protected List specifications(DependencyPropertyPersist item) { - return Arrays.asList( - this.spec() - .must(() -> !this.isEmpty(item.getCode())) - .failOn(DependencyPropertyPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._code}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getTarget())) - .failOn(DependencyPropertyPersist._target).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._target}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getRequired())) - .failOn(DependencyPropertyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{DependencyPropertyPersist._required}, LocaleContextHolder.getLocale())) - ); - } - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryCaseConfigPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryCaseConfigPersist.java new file mode 100644 index 000000000..8d49280a8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryCaseConfigPersist.java @@ -0,0 +1,107 @@ +package eu.eudat.model.persist.referencetypedefinition; + +import eu.eudat.commons.enums.FieldType; +import eu.eudat.commons.types.referencetype.QueryCaseConfigEntity; +import eu.eudat.commons.validation.BaseValidator; +import eu.eudat.model.persist.ReferencePersist; +import eu.eudat.model.persist.descriptionproperties.FieldPersist; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; +import eu.eudat.convention.ConventionService; +import eu.eudat.errorcode.ErrorThesaurusProperties; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Scope; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +public class QueryCaseConfigPersist { + + private String likePattern; + public static final String _likePattern = "likePattern"; + + private String separator; + public static final String _separator = "separator"; + + private String value; + public static final String _value = "value"; + + private UUID referenceTypeId; + public static final String _referenceTypeId = "referenceTypeId"; + private String referenceTypeSourceKey; + public static final String _referenceTypeSourceKey = "referenceTypeSourceKey"; + + + public String getLikePattern() { + return likePattern; + } + + public void setLikePattern(String likePattern) { + this.likePattern = likePattern; + } + + public String getSeparator() { + return separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public UUID getReferenceTypeId() { + return referenceTypeId; + } + + public void setReferenceTypeId(UUID referenceTypeId) { + this.referenceTypeId = referenceTypeId; + } + + public String getReferenceTypeSourceKey() { + return referenceTypeSourceKey; + } + + public void setReferenceTypeSourceKey(String referenceTypeSourceKey) { + this.referenceTypeSourceKey = referenceTypeSourceKey; + } + + @Component(QueryCaseConfigPersistValidator.ValidatorName) + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + public static class QueryCaseConfigPersistValidator extends BaseValidator { + + public static final String ValidatorName = "QueryCaseConfigPersistValidator"; + private final MessageSource messageSource; + + protected QueryCaseConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + super(conventionService, errors); + this.messageSource = messageSource; + } + + @Override + protected Class modelClass() { + return QueryCaseConfigPersist.class; + } + + @Override + protected List specifications(QueryCaseConfigPersist item) { + return Arrays.asList( + this.spec() + .must(() -> !this.isEmpty(item.getValue())) + .failOn(QueryCaseConfigPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryCaseConfigPersist._value}, LocaleContextHolder.getLocale())) + ); + } + } + +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryConfigPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryConfigPersist.java index 9bdfc9641..af5ba6918 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryConfigPersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/QueryConfigPersist.java @@ -1,9 +1,10 @@ package eu.eudat.model.persist.referencetypedefinition; import eu.eudat.commons.validation.BaseValidator; -import gr.cite.tools.validation.specification.Specification; import eu.eudat.convention.ConventionService; import eu.eudat.errorcode.ErrorThesaurusProperties; +import gr.cite.tools.validation.ValidatorFactory; +import gr.cite.tools.validation.specification.Specification; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Scope; @@ -15,60 +16,49 @@ import java.util.List; public class QueryConfigPersist { - private String condition; - public static final String _condition = "condition"; + private String name; + public static final String _name = "name"; + private String defaultValue; + public static final String _defaultValue = "defaultValue"; + List cases; + public static final String _cases = "cases"; - private String separator; - public static final String _separator = "separator"; - - private String value; - public static final String _value = "value"; - - private Integer ordinal; - public static final String _ordinal = "ordinal"; - - public String getCondition() { - return condition; + public String getName() { + return name; } - public void setCondition(String condition) { - this.condition = condition; + public void setName(String name) { + this.name = name; } - public String getSeparator() { - return separator; + public String getDefaultValue() { + return defaultValue; } - public void setSeparator(String separator) { - this.separator = separator; + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; } - public String getValue() { - return value; + public List getCases() { + return cases; } - public void setValue(String value) { - this.value = value; - } - - public Integer getOrdinal() { - return ordinal; - } - - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; + public void setCases(List cases) { + this.cases = cases; } @Component(QueryConfigPersistValidator.ValidatorName) @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public static class QueryConfigPersistValidator extends BaseValidator { - public static final String ValidatorName = "QueryConfigPersistValidator"; + public static final String ValidatorName = "QueryConfigPersistPersistValidator"; private final MessageSource messageSource; + private final ValidatorFactory validatorFactory; - protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) { + protected QueryConfigPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { super(conventionService, errors); this.messageSource = messageSource; + this.validatorFactory = validatorFactory; } @Override @@ -80,18 +70,14 @@ public class QueryConfigPersist { protected List specifications(QueryConfigPersist item) { return Arrays.asList( this.spec() - .must(() -> !this.isEmpty(item.getCondition())) - .failOn(QueryConfigPersist._condition).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._condition}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getSeparator())) - .failOn(QueryConfigPersist._separator).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._separator}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getValue())) - .failOn(QueryConfigPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._value}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getOrdinal())) - .failOn(QueryConfigPersist._ordinal).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._ordinal}, LocaleContextHolder.getLocale())) - ); + .must(() -> !this.isEmpty(item.getName())) + .failOn(QueryConfigPersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{QueryConfigPersist._name}, LocaleContextHolder.getLocale())), + this.navSpec() + .iff(() -> !this.isListNullOrEmpty(item.getCases())) + .on(QueryConfigPersist._cases) + .over(item.getCases()) + .using((itm) -> this.validatorFactory.validator(QueryCaseConfigPersist.QueryCaseConfigPersistValidator.class)) + ); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java deleted file mode 100644 index e70812649..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/referencetypedefinition/ReferenceTypeSourceBaseDependencyPersist.java +++ /dev/null @@ -1,113 +0,0 @@ -package eu.eudat.model.persist.referencetypedefinition; - -import eu.eudat.commons.validation.BaseValidator; -import gr.cite.tools.validation.ValidatorFactory; -import gr.cite.tools.validation.specification.Specification; -import eu.eudat.convention.ConventionService; -import eu.eudat.errorcode.ErrorThesaurusProperties; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.MessageSource; -import org.springframework.context.annotation.Scope; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; - -import java.util.Arrays; -import java.util.List; - -public class ReferenceTypeSourceBaseDependencyPersist { - - private String referenceTypeCode; - - public static final String _referenceTypeCode = "referenceTypeCode"; - - private String key; - - public static final String _key = "key"; - - private Boolean required; - - public static final String _required = "required"; - - private List properties; - - public static final String _properties = "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 getProperties() { - return properties; - } - - public void setProperties(List properties) { - this.properties = properties; - } - - @Component(ReferenceTypeSourceBaseDependencyPersistValidator.ValidatorName) - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - public static class ReferenceTypeSourceBaseDependencyPersistValidator extends BaseValidator { - - public static final String ValidatorName = "ReferenceTypeSourceBaseDependencyPersistValidator"; - - private final MessageSource messageSource; - - private final ValidatorFactory validatorFactory; - - protected ReferenceTypeSourceBaseDependencyPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) { - super(conventionService, errors); - this.messageSource = messageSource; - this.validatorFactory = validatorFactory; - } - - @Override - protected Class modelClass() { - return ReferenceTypeSourceBaseDependencyPersist.class; - } - - @Override - protected List specifications(ReferenceTypeSourceBaseDependencyPersist item) { - return Arrays.asList( - this.spec() - .must(() -> !this.isEmpty(item.getReferenceTypeCode())) - .failOn(ReferenceTypeSourceBaseDependencyPersist._referenceTypeCode).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._referenceTypeCode}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isEmpty(item.getKey())) - .failOn(ReferenceTypeSourceBaseDependencyPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._key}, LocaleContextHolder.getLocale())), - this.spec() - .must(() -> !this.isNull(item.getRequired())) - .failOn(ReferenceTypeSourceBaseDependencyPersist._required).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._required}, LocaleContextHolder.getLocale())), - - this.spec() - .must(() -> !this.isListNullOrEmpty(item.getProperties())) - .failOn(ReferenceTypeSourceBaseDependencyPersist._properties).failWith(messageSource.getMessage("Validation_Required", new Object[]{ReferenceTypeSourceBaseDependencyPersist._properties}, LocaleContextHolder.getLocale())), - this.navSpec() - .iff(() -> !this.isListNullOrEmpty(item.getProperties())) - .on(ReferenceTypeSourceBaseDependencyPersist._properties) - .over(item.getProperties()) - .using((itm) -> this.validatorFactory.validator(DependencyPropertyPersist.DependencyPropertyPersistValidator.class)) - ); - } - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryCaseConfig.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryCaseConfig.java new file mode 100644 index 000000000..9579fe7a9 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryCaseConfig.java @@ -0,0 +1,66 @@ +package eu.eudat.model.referencetypedefinition; + + +import eu.eudat.commons.types.referencetype.QueryCaseConfigEntity; +import eu.eudat.model.ReferenceType; + +import java.util.List; + +public class QueryCaseConfig { + + public final static String _likePattern = "likePattern"; + private String likePattern; + + public final static String _separator = "separator"; + private String separator; + + public final static String _value = "value"; + private String value; + + public final static String _referenceType = "referenceType"; + private ReferenceType referenceType; + + public final static String _referenceTypeSourceKey = "referenceTypeSourceKey"; + private String referenceTypeSourceKey; + + public String getLikePattern() { + return likePattern; + } + + public void setLikePattern(String likePattern) { + this.likePattern = likePattern; + } + + public String getSeparator() { + return separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public ReferenceType getReferenceType() { + return referenceType; + } + + public void setReferenceType(ReferenceType referenceType) { + this.referenceType = referenceType; + } + + public String getReferenceTypeSourceKey() { + return referenceTypeSourceKey; + } + + public void setReferenceTypeSourceKey(String referenceTypeSourceKey) { + this.referenceTypeSourceKey = referenceTypeSourceKey; + } +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryConfig.java b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryConfig.java index be5a774d1..a9b16f8c2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryConfig.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/referencetypedefinition/QueryConfig.java @@ -1,50 +1,40 @@ package eu.eudat.model.referencetypedefinition; +import java.util.List; public class QueryConfig { - public final static String _condition = "condition"; - private String condition; + public final static String _name = "name"; + private String name; - public final static String _separator = "separator"; - private String separator; + public final static String _defaultValue = "defaultValue"; - public final static String _value = "value"; - private String value; + private String defaultValue; - public final static String _ordinal = "ordinal"; - private Integer ordinal; + public final static String _cases = "cases"; + List cases; - - public String getCondition() { - return condition; + public String getName() { + return name; } - public void setCondition(String condition) { - this.condition = condition; + public void setName(String name) { + this.name = name; } - public String getSeparator() { - return separator; + public String getDefaultValue() { + return defaultValue; } - public void setSeparator(String separator) { - this.separator = separator; + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; } - public String getValue() { - return value; + public List getCases() { + return cases; } - public void setValue(String value) { - this.value = value; - } - - public Integer getOrdinal() { - return ordinal; - } - - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; + public void setCases(List cases) { + this.cases = cases; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java index b694a29b3..d895cf6b1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/referencetype/ReferenceTypeServiceImpl.java @@ -230,10 +230,27 @@ public class ReferenceTypeServiceImpl implements ReferenceTypeService { QueryConfigEntity data = new QueryConfigEntity(); if (persist == null) return data; -// data.setCondition(persist.getCondition()); //TODO -// data.setSeparator(persist.getSeparator()); -// data.setValue(persist.getValue()); -// data.setOrdinal(persist.getOrdinal()); + data.setName(persist.getName()); + data.setDefaultValue(persist.getDefaultValue()); + if (!this.conventionService.isListNullOrEmpty(persist.getCases())){ + data.setCases(new ArrayList<>()); + for (QueryCaseConfigPersist queryCaseConfigPersist: persist.getCases()) { + data.getCases().add(this.buildQueryCaseConfigEntity(queryCaseConfigPersist)); + } + } + + return data; + } + + private @NotNull QueryCaseConfigEntity buildQueryCaseConfigEntity(QueryCaseConfigPersist persist){ + QueryCaseConfigEntity data = new QueryCaseConfigEntity(); + if (persist == null) return data; + + data.setReferenceTypeId(persist.getReferenceTypeId()); + data.setReferenceTypeSourceKey(persist.getReferenceTypeSourceKey()); + data.setSeparator(persist.getSeparator()); + data.setValue(persist.getValue()); + data.setLikePattern(persist.getLikePattern()); return data; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java index 2e3ac77e7..b3c1498b5 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/remotefetcher/RemoteFetcherServiceImpl.java @@ -6,6 +6,7 @@ import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import eu.eudat.commons.enums.ReferenceTypeSourceType; import eu.eudat.commons.exceptions.HugeResultSetException; +import eu.eudat.commons.types.dashborad.RecentActivityItemEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.ReferenceEntity; import eu.eudat.model.Reference; @@ -159,10 +160,12 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService { 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); + + Comparator queryCaseConfigcomparator = Comparator.comparing(x-> x.getReferenceTypeId() == null ? 0 : 1); //Reference QueryCaseConfig are more important + 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()))) + ).max(queryCaseConfigcomparator).orElse(null); String filterValue = queryConfig.getDefaultValue(); @@ -173,24 +176,25 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService { 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()); - } } - } - - 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 if (!this.conventionService.isNullOrEmpty(likeValue)) { + 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); } } else { - filterValue = filterValue.replaceAll("\\{like}", likeValue); + filterValue = queryConfig.getDefaultValue(); } - } - finalQuery = finalQuery.replaceAll("{" + queryConfig.getName() + "}", filterValue); + finalQuery = finalQuery.replaceAll("{" + queryConfig.getName() + "}", filterValue); } return finalQuery; diff --git a/dmp-backend/web/pom.xml b/dmp-backend/web/pom.xml index 57ac4f5b9..537f26e63 100644 --- a/dmp-backend/web/pom.xml +++ b/dmp-backend/web/pom.xml @@ -74,7 +74,11 @@ 3.1.5 - + + io.swagger + swagger-annotations + 1.5.20 +