class DeviceHealthManagerImpl implements DeviceHealthManager {

    @Override
    public void updateHealth(final String deviceName) {

        Device device = deviceManager.getDevice(deviceName);

        if (null == device) {
            throw new IllegalArgumentException("No device with name: " + deviceName);
        }

        List<DeviceState> deviceStates = deviceStateManager.getStates(device);
        Report report = null;
        try {
            ReportSummary latestReportSummary =
                    reportSummaryManager.getNewestReport(device.getName());
            // if there's no (latest) report for this device, set the health to Unknown
            if (null == latestReportSummary) {
                LOGGER.warn("No latest report for {}. Setting health status to Unknown", device);
                device.setHealthStatus(HealthStatus.UNKNOWN);
            } else {
                report = latestReportSummary.getReport();
            }
        } catch (Exception e) {
            LOGGER.warn("Failed to get latest report for {}. "
                    + "Setting health status to Unknown", device, e);
            device.setHealthStatus(HealthStatus.UNKNOWN);
        }

        if (null != report) {
            Disjunction disjunction = Restrictions.disjunction();
            boolean hasValidCriterions = false;
            for (DeviceState state : deviceStates) {
                Criterion criterion = state.getDeviceTrustAlertCriterion();
                if (null != criterion) {
                    disjunction.add(criterion);
                    hasValidCriterions = true;
                }
            }
            if (!hasValidCriterions) {
                disjunction = null;
            }

            int alertCount = alertManager.getTrustAlertCount(device, report, disjunction);
            LOGGER.info("Found {} trust alerts for {}", alertCount, device);
            if (alertCount > 0) {
                device.setHealthStatus(HealthStatus.UNTRUSTED);
            } else {
                device.setHealthStatus(HealthStatus.TRUSTED);
            }
        }
        deviceManager.updateDevice(device);
    }

}