use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.
the class TransactionalRepositoryDecoratorTest method aggregate.
@Test
public void aggregate() throws Exception {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
transactionalRepo.aggregate(aggregateQuery);
verify(transactionManager).getTransaction(any(TransactionDefinition.class));
verify(delegateRepository).aggregate(aggregateQuery);
}
use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.
the class EntityTypeRepositorySecurityDecoratorTest method aggregateUser.
@WithMockUser(username = USERNAME)
@Test(expectedExceptions = UnsupportedOperationException.class)
public void aggregateUser() {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
repo.aggregate(aggregateQuery);
}
use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testAggregate.
@WithMockUser(username = USERNAME, roles = "SU")
@Test
public void testAggregate() {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
AggregateResult aggregateResponse = mock(AggregateResult.class);
when(delegateRepository.aggregate(aggregateQuery)).thenReturn(aggregateResponse);
assertEquals(rowLevelSecurityRepositoryDecorator.aggregate(aggregateQuery), aggregateResponse);
}
use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.
the class RowLevelSecurityRepositoryDecoratorTest method testAggregatePermissionDenied.
@WithMockUser(username = USERNAME)
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testAggregatePermissionDenied() {
AggregateQuery aggregateQuery = mock(AggregateQuery.class);
rowLevelSecurityRepositoryDecorator.aggregate(aggregateQuery);
}
use of org.molgenis.data.aggregation.AggregateQuery in project molgenis by molgenis.
the class RestControllerV2 method createEntityCollectionResponse.
private EntityCollectionResponseV2 createEntityCollectionResponse(String entityTypeId, EntityCollectionRequestV2 request, HttpServletRequest httpRequest, boolean includeCategories) {
EntityType meta = dataService.getEntityType(entityTypeId);
Query<Entity> q = request.getQ() != null ? request.getQ().createQuery(meta) : new QueryImpl<>();
q.pageSize(request.getNum()).offset(request.getStart()).sort(request.getSort());
Fetch fetch = AttributeFilterToFetchConverter.convert(request.getAttrs(), meta, LocaleContextHolder.getLocale().getLanguage());
if (fetch != null) {
q.fetch(fetch);
}
if (request.getAggs() != null) {
// return aggregates for aggregate query
AggregateQuery aggsQ = request.getAggs().createAggregateQuery(meta, q);
Attribute xAttr = aggsQ.getAttributeX();
Attribute yAttr = aggsQ.getAttributeY();
if (xAttr == null && yAttr == null) {
throw new MolgenisQueryException("Aggregate query is missing 'x' or 'y' attribute");
}
AggregateResult aggs = dataService.aggregate(entityTypeId, aggsQ);
AttributeResponseV2 xAttrResponse = xAttr != null ? new AttributeResponseV2(entityTypeId, meta, xAttr, fetch, permissionService, dataService) : null;
AttributeResponseV2 yAttrResponse = yAttr != null ? new AttributeResponseV2(entityTypeId, meta, yAttr, fetch, permissionService, dataService) : null;
return new EntityAggregatesResponse(aggs, xAttrResponse, yAttrResponse, BASE_URI + '/' + entityTypeId);
} else {
Long count = dataService.count(entityTypeId, new QueryImpl<>(q).setOffset(0).setPageSize(0));
Iterable<Entity> it;
if (count > 0 && q.getPageSize() > 0) {
it = () -> dataService.findAll(entityTypeId, q).iterator();
} else {
it = Collections.emptyList();
}
EntityPager pager = new EntityPager(request.getStart(), request.getNum(), count, it);
List<Map<String, Object>> entities = new ArrayList<>();
for (Entity entity : it) {
Map<String, Object> responseData = new LinkedHashMap<>();
createEntityValuesResponse(entity, fetch, responseData);
entities.add(responseData);
}
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getFullURL(httpRequest));
String prevHref = null;
if (pager.getPrevStart() != null) {
builder.replaceQueryParam("start", pager.getPrevStart());
prevHref = builder.build(false).toUriString();
}
String nextHref = null;
if (pager.getNextStart() != null) {
builder.replaceQueryParam("start", pager.getNextStart());
nextHref = builder.build(false).toUriString();
}
return new EntityCollectionResponseV2(pager, entities, fetch, BASE_URI + '/' + entityTypeId, meta, permissionService, dataService, prevHref, nextHref, includeCategories);
}
}
Aggregations