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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations