Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): Exclude Disabled pipelines query parameter #1520

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,45 @@ public Collection<Pipeline> getTriggeredPipelines(
public List<Pipeline> listByApplication(
@PathVariable(value = "application") String application,
@RequestParam(value = "pipelineNameFilter", required = false) String pipelineNameFilter,
@RequestParam(required = false, value = "refresh", defaultValue = "true") boolean refresh) {
@RequestParam(required = false, value = "refresh", defaultValue = "true") boolean refresh,
@RequestParam(required = false, value = "pipelineStateFilter", defaultValue = "all")
String pipelineStateFilter) {
List<Pipeline> pipelines =
new ArrayList<>(
pipelineDAO.getPipelinesByApplication(application, pipelineNameFilter, refresh));

if (pipelineStateFilter.isEmpty() || pipelineStateFilter.equalsIgnoreCase("all")) {
return sortPipelines(pipelines);
}

Boolean enabledPipelines;
if (pipelineStateFilter.equalsIgnoreCase("enabled")) {
enabledPipelines = true;
} else if (pipelineStateFilter.equalsIgnoreCase("disabled")) {
enabledPipelines = false;
} else {
enabledPipelines = null;
}

Predicate<Pipeline> pipelinePredicate =
pipeline -> {
// pipeline.getDisabled may be null, so check that before comparing. If
// pipeline.getDisabled is null, the pipeline is enabled.
boolean pipelineEnabled =
(pipeline.getDisabled() == null) || (pipeline.getDisabled() == false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: MIght use the Optional stuff here :)


return ((enabledPipelines == null) || (pipelineEnabled == enabledPipelines));
};

List<Pipeline> retval =
pipelines.stream().filter(pipelinePredicate).collect(Collectors.toList());

log.debug("returning {} of {} total pipeline(s)", retval.size(), pipelines.size());

return sortPipelines(retval);
}

private List<Pipeline> sortPipelines(List<Pipeline> pipelines) {
pipelines.sort(
(p1, p2) -> {
if (p1.getIndex() != null && p2.getIndex() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ abstract class PipelineControllerTck extends Specification {
void "should provide a valid, unique index when listing all for an application"() {
given:
pipelineDAO.create(null, new Pipeline([
name: "c", application: "test"
name: "c", application: "test", "disabled": true
]))
pipelineDAO.create(null, new Pipeline([
name: "b", application: "test"
Expand All @@ -149,7 +149,7 @@ abstract class PipelineControllerTck extends Specification {
name: "b1", application: "test", index: 1
]))
pipelineDAO.create(null, new Pipeline([
name: "a3", application: "test", index: 3
name: "a3", application: "test", index: 3, "disabled": true
]))

when:
Expand All @@ -161,6 +161,40 @@ abstract class PipelineControllerTck extends Specification {
.andExpect(jsonPath('$.[*].index').value([0, 1, 2, 3, 4]))
}

@Unroll
void "should provide a valid, unique index when listing all for an application excluding the disabled Pipelines - pipelineStateFilter"() {
given:
pipelineDAO.create(null, new Pipeline([
name: "c", application: "test", "disabled": true
]))
pipelineDAO.create(null, new Pipeline([
name: "b", application: "test"
]))
pipelineDAO.create(null, new Pipeline([
name: "a1", application: "test", index: 1
]))
pipelineDAO.create(null, new Pipeline([
name: "b1", application: "test", index: 1
]))
pipelineDAO.create(null, new Pipeline([
name: "a3", application: "test", index: 3, "disabled": true
]))

when:
def response = mockMvc.perform(get("/pipelines/test?pipelineStateFilter=${filter}"))

then:
response
.andExpect(jsonPath('$.[*].name').value(nameExpectedArray))
.andExpect(jsonPath('$.[*].index').value(indexExpectedArray))

where:
filter || nameExpectedArray | indexExpectedArray
"all" || ["a1","b1","a3","b","c"] | [0, 1, 2, 3, 4]
"disabled" || ["a3", "c"] | [0, 1]
"enabled" || ["a1","b1","b"] | [0, 1, 2]
}

void "should use pipelineNameFilter when getting pipelines for an application"() {
given:
pipelineDAO.create("0", new Pipeline(application: "test", name: "pipelineName1"))
Expand Down
Loading