130 lines
4.9 KiB
Java
130 lines
4.9 KiB
Java
package gr.cite.annotation.query;
|
|
|
|
import gr.cite.annotation.common.enums.IsActive;
|
|
import gr.cite.annotation.common.enums.TenantConfigurationType;
|
|
import gr.cite.annotation.data.TenantConfigurationEntity;
|
|
import gr.cite.annotation.model.TenantConfiguration;
|
|
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.Predicate;
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.time.Instant;
|
|
import java.util.*;
|
|
|
|
@Component
|
|
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
|
public class TenantConfigurationQuery extends QueryBase<TenantConfigurationEntity> {
|
|
|
|
private List<UUID> ids;
|
|
|
|
private List<IsActive> isActives;
|
|
|
|
private List<TenantConfigurationType> type;
|
|
|
|
public TenantConfigurationQuery ids(UUID... ids) {
|
|
this.ids = Arrays.asList(ids);
|
|
return this;
|
|
}
|
|
|
|
public TenantConfigurationQuery ids(List<UUID> ids) {
|
|
this.ids = ids;
|
|
return this;
|
|
}
|
|
|
|
public TenantConfigurationQuery isActive(IsActive... isActives) {
|
|
this.isActives = Arrays.asList(isActives);
|
|
return this;
|
|
}
|
|
|
|
public TenantConfigurationQuery isActive(List<IsActive> isActive) {
|
|
this.isActives = isActive;
|
|
return this;
|
|
}
|
|
|
|
public TenantConfigurationQuery type(TenantConfigurationType... type) {
|
|
this.type = Arrays.asList(type);
|
|
return this;
|
|
}
|
|
|
|
public TenantConfigurationQuery type(List<TenantConfigurationType> type) {
|
|
this.type = type;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
protected Boolean isFalseQuery() {
|
|
return this.isEmpty(this.ids) || this.isEmpty(this.isActives);
|
|
}
|
|
|
|
@Override
|
|
protected Class<TenantConfigurationEntity> entityClass() {
|
|
return TenantConfigurationEntity.class;
|
|
}
|
|
|
|
@Override
|
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
if (this.ids != null) {
|
|
predicates.add(queryContext.Root.get(TenantConfigurationEntity._id).in(ids));
|
|
}
|
|
|
|
if (this.isActives != null) {
|
|
predicates.add(queryContext.Root.get(TenantConfigurationEntity._isActive).in(isActives));
|
|
}
|
|
|
|
if (type != null) {
|
|
predicates.add(queryContext.Root.get(TenantConfigurationEntity._type).in(type));
|
|
}
|
|
|
|
if (!predicates.isEmpty()) {
|
|
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
|
|
return queryContext.CriteriaBuilder.and(predicatesArray);
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected String fieldNameOf(FieldResolver item) {
|
|
if (item.match(TenantConfiguration._id))
|
|
return TenantConfigurationEntity._id;
|
|
else if (item.match(TenantConfiguration._tenantId))
|
|
return TenantConfigurationEntity._tenantId;
|
|
else if (item.match(TenantConfiguration._defaultUserLocaleData))
|
|
return TenantConfiguration._defaultUserLocaleData;
|
|
else if (item.match(TenantConfiguration._emailClientData))
|
|
return TenantConfiguration._emailClientData;
|
|
else if (item.match(TenantConfiguration._type))
|
|
return TenantConfigurationEntity._type;
|
|
else if (item.match(TenantConfiguration._value))
|
|
return TenantConfigurationEntity._value;
|
|
else if (item.match(TenantConfiguration._createdAt))
|
|
return TenantConfigurationEntity._createdAt;
|
|
else if (item.match(TenantConfiguration._updatedAt))
|
|
return TenantConfigurationEntity._updatedAt;
|
|
else if (item.match(TenantConfiguration._isActive))
|
|
return TenantConfigurationEntity._isActive;
|
|
else
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected TenantConfigurationEntity convert(Tuple tuple, Set<String> columns) {
|
|
TenantConfigurationEntity item = new TenantConfigurationEntity();
|
|
item.setId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._id, UUID.class));
|
|
item.setValue(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._value, String.class));
|
|
item.setType(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._type, TenantConfigurationType.class));
|
|
item.setTenantId(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._tenantId, UUID.class));
|
|
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._createdAt, Instant.class));
|
|
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._updatedAt, Instant.class));
|
|
item.setIsActive(QueryBase.convertSafe(tuple, columns, TenantConfigurationEntity._isActive, IsActive.class));
|
|
return item;
|
|
}
|
|
}
|