Skip to content

Commit 33a07be

Browse files
authored
EPMRPP-112320 || Enable Filter Changes on Locked Dashboards (#1199)
* EPMRPP-112320 revert locked filters * Revert "EPMRPP-111882 || Find locked dashboards (#1196)" This reverts commit e8ca230. * EPMRPP-112320 fix tests
1 parent a2feb93 commit 33a07be

4 files changed

Lines changed: 27 additions & 135 deletions

File tree

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

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public interface DashboardRepository extends ReportPortalRepository<Dashboard, L
3333
* Finds dashboard by 'id' and 'project id'
3434
*
3535
* @param id {@link Dashboard#id}
36-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose
37-
* dashboard will be extracted
36+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose dashboard will be
37+
* extracted
3838
* @return {@link Dashboard} wrapped in the {@link Optional}
3939
*/
4040
Optional<Dashboard> findByIdAndProjectId(Long id, Long projectId);
@@ -46,8 +46,8 @@ public interface DashboardRepository extends ReportPortalRepository<Dashboard, L
4646
*
4747
* @param name {@link Dashboard#name}
4848
* @param owner {@link Dashboard#owner}
49-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which
50-
* dashboard existence will be checked
49+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which dashboard existence
50+
* will be checked
5151
* @return if exists 'true' else 'false'
5252
*/
5353
boolean existsByNameAndOwnerAndProjectId(String name, String owner, Long projectId);
@@ -63,13 +63,12 @@ public interface DashboardRepository extends ReportPortalRepository<Dashboard, L
6363

6464

6565
/**
66-
* Toggles the lock flag for the specified dashboard and all related widgets and filters.
66+
* Toggles the lock flag for the specified dashboard and all related widgets.
6767
*
68-
* <p>Performs three native update statements:
68+
* <p>Performs native update statements:
6969
* <ul>
7070
* <li>Updates the dashboard owned_entity row.</li>
7171
* <li>Updates owned_entity rows for widgets linked to the dashboard.</li>
72-
* <li>Updates owned_entity rows for filters linked to those widgets.</li>
7372
* </ul>
7473
*
7574
* @param dashboardId id of the dashboard to toggle lock for
@@ -79,8 +78,7 @@ public interface DashboardRepository extends ReportPortalRepository<Dashboard, L
7978
WITH widget_ids AS (SELECT widget_id FROM dashboard_widget WHERE dashboard_id = :dashboardId)
8079
UPDATE owned_entity SET locked = true
8180
WHERE id = :dashboardId
82-
OR id IN (SELECT widget_id FROM widget_ids)
83-
OR id IN (SELECT filter_id FROM widget_filter WHERE widget_id IN (SELECT widget_id FROM widget_ids));
81+
OR id IN (SELECT widget_id FROM widget_ids);
8482
""", nativeQuery = true)
8583
void lockDashboard(@Param("dashboardId") Long dashboardId);
8684

@@ -90,43 +88,8 @@ OR id IN (SELECT widget_id FROM widget_ids)
9088
WITH widget_ids AS (SELECT widget_id FROM dashboard_widget WHERE dashboard_id = :dashboardId)
9189
UPDATE owned_entity SET locked = false
9290
WHERE id = :dashboardId
93-
OR id IN (SELECT widget_id FROM widget_ids)
94-
OR (
95-
id IN (SELECT filter_id FROM widget_filter WHERE widget_id IN (SELECT widget_id FROM widget_ids))
96-
AND id NOT IN (
97-
SELECT DISTINCT wf.filter_id
98-
FROM widget_filter wf
99-
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
100-
JOIN owned_entity oe ON dw.dashboard_id = oe.id
101-
WHERE oe.locked = true AND oe.id != :dashboardId
102-
)
103-
);
91+
OR id IN (SELECT widget_id FROM widget_ids);
10492
""", nativeQuery = true)
10593
void unlockDashboard(@Param("dashboardId") Long dashboardId);
10694

107-
/**
108-
* Unlocks all dashboard filters that are related to the specified dashboard
109-
* and not related to any other locked dashboard.
110-
*
111-
* @param dashboardId id of the dashboard to unlock filters for
112-
*/
113-
@Modifying
114-
@Query(value = """
115-
UPDATE owned_entity SET locked = false
116-
WHERE id IN (
117-
SELECT DISTINCT wf.filter_id
118-
FROM widget_filter wf
119-
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
120-
WHERE dw.dashboard_id = :dashboardId
121-
)
122-
AND id NOT IN (
123-
SELECT DISTINCT wf.filter_id
124-
FROM widget_filter wf
125-
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
126-
JOIN owned_entity oe ON dw.dashboard_id = oe.id
127-
WHERE oe.locked = true AND oe.id != :dashboardId
128-
);
129-
""", nativeQuery = true)
130-
void unlockDashboardFilters(@Param("dashboardId") Long dashboardId);
131-
13295
}

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.List;
2222
import java.util.Optional;
23-
import org.springframework.data.jpa.repository.Query;
24-
import org.springframework.data.repository.query.Param;
2523

2624
/**
2725
* @author Pavel Bortnik
@@ -33,20 +31,23 @@ public interface UserFilterRepository extends ReportPortalRepository<UserFilter,
3331
* Finds filter by 'id' and 'project id'
3432
*
3533
* @param id {@link UserFilter#id}
36-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filter will be extracted
34+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filter
35+
* will be extracted
3736
* @return {@link UserFilter} wrapped in the {@link Optional}
3837
*/
3938
Optional<UserFilter> findByIdAndProjectId(Long id, Long projectId);
4039

4140
/**
4241
* @param ids {@link Iterable} of the filter Ids
43-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filters will be extracted
42+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose
43+
* filters will be extracted
4444
* @return The {@link List} of the {@link UserFilter}
4545
*/
4646
List<UserFilter> findAllByIdInAndProjectId(Collection<Long> ids, Long projectId);
4747

4848
/**
49-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filters will be extracted
49+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose
50+
* filters will be extracted
5051
* @return The {@link List} of the {@link UserFilter}
5152
*/
5253
List<UserFilter> findAllByProjectId(Long projectId);
@@ -56,8 +57,8 @@ public interface UserFilterRepository extends ReportPortalRepository<UserFilter,
5657
*
5758
* @param name {@link UserFilter#name}
5859
* @param owner {@link UserFilter#owner}
59-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which filter existence will
60-
* be checked
60+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which
61+
* filter existence will be checked
6162
* @return if exists 'true' else 'false'
6263
*/
6364
boolean existsByNameAndOwnerAndProjectId(String name, String owner, Long projectId);
@@ -66,31 +67,10 @@ public interface UserFilterRepository extends ReportPortalRepository<UserFilter,
6667
* Checks the existence of the {@link UserFilter} with specified name on a project
6768
*
6869
* @param name {@link UserFilter#name}
69-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which filter existence will
70-
* be checked
70+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which
71+
* filter existence will be checked
7172
* @return if exists 'true' else 'false'
7273
*/
7374
boolean existsByNameAndProjectId(String name, Long projectId);
7475

75-
/**
76-
* Finds locked dashboards that use the specified filter. Returns dashboard names.
77-
*
78-
* @param filterId The filter ID
79-
* @param projectId The project ID to filter dashboards
80-
* @return List of dashboard names
81-
*/
82-
@Query(value = """
83-
SELECT d.name
84-
FROM dashboard d
85-
INNER JOIN owned_entity oe ON d.id = oe.id
86-
WHERE oe.locked = true
87-
AND oe.project_id = :projectId
88-
AND d.id IN (
89-
SELECT dw.dashboard_id
90-
FROM dashboard_widget dw
91-
INNER JOIN widget_filter wf ON dw.widget_id = wf.widget_id
92-
WHERE wf.filter_id = :filterId
93-
)
94-
""", nativeQuery = true)
95-
List<String> findLockedDashboardsByFilterId(@Param("filterId") Long filterId, @Param("projectId") Long projectId);
9676
}

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

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.epam.ta.reportportal.entity.widget.Widget;
2020
import java.util.List;
2121
import java.util.Optional;
22-
import org.springframework.data.jpa.repository.Modifying;
2322
import org.springframework.data.jpa.repository.Query;
2423
import org.springframework.data.repository.query.Param;
2524

@@ -33,15 +32,13 @@ public interface WidgetRepository extends ReportPortalRepository<Widget, Long>,
3332
* Finds widget by 'id' and 'project id'
3433
*
3534
* @param id {@link Widget#id}
36-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widget
37-
* will be extracted
35+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widget will be extracted
3836
* @return {@link Widget} wrapped in the {@link Optional}
3937
*/
4038
Optional<Widget> findByIdAndProjectId(Long id, Long projectId);
4139

4240
/**
43-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose
44-
* widgets will be extracted
41+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widgets will be extracted
4542
* @return The {@link List} of the {@link Widget}
4643
*/
4744
List<Widget> findAllByProjectId(Long projectId);
@@ -51,8 +48,8 @@ public interface WidgetRepository extends ReportPortalRepository<Widget, Long>,
5148
*
5249
* @param name {@link Widget#name}
5350
* @param owner {@link Widget#owner}
54-
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which
55-
* widget existence will be checked
51+
* @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which widget existence will
52+
* be checked
5653
* @return if exists 'true' else 'false'
5754
*/
5855
boolean existsByNameAndOwnerAndProjectId(String name, String owner, Long projectId);
@@ -74,49 +71,4 @@ List<Widget> findAllByProjectIdAndWidgetTypeInAndContentFieldsContains(
7471
+ " WHERE se.project_id = :projectId AND w.widget_type IN :widgetTypes AND cf.field LIKE :contentFieldPart || '%'", nativeQuery = true)
7572
List<Widget> findAllByProjectIdAndWidgetTypeInAndContentFieldContaining(@Param("projectId") Long projectId,
7673
@Param("widgetTypes") List<String> widgetTypes, @Param("contentFieldPart") String contentFieldPart);
77-
78-
/**
79-
* Unlocks all widget filters that are related to the specified widget
80-
* and not related to any other locked dashboard.
81-
*
82-
* @param widgetId id of the widget to unlock filters for
83-
*/
84-
@Modifying
85-
@Query(value = """
86-
UPDATE owned_entity SET locked = false
87-
WHERE id IN (
88-
SELECT DISTINCT wf.filter_id
89-
FROM widget_filter wf
90-
WHERE wf.widget_id = :widgetId
91-
)
92-
AND id NOT IN (
93-
SELECT DISTINCT wf.filter_id
94-
FROM widget_filter wf
95-
JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id
96-
JOIN owned_entity oe ON dw.dashboard_id = oe.id
97-
WHERE oe.locked = true
98-
);
99-
""", nativeQuery = true)
100-
void unlockWidgetFilters(@Param("widgetId") Long widgetId);
101-
102-
103-
/**
104-
* Locks all widget filters that are related to the specified widget.
105-
*
106-
* <p>This operation sets the `locked` flag to true on entries in the
107-
* `owned_entity` table for every filter referenced by the given widget
108-
* (via the `widget_filter` join table).</p>
109-
*
110-
* @param widgetId id of the widget to lock filters for
111-
*/
112-
@Modifying
113-
@Query(value = """
114-
UPDATE owned_entity SET locked = true
115-
WHERE id IN (
116-
SELECT DISTINCT wf.filter_id
117-
FROM widget_filter wf
118-
WHERE wf.widget_id = :widgetId
119-
);
120-
""", nativeQuery = true)
121-
void lockWidgetFilters(@Param("widgetId") Long widgetId);
12274
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,17 @@ void toggleDashboardLock() {
129129
}
130130

131131
@Test
132-
void unlockDashboardFilters() {
132+
void lockDashboardShouldNotLockFilters() {
133133
dashboardRepository.lockDashboard(13L);
134-
dashboardRepository.lockDashboard(18L);
135134
entityManager.flush();
136135
entityManager.clear();
137136

138-
assertTrue(filterRepository.findById(2L).get().getLocked());
139-
assertTrue(filterRepository.findById(3L).get().getLocked());
140-
141-
dashboardRepository.unlockDashboardFilters(13L);
142-
entityManager.clear();
137+
// Dashboard should be locked
138+
Dashboard dashboard = dashboardRepository.findById(13L).get();
139+
assertTrue(dashboard.getLocked());
143140

141+
// Filters should NOT be locked
144142
assertFalse(filterRepository.findById(2L).get().getLocked());
145-
assertTrue(filterRepository.findById(3L).get().getLocked());
146143
}
147144

148145
}

0 commit comments

Comments
 (0)