Commit e7fcb8fc authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-537 | do not display duplicate widgets

parent c3837704
package ee.stat.dashboard.repository;
import ee.stat.dashboard.model.user.widget.UserWidget;
import ee.stat.dashboard.repository.custom.UserWidgetCustomRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
import java.util.Optional;
public interface UserWidgetRepository extends JpaRepository<UserWidget, Long> {
List<UserWidget> findDistinctByAppUserAndDashboardAndSelectedOrderByOrderNrAsc(Long user, Long dashboard, boolean selected);
public interface UserWidgetRepository extends JpaRepository<UserWidget, Long>, UserWidgetCustomRepository {
List<UserWidget> findAllByDashboard(Long dashboard);
......
package ee.stat.dashboard.repository.custom;
import ee.stat.dashboard.model.user.widget.UserWidget;
import java.util.List;
public interface UserWidgetCustomRepository {
List<UserWidget> findByDashboardAndAppUserAndSelectedOrderByOrderNrAsc(Long dashboard, Long user, boolean selected);
}
package ee.stat.dashboard.repository.custom;
import ee.stat.dashboard.model.user.widget.UserWidget;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
public class UserWidgetCustomRepositoryImpl implements UserWidgetCustomRepository {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<UserWidget> findByDashboardAndAppUserAndSelectedOrderByOrderNrAsc(Long dashboard, Long appUser, boolean selected) {
return entityManager.createNativeQuery("" +
"select uw2.*\n" +
"from user_widget uw2\n" +
"where id in (\n" +
" select min(id)\n" +
" from user_widget uw\n" +
" where dashboard = :dashboard\n" +
" and app_user = :appUser\n" +
" and uw.selected = :selected\n" +
" group by widget, dashboard, app_user)\n" +
"order by uw2.order_nr", UserWidget.class)
.setParameter("dashboard", dashboard)
.setParameter("appUser", appUser)
.setParameter("selected", selected)
.getResultList();
}
}
......@@ -17,7 +17,7 @@ public class UserWidgetService {
private UserWidgetRepository userWidgetRepository;
public List<Long> getSelectedWidgets(Dashboard dashboard, StatUser user) {
return userWidgetRepository.findDistinctByAppUserAndDashboardAndSelectedOrderByOrderNrAsc(user.getId(), dashboard.getId(), true)
return userWidgetRepository.findByDashboardAndAppUserAndSelectedOrderByOrderNrAsc(dashboard.getId(), user.getId(), true)
.stream()
.map(UserWidget::getWidget)
.collect(Collectors.toList());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment