Search in sources :

Example 1 with JpaAlertChangeEvent

use of com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent in project kylo by Teradata.

the class DefaultAlertManager method updateAlertChangeEntry.

protected <C extends Serializable> Alert updateAlertChangeEntry(JpaAlert.AlertId id, String descr, C content) {
    final Principal user = SecurityContextHolder.getContext().getAuthentication() != null ? SecurityContextHolder.getContext().getAuthentication() : null;
    Alert changed = this.metadataAccess.commit(() -> {
        JpaAlert alert = findAlert(id).orElseThrow(() -> new AlertNotfoundException(id));
        List<AlertChangeEvent> events = alert.getEvents();
        if (events != null && !events.isEmpty()) {
            JpaAlertChangeEvent event = (JpaAlertChangeEvent) events.get(0);
            event.setDescription(descr);
            event.setContent(content);
            event.setChangeTime(DateTime.now());
        }
        return asValue(alert);
    }, MetadataAccess.SERVICE);
    updateLastUpdatedTime();
    notifyReceivers(1);
    return changed;
}
Also used : AlertNotfoundException(com.thinkbiganalytics.alerts.api.AlertNotfoundException) JpaAlertChangeEvent(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent) Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Principal(java.security.Principal) AlertChangeEvent(com.thinkbiganalytics.alerts.api.AlertChangeEvent) JpaAlertChangeEvent(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent)

Example 2 with JpaAlertChangeEvent

use of com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent in project kylo by Teradata.

the class DefaultAlertManager method changeAlert.

protected <C extends Serializable> Alert changeAlert(JpaAlert.AlertId id, State state, String descr, C content) {
    final Principal user = SecurityContextHolder.getContext().getAuthentication() != null ? SecurityContextHolder.getContext().getAuthentication() : null;
    Alert changed = this.metadataAccess.commit(() -> {
        JpaAlert alert = findAlert(id).orElseThrow(() -> new AlertNotfoundException(id));
        JpaAlertChangeEvent event = new JpaAlertChangeEvent(state, user, descr, content);
        alert.addEvent(event);
        // need to save it
        repository.save(alert);
        return asValue(alert);
    }, MetadataAccess.SERVICE);
    updateLastUpdatedTime();
    notifyReceivers(1);
    return changed;
}
Also used : AlertNotfoundException(com.thinkbiganalytics.alerts.api.AlertNotfoundException) JpaAlertChangeEvent(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent) Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Principal(java.security.Principal)

Example 3 with JpaAlertChangeEvent

use of com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent in project kylo by Teradata.

the class KyloEntityAwareAlertManager method entityDeleted.

public Iterator<Alert> entityDeleted(AlertCriteria criteria, String message) {
    log.info("Query for Entity Alerts data");
    List<Alert> handledAlerts = this.metadataAccess.commit(() -> {
        List<Alert> alerts = new ArrayList<>();
        criteria.state(Alert.State.UNHANDLED);
        KyloEntityAwareAlertCriteria critImpl = ensureAlertCriteriaType(criteria);
        critImpl.createEntityQuery().fetch().stream().forEach(jpaAlert -> {
            JpaAlertChangeEvent event = new JpaAlertChangeEvent(Alert.State.HANDLED, MetadataAccess.SERVICE, message, null);
            jpaAlert.addEvent(event);
            // hide it
            jpaAlert.setCleared(true);
            alerts.add(asValue(jpaAlert));
        });
        return alerts;
    }, MetadataAccess.SERVICE);
    return handledAlerts.iterator();
}
Also used : KyloEntityAwareAlertCriteria(com.thinkbiganalytics.alerts.spi.defaults.KyloEntityAwareAlertCriteria) ArrayList(java.util.ArrayList) JpaAlertChangeEvent(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent) Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) EntityAlert(com.thinkbiganalytics.alerts.api.EntityAlert)

Aggregations

Alert (com.thinkbiganalytics.alerts.api.Alert)3 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)3 JpaAlertChangeEvent (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent)3 AlertNotfoundException (com.thinkbiganalytics.alerts.api.AlertNotfoundException)2 Principal (java.security.Principal)2 AlertChangeEvent (com.thinkbiganalytics.alerts.api.AlertChangeEvent)1 EntityAlert (com.thinkbiganalytics.alerts.api.EntityAlert)1 KyloEntityAwareAlertCriteria (com.thinkbiganalytics.alerts.spi.defaults.KyloEntityAwareAlertCriteria)1 ArrayList (java.util.ArrayList)1