@Override
public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
for (Capacity summedCapacity : result) {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
capacityResponse.setCapacityType(summedCapacity.getCapacityType());
capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
if (summedCapacity.getPodId() != null) {
capacityResponse.setPodId(ApiDBUtils.findPodById(summedCapacity.getPodId()).getUuid());
HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
if (pod != null) {
capacityResponse.setPodId(pod.getUuid());
capacityResponse.setPodName(pod.getName());
}
}
if (summedCapacity.getClusterId() != null) {
ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
if (cluster != null) {
capacityResponse.setClusterId(cluster.getUuid());
capacityResponse.setClusterName(cluster.getName());
if (summedCapacity.getPodId() == null) {
HostPodVO pod = ApiDBUtils.findPodById(cluster.getPodId());
capacityResponse.setPodId(pod.getUuid());
capacityResponse.setPodName(pod.getName());
}
}
}
DataCenter zone = ApiDBUtils.findZoneById(summedCapacity.getDataCenterId());
if (zone != null) {
capacityResponse.setZoneId(zone.getUuid());
capacityResponse.setZoneName(zone.getName());
}
if (summedCapacity.getUsedPercentage() != null) {
capacityResponse.setPercentUsed(format.format(summedCapacity.getUsedPercentage() * 100f));
} else if (summedCapacity.getTotalCapacity() != 0) {
capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity()
* 100f));
} else {
capacityResponse.setPercentUsed(format.format(0L));
}
capacityResponse.setObjectName("capacity");
capacityResponses.add(capacityResponse);
}
return capacityResponses;
}