@@ -1295,6 +1295,7 @@ private List<CustomView> _getCustomViews(final @NotNull User user, final Contain
12951295 return new ArrayList <>(views );
12961296 }
12971297
1298+ @ Deprecated
12981299 @ Override
12991300 public List <CustomView > getDatabaseCustomViews (@ NotNull User user , Container container , @ Nullable User owner , @ Nullable String schemaName , @ Nullable String queryName , boolean includeInherited , boolean sharedOnly )
13001301 {
@@ -1335,6 +1336,73 @@ public List<CustomView> getDatabaseCustomViews(@NotNull User user, Container con
13351336 return allViews .stream ().filter (view -> !(view instanceof ModuleCustomView )).collect (Collectors .toList ());
13361337 }
13371338
1339+ @ Override
1340+ public List <CustomView > getDatabaseCustomViews (@ NotNull User user , @ NotNull Container container , @ Nullable String schemaName , @ Nullable String queryName )
1341+ {
1342+ // GitHub Issue 1058: Sample Finder saved views in subfolder break after MVTC to TC conversion
1343+ Collection <GUID > containerIds = container .getProductFoldersDataContainerFilter (user ).getIds ();
1344+
1345+ SimpleFilter filter = new SimpleFilter ();
1346+ if (containerIds != null )
1347+ filter .addInClause (FieldKey .fromParts ("Container" ), containerIds );
1348+ else
1349+ filter = SimpleFilter .createContainerFilter (container , "Container" );
1350+
1351+ if (schemaName != null )
1352+ filter .addCondition (FieldKey .fromParts ("Schema" ), schemaName );
1353+ if (queryName != null )
1354+ filter .addCondition (FieldKey .fromParts ("QueryName" ), queryName );
1355+
1356+ List <CstmView > cstmViews = new TableSelector (QueryManager .get ().getTableInfoCustomView (), filter , null ).getArrayList (CstmView .class );
1357+
1358+ List <CustomView > result = new ArrayList <>();
1359+
1360+ Map <Container , List <CstmView >> containerViews = new HashMap <>();
1361+ for (CstmView cstmView : cstmViews )
1362+ {
1363+ Container viewContainer = cstmView .lookupContainer ();
1364+ if (viewContainer != null )
1365+ containerViews .computeIfAbsent (viewContainer , k -> new ArrayList <>()).add (cstmView );
1366+ }
1367+
1368+ for (Map .Entry <Container , List <CstmView >> containerCstmViews : containerViews .entrySet ())
1369+ {
1370+ Map <String , UserSchema > schemas = new HashMap <>();
1371+ Map <Pair <String , String >, QueryDefinition > queryDefs = new HashMap <>();
1372+ Container viewContainer = containerCstmViews .getKey ();
1373+ List <CstmView > views = containerCstmViews .getValue ();
1374+ DefaultSchema defaultSchema = DefaultSchema .get (user , viewContainer );
1375+
1376+ for (CstmView cstmView : views )
1377+ {
1378+ Pair <String , String > key = new Pair <>(cstmView .getSchema (), cstmView .getQueryName ());
1379+ QueryDefinition queryDef = queryDefs .get (key );
1380+ if (queryDef == null )
1381+ {
1382+ UserSchema schema = schemas .get (cstmView .getSchema ());
1383+ if (schema == null )
1384+ {
1385+ schema = defaultSchema .getUserSchema (cstmView .getSchema ());
1386+ schemas .put (cstmView .getSchema (), schema );
1387+ }
1388+ if (schema != null )
1389+ {
1390+ queryDef = schema .getQueryDefForTable (cstmView .getQueryName ());
1391+ queryDefs .put (key , queryDef );
1392+ }
1393+ }
1394+
1395+ if (queryDef != null )
1396+ {
1397+ result .add (new CustomViewImpl (queryDef , cstmView ));
1398+ }
1399+ }
1400+ }
1401+
1402+ return result ;
1403+ }
1404+
1405+
13381406 @ Override
13391407 public List <CustomView > getFileBasedCustomViews (Container container , QueryDefinition qd , Path path , String query , Module ... extraModules )
13401408 {
0 commit comments