Skip to content

Commit c1d95a3

Browse files
authored
EPMRPP-111704 || add method to unlock dashboard filters (#1190)
1 parent ed5ce86 commit c1d95a3

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

src/main/java/com/epam/ta/reportportal/dao/DashboardRepository.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,29 @@ OR id IN (SELECT widget_id FROM widget_ids)
8585
""", nativeQuery = true)
8686
void toggleDashboardLock(@Param("dashboardId") Long dashboardId, @Param("isLocked") boolean isLocked);
8787

88+
/**
89+
* Unlocks all dashboard filters that are related to the specified dashboard
90+
* and not related to any other locked dashboard.
91+
*
92+
* @param dashboardId id of the dashboard to unlock filters for
93+
*/
94+
@Modifying
95+
@Query(value = """
96+
UPDATE owned_entity SET locked = false
97+
WHERE id IN (
98+
SELECT DISTINCT wf.filter_id
99+
FROM widget_filter wf
100+
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
101+
WHERE dw.dashboard_id = :dashboardId
102+
)
103+
AND id NOT IN (
104+
SELECT DISTINCT wf.filter_id
105+
FROM widget_filter wf
106+
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
107+
JOIN owned_entity oe ON dw.dashboard_id = oe.id
108+
WHERE oe.locked = true AND oe.id != :dashboardId
109+
);
110+
""", nativeQuery = true)
111+
void unlockDashboardFilters(@Param("dashboardId") Long dashboardId);
112+
88113
}

src/test/java/com/epam/ta/reportportal/dao/DashboardRepositoryTest.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.epam.ta.reportportal.commons.querygen.Filter;
2828
import com.epam.ta.reportportal.commons.querygen.FilterCondition;
2929
import com.epam.ta.reportportal.entity.dashboard.Dashboard;
30+
import jakarta.persistence.EntityManager;
3031
import java.util.List;
3132
import java.util.Optional;
3233
import org.junit.jupiter.api.Test;
@@ -44,32 +45,38 @@
4445
class DashboardRepositoryTest extends BaseTest {
4546

4647
@Autowired
47-
private DashboardRepository repository;
48+
private DashboardRepository dashboardRepository;
49+
50+
@Autowired
51+
private UserFilterRepository filterRepository;
52+
53+
@Autowired
54+
private EntityManager entityManager;
4855

4956
@Test
5057
public void shouldFindByIdAndProjectIdWhenExists() {
51-
Optional<Dashboard> dashboard = repository.findByIdAndProjectId(13L, 1L);
58+
Optional<Dashboard> dashboard = dashboardRepository.findByIdAndProjectId(13L, 1L);
5259

5360
assertTrue(dashboard.isPresent());
5461
}
5562

5663
@Test
5764
public void shouldNotFindByIdAndProjectIdWhenIdNotExists() {
58-
Optional<Dashboard> dashboard = repository.findByIdAndProjectId(55L, 1L);
65+
Optional<Dashboard> dashboard = dashboardRepository.findByIdAndProjectId(55L, 1L);
5966

6067
assertFalse(dashboard.isPresent());
6168
}
6269

6370
@Test
6471
public void shouldNotFindByIdAndProjectIdWhenProjectIdNotExists() {
65-
Optional<Dashboard> dashboard = repository.findByIdAndProjectId(5L, 11L);
72+
Optional<Dashboard> dashboard = dashboardRepository.findByIdAndProjectId(5L, 11L);
6673

6774
assertFalse(dashboard.isPresent());
6875
}
6976

7077
@Test
7178
public void shouldNotFindByIdAndProjectIdWhenIdAndProjectIdNotExist() {
72-
Optional<Dashboard> dashboard = repository.findByIdAndProjectId(55L, 11L);
79+
Optional<Dashboard> dashboard = dashboardRepository.findByIdAndProjectId(55L, 11L);
7380

7481
assertFalse(dashboard.isPresent());
7582
}
@@ -78,7 +85,7 @@ public void shouldNotFindByIdAndProjectIdWhenIdAndProjectIdNotExist() {
7885
void findAllByProjectId() {
7986
final long superadminProjectId = 1L;
8087

81-
final List<Dashboard> dashboards = repository.findAllByProjectId(superadminProjectId);
88+
final List<Dashboard> dashboards = dashboardRepository.findAllByProjectId(superadminProjectId);
8289

8390
assertNotNull(dashboards, "Dashboards should not be null");
8491
assertEquals(4, dashboards.size(), "Unexpected dashboards size");
@@ -88,7 +95,7 @@ void findAllByProjectId() {
8895

8996
@Test
9097
void shouldFindBySpecifiedNameAndProjectId() {
91-
assertTrue(repository.existsByNameAndProjectId("test admin dashboard", 1L));
98+
assertTrue(dashboardRepository.existsByNameAndProjectId("test admin dashboard", 1L));
9299
}
93100

94101
private Filter buildDefaultFilter() {
@@ -103,21 +110,39 @@ private Filter buildDefaultFilter() {
103110
void shouldFindByFilterAndSortByLocked() {
104111
Filter filter = buildDefaultFilter();
105112
Pageable pageable = PageRequest.of(1, 50, Sort.by("locked"));
106-
Page<Dashboard> page = repository.findByFilter(filter, pageable);
113+
Page<Dashboard> page = dashboardRepository.findByFilter(filter, pageable);
107114
assertEquals(1, page.getTotalElements());
108115
}
109116

110117
@Test
111118
void shouldFindByFilter() {
112119
Filter filter = buildDefaultFilter();
113-
List<Dashboard> byFilter = repository.findByFilter(filter);
120+
List<Dashboard> byFilter = dashboardRepository.findByFilter(filter);
114121
assertEquals(1, byFilter.size());
115122
}
116123

117124
@Test
118125
void toggleDashboardLock() {
119-
repository.toggleDashboardLock(13L, true);
120-
Dashboard dashboard = repository.findById(13L).get();
126+
dashboardRepository.toggleDashboardLock(13L, true);
127+
Dashboard dashboard = dashboardRepository.findById(13L).get();
121128
assertTrue(dashboard.getLocked());
122129
}
130+
131+
@Test
132+
void unlockDashboardFilters() {
133+
dashboardRepository.toggleDashboardLock(13L, true);
134+
dashboardRepository.toggleDashboardLock(18L, true);
135+
entityManager.flush();
136+
entityManager.clear();
137+
138+
assertTrue(filterRepository.findById(2L).get().getLocked());
139+
assertTrue(filterRepository.findById(3L).get().getLocked());
140+
141+
dashboardRepository.unlockDashboardFilters(13L);
142+
entityManager.clear();
143+
144+
assertFalse(filterRepository.findById(2L).get().getLocked());
145+
assertTrue(filterRepository.findById(3L).get().getLocked());
146+
}
147+
123148
}

0 commit comments

Comments
 (0)