Search in sources :

Example 1 with BuildRecordRepository

use of org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository 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

HashSet (java.util.HashSet)1 Map (java.util.Map)1 Page (org.jboss.pnc.dto.response.Page)1 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)1 BuildRecord (org.jboss.pnc.model.BuildRecord)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)1 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)1 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)1 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)1