Skip to content

Commit

Permalink
feat(web): Exclude Disabled pipelines query parameter (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis authored Jan 17, 2025
1 parent cde8367 commit f22ddd2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,35 @@ 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 = "enabledPipelines") Boolean enabledPipelines) {
List<Pipeline> pipelines =
new ArrayList<>(
pipelineDAO.getPipelinesByApplication(application, pipelineNameFilter, refresh));

if (enabledPipelines == null) {
return sortPipelines(pipelines);
}

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);

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 - enabledPipelines"() {
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?enabledPipelines=${filter}"))

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

where:
filter || nameExpectedArray | indexExpectedArray
"" || ["a1","b1","a3","b","c"] | [0, 1, 2, 3, 4]
false || ["a3", "c"] | [0, 1]
true || ["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

0 comments on commit f22ddd2

Please sign in to comment.