com.wizzdi.messaging.data.ChatUserRepository 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.BasicRepository;
import com.wizzdi.flexicore.security.data.SecuredBasicRepository;
import com.wizzdi.messaging.model.ChatUser;
import com.wizzdi.messaging.request.ChatUserFilter;
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;
@Component
@Extension
public class ChatUserRepository implements Plugin {
@PersistenceContext
private EntityManager em;
@Autowired
private SecuredBasicRepository securedBasicRepository;
public List listAllChatUsers(ChatUserFilter ChatUserFilter, SecurityContextBase securityContext) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery q = cb.createQuery(ChatUser.class);
Root r = q.from(ChatUser.class);
List predicates = new ArrayList<>();
addChatUserPredicates(ChatUserFilter, cb, q, r, predicates, securityContext);
q.select(r).where(predicates.toArray(Predicate[]::new));
TypedQuery query = em.createQuery(q);
BasicRepository.addPagination(ChatUserFilter, query);
return query.getResultList();
}
public void addChatUserPredicates(ChatUserFilter chatUserFilter, CriteriaBuilder cb, CommonAbstractCriteria q, From, T> r, List predicates, SecurityContextBase securityContext) {
securedBasicRepository.addSecuredBasicPredicates(chatUserFilter.getBasicPropertiesFilter(),cb,q,r,predicates,securityContext);
}
public long countAllChatUsers(ChatUserFilter ChatUserFilter, SecurityContextBase securityContext) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery q = cb.createQuery(Long.class);
Root r = q.from(ChatUser.class);
List predicates = new ArrayList<>();
addChatUserPredicates(ChatUserFilter, cb, q, r, predicates, securityContext);
q.select(cb.count(r)).where(predicates.toArray(Predicate[]::new));
TypedQuery query = em.createQuery(q);
return query.getSingleResult();
}
public List listByIds(Class c, Set ids, SecurityContextBase securityContext) {
return securedBasicRepository.listByIds(c, ids, securityContext);
}
public T getByIdOrNull(String id, Class c, SecurityContextBase securityContext) {
return securedBasicRepository.getByIdOrNull(id, c, securityContext);
}
public T getByIdOrNull(String id, Class c, SingularAttribute baseclassAttribute, SecurityContextBase securityContext) {
return securedBasicRepository.getByIdOrNull(id, c, baseclassAttribute, securityContext);
}
public List listByIds(Class c, Set ids, SingularAttribute baseclassAttribute, SecurityContextBase securityContext) {
return securedBasicRepository.listByIds(c, ids, baseclassAttribute, securityContext);
}
public List findByIds(Class c, Set ids, SingularAttribute idAttribute) {
return securedBasicRepository.findByIds(c, ids, idAttribute);
}
public List findByIds(Class c, Set requested) {
return securedBasicRepository.findByIds(c, requested);
}
public T findByIdOrNull(Class type, String id) {
return securedBasicRepository.findByIdOrNull(type, id);
}
@Transactional
public void merge(Object base) {
securedBasicRepository.merge(base);
}
@Transactional
public void massMerge(List> toMerge) {
securedBasicRepository.massMerge(toMerge);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy