Changed the structure of the response body for Distribution statistics (#1397)

* changed the structure of the response body

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Fixed tests

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* refactoring

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

---------

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>
This commit is contained in:
Denislav Prinov
2023-07-17 13:46:52 +03:00
committed by GitHub
parent 56ea5b15c9
commit 71740ccdda
3 changed files with 36 additions and 36 deletions

View File

@@ -16,20 +16,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtDistributionSetStatistics {
private static final String TOTAL = "total";
@JsonProperty
@JsonProperty("actions")
private Map<String, Long> totalActionsPerStatus;
@JsonProperty
@JsonProperty("rollouts")
private Map<String, Long> totalRolloutsPerStatus;
@JsonProperty
private Long totalAutoAssignments;
private MgmtDistributionSetStatistics() {
// Private constructor to enforce the use of the builder pattern
}
@@ -47,14 +46,15 @@ public class MgmtDistributionSetStatistics {
}
public static class Builder {
private Map<String, Long> totalActionsPerStatus;
private Map<String, Long> totalRolloutsPerStatus;
private final Map<String, Long> totalActionsPerStatus;
private final Map<String, Long> totalRolloutsPerStatus;
private Long totalAutoAssignments;
private final boolean fullRepresentation;
public Builder() {
public Builder(boolean fullRepresentation) {
totalActionsPerStatus = new HashMap<>();
totalRolloutsPerStatus = new HashMap<>();
this.fullRepresentation = fullRepresentation;
}
public Builder addTotalActionPerStatus(String status, Long count) {
@@ -76,13 +76,13 @@ public class MgmtDistributionSetStatistics {
MgmtDistributionSetStatistics statistics = new MgmtDistributionSetStatistics();
statistics.totalActionsPerStatus = calculateTotalWithStatus(totalActionsPerStatus);
statistics.totalRolloutsPerStatus = calculateTotalWithStatus(totalRolloutsPerStatus);
statistics.totalAutoAssignments = totalAutoAssignments;
statistics.totalAutoAssignments = fullRepresentation ? (totalAutoAssignments == null ? Long.valueOf(0) : totalAutoAssignments) : totalAutoAssignments;
return statistics;
}
private Map<String, Long> calculateTotalWithStatus(Map<String, Long> statusMap) {
if (statusMap.isEmpty()) {
return null;
if (!fullRepresentation && statusMap.isEmpty()) {
return statusMap;
}
long total = statusMap.values().stream().mapToLong(Long::longValue).sum();