description refactor
This commit is contained in:
parent
7ef668eede
commit
41fc3407eb
|
@ -75,6 +75,11 @@ public final class Permission {
|
|||
public static String EditDescription = "EditDescription";
|
||||
public static String DeleteDescription = "DeleteDescription";
|
||||
|
||||
//DescriptionTag
|
||||
public static String BrowseDescriptionTag = "BrowseDescriptionTag";
|
||||
public static String EditDescriptionTag = "EditDescriptionTag";
|
||||
public static String DeleteDescriptionTag = "DeleteDescriptionTag";
|
||||
|
||||
//DescriptionTemplateType
|
||||
public static String BrowseEntityDoi = "BrowseEntityDoi";
|
||||
public static String EditEntityDoi = "EditEntityDoi";
|
||||
|
|
|
@ -77,9 +77,13 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
|
|||
|
||||
@Column(name = "dmp_description_template", columnDefinition = "uuid", nullable = false)
|
||||
private UUID dmpDescriptionTemplateId;
|
||||
|
||||
public static final String _dmpDescriptionTemplateId = "dmpDescriptionTemplateId";
|
||||
|
||||
@Column(name = "dmp", columnDefinition = "uuid", nullable = false)
|
||||
private UUID dmpId;
|
||||
|
||||
public static final String _dmpId = "dmpId";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -168,6 +172,14 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
|
|||
this.dmpDescriptionTemplateId = dmpDescriptionTemplateId;
|
||||
}
|
||||
|
||||
public UUID getDmpId() {
|
||||
return dmpId;
|
||||
}
|
||||
|
||||
public void setDmpId(UUID dmpId) {
|
||||
this.dmpId = dmpId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DescriptionEntity entity) {
|
||||
// this.setUri(entity.getUri());
|
||||
|
|
|
@ -67,6 +67,10 @@ public class Description {
|
|||
|
||||
public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate";
|
||||
|
||||
private Dmp dmp;
|
||||
|
||||
public static final String _dmp = "dmp";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -179,4 +183,12 @@ public class Description {
|
|||
public void setDescriptionTags(List<DescriptionTag> descriptionTags) {
|
||||
this.descriptionTags = descriptionTags;
|
||||
}
|
||||
|
||||
public Dmp getDmp() {
|
||||
return dmp;
|
||||
}
|
||||
|
||||
public void setDmp(Dmp dmp) {
|
||||
this.dmp = dmp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,9 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate));
|
||||
Map<UUID, DmpDescriptionTemplate> dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data);
|
||||
|
||||
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate));
|
||||
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
|
||||
|
||||
FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences));
|
||||
Map<UUID, List<DescriptionReference>> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data);
|
||||
|
||||
|
@ -82,6 +85,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
if (fields.hasField(this.asIndexer(Description._isActive))) m.setIsActive(d.getIsActive());
|
||||
if (fields.hasField(this.asIndexer(Description._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt());
|
||||
if (fields.hasField(this.asIndexer(Description._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
|
||||
if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpDescriptionTemplateId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId()));
|
||||
if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) m.setDescriptionReferences(descriptionReferencesMap.get(d.getId()));
|
||||
if (!descriptionTagsFields.isEmpty() && descriptionTagsMap != null && descriptionTagsMap.containsKey(d.getId())) m.setDescriptionTags(descriptionTagsMap.get(d.getId()));
|
||||
|
@ -127,6 +131,36 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
|
||||
|
||||
Map<UUID, Dmp> itemMap;
|
||||
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
||||
itemMap = this.asEmpty(
|
||||
data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()),
|
||||
x -> {
|
||||
Dmp item = new Dmp();
|
||||
item.setId(x);
|
||||
return item;
|
||||
},
|
||||
Dmp::getId);
|
||||
} else {
|
||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
||||
}
|
||||
if (!fields.hasField(Dmp._id)) {
|
||||
itemMap.forEach((id, item) -> {
|
||||
if (item != null)
|
||||
item.setId(null);
|
||||
});
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionReference>> collectDescriptionReferences(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionReference.class.getSimpleName());
|
||||
|
|
|
@ -48,6 +48,9 @@ public class DescriptionCensor extends BaseCensor {
|
|||
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmpDescriptionTemplate));
|
||||
this.censorFactory.censor(DmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields, userId);
|
||||
|
||||
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmp));
|
||||
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
|
||||
|
||||
FieldSet propertiesFields = fields.extractPrefixed(this.asIndexerPrefix(Description._properties));
|
||||
this.censorFactory.censor(PropertyDefinitionCensor.class).censor(propertiesFields, userId);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public class DescriptionTagCensor extends BaseCensor {
|
|||
if (fields == null || fields.isEmpty())
|
||||
return;
|
||||
|
||||
this.authService.authorizeForce(Permission.BrowseDescriptionReference);
|
||||
this.authService.authorizeForce(Permission.BrowseDescriptionTag);
|
||||
FieldSet descriptionFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionTag._description));
|
||||
this.censorFactory.censor(DescriptionCensor.class).censor(descriptionFields, userId);
|
||||
FieldSet tagFields = fields.extractPrefixed(this.asIndexerPrefix(DescriptionTag._tag));
|
||||
|
|
|
@ -33,6 +33,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
private String like;
|
||||
private Collection<UUID> ids;
|
||||
private DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery;
|
||||
private DmpQuery dmpQuery;
|
||||
private Collection<UUID> excludedIds;
|
||||
|
||||
private Collection<IsActive> isActives;
|
||||
|
@ -75,6 +76,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public DescriptionQuery dmpSubQuery(DmpQuery subQuery) {
|
||||
this.dmpQuery = subQuery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptionQuery excludedIds(Collection<UUID> values) {
|
||||
this.excludedIds = values;
|
||||
return this;
|
||||
|
@ -130,7 +136,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
return
|
||||
this.isEmpty(this.ids) ||
|
||||
this.isEmpty(this.isActives) ||
|
||||
this.isEmpty(this.excludedIds) ||
|
||||
this.isEmpty(this.excludedIds) || this.isFalseQuery(this.dmpQuery) ||
|
||||
this.isEmpty(this.statuses) || this.isFalseQuery(this.dmpDescriptionTemplateQuery);
|
||||
}
|
||||
|
||||
|
@ -150,14 +156,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null || usePublic ) {
|
||||
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
|
||||
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._id))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
|
||||
)
|
||||
));
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(dmpDescriptionTemplateSubquery));
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
|
||||
}
|
||||
if (predicates.size() > 0) {
|
||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||
|
@ -205,6 +204,11 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
this.applySubQuery(this.dmpDescriptionTemplateQuery, queryContext.CriteriaBuilder, subQuery);
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpDescriptionTemplateId)).value(subQuery));
|
||||
}
|
||||
if (this.dmpQuery != null) {
|
||||
Subquery<DmpEntity> subQuery = queryContext.Query.subquery(this.dmpQuery.entityClass());
|
||||
this.applySubQuery(this.dmpQuery, queryContext.CriteriaBuilder, subQuery);
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmpId)).value(subQuery));
|
||||
}
|
||||
if (!predicates.isEmpty()) {
|
||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||
return queryContext.CriteriaBuilder.and(predicatesArray);
|
||||
|
@ -226,6 +230,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
else if (item.match(Description._isActive)) return DescriptionEntity._isActive;
|
||||
else if (item.match(Description._finalizedAt)) return DescriptionEntity._finalizedAt;
|
||||
else if (item.match(Description._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId;
|
||||
else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId;
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
@ -242,6 +247,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
|
|||
item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class));
|
||||
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class));
|
||||
item.setDmpDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplateId, UUID.class));
|
||||
item.setDmpId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpId, UUID.class));
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.eudat.query;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
|
@ -148,7 +149,7 @@ public class DescriptionReferenceQuery extends QueryBase<DescriptionReferenceEnt
|
|||
@Override
|
||||
protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) {
|
||||
if (this.authorize.contains(AuthorizationFlags.None)) return null;
|
||||
//if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescription)) return null;
|
||||
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionReference)) return null;
|
||||
UUID userId;
|
||||
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
|
||||
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe();
|
||||
|
@ -156,18 +157,11 @@ public class DescriptionReferenceQuery extends QueryBase<DescriptionReferenceEnt
|
|||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null || usePublic ) {
|
||||
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
|
||||
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._id))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
|
||||
)
|
||||
));
|
||||
Subquery<UUID> descriptionSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
|
||||
new BuildSubQueryInput.Builder<>(DescriptionEntity.class, UUID.class, queryContext)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DescriptionEntity._id))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DescriptionEntity._dmpDescriptionTemplateId)).value(dmpDescriptionTemplateSubquery)
|
||||
cb.in(subQueryRoot.get(DescriptionEntity._dmpDescriptionTemplateId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
|
||||
)
|
||||
));
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionReferenceEntity._descriptionId)).value(descriptionSubquery));
|
||||
|
|
|
@ -147,7 +147,7 @@ public class DescriptionTagQuery extends QueryBase<DescriptionTagEntity> {
|
|||
@Override
|
||||
protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) {
|
||||
if (this.authorize.contains(AuthorizationFlags.None)) return null;
|
||||
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescription)) return null;
|
||||
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDescriptionTag)) return null;
|
||||
UUID userId;
|
||||
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
|
||||
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe();
|
||||
|
@ -155,18 +155,11 @@ public class DescriptionTagQuery extends QueryBase<DescriptionTagEntity> {
|
|||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null || usePublic ) {
|
||||
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
|
||||
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._id))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
|
||||
)
|
||||
));
|
||||
Subquery<UUID> descriptionSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
|
||||
new BuildSubQueryInput.Builder<>(DescriptionEntity.class, UUID.class, queryContext)
|
||||
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DescriptionEntity._id))
|
||||
.filterFunc((subQueryRoot, cb) ->
|
||||
cb.in(subQueryRoot.get(DescriptionEntity._dmpDescriptionTemplateId)).value(dmpDescriptionTemplateSubquery)
|
||||
cb.in(subQueryRoot.get(DescriptionEntity._dmpDescriptionTemplateId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
|
||||
)
|
||||
));
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTagEntity._descriptionId)).value(descriptionSubquery));
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package eu.eudat.query;
|
||||
|
||||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.authorization.Permission;
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.commons.scope.user.UserScope;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DescriptionReferenceEntity;
|
||||
import eu.eudat.data.DmpReferenceEntity;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.query.utils.BuildSubQueryInput;
|
||||
import eu.eudat.query.utils.QueryUtilsService;
|
||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||
import gr.cite.tools.data.query.FieldResolver;
|
||||
import gr.cite.tools.data.query.QueryBase;
|
||||
|
@ -12,6 +17,7 @@ import gr.cite.tools.data.query.QueryContext;
|
|||
import jakarta.persistence.Tuple;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Subquery;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -102,13 +108,15 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
|
|||
private final UserScope userScope;
|
||||
|
||||
private final AuthorizationService authService;
|
||||
private final QueryUtilsService queryUtilsService;
|
||||
|
||||
public DmpReferenceQuery(
|
||||
UserScope userScope,
|
||||
AuthorizationService authService
|
||||
) {
|
||||
AuthorizationService authService,
|
||||
QueryUtilsService queryUtilsService) {
|
||||
this.userScope = userScope;
|
||||
this.authService = authService;
|
||||
this.queryUtilsService = queryUtilsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,6 +129,27 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
|
|||
return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.referenceIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <X, Y> Predicate applyAuthZ(QueryContext<X, Y> queryContext) {
|
||||
if (this.authorize.contains(AuthorizationFlags.None)) return null;
|
||||
if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseDmpReference)) return null;
|
||||
UUID userId;
|
||||
boolean usePublic = this.authorize.contains(AuthorizationFlags.Public);
|
||||
if (this.authorize.contains(AuthorizationFlags.DmpAssociated)) userId = this.userScope.getUserIdSafe();
|
||||
else userId = null;
|
||||
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null || usePublic ) {
|
||||
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic)));
|
||||
}
|
||||
if (predicates.size() > 0) {
|
||||
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
||||
return queryContext.CriteriaBuilder.and(predicatesArray);
|
||||
} else {
|
||||
return queryContext.CriteriaBuilder.or(); //Creates a false query
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
|
|
|
@ -18,6 +18,7 @@ public class DescriptionLookup extends Lookup {
|
|||
private List<UUID> excludedIds;
|
||||
|
||||
private DmpDescriptionTemplateLookup dmpDescriptionTemplateSubQuery;
|
||||
private DmpLookup dmpSubQuery;
|
||||
|
||||
private List<IsActive> isActive;
|
||||
|
||||
|
@ -71,12 +72,21 @@ public class DescriptionLookup extends Lookup {
|
|||
this.dmpDescriptionTemplateSubQuery = dmpDescriptionTemplateSubQuery;
|
||||
}
|
||||
|
||||
public DmpLookup getDmpSubQuery() {
|
||||
return dmpSubQuery;
|
||||
}
|
||||
|
||||
public void setDmpSubQuery(DmpLookup dmpSubQuery) {
|
||||
this.dmpSubQuery = dmpSubQuery;
|
||||
}
|
||||
|
||||
public DescriptionQuery enrich(QueryFactory queryFactory) {
|
||||
DescriptionQuery query = queryFactory.query(DescriptionQuery.class);
|
||||
if (this.like != null) query.like(this.like);
|
||||
if (this.ids != null) query.ids(this.ids);
|
||||
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
||||
if (this.dmpDescriptionTemplateSubQuery != null) query.dmpDescriptionTemplateSubQuery(this.dmpDescriptionTemplateSubQuery.enrich(queryFactory));
|
||||
if (this.dmpSubQuery != null) query.dmpSubQuery(this.dmpSubQuery.enrich(queryFactory));
|
||||
if (this.isActive != null) query.isActive(this.isActive);
|
||||
if (this.statuses != null) query.statuses(this.statuses);
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
|||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -45,7 +43,7 @@ public class DatasetRepository extends ElasticRepository<Dataset, DatasetCriteri
|
|||
private final Environment environment;
|
||||
|
||||
public DatasetRepository(RestHighLevelClient client, DmpRepository dmpRepository, Environment environment) {
|
||||
super(client);
|
||||
super(client, environment);
|
||||
this.dmpRepository = dmpRepository;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.action.index.IndexRequest;
|
|||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.core.CountRequest;
|
||||
|
@ -45,7 +44,7 @@ public class DmpRepository extends ElasticRepository<Dmp, DmpCriteria> {
|
|||
|
||||
@Autowired
|
||||
public DmpRepository(RestHighLevelClient client, Environment environment) {
|
||||
super(client);
|
||||
super(client, environment);
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@ package eu.eudat.elastic.repository;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.elastic.criteria.Criteria;
|
||||
import eu.eudat.elastic.entities.ElasticEntity;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -22,9 +21,13 @@ public abstract class ElasticRepository<T extends ElasticEntity,C extends Criter
|
|||
public RestHighLevelClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public ElasticRepository(RestHighLevelClient client) {
|
||||
public ElasticRepository(RestHighLevelClient client, Environment environment) {
|
||||
try {
|
||||
if (Boolean.FALSE.equals(environment.getProperty("elasticsearch.enabled", boolean.class))){
|
||||
logger.warn("Unable to connect to Elastic Services");
|
||||
this.client = null;
|
||||
return;
|
||||
}
|
||||
if (client.ping(RequestOptions.DEFAULT)) {
|
||||
this.client = client;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
elasticsearch:
|
||||
enabled: false
|
Loading…
Reference in New Issue