more reference type changes

This commit is contained in:
Efstratios Giannopoulos 2024-02-13 18:16:59 +02:00
parent f826c2297b
commit 384b9883a8
19 changed files with 686 additions and 336 deletions

View File

@ -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<QueryCaseConfig, QueryCaseConfigEntity> {
private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private EnumSet<AuthorizationFlags> 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<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<QueryCaseConfig> build(FieldSet fields, List<QueryCaseConfigEntity> 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<UUID, ReferenceType> referenceTypeItemsMap = this.collectReferenceTypes(referenceTypeFields, data);
List<QueryCaseConfig> 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<UUID, ReferenceType> collectReferenceTypes(FieldSet fields, List<QueryCaseConfigEntity> 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.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;
}
}

View File

@ -44,17 +44,20 @@ public class QueryConfigBuilder extends BaseBuilder<QueryConfig, QueryConfigEnti
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet casesFields = fields.extractPrefixed(this.asPrefix(QueryConfig._cases));
List<QueryConfig> 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;
}
}

View File

@ -57,10 +57,8 @@ 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 typeFields = fields.extractPrefixed(this.asPrefix(Model._referenceTypeDependencies));
// Map<UUID, ReferenceType> referenceTypeItemsMap = this.collectReferenceTypes(typeFields, data);
FieldSet referenceTypeDependenciesFields = fields.extractPrefixed(this.asPrefix(Model._referenceTypeDependencies));
Map<UUID, ReferenceType> referenceTypeItemsMap = this.collectReferenceTypes(referenceTypeDependenciesFields, data);
List<Model> models = new ArrayList<>();
for (Entity d : data) {
@ -69,7 +67,13 @@ 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.setReferenceTypeDependencies(this.builderFactory.builder(ReferenceTypeSourceBaseDependencyBuilder.class).authorize(this.authorize).build(dependenciesFields, d.getDependencies()));
if (!referenceTypeDependenciesFields.isEmpty() && referenceTypeItemsMap != null && d.getReferenceTypeDependencyIds() != null) {
List<ReferenceType> 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<Model extends
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;
// }
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(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;
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<DependencyPropertyPersist> {
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<DependencyPropertyPersist> modelClass() {
return DependencyPropertyPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<QueryCaseConfigPersist> {
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<QueryCaseConfigPersist> modelClass() {
return QueryCaseConfigPersist.class;
}
@Override
protected List<Specification> 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()))
);
}
}
}

View File

@ -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<QueryCaseConfigPersist> 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<QueryCaseConfigPersist> 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<QueryCaseConfigPersist> cases) {
this.cases = cases;
}
@Component(QueryConfigPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class QueryConfigPersistValidator extends BaseValidator<QueryConfigPersist> {
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,17 +70,13 @@ public class QueryConfigPersist {
protected List<Specification> 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))
);
}
}

View File

@ -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<DependencyPropertyPersist> 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<DependencyPropertyPersist> getProperties() {
return properties;
}
public void setProperties(List<DependencyPropertyPersist> properties) {
this.properties = properties;
}
@Component(ReferenceTypeSourceBaseDependencyPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class ReferenceTypeSourceBaseDependencyPersistValidator extends BaseValidator<ReferenceTypeSourceBaseDependencyPersist> {
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<ReferenceTypeSourceBaseDependencyPersist> modelClass() {
return ReferenceTypeSourceBaseDependencyPersist.class;
}
@Override
protected List<Specification> 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))
);
}
}
}

View File

@ -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;
}
}

View File

@ -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<QueryCaseConfig> 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<QueryCaseConfig> 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<QueryCaseConfig> cases) {
this.cases = cases;
}
}

View File

@ -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;
}

View File

@ -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){
Comparator<QueryCaseConfig> 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())))
).findFirst().orElse(null);
).max(queryCaseConfigcomparator).orElse(null);
String filterValue = queryConfig.getDefaultValue();
@ -173,13 +176,12 @@ 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());
}
}
}
} else if (!this.conventionService.isNullOrEmpty(likeValue)) {
if (caseConfig.getSeparator() != null) {
String[] likes = likeValue.split(caseConfig.getSeparator());
for (int i = 0; i < likes.length; i++) {
@ -188,7 +190,9 @@ public class RemoteFetcherServiceImpl implements RemoteFetcherService {
} else {
filterValue = filterValue.replaceAll("\\{like}", likeValue);
}
} else {
filterValue = queryConfig.getDefaultValue();
}
}
finalQuery = finalQuery.replaceAll("{" + queryConfig.getName() + "}", filterValue);
}

View File

@ -74,7 +74,11 @@
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>