ParseQueueStats(ParseJson<QueueStats> json) {
this.json = checkNotNull(json, "json");
}
public QueueStats apply(HttpResponse from) {
QueueStats rawQueueStats = json.apply(from);
if (rawQueueStats.getMessagesStats().getTotal() == 0) {
return rawQueueStats;
}
else {
// change the hrefs to ids
Aged oldestWithHref = rawQueueStats.getMessagesStats().getOldest().get();
Aged oldestWithId = oldestWithHref.toBuilder()
.id(TO_ID_FROM_HREF.apply(oldestWithHref.getId()))
.build();
Aged newestWithHref = rawQueueStats.getMessagesStats().getNewest().get();
Aged newestWithId = newestWithHref.toBuilder()
.id(TO_ID_FROM_HREF.apply(newestWithHref.getId()))
.build();
MessagesStats messagesStatsWithIds = rawQueueStats.getMessagesStats().toBuilder()
.oldest(oldestWithId)
.newest(newestWithId)
.build();
QueueStats queueStatsWithIds = rawQueueStats.toBuilder().messageStats(messagesStatsWithIds).build();
return queueStatsWithIds;
}
}