Skip to content

Commit

Permalink
[#9317] Add default parameter for AgentListController
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Dec 9, 2022
1 parent 9382632 commit eabe4a8
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* @author intr3p1d
Expand All @@ -29,14 +30,19 @@
public class AgentListController {
private final AgentInfoService agentInfoService;

private SortByAgentInfo.Rules DEFAULT_SORTBY = SortByAgentInfo.Rules.AGENT_ID_ASC;

public AgentListController(AgentInfoService agentInfoService) {
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
}

@GetMapping(value = "/search-all")
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() {
long timestamp = System.currentTimeMillis();
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, Range.between(timestamp, timestamp));
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(
AgentInfoFilter::accept,
Range.between(timestamp, timestamp)
);
return treeView(allAgentsList);
}

Expand All @@ -45,7 +51,10 @@ public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList(
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter filter = new DefaultAgentInfoFilter(from);
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, Range.between(from, to));
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(
filter,
Range.between(from, to)
);
return treeView(allAgentsList);
}

Expand All @@ -55,28 +64,40 @@ private static TreeView<InstancesList<AgentAndStatus>> treeView(AgentsMapByAppli
}


@GetMapping(value = "/search-application", params = {"application", "sortBy"})
@GetMapping(value = "/search-application", params = {"application"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") String applicationName,
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) {
@RequestParam(value = "sortBy") Optional<SortByAgentInfo.Rules> sortBy) {
SortByAgentInfo.Rules paramSortBy = sortBy.orElse(DEFAULT_SORTBY);
long timestamp = System.currentTimeMillis();
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning
);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, Range.between(timestamp, timestamp), sortBy);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
runningAgentFilter,
applicationName,
Range.between(timestamp, timestamp),
paramSortBy
);
return treeView(list);
}

@GetMapping(value = "/search-application", params = {"application", "from", "to", "sortBy"})
@GetMapping(value = "/search-application", params = {"application", "from", "to"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") String applicationName,
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) {
@RequestParam(value = "sortBy") Optional<SortByAgentInfo.Rules> sortBy) {
SortByAgentInfo.Rules paramSortBy = sortBy.orElse(DEFAULT_SORTBY);
AgentInfoFilter currentRunFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(from)
);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, Range.between(from, to), sortBy);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
currentRunFilter,
applicationName,
Range.between(from, to),
paramSortBy
);
return treeView(list);
}

Expand Down

0 comments on commit eabe4a8

Please sign in to comment.