Search in sources :

Example 1 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getAnyLatestSuccessfulBuildRecordWithBuildConfig.

@Override
public BuildRecord getAnyLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(temporaryBuild));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 2 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithRevision.

@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithRevision(IdRev idRev, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationIdRev(idRev), withSuccess(), includeTemporary(idRev, temporaryBuild, alignmentPreference));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 3 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildRecordRepositoryImpl method getPreferredLatestSuccessfulBuildRecordWithBuildConfig.

@Override
public BuildRecord getPreferredLatestSuccessfulBuildRecordWithBuildConfig(Integer configurationId, boolean temporaryBuild, AlignmentPreference alignmentPreference) {
    PageInfo pageInfo = new DefaultPageInfo(0, 1);
    SortInfo sortInfo = new DefaultSortInfo(SortInfo.SortingDirection.DESC, BuildRecord_.submitTime.getName());
    List<BuildRecord> buildRecords = queryWithPredicates(pageInfo, sortInfo, withBuildConfigurationId(configurationId), withSuccess(), includeTemporary(configurationId, temporaryBuild, alignmentPreference));
    if (buildRecords.size() == 0) {
        return null;
    } else {
        return buildRecords.get(0);
    }
}
Also used : PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) DefaultSortInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)

Example 4 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildProviderImpl method getBuilds.

/**
 * Returns the page of builds (running or finished) filtered by given BuildPageInfo and predicate.
 */
private Page<Build> getBuilds(BuildPageInfo pageInfo, java.util.function.Predicate<BuildTask> predicate, Predicate<BuildRecord> dbPredicate) {
    List<Build> runningBuilds = readRunningBuilds(pageInfo, predicate);
    int firstPossibleDBIndex = pageInfo.getPageIndex() * pageInfo.getPageSize() - runningBuilds.size();
    int lastPossibleDBIndex = (pageInfo.getPageIndex() + 1) * pageInfo.getPageSize() - 1;
    int toSkip = min(runningBuilds.size(), pageInfo.getPageIndex() * pageInfo.getPageSize());
    Predicate<BuildRecord>[] predicates = preparePredicates(dbPredicate, pageInfo.getQ(), pageInfo.getBuildConfigName());
    Comparator<Build> comparing = Comparator.comparing(Build::getSubmitTime).reversed();
    if (!StringUtils.isEmpty(pageInfo.getSort())) {
        comparing = rsqlPredicateProducer.getComparator(pageInfo.getSort());
    }
    SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, pageInfo.getSort());
    MergeIterator<Build> builds = new MergeIterator(runningBuilds.iterator(), new BuildIterator(firstPossibleDBIndex, lastPossibleDBIndex, pageInfo.getPageSize(), sortInfo, predicates), comparing);
    List<Build> resultList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(builds, Spliterator.ORDERED | Spliterator.SORTED), false).skip(toSkip).limit(pageInfo.getPageSize()).collect(Collectors.toList());
    int hits = repository.count(predicates) + runningBuilds.size();
    return new Page<>(pageInfo.getPageIndex(), pageInfo.getPageSize(), (int) Math.ceil((double) hits / pageInfo.getPageSize()), hits, resultList);
}
Also used : BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build) Page(org.jboss.pnc.dto.response.Page) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) MergeIterator(org.jboss.pnc.facade.util.MergeIterator)

Example 5 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class BuildProviderImpl method getByAttribute.

public Page<Build> getByAttribute(BuildPageInfo buildPageInfo, Map<String, String> attributeConstraints) {
    Set<Predicate<BuildRecord>> predicates = new HashSet<>();
    for (Map.Entry<String, String> entry : attributeConstraints.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (key.startsWith("!")) {
            predicates.add(withoutAttribute(key.substring(1)));
        } else {
            predicates.add(withAttribute(key, value));
        }
    }
    Predicate<BuildRecord> queryPredicate = rsqlPredicateProducer.getCriteriaPredicate(BuildRecord.class, buildPageInfo.getQ());
    predicates.add(queryPredicate);
    Predicate<BuildRecord>[] predicatesArray = predicates.toArray(new Predicate[predicates.size()]);
    PageInfo pageInfo = toPageInfo(buildPageInfo);
    SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, buildPageInfo.getSort());
    List<BuildRecord> resultList = ((BuildRecordRepository) BuildProviderImpl.this.repository).queryWithPredicatesUsingCursor(pageInfo, sortInfo, predicatesArray);
    int hits = repository.count(predicatesArray);
    return new Page<>(buildPageInfo.getPageIndex(), buildPageInfo.getPageSize(), hits, resultList.stream().map(b -> mapper.toDTO(b)).collect(Collectors.toList()));
}
Also used : Page(org.jboss.pnc.dto.response.Page) BuildRecord(org.jboss.pnc.model.BuildRecord) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) Map(java.util.Map) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet)

Aggregations

SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)20 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Test (org.junit.Test)9 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)8 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)7 DefaultSortInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)5 ArrayList (java.util.ArrayList)3 Build (org.jboss.pnc.dto.Build)3 Page (org.jboss.pnc.dto.response.Page)3 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)2 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)2 Node (cz.jirutka.rsql.parser.ast.Node)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EmptySortInfo (org.jboss.pnc.datastore.limits.rsql.EmptySortInfo)1 MergeIterator (org.jboss.pnc.facade.util.MergeIterator)1 BuildRecordPredicates.temporaryBuild (org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1