All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wizzdi.messaging.data.ChatRepository Maven / Gradle / Ivy

There is a newer version: 8.0.3
Show newest version
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.Chat;
import com.wizzdi.messaging.request.ChatFilter;
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 ChatRepository implements Plugin {
	@PersistenceContext
	private EntityManager em;
	@Autowired
	private SecuredBasicRepository securedBasicRepository;



	public List listAllChats(ChatFilter ChatFilter, SecurityContextBase securityContext) {
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery q = cb.createQuery(Chat.class);
		Root r = q.from(Chat.class);
		List predicates = new ArrayList<>();
		addChatPredicates(ChatFilter, cb, q, r, predicates, securityContext);
		q.select(r).where(predicates.toArray(Predicate[]::new));
		TypedQuery query = em.createQuery(q);
		BasicRepository.addPagination(ChatFilter, query);
		return query.getResultList();

	}

	public  void addChatPredicates(ChatFilter chatFilter, CriteriaBuilder cb, CommonAbstractCriteria q, From r, List predicates, SecurityContextBase securityContext) {
		

			securedBasicRepository.addSecuredBasicPredicates( chatFilter.getBasicPropertiesFilter(),cb,q,r,predicates,securityContext);




	}

	public long countAllChats(ChatFilter ChatFilter, SecurityContextBase securityContext) {
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery q = cb.createQuery(Long.class);
		Root r = q.from(Chat.class);
		List predicates = new ArrayList<>();
		addChatPredicates(ChatFilter, 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