com.wizzdi.messaging.data.ChatToChatUserRepository Maven / Gradle / Ivy
package com.wizzdi.messaging.data;
import com.flexicore.model.Baseclass;
import com.flexicore.model.Basic;
import com.flexicore.security.SecurityContextBase;
import com.wizzdi.flexicore.boot.base.interfaces.Plugin;
import com.wizzdi.flexicore.security.data.BaseclassRepository;
import com.wizzdi.flexicore.security.data.BasicRepository;
import com.wizzdi.flexicore.security.request.BasicPropertiesFilter;
import com.wizzdi.flexicore.security.request.SoftDeleteOption;
import com.wizzdi.messaging.model.*;
import com.wizzdi.messaging.request.ChatToChatUserFilter;
import org.pf4j.Extension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.criteria.*;
import jakarta.persistence.metamodel.SingularAttribute;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Component
@Extension
public class ChatToChatUserRepository implements Plugin {
@PersistenceContext
private EntityManager em;
@Autowired
private BaseclassRepository baseclassRepository;
@Autowired
private BasicRepository basicRepository;
public List listAllChatToChatUsers(ChatToChatUserFilter ChatToChatUserFilter, SecurityContextBase securityContext) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery q = cb.createQuery(ChatToChatUser.class);
Root r = q.from(ChatToChatUser.class);
List predicates = new ArrayList<>();
addChatToChatUserPredicates(ChatToChatUserFilter, cb, q, r, predicates, securityContext);
q.select(r).where(predicates.toArray(Predicate[]::new));
TypedQuery query = em.createQuery(q);
BasicRepository.addPagination(ChatToChatUserFilter, query);
return query.getResultList();
}
public void addChatToChatUserPredicates(ChatToChatUserFilter chatToChatUserFilter, CriteriaBuilder cb, CommonAbstractCriteria q, From, T> r, List predicates, SecurityContextBase securityContext) {
if (chatToChatUserFilter.getBasicPropertiesFilter() == null) {
chatToChatUserFilter.setBasicPropertiesFilter(new BasicPropertiesFilter().setSoftDelete(SoftDeleteOption.NON_DELETED_ONLY));
}
BasicRepository.addBasicPropertiesFilter(chatToChatUserFilter.getBasicPropertiesFilter(), cb, q, r, predicates);
if(chatToChatUserFilter.getDisabled()==null){
chatToChatUserFilter.setDisabled(false);
}
predicates.add(cb.equal(r.get(ChatToChatUser_.disabled),chatToChatUserFilter.getDisabled()));
if (chatToChatUserFilter.getChats() != null && !chatToChatUserFilter.getChats().isEmpty()) {
Set ids = chatToChatUserFilter.getChats().stream().map(f -> f.getId()).collect(Collectors.toSet());
Join join = r.join(ChatToChatUser_.chat);
predicates.add(join.get(Chat_.id).in(ids));
}
if (chatToChatUserFilter.getChatUsers() != null && !chatToChatUserFilter.getChatUsers().isEmpty()) {
Set ids = chatToChatUserFilter.getChatUsers().stream().map(f -> f.getId()).collect(Collectors.toSet());
Join join = r.join(ChatToChatUser_.chatUser);
predicates.add(join.get(ChatUser_.id).in(ids));
}
}
public long countAllChatToChatUsers(ChatToChatUserFilter ChatToChatUserFilter, SecurityContextBase securityContext) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery q = cb.createQuery(Long.class);
Root r = q.from(ChatToChatUser.class);
List predicates = new ArrayList<>();
addChatToChatUserPredicates(ChatToChatUserFilter, cb, q, r, predicates, securityContext);
q.select(cb.count(r)).where(predicates.toArray(Predicate[]::new));
TypedQuery query = em.createQuery(q);
return query.getSingleResult();
}
@Transactional
public void merge(Object base) {
basicRepository.merge(base);
}
@Transactional
public void massMerge(List> toMerge) {
basicRepository.massMerge(toMerge);
}
public List listByIds(Class c, Set ids, SecurityContextBase securityContext) {
return baseclassRepository.listByIds(c, ids, securityContext);
}
public List listByIds(Class c, Set ids, SingularAttribute baseclassAttribute, SecurityContextBase securityContext) {
return baseclassRepository.listByIds(c, ids, baseclassAttribute, securityContext);
}
public T getByIdOrNull(String id, Class c, SingularAttribute baseclassAttribute, SecurityContextBase securityContext) {
return baseclassRepository.getByIdOrNull(id, c, baseclassAttribute, securityContext);
}
public T getByIdOrNull(String id, Class c, SecurityContextBase securityContext) {
return baseclassRepository.getByIdOrNull(id, c, securityContext);
}
public List findByIds(Class c, Set requested) {
return baseclassRepository.findByIds(c, requested);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy