diff --git a/src/main/java/com/epam/ta/reportportal/dao/DashboardRepository.java b/src/main/java/com/epam/ta/reportportal/dao/DashboardRepository.java index 772fc6a6c..381a4fd16 100644 --- a/src/main/java/com/epam/ta/reportportal/dao/DashboardRepository.java +++ b/src/main/java/com/epam/ta/reportportal/dao/DashboardRepository.java @@ -33,8 +33,8 @@ public interface DashboardRepository extends ReportPortalRepository findByIdAndProjectId(Long id, Long projectId); @@ -46,8 +46,8 @@ public interface DashboardRepository extends ReportPortalRepositoryPerforms three native update statements: + *

Performs native update statements: *

* * @param dashboardId id of the dashboard to toggle lock for @@ -79,8 +78,7 @@ public interface DashboardRepository extends ReportPortalRepository findByIdAndProjectId(Long id, Long projectId); /** * @param ids {@link Iterable} of the filter Ids - * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filters will be extracted + * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose + * filters will be extracted * @return The {@link List} of the {@link UserFilter} */ List findAllByIdInAndProjectId(Collection ids, Long projectId); /** - * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose filters will be extracted + * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose + * filters will be extracted * @return The {@link List} of the {@link UserFilter} */ List findAllByProjectId(Long projectId); @@ -56,8 +57,8 @@ public interface UserFilterRepository extends ReportPortalRepository findLockedDashboardsByFilterId(@Param("filterId") Long filterId, @Param("projectId") Long projectId); } diff --git a/src/main/java/com/epam/ta/reportportal/dao/WidgetRepository.java b/src/main/java/com/epam/ta/reportportal/dao/WidgetRepository.java index aa3aa3139..783574b02 100644 --- a/src/main/java/com/epam/ta/reportportal/dao/WidgetRepository.java +++ b/src/main/java/com/epam/ta/reportportal/dao/WidgetRepository.java @@ -19,7 +19,6 @@ import com.epam.ta.reportportal.entity.widget.Widget; import java.util.List; import java.util.Optional; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -33,15 +32,13 @@ public interface WidgetRepository extends ReportPortalRepository, * Finds widget by 'id' and 'project id' * * @param id {@link Widget#id} - * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widget - * will be extracted + * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widget will be extracted * @return {@link Widget} wrapped in the {@link Optional} */ Optional findByIdAndProjectId(Long id, Long projectId); /** - * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose - * widgets will be extracted + * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} whose widgets will be extracted * @return The {@link List} of the {@link Widget} */ List findAllByProjectId(Long projectId); @@ -51,8 +48,8 @@ public interface WidgetRepository extends ReportPortalRepository, * * @param name {@link Widget#name} * @param owner {@link Widget#owner} - * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which - * widget existence will be checked + * @param projectId Id of the {@link com.epam.ta.reportportal.entity.project.Project} on which widget existence will + * be checked * @return if exists 'true' else 'false' */ boolean existsByNameAndOwnerAndProjectId(String name, String owner, Long projectId); @@ -74,49 +71,4 @@ List findAllByProjectIdAndWidgetTypeInAndContentFieldsContains( + " WHERE se.project_id = :projectId AND w.widget_type IN :widgetTypes AND cf.field LIKE :contentFieldPart || '%'", nativeQuery = true) List findAllByProjectIdAndWidgetTypeInAndContentFieldContaining(@Param("projectId") Long projectId, @Param("widgetTypes") List widgetTypes, @Param("contentFieldPart") String contentFieldPart); - - /** - * Unlocks all widget filters that are related to the specified widget - * and not related to any other locked dashboard. - * - * @param widgetId id of the widget to unlock filters for - */ - @Modifying - @Query(value = """ - UPDATE owned_entity SET locked = false - WHERE id IN ( - SELECT DISTINCT wf.filter_id - FROM widget_filter wf - WHERE wf.widget_id = :widgetId - ) - AND id NOT IN ( - SELECT DISTINCT wf.filter_id - FROM widget_filter wf - JOIN dashboard_widget dw ON wf.widget_id = dw.widget_id - JOIN owned_entity oe ON dw.dashboard_id = oe.id - WHERE oe.locked = true - ); - """, nativeQuery = true) - void unlockWidgetFilters(@Param("widgetId") Long widgetId); - - - /** - * Locks all widget filters that are related to the specified widget. - * - *

This operation sets the `locked` flag to true on entries in the - * `owned_entity` table for every filter referenced by the given widget - * (via the `widget_filter` join table).

- * - * @param widgetId id of the widget to lock filters for - */ - @Modifying - @Query(value = """ - UPDATE owned_entity SET locked = true - WHERE id IN ( - SELECT DISTINCT wf.filter_id - FROM widget_filter wf - WHERE wf.widget_id = :widgetId - ); - """, nativeQuery = true) - void lockWidgetFilters(@Param("widgetId") Long widgetId); } diff --git a/src/test/java/com/epam/ta/reportportal/dao/DashboardRepositoryTest.java b/src/test/java/com/epam/ta/reportportal/dao/DashboardRepositoryTest.java index 733f75f24..3ceabb9ad 100644 --- a/src/test/java/com/epam/ta/reportportal/dao/DashboardRepositoryTest.java +++ b/src/test/java/com/epam/ta/reportportal/dao/DashboardRepositoryTest.java @@ -129,20 +129,17 @@ void toggleDashboardLock() { } @Test - void unlockDashboardFilters() { + void lockDashboardShouldNotLockFilters() { dashboardRepository.lockDashboard(13L); - dashboardRepository.lockDashboard(18L); entityManager.flush(); entityManager.clear(); - assertTrue(filterRepository.findById(2L).get().getLocked()); - assertTrue(filterRepository.findById(3L).get().getLocked()); - - dashboardRepository.unlockDashboardFilters(13L); - entityManager.clear(); + // Dashboard should be locked + Dashboard dashboard = dashboardRepository.findById(13L).get(); + assertTrue(dashboard.getLocked()); + // Filters should NOT be locked assertFalse(filterRepository.findById(2L).get().getLocked()); - assertTrue(filterRepository.findById(3L).get().getLocked()); } }