Search in sources :

Example 1 with JpaAlert

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

the class DefaultAlertCriteria method createQuery.

public JPAQuery<JpaAlert> createQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    JPAQuery<JpaAlert> query = queryFactory.select(alert).from(alert).limit(getLimit());
    List<Predicate> preds = filter(alert);
    BooleanBuilder orFilter = orFilter(alert);
    // In all other cases sort descending. The results will be ordered correctly when aggregated by the provider.
    if (getLimit() != Integer.MAX_VALUE && getAfterTime() != null && getBeforeTime() == null) {
        query.orderBy(alert.createdTime.asc());
    } else {
        query.orderBy(alert.createdTime.desc());
    }
    return addWhere(query, preds, orFilter);
}
Also used : QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) Predicate(com.querydsl.core.types.Predicate)

Example 2 with JpaAlert

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

the class DefaultAlertManager method create.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.alerts.spi.AlertManager#create(java.net.URI, com.thinkbiganalytics.alerts.api.Alert.Level, java.lang.String, java.io.Serializable)
     */
@Override
public <C extends Serializable> Alert create(URI type, String subtype, Level level, String description, C content) {
    final Principal user = SecurityContextHolder.getContext().getAuthentication() != null ? SecurityContextHolder.getContext().getAuthentication() : null;
    // reset the subtype if the content is an Entity
    if (subtype == null) {
        subtype = "Other";
    }
    if (content != null && content instanceof EntityIdentificationAlertContent) {
        subtype = "Entity";
    }
    final String finalSubType = subtype;
    Alert created = this.metadataAccess.commit(() -> {
        JpaAlert alert = new JpaAlert(type, finalSubType, level, user, description, content);
        this.repository.save(alert);
        return asValue(alert);
    }, MetadataAccess.SERVICE);
    updateLastUpdatedTime();
    notifyReceivers(1);
    return created;
}
Also used : Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Principal(java.security.Principal) EntityIdentificationAlertContent(com.thinkbiganalytics.alerts.spi.EntityIdentificationAlertContent)

Example 3 with JpaAlert

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

the class DefaultAlertManager method remove.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.alerts.spi.AlertManager#remove(com.thinkbiganalytics.alerts.api.Alert.ID)
     */
@Override
public Alert remove(Alert.ID id) {
    JpaAlert.AlertId idImpl = (JpaAlert.AlertId) resolve(id);
    JpaAlert jpaAlert = this.metadataAccess.commit(() -> {
        JpaAlert alert = repository.findOne(idImpl);
        this.repository.delete(id);
        return alert;
    }, MetadataAccess.SERVICE);
    updateLastUpdatedTime();
    return jpaAlert;
}
Also used : AlertId(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert.AlertId) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) AlertId(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert.AlertId)

Example 4 with JpaAlert

use of com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert 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 5 with JpaAlert

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

the class KyloEntityAwareAlertCriteria method createQuery.

public JPAQuery<JpaAlert> createQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    QJpaOpsManagerFeed slaFeed = new QJpaOpsManagerFeed("slaFeed");
    QJpaServiceLevelAgreementDescription sla = QJpaServiceLevelAgreementDescription.jpaServiceLevelAgreementDescription;
    JPAQuery<JpaAlert> query = queryFactory.select(alert).distinct().from(alert).leftJoin(feed).on(feed.id.uuid.eq(alert.entityId.value).and(alert.entityType.eq(Expressions.stringPath("'FEED'")))).leftJoin(sla).on(sla.slaId.uuid.eq(alert.entityId.value).and(alert.entityType.eq(Expressions.stringPath("'SLA'")))).leftJoin(sla.feeds, slaFeed).limit(getLimit());
    List<Predicate> preds = filter(alert);
    boolean entityAccessControlled = !isAsServiceAccount() && controller.isEntityAccessControlled();
    preds.add(feed.isNull().or(feed.isNotNull().and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, entityAccessControlled))));
    preds.add(slaFeed.isNull().or(slaFeed.isNotNull().and(FeedAclIndexQueryAugmentor.generateExistsExpression(slaFeed.id, entityAccessControlled))));
    BooleanBuilder orFilter = orFilter(alert, feed, sla);
    addEntityFilter(alert, preds);
    // In all other cases sort descending. The results will be ordered correctly when aggregated by the provider.
    if (getLimit() != Integer.MAX_VALUE && getAfterTime() != null && getBeforeTime() == null) {
        query.orderBy(alert.createdTime.asc());
    } else {
        query.orderBy(alert.createdTime.desc());
    }
    return super.addWhere(query, preds, orFilter);
}
Also used : QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) QJpaServiceLevelAgreementDescription(com.thinkbiganalytics.metadata.jpa.sla.QJpaServiceLevelAgreementDescription) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) Predicate(com.querydsl.core.types.Predicate)

Aggregations

JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)10 Alert (com.thinkbiganalytics.alerts.api.Alert)4 BooleanBuilder (com.querydsl.core.BooleanBuilder)3 Predicate (com.querydsl.core.types.Predicate)3 JpaAlertChangeEvent (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlertChangeEvent)3 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)3 Principal (java.security.Principal)3 AlertNotfoundException (com.thinkbiganalytics.alerts.api.AlertNotfoundException)2 AlertChangeEvent (com.thinkbiganalytics.alerts.api.AlertChangeEvent)1 EntityAlert (com.thinkbiganalytics.alerts.api.EntityAlert)1 EntityIdentificationAlertContent (com.thinkbiganalytics.alerts.spi.EntityIdentificationAlertContent)1 KyloEntityAwareAlertCriteria (com.thinkbiganalytics.alerts.spi.defaults.KyloEntityAwareAlertCriteria)1 AlertId (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert.AlertId)1 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)1 QJpaServiceLevelAgreementDescription (com.thinkbiganalytics.metadata.jpa.sla.QJpaServiceLevelAgreementDescription)1 ArrayList (java.util.ArrayList)1