Search in sources :

Example 21 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project spring-data-commons by spring-projects.

the class QuerydslDefaultBinding method bind.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.web.querydsl.QueryDslPredicateBuilder#buildPredicate(org.springframework.data.mapping.PropertyPath, java.lang.Object)
	 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Optional<Predicate> bind(Path<?> path, Collection<? extends Object> value) {
    Assert.notNull(path, "Path must not be null!");
    Assert.notNull(value, "Value must not be null!");
    if (value.isEmpty()) {
        return Optional.empty();
    }
    if (path instanceof CollectionPathBase) {
        BooleanBuilder builder = new BooleanBuilder();
        for (Object element : value) {
            builder.and(((CollectionPathBase) path).contains(element));
        }
        return Optional.of(builder.getValue());
    }
    if (path instanceof SimpleExpression) {
        if (value.size() > 1) {
            return Optional.of(((SimpleExpression) path).in(value));
        }
        return Optional.of(((SimpleExpression) path).eq(value.iterator().next()));
    }
    throw new IllegalArgumentException(String.format("Cannot create predicate for path '%s' with type '%s'.", path, path.getMetadata().getPathType()));
}
Also used : BooleanBuilder(com.querydsl.core.BooleanBuilder) CollectionPathBase(com.querydsl.core.types.dsl.CollectionPathBase) SimpleExpression(com.querydsl.core.types.dsl.SimpleExpression)

Example 22 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project hse-cws by holuhoev.

the class FacultyDatasource method getFacultyFilter.

public DataSourceResult getFacultyFilter(final Integer instituteId, final String name) {
    QFaculty qFaculty = QFaculty.faculty;
    BooleanBuilder builder = new BooleanBuilder();
    if (instituteId != null) {
        builder.and(qFaculty.instituteId.eq(instituteId));
    }
    if (name != null && !name.isEmpty()) {
        builder.and(qFaculty.name.containsIgnoreCase(name));
    }
    Sort sort = new Sort(Sort.Direction.ASC, "name");
    Iterable<Faculty> faculties = facultyRepository.findAll(builder, sort);
    return DataSourceResult.create(faculties);
}
Also used : QFaculty(hse.holuhoev.domain.QFaculty) Faculty(hse.holuhoev.domain.Faculty) QFaculty(hse.holuhoev.domain.QFaculty) BooleanBuilder(com.querydsl.core.BooleanBuilder) Sort(org.springframework.data.domain.Sort)

Example 23 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project hse-cws by holuhoev.

the class GroupDatasource method getGroupFilter.

public DataSourceResult getGroupFilter(final Integer facultyId, final Integer instituteId, final Course course, final String number, final EducationType educationType) {
    QGroup qGroup = QGroup.group;
    BooleanBuilder builder = new BooleanBuilder();
    if (facultyId != null) {
        builder.and(qGroup.facultyId.eq(facultyId));
    }
    if (instituteId != null) {
        builder.and(qGroup.instituteId.eq(instituteId));
    }
    if (course != null) {
        builder.and(qGroup.course.eq(course));
    }
    if (number != null) {
        builder.and(qGroup.number.containsIgnoreCase(number));
    }
    if (educationType != null) {
        builder.and(qGroup.educationType.eq(educationType));
    }
    Sort sort = new Sort(Sort.Direction.ASC, "course", "number");
    Iterable<Group> groups = groupRepository.findAll(builder, sort);
    return DataSourceResult.create(groups, new HashMap<>());
}
Also used : QGroup(hse.holuhoev.domain.QGroup) Group(hse.holuhoev.domain.Group) BooleanBuilder(com.querydsl.core.BooleanBuilder) QGroup(hse.holuhoev.domain.QGroup) Sort(org.springframework.data.domain.Sort)

Example 24 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project hse-cws by holuhoev.

the class LecturerWorkloadDatasource method getLecturerSumWorkload.

