Search in sources :

Example 11 with AggregateResult

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

the class DataServiceIT method testAggregateOneDimensionalDistinct.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateOneDimensionalDistinct() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrDistinct(entityType.getAttribute(ATTR_ENUM));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(singletonList(1L), singletonList(1L)), asList(0L, 1L), emptyList());
    assertEquals(result, expectedResult);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 12 with AggregateResult

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

the class DataServiceIT method testAggregateTwoDimensional.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateTwoDimensional() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL)).attrY(entityType.getAttribute(ATTR_ENUM));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(asList(0L, 1L), asList(2L, 0L)), asList(0L, 1L), asList("option1", "option2"));
    assertEquals(result, expectedResult);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 13 with AggregateResult

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

the class DataServiceIT method testAggregateOneDimensional.

@WithMockUser(username = USERNAME_READ)
@Test(groups = "readtest")
public void testAggregateOneDimensional() {
    AggregateQuery aggregateQuery = new AggregateQueryImpl().query(new QueryImpl<>()).attrX(entityType.getAttribute(ATTR_BOOL));
    AggregateResult result = dataService.aggregate(entityType.getId(), aggregateQuery);
    AggregateResult expectedResult = new AggregateResult(asList(singletonList(1L), singletonList(2L)), asList(0L, 1L), emptyList());
    assertEquals(result, expectedResult);
}
Also used : AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) QueryImpl(org.molgenis.data.support.QueryImpl) AggregateResult(org.molgenis.data.aggregation.AggregateResult) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 14 with AggregateResult

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

the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionRecoverable.

@Test
public void aggregateUnknownIndexExceptionRecoverable() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg")).thenReturn(aggregateResult);
    assertEquals(indexedRepositoryDecorator.aggregate(aggregateQuery), aggregateResult);
    verify(delegateRepository, never()).count(unsupportedQuery);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test)

Example 15 with AggregateResult

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

the class MappingServiceController method advancedMappingEditor.

/**
 * Returns a view that allows the user to edit mappings involving xrefs / categoricals / strings
 */
@PostMapping("/advancedmappingeditor")
public String advancedMappingEditor(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam() String source, @RequestParam() String targetAttribute, @RequestParam() String sourceAttribute, @RequestParam String algorithm, Model model) {
    MappingProject project = mappingService.getMappingProject(mappingProjectId);
    MappingTarget mappingTarget = project.getMappingTarget(target);
    EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
    AttributeMapping attributeMapping = entityMapping.getAttributeMapping(targetAttribute);
    model.addAttribute("mappingProject", project);
    model.addAttribute("entityMapping", entityMapping);
    model.addAttribute("attributeMapping", attributeMapping);
    // set variables for the target column in the mapping editor
    Attribute targetAttr = dataService.getEntityType(target).getAttribute(targetAttribute);
    Stream<Entity> targetAttributeEntities;
    String targetAttributeIdAttribute = null;
    String targetAttributeLabelAttribute = null;
    if (EntityTypeUtils.isReferenceType(targetAttr)) {
        targetAttributeEntities = dataService.findAll(dataService.getEntityType(target).getAttribute(targetAttribute).getRefEntity().getId());
        targetAttributeIdAttribute = dataService.getEntityType(target).getAttribute(targetAttribute).getRefEntity().getIdAttribute().getName();
        targetAttributeLabelAttribute = dataService.getEntityType(target).getAttribute(targetAttribute).getRefEntity().getLabelAttribute().getName();
    } else {
        targetAttributeEntities = dataService.findAll(dataService.getEntityType(target).getId());
        targetAttributeIdAttribute = dataService.getEntityType(target).getIdAttribute().getName();
        targetAttributeLabelAttribute = dataService.getEntityType(target).getLabelAttribute().getName();
    }
    model.addAttribute("targetAttributeEntities", (Iterable<Entity>) targetAttributeEntities::iterator);
    model.addAttribute("targetAttributeIdAttribute", targetAttributeIdAttribute);
    model.addAttribute("targetAttributeLabelAttribute", targetAttributeLabelAttribute);
    // set variables for the source column in the mapping editor
    Attribute sourceAttr = dataService.getEntityType(source).getAttribute(sourceAttribute);
    Stream<Entity> sourceAttributeEntities;
    String sourceAttributeIdAttribute = null;
    String sourceAttributeLabelAttribute = null;
    if (EntityTypeUtils.isReferenceType(sourceAttr)) {
        sourceAttributeEntities = dataService.findAll(dataService.getEntityType(source).getAttribute(sourceAttribute).getRefEntity().getId());
        sourceAttributeIdAttribute = dataService.getEntityType(source).getAttribute(sourceAttribute).getRefEntity().getIdAttribute().getName();
        sourceAttributeLabelAttribute = dataService.getEntityType(source).getAttribute(sourceAttribute).getRefEntity().getLabelAttribute().getName();
    } else {
        sourceAttributeEntities = dataService.findAll(dataService.getEntityType(source).getId());
        sourceAttributeIdAttribute = dataService.getEntityType(source).getIdAttribute().getName();
        sourceAttributeLabelAttribute = dataService.getEntityType(source).getLabelAttribute().getName();
    }
    List<Entity> sourceAttributeEntityList = sourceAttributeEntities.collect(toList());
    model.addAttribute("sourceAttributeEntities", sourceAttributeEntityList);
    model.addAttribute("numberOfSourceAttributes", sourceAttributeEntityList.size());
    model.addAttribute("sourceAttributeIdAttribute", sourceAttributeIdAttribute);
    model.addAttribute("sourceAttributeLabelAttribute", sourceAttributeLabelAttribute);
    // Check if the selected source attribute is isAggregatable
    Attribute sourceAttributeAttribute = dataService.getEntityType(source).getAttribute(sourceAttribute);
    if (sourceAttributeAttribute.isAggregatable()) {
        AggregateResult aggregate = dataService.aggregate(source, new AggregateQueryImpl().attrX(sourceAttributeAttribute).query(new QueryImpl<>()));
        List<Long> aggregateCounts = new ArrayList<>();
        for (List<Long> count : aggregate.getMatrix()) {
            aggregateCounts.add(count.get(0));
        }
        model.addAttribute("aggregates", aggregateCounts);
    }
    model.addAttribute("target", target);
    model.addAttribute("source", source);
    model.addAttribute("targetAttribute", dataService.getEntityType(target).getAttribute(targetAttribute));
    model.addAttribute("sourceAttribute", dataService.getEntityType(source).getAttribute(sourceAttribute));
    model.addAttribute("hasWritePermission", hasWritePermission(project, false));
    CategoryMapping<String, String> categoryMapping = null;
    if (algorithm == null) {
        algorithm = attributeMapping.getAlgorithm();
    }
    try {
        categoryMapping = create(algorithm);
    } catch (Exception ignore) {
    }
    if (categoryMapping == null) {
        categoryMapping = createEmpty(sourceAttribute);
    }
    model.addAttribute("categoryMapping", categoryMapping);
    return VIEW_CATEGORY_MAPPING_EDITOR;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) URISyntaxException(java.net.URISyntaxException) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) QueryImpl(org.molgenis.data.support.QueryImpl) 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