Search in sources :

Example 1 with SearchCriteria

use of com.thinkbiganalytics.metadata.api.SearchCriteria in project kylo by Teradata.

the class JpaBatchJobExecutionProvider method findAll.

/**
 * Find all BatchJobExecution objects with the provided filter. the filter needs to match
 *
 * @return a paged result set of all the job executions matching the incoming filter
 */
@Override
public Page<? extends BatchJobExecution> findAll(String filter, Pageable pageable) {
    QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
    // if the filter contains a filter on the feed then delegate to the findAllForFeed method to include any check data jobs
    List<SearchCriteria> searchCriterias = GenericQueryDslFilter.parseFilterString(filter);
    SearchCriteria feedFilter = searchCriterias.stream().map(searchCriteria -> searchCriteria.withKey(CommonFilterTranslations.resolvedFilter(jobExecution, searchCriteria.getKey()))).filter(sc -> sc.getKey().equalsIgnoreCase(CommonFilterTranslations.jobExecutionFeedNameFilterKey)).findFirst().orElse(null);
    if (feedFilter != null && feedFilter.getPreviousSearchCriteria() != null && !feedFilter.isValueCollection()) {
        // remove the feed filter from the list and filter by this feed
        searchCriterias.remove(feedFilter.getPreviousSearchCriteria());
        String feedValue = feedFilter.getValue().toString();
        // remove any quotes around the feedValue
        feedValue = feedValue.replaceAll("^\"|\"$", "");
        return findAllForFeed(feedValue, searchCriterias, pageable);
    } else {
        pageable = CommonFilterTranslations.resolveSortFilters(jobExecution, pageable);
        QJpaBatchJobInstance jobInstancePath = new QJpaBatchJobInstance("jobInstance");
        QJpaOpsManagerFeed feedPath = new QJpaOpsManagerFeed("feed");
        return findAllWithFetch(jobExecution, GenericQueryDslFilter.buildFilter(jobExecution, filter).and(augment(feedPath.id)), pageable, QueryDslFetchJoin.innerJoin(jobExecution.nifiEventJobExecution), QueryDslFetchJoin.innerJoin(jobExecution.jobInstance, jobInstancePath), QueryDslFetchJoin.innerJoin(jobInstancePath.feed, feedPath));
    }
}
Also used : AlertManager(com.thinkbiganalytics.alerts.spi.AlertManager) JobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.JobStatusCount) BatchRelatedFlowFile(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchRelatedFlowFile) ClusterServiceMessageReceiver(com.thinkbiganalytics.cluster.ClusterServiceMessageReceiver) JpaNifiEventJobExecution(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.JpaNifiEventJobExecution) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Projections(com.querydsl.core.types.Projections) FeedAclIndexQueryAugmentor(com.thinkbiganalytics.metadata.jpa.feed.FeedAclIndexQueryAugmentor) StringUtils(org.apache.commons.lang3.StringUtils) GenericQueryDslFilter(com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) BatchAndStreamingJobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchAndStreamingJobStatusCount) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) OpsManagerFeed(com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed) Pageable(org.springframework.data.domain.Pageable) BigInteger(java.math.BigInteger) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) NifiFeedStatisticsProvider(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStatisticsProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ClusterMessage(com.thinkbiganalytics.cluster.ClusterMessage) Page(org.springframework.data.domain.Page) Expression(com.querydsl.core.types.Expression) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) JPAExpressions(com.querydsl.jpa.JPAExpressions) JpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.JpaOpsManagerFeed) JPAQuery(com.querydsl.jpa.impl.JPAQuery) BatchJobExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecutionProvider) ReadablePeriod(org.joda.time.ReadablePeriod) List(java.util.List) ExecutionConstants(com.thinkbiganalytics.metadata.api.jobrepo.ExecutionConstants) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PostConstruct(javax.annotation.PostConstruct) ClusterService(com.thinkbiganalytics.cluster.ClusterService) BatchJobExecution(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobExecution) CommonFilterTranslations(com.thinkbiganalytics.metadata.jpa.support.CommonFilterTranslations) Predicate(com.querydsl.core.types.Predicate) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria) Authentication(org.springframework.security.core.Authentication) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FeedOperationBatchStatusChange(com.thinkbiganalytics.metadata.api.event.feed.FeedOperationBatchStatusChange) BatchStepExecutionProvider(com.thinkbiganalytics.metadata.api.jobrepo.step.BatchStepExecutionProvider) Stopwatch(com.google.common.base.Stopwatch) MessageDigest(java.security.MessageDigest) DateTimeUtil(com.thinkbiganalytics.DateTimeUtil) BooleanBuilder(com.querydsl.core.BooleanBuilder) QOpsManagerFeedId(com.thinkbiganalytics.metadata.jpa.feed.QOpsManagerFeedId) BooleanUtils(org.apache.commons.lang3.BooleanUtils) HashMap(java.util.HashMap) JPQLQuery(com.querydsl.jpa.JPQLQuery) DefaultAlertChangeEventContent(com.thinkbiganalytics.alerts.spi.DefaultAlertChangeEventContent) QueryDslFetchJoin(com.thinkbiganalytics.metadata.jpa.support.QueryDslFetchJoin) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AlertProvider(com.thinkbiganalytics.alerts.api.AlertProvider) RoleSetExposingSecurityExpressionRoot(com.thinkbiganalytics.metadata.config.RoleSetExposingSecurityExpressionRoot) NifiRelatedRootFlowFilesRepository(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.NifiRelatedRootFlowFilesRepository) Alert(com.thinkbiganalytics.alerts.api.Alert) CheckDataStepConstants(com.thinkbiganalytics.jobrepo.common.constants.CheckDataStepConstants) Service(org.springframework.stereotype.Service) QueryDslPagingSupport(com.thinkbiganalytics.metadata.jpa.support.QueryDslPagingSupport) Named(javax.inject.Named) ProvenanceEventRecordDTO(com.thinkbiganalytics.nifi.provenance.model.ProvenanceEventRecordDTO) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) Logger(org.slf4j.Logger) BatchJobInstance(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchJobInstance) FeedNameUtil(com.thinkbiganalytics.support.FeedNameUtil) OptimisticLockException(javax.persistence.OptimisticLockException) ConstructorExpression(com.querydsl.core.types.ConstructorExpression) DateTime(org.joda.time.DateTime) NifiFeedStats(com.thinkbiganalytics.metadata.api.jobrepo.nifi.NifiFeedStats) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) OperationalAlerts(com.thinkbiganalytics.metadata.api.alerts.OperationalAlerts) QJpaNifiFeedStats(com.thinkbiganalytics.metadata.jpa.jobrepo.nifi.QJpaNifiFeedStats) TimeUnit(java.util.concurrent.TimeUnit) JobStatusDslQueryExpressionBuilder(com.thinkbiganalytics.metadata.jpa.support.JobStatusDslQueryExpressionBuilder) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) FeedConstants(com.thinkbiganalytics.jobrepo.common.constants.FeedConstants) Collections(java.util.Collections) OpsManagerFeedRepository(com.thinkbiganalytics.metadata.jpa.feed.OpsManagerFeedRepository) QJpaOpsManagerFeed(com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria)

