Skip to content

Commit c9464ab

Browse files
feat: extend datasets commands visibility, labels, filter support (#632)
* feat: extend datasets commands visibility, labels, filter support * chore: update datasets commands to use V2 dataset api * fix: resolve dataset by name when dataset hidden * chore: minor doc update * fix: update reflect-config with new objects * fix: minor fixes
1 parent 0f567e4 commit c9464ab

16 files changed

Lines changed: 647 additions & 67 deletions

File tree

conf/reflect-config.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,18 @@
12061206
"queryAllDeclaredMethods":true,
12071207
"methods":[{"name":"<init>","parameterTypes":[] }]
12081208
},
1209+
{
1210+
"name":"io.seqera.tower.cli.commands.datasets.DatasetMultiRefOptions",
1211+
"allDeclaredFields":true,
1212+
"queryAllDeclaredMethods":true,
1213+
"methods":[{"name":"<init>","parameterTypes":[] }]
1214+
},
1215+
{
1216+
"name":"io.seqera.tower.cli.commands.datasets.DatasetMultiRefOptions$DatasetMultiRef",
1217+
"allDeclaredFields":true,
1218+
"queryAllDeclaredMethods":true,
1219+
"methods":[{"name":"<init>","parameterTypes":[] }]
1220+
},
12091221
{
12101222
"name":"io.seqera.tower.cli.commands.datasets.DatasetRefOptions",
12111223
"allDeclaredFields":true,
@@ -1230,12 +1242,30 @@
12301242
"queryAllDeclaredMethods":true,
12311243
"methods":[{"name":"<init>","parameterTypes":[] }]
12321244
},
1245+
{
1246+
"name":"io.seqera.tower.cli.commands.datasets.HideCmd",
1247+
"allDeclaredFields":true,
1248+
"queryAllDeclaredMethods":true,
1249+
"methods":[{"name":"<init>","parameterTypes":[] }]
1250+
},
1251+
{
1252+
"name":"io.seqera.tower.cli.commands.datasets.LabelsCmd",
1253+
"allDeclaredFields":true,
1254+
"queryAllDeclaredMethods":true,
1255+
"methods":[{"name":"<init>","parameterTypes":[] }]
1256+
},
12331257
{
12341258
"name":"io.seqera.tower.cli.commands.datasets.ListCmd",
12351259
"allDeclaredFields":true,
12361260
"queryAllDeclaredMethods":true,
12371261
"methods":[{"name":"<init>","parameterTypes":[] }]
12381262
},
1263+
{
1264+
"name":"io.seqera.tower.cli.commands.datasets.ShowCmd",
1265+
"allDeclaredFields":true,
1266+
"queryAllDeclaredMethods":true,
1267+
"methods":[{"name":"<init>","parameterTypes":[] }]
1268+
},
12391269
{
12401270
"name":"io.seqera.tower.cli.commands.datasets.UpdateCmd",
12411271
"allDeclaredFields":true,
@@ -2159,6 +2189,12 @@
21592189
"queryAllDeclaredMethods":true,
21602190
"queryAllDeclaredConstructors":true
21612191
},
2192+
{
2193+
"name":"io.seqera.tower.cli.responses.datasets.DatasetsVisibility",
2194+
"allDeclaredFields":true,
2195+
"queryAllDeclaredMethods":true,
2196+
"queryAllDeclaredConstructors":true
2197+
},
21622198
{
21632199
"name":"io.seqera.tower.cli.responses.labels.DeleteLabelsResponse",
21642200
"allDeclaredFields":true,

src/main/java/io/seqera/tower/cli/commands/DatasetsCmd.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import io.seqera.tower.cli.commands.datasets.AddCmd;
2121
import io.seqera.tower.cli.commands.datasets.DeleteCmd;
2222
import io.seqera.tower.cli.commands.datasets.DownloadCmd;
23+
import io.seqera.tower.cli.commands.datasets.HideCmd;
24+
import io.seqera.tower.cli.commands.datasets.LabelsCmd;
2325
import io.seqera.tower.cli.commands.datasets.ListCmd;
26+
import io.seqera.tower.cli.commands.datasets.ShowCmd;
2427
import io.seqera.tower.cli.commands.datasets.UpdateCmd;
2528
import io.seqera.tower.cli.commands.datasets.UrlCmd;
2629
import io.seqera.tower.cli.commands.datasets.ViewCmd;
@@ -33,7 +36,10 @@
3336
AddCmd.class,
3437
DeleteCmd.class,
3538
DownloadCmd.class,
39+
HideCmd.class,
40+
LabelsCmd.class,
3641
ListCmd.class,
42+
ShowCmd.class,
3743
ViewCmd.class,
3844
UpdateCmd.class,
3945
UrlCmd.class,

src/main/java/io/seqera/tower/cli/commands/datasets/AbstractDatasetsCmd.java

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.seqera.tower.model.ListDatasetsResponse;
2727
import picocli.CommandLine;
2828

29+
import java.util.ArrayList;
2930
import java.util.Comparator;
3031
import java.util.List;
3132
import java.util.Objects;
@@ -35,7 +36,7 @@
3536
public abstract class AbstractDatasetsCmd extends AbstractApiCmd {
3637

3738
protected DatasetDto datasetByName(Long workspaceId, String datasetName) throws ApiException {
38-
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasets(workspaceId);
39+
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasetsV2(workspaceId, null, null, datasetName, null, null, "all", List.of());
3940

4041
if (listDatasetsResponse == null || listDatasetsResponse.getDatasets() == null) {
4142
throw new DatasetNotFoundException(workspaceRef(workspaceId));
@@ -49,36 +50,14 @@ protected DatasetDto datasetByName(Long workspaceId, String datasetName) throws
4950
throw new DatasetNotFoundException(datasetName, workspaceRef(workspaceId));
5051
}
5152

52-
return datasetList.stream().findFirst().orElse(null);
53-
}
54-
55-
protected List<DatasetDto> searchByName(Long workspaceId, String datasetName) throws ApiException {
56-
ListDatasetsResponse listDatasetsResponse = datasetsApi().listDatasets(workspaceId);
57-
58-
if (datasetName == null) {
59-
return listDatasetsResponse.getDatasets();
60-
}
61-
62-
if (listDatasetsResponse == null || listDatasetsResponse.getDatasets() == null) {
63-
throw new DatasetNotFoundException(workspaceRef(workspaceId));
64-
}
65-
66-
List<DatasetDto> datasetList = listDatasetsResponse.getDatasets().stream()
67-
.filter(it -> it.getName().startsWith(datasetName))
68-
.collect(Collectors.toList());
69-
70-
if (datasetList.isEmpty()) {
71-
throw new DatasetNotFoundException(datasetName, workspaceRef(workspaceId));
72-
}
73-
74-
return datasetList;
53+
return datasetList.get(0);
7554
}
7655

7756
protected DatasetDto fetchDescribeDatasetResponse(DatasetRefOptions datasetRefOptions, Long wspId) throws ApiException {
7857
DatasetDto response;
7958

8059
if (datasetRefOptions.dataset.datasetId != null) {
81-
response = datasetsApi().describeDataset(wspId, datasetRefOptions.dataset.datasetId, List.of()).getDataset();
60+
response = datasetsApi().describeDatasetV2(datasetRefOptions.dataset.datasetId, wspId, List.of()).getDataset();
8261
} else {
8362
response = datasetByName(wspId, datasetRefOptions.dataset.datasetName);
8463
}
@@ -89,7 +68,7 @@ protected DatasetDto fetchDescribeDatasetResponse(DatasetRefOptions datasetRefOp
8968
protected DatasetVersionDto fetchDatasetVersion(Long wspId, String datasetId, String datasetMediaType, Long version) throws ApiException {
9069
DatasetVersionDto datasetVersion;
9170

92-
ListDatasetVersionsResponse listDatasetVersionsResponse = datasetsApi().listDatasetVersions(wspId, datasetId, datasetMediaType);
71+
ListDatasetVersionsResponse listDatasetVersionsResponse = datasetsApi().listDatasetVersionsV2(datasetId, wspId, datasetMediaType);
9372

9473
if (listDatasetVersionsResponse == null || listDatasetVersionsResponse.getVersions() == null) {
9574
throw new TowerException(String.format("No versions were found for dataset %s", datasetId));
@@ -129,13 +108,26 @@ protected String getDatasetRef(DatasetRefOptions datasetRefOptions) {
129108
return datasetRefOptions.dataset.datasetName != null ? datasetRefOptions.dataset.datasetName : datasetRefOptions.dataset.datasetId;
130109
}
131110

111+
protected List<String> resolveDatasetIds(DatasetMultiRefOptions options, Long wspId) throws ApiException {
112+
List<String> ids = new ArrayList<>();
113+
if (options.dataset.datasetIds != null) {
114+
ids.addAll(options.dataset.datasetIds);
115+
}
116+
if (options.dataset.datasetNames != null) {
117+
for (String name : options.dataset.datasetNames) {
118+
ids.add(datasetByName(wspId, name).getId());
119+
}
120+
}
121+
return ids;
122+
}
123+
132124
protected void deleteDatasetByName(String datasetName, Long wspId) throws DatasetNotFoundException, ApiException {
133125
DatasetDto response = datasetByName(wspId, datasetName);
134126
deleteDatasetById(response.getId(), wspId);
135127
}
136128

137129
protected void deleteDatasetById(String datasetId, Long wspId) throws DatasetNotFoundException, ApiException {
138-
datasetsApi().deleteDataset(wspId, datasetId);
130+
datasetsApi().deleteDatasetV2(datasetId, wspId);
139131
}
140132

141133

src/main/java/io/seqera/tower/cli/commands/datasets/AddCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ protected Response exec() throws ApiException, IOException {
7272

7373
if (overwrite) tryDeleteDataset(name, wspId);
7474

75-
CreateDatasetResponse response = datasetsApi().createDataset(wspId, request);
75+
CreateDatasetResponse response = datasetsApi().createDatasetV2(request, wspId);
7676

77-
datasetsApi().uploadDataset(wspId, response.getDataset().getId(), header, fileName.toFile());
77+
datasetsApi().uploadDatasetV2(response.getDataset().getId(), wspId, header, fileName.toFile());
7878

7979
return new DatasetCreate(response.getDataset().getName(), workspace.workspace, response.getDataset().getId());
8080
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2021-2026, Seqera.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.seqera.tower.cli.commands.datasets;
18+
19+
import picocli.CommandLine;
20+
21+
import java.util.List;
22+
23+
public class DatasetMultiRefOptions {
24+
25+
@CommandLine.ArgGroup(multiplicity = "1")
26+
public DatasetMultiRef dataset;
27+
28+
public static class DatasetMultiRef {
29+
30+
@CommandLine.Option(names = {"-i", "--id"}, arity = "1..*", description = "Dataset unique identifier(s). May be combined with --name.")
31+
public List<String> datasetIds;
32+
33+
@CommandLine.Option(names = {"-n", "--name"}, arity = "1..*", description = "Dataset name(s). May be combined with --id.")
34+
public List<String> datasetNames;
35+
}
36+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021-2026, Seqera.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.seqera.tower.cli.commands.datasets;
18+
19+
import io.seqera.tower.ApiException;
20+
import io.seqera.tower.api.LabelsApi;
21+
import io.seqera.tower.cli.commands.labels.BaseLabelsManager;
22+
import io.seqera.tower.model.AssociateDatasetsLabelsRequest;
23+
24+
import java.util.List;
25+
26+
public class DatasetsLabelsManager extends BaseLabelsManager<AssociateDatasetsLabelsRequest, String> {
27+
28+
public DatasetsLabelsManager(LabelsApi api) {
29+
super(api, "dataset");
30+
}
31+
32+
@Override
33+
protected AssociateDatasetsLabelsRequest getRequest(List<Long> labelsIds, String entityId) {
34+
return new AssociateDatasetsLabelsRequest().labelIds(labelsIds).datasetIds(List.of(entityId));
35+
}
36+
37+
@Override
38+
protected void apply(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
39+
api.applyLabelsToDatasets(request, wspId);
40+
}
41+
42+
@Override
43+
protected void remove(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
44+
api.removeLabelsFromDatasets(request, wspId);
45+
}
46+
47+
@Override
48+
protected void append(AssociateDatasetsLabelsRequest request, Long wspId) throws ApiException {
49+
api.addLabelsToDatasets(request, wspId);
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021-2026, Seqera.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.seqera.tower.cli.commands.datasets;
18+
19+
import io.seqera.tower.ApiException;
20+
import io.seqera.tower.cli.commands.global.WorkspaceRequiredOptions;
21+
import io.seqera.tower.cli.responses.Response;
22+
import io.seqera.tower.cli.responses.datasets.DatasetsVisibility;
23+
import io.seqera.tower.model.ChangeDatasetVisibilityRequest;
24+
import picocli.CommandLine;
25+
26+
import java.io.IOException;
27+
import java.util.List;
28+
29+
@CommandLine.Command(
30+
name = "hide",
31+
description = "Hide one or more datasets"
32+
)
33+
public class HideCmd extends AbstractDatasetsCmd {
34+
35+
@CommandLine.Mixin
36+
public DatasetMultiRefOptions datasetMultiRefOptions;
37+
38+
@CommandLine.Mixin
39+
public WorkspaceRequiredOptions workspace;
40+
41+
@Override
42+
protected Response exec() throws ApiException, IOException {
43+
Long wspId = workspaceId(workspace.workspace);
44+
List<String> ids = resolveDatasetIds(datasetMultiRefOptions, wspId);
45+
46+
ChangeDatasetVisibilityRequest request = new ChangeDatasetVisibilityRequest().datasetIds(ids);
47+
datasetsApi().hideDatasets(request, wspId);
48+
49+
return new DatasetsVisibility(ids, workspace.workspace, true);
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2021-2026, Seqera.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.seqera.tower.cli.commands.datasets;
18+
19+
import io.seqera.tower.ApiException;
20+
import io.seqera.tower.cli.commands.labels.LabelsSubcmdOptions;
21+
import io.seqera.tower.cli.responses.Response;
22+
import picocli.CommandLine;
23+
24+
import java.io.IOException;
25+
26+
@CommandLine.Command(name = "labels", description = "Manage dataset labels")
27+
public class LabelsCmd extends AbstractDatasetsCmd {
28+
29+
@CommandLine.Mixin
30+
public DatasetRefOptions datasetRefOptions;
31+
32+
@CommandLine.Mixin
33+
public LabelsSubcmdOptions labelsSubcmdOptions;
34+
35+
@Override
36+
protected Response exec() throws ApiException, IOException {
37+
Long wspId = workspaceId(labelsSubcmdOptions.workspace.workspace);
38+
String datasetId = fetchDescribeDatasetResponse(datasetRefOptions, wspId).getId();
39+
40+
DatasetsLabelsManager manager = new DatasetsLabelsManager(labelsApi());
41+
return manager.execute(wspId, datasetId, labelsSubcmdOptions);
42+
}
43+
}

0 commit comments

Comments
 (0)