Search in sources :

Example 6 with QJpaAlert

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

the class DefaultAlertCriteria method filter.

protected List<Predicate> filter(QJpaAlert alert) {
    List<Predicate> preds = new ArrayList<>();
    if (getStates().size() > 0) {
        preds.add(alert.state.in(getStates()));
    }
    if (getLevels().size() > 0) {
        preds.add(alert.level.in(getLevels()));
    }
    if (getAfterTime() != null) {
        preds.add(alert.createdTime.gt(getAfterTime()));
    }
    if (getBeforeTime() != null) {
        preds.add(alert.createdTime.lt(getBeforeTime()));
    }
    if (getAfterTime() != null) {
        preds.add(alert.createdTime.gt(getAfterTime()));
    }
    if (getBeforeTime() != null) {
        preds.add(alert.createdTime.lt(getBeforeTime()));
    }
    if (!isIncludeCleared()) {
        preds.add(alert.cleared.isFalse());
    }
    if (getTypes().size() > 0) {
        BooleanBuilder likes = new BooleanBuilder();
        getTypes().stream().map(uri -> alert.typeString.like(uri.toASCIIString().concat("%"))).forEach(pred -> likes.or(pred));
        preds.add(likes);
    }
    if (getSubtypes().size() > 0) {
        preds.add(alert.subtype.in(getSubtypes()));
    }
    return preds;
}
Also used : JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) QueryBase(com.querydsl.core.support.QueryBase) Projections(com.querydsl.core.types.Projections) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) JPAQuery(com.querydsl.jpa.impl.JPAQuery) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) BaseAlertCriteria(com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria) List(java.util.List) Lists(com.google.common.collect.Lists) Alert(com.thinkbiganalytics.alerts.api.Alert) DefaultAlertSummary(com.thinkbiganalytics.metadata.jpa.alerts.DefaultAlertSummary) Predicate(com.querydsl.core.types.Predicate) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) Predicate(com.querydsl.core.types.Predicate)

Example 7 with QJpaAlert

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

the class DefaultAlertCriteria method orFilter.

protected BooleanBuilder orFilter(QJpaAlert alert) {
    BooleanBuilder globalFilter = new BooleanBuilder();
    if (StringUtils.isNotBlank(getOrFilter())) {
        Lists.newArrayList(StringUtils.split(getOrFilter(), ",")).stream().forEach(filter -> {
            filter = StringUtils.trim(filter);
            if (filter != null) {
                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) {
                }
                preds.add(alert.typeString.like(filter.concat("%")));
                preds.add(alert.subtype.like(filter.concat("%")));
                booleanBuilder.andAnyOf(preds.toArray(new Predicate[preds.size()]));
                globalFilter.and(booleanBuilder);
            }
        });
    }
    return globalFilter;
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) ArrayList(java.util.ArrayList) JpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert) Alert(com.thinkbiganalytics.alerts.api.Alert) QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) Predicate(com.querydsl.core.types.Predicate)

Example 8 with QJpaAlert

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

the class KyloEntityAwareAlertCriteria method createSummaryQuery.

public JPAQuery<AlertSummary> createSummaryQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    QJpaOpsManagerFeed slaFeed = new QJpaOpsManagerFeed("slaFeed");
    QJpaServiceLevelAgreementDescription sla = QJpaServiceLevelAgreementDescription.jpaServiceLevelAgreementDescription;
    JPAQuery query = queryFactory.select(Projections.bean(KyloEntityAwareAlertSummary.class, alert.typeString.as("type"), alert.subtype.as("subtype"), alert.level.as("level"), feed.id.as("feedId"), feed.name.as("feedName"), sla.slaId.as("slaId"), sla.name.as("slaName"), alert.count().as("count"), alert.createdTimeMillis.max().as("lastAlertTimestamp"))).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).groupBy(alert.typeString, alert.subtype, feed.id, feed.name, sla.slaId, sla.name, alert.level);
    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);
    return (JPAQuery<AlertSummary>) 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) JPAQuery(com.querydsl.jpa.impl.JPAQuery) 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