Example 2 with SearchCriteria

use of com.thinkbiganalytics.metadata.api.SearchCriteria in project kylo by Teradata.

the class GenericQueryDslFilter method parseFilterString.

/**
 * convert a passed in filter string to a list of criteria objects
 *
 * @param filterString a filter, <column><operator><value> Example: jobinstance.name==jobName,jobExcutionId>=200.  that will search for all jobs named 'jobName' and jobExecutionId >= 200
 * @return a list of criteria objects
 */
public static List<SearchCriteria> parseFilterString(String filterString) {
    List<SearchCriteria> searchCriterias = new ArrayList<>();
    if (StringUtils.isNotBlank(filterString)) {
        // first match and split on , for various filters
        String[] filterConditions = filterString.split(",(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
        List<String> filterConditionsList = Arrays.asList(filterConditions);
        // Pattern used to match the <column><operator><value>
        String validOperatorsRegEx = operators.keySet().stream().map(key -> key).collect(Collectors.joining("|"));
        Pattern columnOperatorValuePattern = Pattern.compile("(.*)(" + validOperatorsRegEx + ")(.*)");
        filterConditionsList.stream().forEach(filter -> {
            Matcher matcher = columnOperatorValuePattern.matcher(filter);
            while (matcher.find()) {
                String field = matcher.group(1).trim();
                String operator = matcher.group(2).trim();
                String value = matcher.group(3).trim();
                searchCriterias.add(new SearchCriteria(field, operator, value));
            }
        });
    }
    return searchCriterias;
}
Also used : EnumOperation(com.querydsl.core.types.dsl.EnumOperation) EnumTemplate(com.querydsl.core.types.dsl.EnumTemplate) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) ImmutableCollection(com.google.common.collect.ImmutableCollection) BooleanBuilder(com.querydsl.core.BooleanBuilder) Ops(com.querydsl.core.types.Ops) Path(com.querydsl.core.types.Path) ConvertUtilsBean(org.apache.commons.beanutils.ConvertUtilsBean) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Matcher(java.util.regex.Matcher) StringPath(com.querydsl.core.types.dsl.StringPath) Operator(com.querydsl.core.types.Operator) Formatters(com.thinkbiganalytics.Formatters) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Visitor(com.querydsl.core.types.Visitor) Logger(org.slf4j.Logger) TemplateExpressionImpl(com.querydsl.core.types.TemplateExpressionImpl) EnumExpression(com.querydsl.core.types.dsl.EnumExpression) ImmutableMap(com.google.common.collect.ImmutableMap) ExpressionUtils(com.querydsl.core.types.ExpressionUtils) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) UUID(java.util.UUID) ComparablePath(com.querydsl.core.types.dsl.ComparablePath) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) Expression(com.querydsl.core.types.Expression) Collectors(java.util.stream.Collectors) EnumPath(com.querydsl.core.types.dsl.EnumPath) OperationImpl(com.querydsl.core.types.OperationImpl) List(java.util.List) Expressions(com.querydsl.core.types.dsl.Expressions) PathImpl(com.querydsl.core.types.PathImpl) EntityPathBase(com.querydsl.core.types.dsl.EntityPathBase) NumberPath(com.querydsl.core.types.dsl.NumberPath) Pattern(java.util.regex.Pattern) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) SearchCriteria(com.thinkbiganalytics.metadata.api.SearchCriteria)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)2 Expression (com.querydsl.core.types.Expression)2 SearchCriteria (com.thinkbiganalytics.metadata.api.SearchCriteria)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 DateTime (org.joda.time.DateTime)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ConstructorExpression (com.querydsl.core.types.ConstructorExpression)1 ExpressionUtils (com.querydsl.core.types.ExpressionUtils)1 OperationImpl (com.querydsl.core.types.OperationImpl)1 Operator (com.querydsl.core.types.Operator)1 Ops (com.querydsl.core.types.Ops)1 Path (com.querydsl.core.types.Path)1