code: public Long countByPanelStateUserAndRole(User user, DelfoiAction action, PanelState state) {
      EntityManager entityManager = getEntityManager();
  
      CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
      CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
      
      Root<PanelUser> panelUserRoot = criteria.from(PanelUser.class);
      Root<PanelUserRoleAction> roleActionRoot = criteria.from(PanelUserRoleAction.class);
      Join<PanelUser, Panel> panelJoin = panelUserRoot.join(PanelUser_.panel);
      criteria.select(criteriaBuilder.countDistinct(panelJoin));
      
      criteria.where(
        criteriaBuilder.and(
          criteriaBuilder.equal(panelJoin, roleActionRoot.get(PanelUserRoleAction_.panel)), 
          criteriaBuilder.equal(roleActionRoot.get(PanelUserRoleAction_.delfoiAction), action), 
          criteriaBuilder.equal(panelUserRoot.get(PanelUser_.role), roleActionRoot.get(PanelUserRoleAction_.userRole)), 
          criteriaBuilder.equal(panelJoin.get(Panel_.state), state),
          criteriaBuilder.equal(panelUserRoot.get(PanelUser_.user), user),
          criteriaBuilder.equal(panelUserRoot.get(PanelUser_.archived), Boolean.FALSE),
          criteriaBuilder.equal(panelJoin.get(Panel_.archived), Boolean.FALSE)
        )
      );
      
      return entityManager.createQuery(criteria).getSingleResult();
    }
docs: Returns count of panels in specific state where user has permission to perform specific action
  
  @param user user
  @param action action
  @param state panel state
  @return count of panels in specific state where user has permission to perform specific action