Skip to content

Commit

Permalink
Add Pagination info in list commands results (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeSeqLabs committed Sep 20, 2023
1 parent 59e96ee commit 4aa4bdb
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.seqera.tower.cli.commands.global.PaginationOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.collaborators.CollaboratorsList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.ListMembersResponse;
import io.seqera.tower.model.OrgAndWorkspaceDbDto;
import picocli.CommandLine;
Expand Down Expand Up @@ -45,6 +46,6 @@ protected Response exec() throws ApiException, IOException {

ListMembersResponse response = api().listOrganizationCollaborators(orgAndWorkspaceDbDto.getOrgId(), max, offset, startsWith);

return new CollaboratorsList(orgAndWorkspaceDbDto.getOrgId(), response.getMembers());
return new CollaboratorsList(orgAndWorkspaceDbDto.getOrgId(), response.getMembers(), PaginationInfo.from(paginationOptions, response.getTotalSize()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.labels.ListLabelsCmdResponse;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.LabelType;
import io.seqera.tower.model.ListLabelsResponse;
import picocli.CommandLine;
Expand Down Expand Up @@ -53,6 +54,6 @@ protected Response exec() throws ApiException, IOException {

ListLabelsResponse res = api().listLabels(wspId, max, offset, filter == null ? "" : filter, labelType, null);

return new ListLabelsCmdResponse(wspId, labelType, res.getLabels());
return new ListLabelsCmdResponse(wspId, labelType, res.getLabels(), PaginationInfo.from(paginationOptions, res.getTotalSize()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.seqera.tower.cli.commands.global.WorkspaceRequiredOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.participants.ParticipantsList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.ParticipantDbDto;
import io.seqera.tower.model.ParticipantType;
import picocli.CommandLine;
Expand Down Expand Up @@ -55,6 +56,6 @@ protected Response exec() throws ApiException, IOException {
response = response.stream().filter(it -> it.getType() == type).collect(Collectors.toList());
}

return new ParticipantsList(orgName(wspId), workspaceName(wspId), response);
return new ParticipantsList(orgName(wspId), workspaceName(wspId), response, PaginationInfo.from(paginationOptions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import io.seqera.tower.cli.exceptions.WorkspaceNotFoundException;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.pipelines.PipelinesList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.ListPipelinesResponse;
import io.seqera.tower.model.PipelineQueryAttribute;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

@Command(
Expand Down Expand Up @@ -68,6 +68,6 @@ protected Response exec() throws ApiException, IOException {
}
}

return new PipelinesList(workspaceRef(wspId), response.getPipelines(), baseWorkspaceUrl(wspId), showLabelsOption.showLabels);
return new PipelinesList(workspaceRef(wspId), response.getPipelines(), baseWorkspaceUrl(wspId), showLabelsOption.showLabels, PaginationInfo.from(paginationOptions, response.getTotalSize()));
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/seqera/tower/cli/commands/runs/ListCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.runs.RunList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.ListWorkflowsResponse;
import io.seqera.tower.model.WorkflowQueryAttribute;
import picocli.CommandLine;

import javax.ws.rs.QueryParam;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected Response exec() throws ApiException, IOException {
}

ListWorkflowsResponse response = api().listWorkflows(queryAttribute, wspId, max, offset, startsWith);
return new RunList(workspaceRef(wspId), response.getWorkflows(), baseWorkspaceUrl(wspId), showLabelsOption.showLabels);
return new RunList(workspaceRef(wspId), response.getWorkflows(), baseWorkspaceUrl(wspId), showLabelsOption.showLabels, PaginationInfo.from(paginationOptions, response.getTotalSize()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.seqera.tower.cli.commands.runs.tasks.enums.TaskColumn;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.runs.tasks.TasksView;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.DescribeTaskResponse;
import io.seqera.tower.model.ListTasksResponse;
import io.seqera.tower.model.Task;
Expand Down Expand Up @@ -65,6 +66,6 @@ protected Response exec() throws ApiException, IOException {
Task task = describeTaskResponse.getTask();
tasks.add(task);
}
return new TasksView(parentCommand.id, cols, tasks);
return new TasksView(parentCommand.id, cols, tasks, PaginationInfo.from(paginationOptions));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.seqera.tower.cli.commands.global.PaginationOptions;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.responses.teams.TeamsList;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.model.ListTeamResponse;
import io.seqera.tower.model.OrgAndWorkspaceDbDto;
import picocli.CommandLine;
Expand Down Expand Up @@ -42,6 +43,6 @@ protected Response exec() throws ApiException, IOException {

ListTeamResponse teamResponse = api().listOrganizationTeams(orgAndWorkspaceDbDto.getOrgId(), max, offset, null);

return new TeamsList(organizationRef, teamResponse.getTeams(), baseOrgUrl(orgAndWorkspaceDbDto.getOrgName()));
return new TeamsList(organizationRef, teamResponse.getTeams(), baseOrgUrl(orgAndWorkspaceDbDto.getOrgName()), PaginationInfo.from(paginationOptions, teamResponse.getTotalSize()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

package io.seqera.tower.cli.responses.collaborators;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.MemberDbDto;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.List;

Expand All @@ -23,9 +26,14 @@ public class CollaboratorsList extends Response {
public final Long organizationId;
public final List<MemberDbDto> members;

public CollaboratorsList(Long organizationId, List<MemberDbDto> members) {
@JsonIgnore
@Nullable
private PaginationInfo paginationInfo;

public CollaboratorsList(Long organizationId, List<MemberDbDto> members, @Nullable PaginationInfo paginationInfo) {
this.organizationId = organizationId;
this.members = members;
this.paginationInfo = paginationInfo;
}

@Override
Expand All @@ -44,7 +52,9 @@ public void toString(PrintWriter out) {
});

table.print();
out.println("");

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@

package io.seqera.tower.cli.responses.labels;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.LabelDbDto;
import io.seqera.tower.model.LabelType;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.List;

Expand All @@ -27,10 +30,15 @@ public class ListLabelsCmdResponse extends Response {

public LabelType labelType;

public ListLabelsCmdResponse(Long wspId, LabelType labelType, List<LabelDbDto> labels) {
@JsonIgnore
@Nullable
private PaginationInfo paginationInfo;

public ListLabelsCmdResponse(Long wspId, LabelType labelType, List<LabelDbDto> labels, @Nullable PaginationInfo paginationInfo) {
this.workspaceId = wspId;
this.labels = labels;
this.labelType = labelType;
this.paginationInfo = paginationInfo;
}

@Override
Expand All @@ -55,9 +63,12 @@ public void toString(PrintWriter out) {
label.getValue(),
label.getResource() ? "Resource" : "Normal"
));

table.print();
out.println("");

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

package io.seqera.tower.cli.responses.participants;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.ParticipantDbDto;
import io.seqera.tower.model.ParticipantType;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.List;

Expand All @@ -27,10 +30,15 @@ public class ParticipantsList extends Response {
public final String workspaceName;
public final List<ParticipantDbDto> participants;

public ParticipantsList(String organizationName, String workspaceName, List<ParticipantDbDto> participants) {
@JsonIgnore
@Nullable
private PaginationInfo paginationInfo;

public ParticipantsList(String organizationName, String workspaceName, List<ParticipantDbDto> participants, @Nullable PaginationInfo paginationInfo) {
this.organizationName = organizationName;
this.workspaceName = workspaceName;
this.participants = participants;
this.paginationInfo = paginationInfo;
}

@Override
Expand All @@ -50,6 +58,9 @@ public void toString(PrintWriter out) {
});

table.print();

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.ListActionsResponseActionInfo;
import io.seqera.tower.model.PipelineDbDto;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static io.seqera.tower.cli.utils.FormatHelper.formatPipelineId;
import static io.seqera.tower.cli.utils.FormatHelper.formatLabels;
Expand All @@ -36,11 +36,16 @@ public class PipelinesList extends Response {
@JsonIgnore
private boolean includeLabels;

public PipelinesList(String workspaceRef, List<PipelineDbDto> pipelines, String baseWorkspaceUrl, boolean includeLabels) {
@JsonIgnore
@Nullable
private PaginationInfo paginationInfo;

public PipelinesList(String workspaceRef, List<PipelineDbDto> pipelines, String baseWorkspaceUrl, boolean includeLabels, @Nullable PaginationInfo paginationInfo) {
this.workspaceRef = workspaceRef;
this.pipelines = pipelines;
this.baseWorkspaceUrl = baseWorkspaceUrl;
this.includeLabels = includeLabels;
this.paginationInfo = paginationInfo;
}

@Override
Expand Down Expand Up @@ -70,7 +75,11 @@ public void toString(PrintWriter out) {

table.addRow(rows.toArray(new String[rows.size()]));
});

table.print();

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/io/seqera/tower/cli/responses/runs/RunList.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.ListWorkflowsResponseListWorkflowsElement;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static io.seqera.tower.cli.utils.FormatHelper.formatTime;
import static io.seqera.tower.cli.utils.FormatHelper.formatWorkflowId;
Expand All @@ -36,18 +37,16 @@ public class RunList extends Response {
@JsonIgnore
public final String baseWorkspaceUrl;

public RunList(String workspaceRef, List<ListWorkflowsResponseListWorkflowsElement> runs, String baseWorkspaceUrl, boolean showLabels) {
this.workspaceRef = workspaceRef;
this.workflows = runs;
this.baseWorkspaceUrl = baseWorkspaceUrl;
this.showLabels = showLabels;
}
@JsonIgnore
@Nullable
private final PaginationInfo paginationInfo;

public RunList(String workspaceRef, List<ListWorkflowsResponseListWorkflowsElement> runs, String baseWorkspaceUrl) {
public RunList(String workspaceRef, List<ListWorkflowsResponseListWorkflowsElement> runs, String baseWorkspaceUrl, boolean showLabels, @Nullable PaginationInfo paginationInfo) {
this.workspaceRef = workspaceRef;
this.workflows = runs;
this.baseWorkspaceUrl = baseWorkspaceUrl;
this.showLabels = false;
this.showLabels = showLabels;
this.paginationInfo = paginationInfo;
}

@Override
Expand Down Expand Up @@ -83,8 +82,10 @@ public void toString(PrintWriter out) {
table.addRow(rowsArray);
});


table.print();

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

package io.seqera.tower.cli.responses.runs.tasks;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.seqera.tower.cli.commands.runs.tasks.enums.TaskColumn;
import io.seqera.tower.cli.responses.Response;
import io.seqera.tower.cli.utils.PaginationInfo;
import io.seqera.tower.cli.utils.TableList;
import io.seqera.tower.model.Task;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,10 +31,15 @@ public class TasksView extends Response {
public final List<TaskColumn> columns;
public final List<Task> tasks;

public TasksView(String runId, List<TaskColumn> columns, List<Task> tasks) {
@JsonIgnore
@Nullable
private PaginationInfo paginationInfo;

public TasksView(String runId, List<TaskColumn> columns, List<Task> tasks, @Nullable PaginationInfo paginationInfo) {
this.runId = runId;
this.columns = columns;
this.tasks = tasks;
this.paginationInfo = paginationInfo;
}

@Override
Expand Down Expand Up @@ -64,7 +72,11 @@ public void toString(PrintWriter out) {
result.forEach(it -> {
table.addRow(it.toArray(new String[0]));
});

table.print();

PaginationInfo.addFooter(out, paginationInfo);

out.println("");
}
}

0 comments on commit 4aa4bdb

Please sign in to comment.