126 lines
3.5 KiB
Java
126 lines
3.5 KiB
Java
package eu.eudat.query;
|
|
|
|
import eu.eudat.data.CredentialEntity;
|
|
import gr.cite.tools.data.query.FieldResolver;
|
|
import gr.cite.tools.data.query.QueryBase;
|
|
import gr.cite.tools.data.query.QueryContext;
|
|
import jakarta.persistence.Tuple;
|
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
|
import jakarta.persistence.criteria.Predicate;
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.*;
|
|
|
|
@Component
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public class CredentialQuery extends QueryBase<CredentialEntity> {
|
|
|
|
private Collection<UUID> ids;
|
|
|
|
private Collection<UUID> userIds;
|
|
|
|
private Collection<Short> statuses;
|
|
|
|
public CredentialQuery ids(UUID value) {
|
|
this.ids = List.of(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery ids(UUID... value) {
|
|
this.ids = Arrays.asList(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery ids(List<UUID> value) {
|
|
this.ids = value;
|
|
return this;
|
|
}
|
|
|
|
|
|
public CredentialQuery userIds(UUID value) {
|
|
this.userIds = List.of(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery userIds(UUID... value) {
|
|
this.userIds = Arrays.asList(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery userIds(List<UUID> value) {
|
|
this.userIds = value;
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery statuses(Short value) {
|
|
this.statuses = List.of(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery statuses(Short... value) {
|
|
this.statuses = Arrays.asList(value);
|
|
return this;
|
|
}
|
|
|
|
public CredentialQuery statuses(List<Short> value) {
|
|
this.statuses = value;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
protected Boolean isFalseQuery() {
|
|
return this.isEmpty(this.ids) || this.isEmpty(this.userIds) || this.isEmpty(this.statuses);
|
|
}
|
|
|
|
@Override
|
|
protected Class<CredentialEntity> entityClass() {
|
|
return CredentialEntity.class;
|
|
}
|
|
|
|
@Override
|
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
if (this.ids != null) {
|
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._id));
|
|
for (UUID item : this.ids)
|
|
inClause.value(item);
|
|
predicates.add(inClause);
|
|
}
|
|
|
|
if (this.userIds != null) {
|
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._userId));
|
|
for (UUID item : this.userIds)
|
|
inClause.value(item);
|
|
predicates.add(inClause);
|
|
}
|
|
|
|
if (this.statuses != null) {
|
|
CriteriaBuilder.In<Short> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(CredentialEntity._isActive));
|
|
for (Short item : this.statuses)
|
|
inClause.value(item);
|
|
predicates.add(inClause);
|
|
}
|
|
|
|
if (!predicates.isEmpty()) {
|
|
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
|
return queryContext.CriteriaBuilder.and(predicatesArray);
|
|
} else {
|
|
return queryContext.CriteriaBuilder.and();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected String fieldNameOf(FieldResolver item) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected CredentialEntity convert(Tuple tuple, Set<String> columns) {
|
|
return null;
|
|
}
|
|
|
|
}
|