package eu.dnetlib.organizations.repository.readonly; import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import eu.dnetlib.organizations.model.view.OrganizationSimpleView; @Repository public interface OrganizationSimpleViewRepository extends ReadOnlyRepository { // SEARCH @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) where idx.txt @@ plainto_tsquery(:text) and o.status in :statuses order by o.name", nativeQuery = true) Page search(@Param("text") String text, @Param("statuses") List statuses, Pageable pageable); // SEARCH FOR USER @Query(value = "select o.* from organizations_simple_view o left outer join org_index_search idx on (idx.id = o.id) left outer join user_countries uc on (uc.country = o.country) where idx.txt @@ plainto_tsquery(:text) and uc.email = :email and o.status in :statuses order by o.name", nativeQuery = true) Page searchForUser(@Param("text") String text, @Param("email") String email, @Param("statuses") List statuses, Pageable pageable); Page findByCountryOrderByName(String country, Pageable pageable); Iterable findByCountryOrderByName(String code); Iterable findByCountryAndStatusOrderByName(String code, String status); Page findByCountryAndStatusOrderByName(String code, String status, Pageable pageable); Page findByTypeOrderByName(String type, Pageable pageable); Page findByTypeAndStatusOrderByName(String type, String status, Pageable pageable); @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where uc.email = ?2 and o.type = ?1 order by o.name", nativeQuery = true) Page findByTypeForUser(String type, String name, Pageable pageable); @Query(value = "select o.* from organizations_simple_view o left outer join user_countries uc on (uc.country = o.country) where o.type = ?1 and o.status = ?2 and uc.email = ?3 order by o.name", nativeQuery = true) Page findByTypeAndStatusForUser(String type, String status, String name, Pageable pageable); }