return new PageList<AlertDefinition>(list, (int) totalCount, pageControl);
}
@Override
public AlertDefinition getAlertDefinitionById(Subject subject, int alertDefinitionId) {
AlertDefinition alertDefinition = entityManager.find(AlertDefinition.class, alertDefinitionId);
if (alertDefinition == null) {
return null; // fail-fast to avoid downstream NPEs
}
if (checkViewPermission(subject, alertDefinition) == false) {
throw new PermissionException("User[" + subject.getName()
+ "] does not have permission to view alertDefinition[id=" + alertDefinitionId + "] for resource[id="
+ alertDefinition.getResource().getId() + "]");
}
alertDefinition.getConditions().size();
// this is now lazy
for (AlertCondition cond : alertDefinition.getConditions()) {
if (cond.getMeasurementDefinition() != null) {
cond.getMeasurementDefinition().getId();
}
}
// DO NOT LOAD ALL ALERTS FOR A DEFINITION... This would be all alerts that have been fired
//alertDefinition.getAlertsForResource().size();
for (AlertNotification notification : alertDefinition.getAlertNotifications()) {
notification.getConfiguration().getProperties().size(); // eager load configuration and properties too
if (notification.getExtraConfiguration() != null) {
notification.getExtraConfiguration().getProperties().size();
}
}