Search in sources :

Example 1 with QJpaAlert

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

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

the class DefaultAlertCriteria method createSummaryQuery.

public JPAQuery<AlertSummary> createSummaryQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    JPAQuery query = queryFactory.select(Projections.bean(DefaultAlertSummary.class, alert.typeString.as("type"), alert.subtype.as("subtype"), alert.level.as("level"), alert.count().as("count"), alert.createdTimeMillis.max().as("lastAlertTimestamp"))).from(alert).groupBy(alert.typeString, alert.subtype, alert.level);
    List<Predicate> preds = filter(alert);
    BooleanBuilder orFilter = orFilter(alert);
    return (JPAQuery<AlertSummary>) addWhere(query, preds, orFilter);
}
Also used : QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) DefaultAlertSummary(com.thinkbiganalytics.metadata.jpa.alerts.DefaultAlertSummary) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Predicate(com.querydsl.core.types.Predicate)

Example 3 with QJpaAlert

use of com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert 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)

Example 4 with QJpaAlert

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

the class KyloEntityAwareAlertCriteria method createEntityQuery.

public JPAQuery<JpaAlert> createEntityQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    JPAQuery<JpaAlert> query = queryFactory.select(alert).from(alert).limit(getLimit());
    List<Predicate> preds = filter(alert);
    addEntityFilter(alert, preds);
    if (entityCriteria == null || entityCriteria.isEmpty()) {
        log.warn("Unable to apply Entity Query.  No Entity Criteria was specified!");
        preds.add(Expressions.stringTemplate("1").eq(Expressions.stringTemplate("2")));
    }
    return super.addWhere(query, preds, new BooleanBuilder());
}
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 5 with QJpaAlert

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

the class KyloEntityAwareAlertCriteria method orFilter.

private BooleanBuilder orFilter(QJpaAlert alert, QJpaOpsManagerFeed feed, QJpaServiceLevelAgreementDescription sla) {
    BooleanBuilder globalFilter = new BooleanBuilder();
    if (StringUtils.isNotBlank(getOrFilter())) {
        Lists.newArrayList(StringUtils.split(getOrFilter(), ",")).stream().forEach(filter -> {
            filter = StringUtils.trim(filter);
            if (filter != null) {
                List<String> in = null;
                if (filter.contains("||")) {
                    // replace the OR || with commas for IN clause
                    in = Arrays.asList(StringUtils.split(filter, "||")).stream().map(f -> StringUtils.trim(f)).collect(Collectors.toList());
                    filter = in.stream().collect(Collectors.joining(","));
                }
                BooleanBuilder booleanBuilder = new BooleanBuilder();
                List<Predicate> preds = new ArrayList<>();
                try {
                    Alert.State state = Alert.State.valueOf(filter.toUpperCase());
                    preds.add(alert.state.eq(state));
                } catch (IllegalArgumentException e) {
                }
                if (in != null) {
                    preds.add(alert.description.in(in));
                    preds.add(alert.entityType.in(in));
                    preds.add(alert.typeString.in(in));
                    preds.add(alert.subtype.in(in));
                    // add in joins on the feed or sla name
                    addOrFilter(feed, CommonFilterTranslations.feedFilters, preds, filter);
                    addOrFilter(sla, KyloEntityAwareAlertManager.alertSlaFilters, preds, filter);
                } else {
                    preds.add(alert.description.likeIgnoreCase(filter.concat("%")));
                    preds.add(alert.entityType.likeIgnoreCase(filter.concat("%")));
                    preds.add(alert.typeString.likeIgnoreCase(filter.concat("%")));
                    preds.add(alert.subtype.like(filter.concat("%")));
                    // add in joins on the feed or sla name
                    addOrFilter(feed, CommonFilterTranslations.feedFilters, preds, filter);
                    addOrFilter(sla, KyloEntityAwareAlertManager.alertSlaFilters, preds, filter);
                }
                booleanBuilder.andAnyOf(preds.toArray(new Predicate[preds.size()]));
                globalFilter.and(booleanBuilder);
            }
        });
    }
    return globalFilter;
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) Alert(com.thinkbiganalytics.alerts.api.Alert) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) Predicate(com.querydsl.core.types.Predicate)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)8 Predicate (com.querydsl.core.types.Predicate)8 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)8 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)6 JPAQuery (com.querydsl.jpa.impl.JPAQuery)3 Alert (com.thinkbiganalytics.alerts.api.Alert)3 ArrayList (java.util.ArrayList)3 DefaultAlertSummary (com.thinkbiganalytics.metadata.jpa.alerts.DefaultAlertSummary)2 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)2 QJpaServiceLevelAgreementDescription (com.thinkbiganalytics.metadata.jpa.sla.QJpaServiceLevelAgreementDescription)2 Lists (com.google.common.collect.Lists)1 QueryBase (com.querydsl.core.support.QueryBase)1 Projections (com.querydsl.core.types.Projections)1 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)1 AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)1 BaseAlertCriteria (com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria)1 List (java.util.List)1 StringUtils (org.apache.commons.lang3.StringUtils)1