Search in sources :

Example 6 with AggregateQueryImpl

use of org.molgenis.data.support.AggregateQueryImpl 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 7 with AggregateQueryImpl

use of org.molgenis.data.support.AggregateQueryImpl 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 8 with AggregateQueryImpl

use of org.molgenis.data.support.AggregateQueryImpl in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method aggregate.

@Test
public void aggregate() {
    when(indexedRepositoryDecorator.getName()).thenReturn("entity");
    Attribute xAttr = when(mock(Attribute.class).getName()).thenReturn("xAttr").getMock();
    Attribute yAttr = when(mock(Attribute.class).getName()).thenReturn("yAttr").getMock();
    Attribute distinctAttr = when(mock(Attribute.class).getName()).thenReturn("distinctAttr").getMock();
    @SuppressWarnings("unchecked") Query<Entity> q = mock(Query.class);
    AggregateQuery aggregateQuery = new AggregateQueryImpl().attrX(xAttr).attrY(yAttr).attrDistinct(distinctAttr).query(q);
    indexedRepositoryDecorator.aggregate(aggregateQuery);
    verify(searchService).aggregate(repositoryEntityType, aggregateQuery);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) Test(org.testng.annotations.Test)

Example 9 with AggregateQueryImpl

use of org.molgenis.data.support.AggregateQueryImpl 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

AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)9 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)8 AggregateResult (org.molgenis.data.aggregation.AggregateResult)7 Test (org.testng.annotations.Test)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 QueryImpl (org.molgenis.data.support.QueryImpl)5 Attribute (org.molgenis.data.meta.model.Attribute)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 URISyntaxException (java.net.URISyntaxException)1 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)1 ResponseEntity (org.springframework.http.ResponseEntity)1