Skip to content

Commit

Permalink
feat(web): Exclude Disabled pipelines query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
christosarvanitis committed Dec 19, 2024
1 parent 38e9529 commit edd381b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,36 @@ 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", defaultValue = "false")
Boolean enabledPipelines) {
List<Pipeline> pipelines =
new ArrayList<>(
pipelineDAO.getPipelinesByApplication(application, pipelineNameFilter, refresh));

if (!enabledPipelines) {
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,33 @@ abstract class PipelineControllerTck extends Specification {
.andExpect(jsonPath('$.[*].index').value([0, 1, 2, 3, 4]))
}

void "should provide a valid, unique index when listing all for an application excluding the disabled Pipelines - enabledPipelines=true"() {
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=true"))

then:
response
.andExpect(jsonPath('$.[*].name').value(["a1", "b1", "b"]))
.andExpect(jsonPath('$.[*].index').value([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 edd381b

Please sign in to comment.