public DataSourceResult getLecturerSumWorkload(final Integer chairId, final String fio, final LocalDate fromDate, final LocalDate toDate, final Integer top, final Integer skip, final Boolean fetchTotal) {
    QLecturer qLecturer = QLecturer.lecturer;
    QLecturerWorkload qLecturerWorkload = QLecturerWorkload.lecturerWorkload;
    BooleanBuilder lecturerBuilder = new BooleanBuilder();
    BooleanBuilder workloadBuilder = new BooleanBuilder();
    if (chairId != null) {
        lecturerBuilder.and(qLecturer.chairId.eq(chairId));
    }
    if (fio != null && !fio.isEmpty()) {
        lecturerBuilder.and(qLecturer.fio.containsIgnoreCase(fio));
    }
    if (fromDate != null) {
        workloadBuilder.and(qLecturerWorkload.date.after(fromDate));
    }
    if (toDate != null) {
        workloadBuilder.and(qLecturerWorkload.date.before(toDate));
    }
    Iterable<Lecturer> lecturers;
    if (top != null) {
        String orderByString = "fio";
        Pageable limit = PageRequest.of(skip, top, Sort.Direction.ASC, orderByString);
        lecturers = lecturerRepository.findAll(lecturerBuilder, limit);
    } else {
        lecturers = lecturerRepository.findAll(lecturerBuilder);
    }
    List<LecturerSumWorkload> result = StreamSupport.stream(lecturers.spliterator(), false).map(lecturer -> {
        BooleanBuilder builder = new BooleanBuilder();
        builder.and(workloadBuilder).and(qLecturerWorkload.lecturerId.eq(lecturer.getId()));
        Integer workload = StreamSupport.stream(lecturerWorkloadRepository.findAll(builder).spliterator(), false).mapToInt(LecturerWorkload::getWorkload).sum();
        return new LecturerSumWorkload(lecturer.getFio(), workload, lecturer.getId());
    }).collect(Collectors.toList());
    Map<String, Object> hints = new HashMap<>();
    hints.put("paging", true);
    if (fetchTotal != null && fetchTotal) {
        Long count = lecturerWorkloadRepository.count(lecturerBuilder);
        hints.put("total", count);
    }
    return DataSourceResult.create(result, hints);
}
Also used : LecturerRepository(hse.holuhoev.repo.LecturerRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) PageRequest(org.springframework.data.domain.PageRequest) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) BooleanBuilder(com.querydsl.core.BooleanBuilder) HashMap(java.util.HashMap) hse.holuhoev.domain(hse.holuhoev.domain) Collectors(java.util.stream.Collectors) List(java.util.List) DataSourceResult(hse.holuhoev.datasource.util.DataSourceResult) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) Map(java.util.Map) LecturerWorkloadRepository(hse.holuhoev.repo.LecturerWorkloadRepository) Optional(java.util.Optional) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) StreamSupport(java.util.stream.StreamSupport) HashMap(java.util.HashMap) Pageable(org.springframework.data.domain.Pageable) BooleanBuilder(com.querydsl.core.BooleanBuilder)

Example 25 with BooleanBuilder

use of com.querydsl.core.BooleanBuilder in project kylo by Teradata.

the class JpaBatchJobExecutionProvider method getJobStatusCount.

/**
 * Get count of Jobs grouped by Status
 * Streaming Feeds are given a count of 1 if they are running, regardless of the number of active running flows
 */
@Override
public List<JobStatusCount> getJobStatusCount(String filter) {
    QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
    QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    BooleanBuilder whereBuilder = new BooleanBuilder();
    if (StringUtils.isNotBlank(filter)) {
        whereBuilder.and(GenericQueryDslFilter.buildFilter(jobExecution, filter));
    }
    ConstructorExpression<JpaBatchJobExecutionStatusCounts> expr = Projections.constructor(JpaBatchJobExecutionStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), jobExecution.jobExecutionId.count().as("count"));
    JPAQuery<?> query = factory.select(expr).from(jobExecution).innerJoin(jobInstance).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).innerJoin(feed).on(jobInstance.feed.id.eq(feed.id)).where(whereBuilder.and(feed.isStream.eq(false)).and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, controller.isEntityAccessControlled()))).groupBy(jobExecution.status);
    List<JobStatusCount> stats = (List<JobStatusCount>) query.fetch();
    // merge in streaming feed stats
    List<? extends NifiFeedStats> streamingFeedStats = feedStatisticsProvider.findFeedStats(true);
    if (streamingFeedStats != null) {
        if (stats == null) {
            stats = new ArrayList<>();
        }
        Long runningCount = streamingFeedStats.stream().filter(s -> s.getRunningFeedFlows() > 0L).count();
        if (runningCount > 0) {
            JobStatusCount runningStatusCount = stats.stream().filter(s -> s.getStatus().equalsIgnoreCase(BatchJobExecution.RUNNING_DISPLAY_STATUS)).findFirst().orElse(null);
            if (runningStatusCount != null) {
                runningCount = runningStatusCount.getCount() + runningCount;
                runningStatusCount.setCount(runningCount);
            } else {
                JpaBatchJobExecutionStatusCounts runningStreamingFeedCounts = new JpaBatchJobExecutionStatusCounts();
                runningStreamingFeedCounts.setCount(runningCount);
                runningStreamingFeedCounts.setStatus(BatchJobExecution.RUNNING_DISPLAY_STATUS);
                stats.add(runningStreamingFeedCounts);
            }
        }
    }
    return stats;
}
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) JobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.JobStatusCount) BatchAndStreamingJobStatusCount(com.thinkbiganalytics.metadata.api.jobrepo.job.BatchAndStreamingJobStatusCount) BooleanBuilder(com.querydsl.core.BooleanBuilder) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

BooleanBuilder (com.querydsl.core.BooleanBuilder)41 Predicate (com.querydsl.core.types.Predicate)12 ArrayList (java.util.ArrayList)10 JPAQuery (com.querydsl.jpa.impl.JPAQuery)8 QJpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert)8 Sort (org.springframework.data.domain.Sort)8 List (java.util.List)7 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)6 Map (java.util.Map)6 Pageable (org.springframework.data.domain.Pageable)6 Alert (com.thinkbiganalytics.alerts.api.Alert)5 Test (org.junit.Test)5 JpaAlert (com.thinkbiganalytics.metadata.jpa.alerts.JpaAlert)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (org.springframework.stereotype.Service)4 Expression (com.querydsl.core.types.Expression)3 Projections (com.querydsl.core.types.Projections)3