Query deleteNotificationLogsQuery = null;
Query deleteAlertsQuery = null;
if (context.type == EntityContext.Type.Resource) {
if (!authorizationManager.hasResourcePermission(subject, Permission.MANAGE_ALERTS, context.resourceId)) {
throw new PermissionException("Can not delete alerts - " + subject + " lacks "
+ Permission.MANAGE_ALERTS + " for resource[id=" + context.resourceId + "]");
}
deleteConditionLogsQuery = entityManager.createNamedQuery(AlertConditionLog.QUERY_DELETE_BY_RESOURCES);
deleteConditionLogsQuery.setParameter("resourceIds", Arrays.asList(context.resourceId));
deleteNotificationLogsQuery = entityManager
.createNamedQuery(AlertNotificationLog.QUERY_DELETE_BY_RESOURCES);
deleteNotificationLogsQuery.setParameter("resourceIds", Arrays.asList(context.resourceId));
deleteAlertsQuery = entityManager.createNamedQuery(Alert.QUERY_DELETE_BY_RESOURCES);
deleteAlertsQuery.setParameter("resourceIds", Arrays.asList(context.resourceId));
} else if (context.type == EntityContext.Type.ResourceGroup) {
if (!authorizationManager.hasGroupPermission(subject, Permission.MANAGE_ALERTS, context.groupId)) {
throw new PermissionException("Can not delete alerts - " + subject + " lacks "
+ Permission.MANAGE_ALERTS + " for group[id=" + context.groupId + "]");
}
deleteConditionLogsQuery = entityManager
.createNamedQuery(AlertConditionLog.QUERY_DELETE_BY_RESOURCE_GROUPS);
deleteConditionLogsQuery.setParameter("groupIds", Arrays.asList(context.groupId));
deleteNotificationLogsQuery = entityManager
.createNamedQuery(AlertNotificationLog.QUERY_DELETE_BY_RESOURCE_GROUPS);
deleteNotificationLogsQuery.setParameter("groupIds", Arrays.asList(context.groupId));
deleteAlertsQuery = entityManager.createNamedQuery(Alert.QUERY_DELETE_BY_RESOURCE_GROUPS);
deleteAlertsQuery.setParameter("groupIds", Arrays.asList(context.groupId));
} else if (context.type == EntityContext.Type.SubsystemView) {
if (!authorizationManager.isInventoryManager(subject)) {
throw new PermissionException("Can not delete alerts - " + subject + " lacks "
+ Permission.MANAGE_INVENTORY + " for global alerts history");
}
deleteConditionLogsQuery = entityManager.createNamedQuery(AlertConditionLog.QUERY_DELETE_ALL);
deleteNotificationLogsQuery = entityManager.createNamedQuery(AlertNotificationLog.QUERY_DELETE_ALL);
deleteAlertsQuery = entityManager.createNamedQuery(Alert.QUERY_DELETE_ALL);