Search in sources :

Example 16 with AggregateResult

use of org.molgenis.data.aggregation.AggregateResult in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method aggregateSuOrSystem.

private void aggregateSuOrSystem() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(delegateRepository.aggregate(aggregateQuery)).thenReturn(aggregateResult);
    assertEquals(repo.aggregate(aggregateQuery), aggregateResult);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery)

Example 17 with AggregateResult

use of org.molgenis.data.aggregation.AggregateResult in project molgenis by molgenis.

the class AggregateAnonymizerRepositoryDecoratorTest method aggregateThreshold.

@Test
public void aggregateThreshold() throws Exception {
    int threshold = 10;
    when(appSettings.getAggregateThreshold()).thenReturn(threshold);
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(delegateRepository.aggregate(aggregateQuery)).thenReturn(aggregateResult);
    AnonymizedAggregateResult anonymizedAggregateResult = mock(AnonymizedAggregateResult.class);
    when(aggregateAnonymizer.anonymize(aggregateResult, threshold)).thenReturn(anonymizedAggregateResult);
    assertEquals(anonymizedAggregateResult, aggregateAnonymizerRepoDecorator.aggregate(aggregateQuery));
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test)

Example 18 with AggregateResult

use of org.molgenis.data.aggregation.AggregateResult in project molgenis by molgenis.

the class EntityAggregatesResponseTest method testAggregateResultResponseToResponseAggregateResult.

// regression test for https://github.com/molgenis/molgenis/issues/6581
@Test
public void testAggregateResultResponseToResponseAggregateResult() {
    EntityType entityType = mock(EntityType.class);
    Attribute longAttribute = when(mock(Attribute.class).getDataType()).thenReturn(LONG).getMock();
    when(longAttribute.getName()).thenReturn("longAttribute");
    Iterable<Attribute> attributes = singletonList(longAttribute);
    when(entityType.getAtomicAttributes()).thenReturn(attributes);
    Entity entity = mock(Entity.class);
    when(entity.get("longAttribute")).thenReturn(123L);
    when(entity.getEntityType()).thenReturn(entityType);
    List<List<Long>> matrix = emptyList();
    List<Object> xLabels = Collections.singletonList(entity);
    List<Object> yLabels = emptyList();
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(aggregateResult.getMatrix()).thenReturn(matrix);
    when(aggregateResult.getxLabels()).thenReturn(xLabels);
    when(aggregateResult.getyLabels()).thenReturn(yLabels);
    AggregateResultResponse aggregateResultResponse = AggregateResultResponse.toResponse(aggregateResult);
    assertEquals(aggregateResultResponse.getMatrix(), matrix);
    assertEquals(aggregateResultResponse.getxLabels(), singletonList(singletonMap("longAttribute", "123")));
    assertEquals(aggregateResultResponse.getyLabels(), emptyList());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) AggregateResult(org.molgenis.data.aggregation.AggregateResult) List(java.util.List) AggregateResultResponse(org.molgenis.data.rest.v2.EntityAggregatesResponse.AggregateResultResponse) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 19 with AggregateResult

use of org.molgenis.data.aggregation.AggregateResult in project molgenis by molgenis.

the class AggregateAnonymizerRepositoryDecorator method aggregate.

@Override
public AggregateResult aggregate(AggregateQuery aggregateQuery) {
    AggregateResult result = delegate().aggregate(aggregateQuery);
    Integer threshold = appSettings.getAggregateThreshold();
    if (threshold != null && threshold > 0) {
        result = aggregateAnonymizer.anonymize(result, threshold);
    }
    return result;
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult)

Aggregations

AggregateResult (org.molgenis.data.aggregation.AggregateResult)19 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)13 Test (org.testng.annotations.Test)12 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 QueryImpl (org.molgenis.data.support.QueryImpl)5 Attribute (org.molgenis.data.meta.model.Attribute)3 List (java.util.List)2 EntityType (org.molgenis.data.meta.model.EntityType)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 URISyntaxException (java.net.URISyntaxException)1 Entity (org.molgenis.data.Entity)1 UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)1 EntityPager (org.molgenis.data.rest.EntityPager)1 AttributeFilterToFetchConverter.createDefaultAttributeFetch (org.molgenis.data.rest.v2.AttributeFilterToFetchConverter.createDefaultAttributeFetch)1 AggregateResultResponse (org.molgenis.data.rest.v2.EntityAggregatesResponse.AggregateResultResponse)1 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)1 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)1 ResponseEntity (org.springframework.http.ResponseEntity)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1