Search in sources :

Example 1 with SourceAlert

use of com.thinkbiganalytics.alerts.api.SourceAlert in project kylo by Teradata.

the class AlertsModel method toModel.

public com.thinkbiganalytics.alerts.rest.model.Alert toModel(com.thinkbiganalytics.alerts.api.Alert alert) {
    com.thinkbiganalytics.alerts.api.Alert baseAlert = alert;
    try {
        if (Proxy.isProxyClass(alert.getClass())) {
            SourceAlert sourceAlert = (SourceAlert) Proxy.getInvocationHandler(alert);
            if (sourceAlert != null) {
                baseAlert = sourceAlert.getWrappedAlert();
            }
        }
    } catch (Exception e) {
        // unable to get base alert from proxy.  log the exception but continue
        log.error("Unable to get base alert from wrapped proxy for : {}, {} ", alert, e.getMessage(), e);
    }
    com.thinkbiganalytics.alerts.rest.model.Alert result = new com.thinkbiganalytics.alerts.rest.model.Alert();
    result.setId(alert.getId().toString());
    result.setActionable(alert.isActionable());
    result.setCreatedTime(alert.getCreatedTime());
    result.setLevel(toModel(alert.getLevel()));
    result.setState(toModel(alert.getState()));
    result.setType(alert.getType());
    result.setDescription(alert.getDescription());
    result.setCleared(alert.isCleared());
    result.setContent(alert.getContent() != null ? alert.getContent().toString() : null);
    result.setSubtype(alert.getSubtype());
    alert.getEvents().forEach(e -> result.getEvents().add(toModel(e)));
    if (baseAlert instanceof EntityAlert) {
        result.setEntityId(((EntityAlert) baseAlert).getEntityId() != null ? ((EntityAlert) baseAlert).getEntityId().toString() : null);
        result.setEntityType(((EntityAlert) baseAlert).getEntityType());
    }
    return result;
}
Also used : SourceAlert(com.thinkbiganalytics.alerts.api.SourceAlert) SourceAlert(com.thinkbiganalytics.alerts.api.SourceAlert) EntityAlert(com.thinkbiganalytics.alerts.api.EntityAlert) Alert(com.thinkbiganalytics.alerts.rest.model.Alert) Alert(com.thinkbiganalytics.alerts.rest.model.Alert) EntityAlert(com.thinkbiganalytics.alerts.api.EntityAlert)

Aggregations

EntityAlert (com.thinkbiganalytics.alerts.api.EntityAlert)1 SourceAlert (com.thinkbiganalytics.alerts.api.SourceAlert)1 Alert (com.thinkbiganalytics.alerts.rest.model.Alert)1