diff --git a/legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/api/DataCubeQueryStoreManager.java b/legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/api/DataCubeQueryStoreManager.java index d32e97444e..d8bc830025 100644 --- a/legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/api/DataCubeQueryStoreManager.java +++ b/legend-engine-application-query/src/main/java/org/finos/legend/engine/application/query/api/DataCubeQueryStoreManager.java @@ -187,6 +187,10 @@ public List searchQueries(QuerySearchSpecification searchSpecific filters.add(filter); } } + if (searchSpecification.showCurrentUserQueriesOnly != null && searchSpecification.showCurrentUserQueriesOnly) + { + filters.add(Filters.in("owner", currentUser, null)); + } List queries = new ArrayList<>(); List aggregateLists = new ArrayList<>(); diff --git a/legend-engine-application-query/src/test/java/org/finos/legend/engine/application/query/api/TestDataCubeQueryStoreManager.java b/legend-engine-application-query/src/test/java/org/finos/legend/engine/application/query/api/TestDataCubeQueryStoreManager.java index 4ace791080..f16b504261 100644 --- a/legend-engine-application-query/src/test/java/org/finos/legend/engine/application/query/api/TestDataCubeQueryStoreManager.java +++ b/legend-engine-application-query/src/test/java/org/finos/legend/engine/application/query/api/TestDataCubeQueryStoreManager.java @@ -271,6 +271,32 @@ public void testGetQueriesWithSearchText() throws Exception Assert.assertEquals(3, store.searchQueries(new TestQuerySearchSpecificationBuilder().withSearchTerm("query").build(), currentUser).size()); } + @Test + public void testGetQueriesWithSearchTextSpec() throws Exception + { + String currentUser = "user1"; + String user2 = "user2"; + store.createQuery(TestQueryBuilder.create("1", "query1", currentUser).build(), currentUser); + store.createQuery(TestQueryBuilder.create("2", "query2", currentUser).build(), currentUser); + store.createQuery(TestQueryBuilder.create("3", "query3", user2).build(), user2); + Assert.assertEquals(1, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withSearchTerm("user2").withIncludeOwner(true).build(), currentUser).size()); + Assert.assertEquals(2, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withSearchTerm("user1").withIncludeOwner(true).build(), currentUser).size()); + Assert.assertEquals(3, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withSearchTerm("user").withIncludeOwner(true).build(), currentUser).size()); + Assert.assertEquals(0, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withSearchTerm("user").withExactNameSearch(true).withIncludeOwner(true).build(), currentUser).size()); + Assert.assertEquals(0, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withSearchTerm("user").withIncludeOwner(false).build(), currentUser).size()); + } + + @Test + public void testGetQueriesForCurrentUser() throws Exception + { + String currentUser = "testUser"; + store.createQuery(TestQueryBuilder.create("1", "query1", currentUser).build(), "testUser1"); + store.createQuery(TestQueryBuilder.create("2", "query2", currentUser).build(), currentUser); + Assert.assertEquals(2, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().build(), currentUser).size()); + Assert.assertEquals(2, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withShowCurrentUserQueriesOnly(false).build(), currentUser).size()); + Assert.assertEquals(1, store.searchQueries(new TestQueryStoreManager.TestQuerySearchSpecificationBuilder().withShowCurrentUserQueriesOnly(true).build(), currentUser).size()); + } + @Test public void testGetNotFoundQuery() {