use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class PredictionServiceTest method getDataValue.
private String getDataValue(DataElement dataElement, CategoryOptionCombo combo, CategoryOptionCombo attributeOptionCombo, OrganisationUnit source, Period period) {
DataExportParams params = new DataExportParams().setDataElementOperands(Sets.newHashSet(new DataElementOperand(dataElement, combo))).setAttributeOptionCombos(Sets.newHashSet(attributeOptionCombo)).setOrganisationUnits(Sets.newHashSet(source)).setPeriods(Sets.newHashSet(periodService.reloadPeriod(period)));
List<DeflatedDataValue> values = dataValueService.getDeflatedDataValues(params);
if (values != null && values.size() > 0) {
return values.get(0).getValue();
}
return null;
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataValidationTask method getDataValueMap.
/**
* Gets data elements and data element operands from the datavalue table.
*/
private void getDataValueMap() {
DataExportParams params = new DataExportParams();
params.setDataElements(periodTypeX.getDataElements());
params.setDataElementOperands(periodTypeX.getDataElementOperands());
params.setIncludedDate(period.getStartDate());
params.setOrganisationUnits(new HashSet<>(orgUnits));
params.setPeriodTypes(periodTypeX.getAllowedPeriodTypes());
params.setCoDimensionConstraints(context.getCoDimensionConstraints());
params.setCogDimensionConstraints(context.getCogDimensionConstraints());
if (context.getAttributeCombo() != null) {
params.setAttributeOptionCombos(Sets.newHashSet(context.getAttributeCombo()));
}
List<DeflatedDataValue> dataValues = dataValueService.getDeflatedDataValues(params);
dataMap = new MapMapMap<>();
MapMapMap<Long, String, DimensionalItemObject, Long> duplicateCheck = new MapMapMap<>();
for (DeflatedDataValue dv : dataValues) {
DataElement dataElement = periodTypeX.getDataElementIdMap().get(dv.getDataElementId());
String deoIdKey = periodTypeX.getDeoIds(dv.getDataElementId(), dv.getCategoryOptionComboId());
DataElementOperand dataElementOperand = periodTypeX.getDataElementOperandIdMap().get(deoIdKey);
Period p = getPeriod(dv.getPeriodId());
long orgUnitId = dv.getSourceId();
String attributeOptionComboUid = getAttributeOptionCombo(dv.getAttributeOptionComboId()).getUid();
if (dataElement != null) {
Object value = getObjectValue(dv.getValue(), dataElement.getValueType());
addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElement, value, p, duplicateCheck);
}
if (dataElementOperand != null) {
Object value = getObjectValue(dv.getValue(), dataElementOperand.getDataElement().getValueType());
addValueToDataMap(orgUnitId, attributeOptionComboUid, dataElementOperand, value, p, duplicateCheck);
}
}
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataElementGroupController method getOperandsByQuery.
@GetMapping("/{uid}/operands/query/{q}")
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
WebOptions options = new WebOptions(parameters);
setUserContext(translateParams);
List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
if (dataElementGroups.isEmpty()) {
throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
}
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands = Lists.newArrayList();
for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
dataElementOperands.add(dataElementOperand);
}
}
metadata.setDataElementOperands(dataElementOperands);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
metadata.setPager(pager);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
metadata.setDataElementOperands(dataElementOperands);
linkService.generateLinks(metadata, false);
model.addAttribute("model", metadata);
model.addAttribute("viewClass", options.getViewClass("basic"));
return StringUtils.uncapitalize(getEntitySimpleName());
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataElementOperandControllerTest method verifyPaginationGetFirstPage.
@Test
void verifyPaginationGetFirstPage() throws Exception {
int pageSize = 15;
long totalSize = 150;
// Given
final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
final List<DataElementOperand> first50elements = dataElementOperands.subList(0, pageSize);
ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(first50elements));
doReturn(totalSize).when(queryService).count(any(Query.class));
// Then
ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("1")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
// Make sure that the first and last element in the page matches with
// the
// original list
List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(0).getDimensionItem()));
assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(pageSize - 1).getDimensionItem()));
}
use of org.hisp.dhis.dataelement.DataElementOperand in project dhis2-core by dhis2.
the class DataElementOperandControllerTest method verifyPaginationGetThirdPage.
@Test
void verifyPaginationGetThirdPage() throws Exception {
int pageSize = 25;
long totalSize = 100;
// Given
final List<DataElement> dataElements = rnd.objects(DataElement.class, 1).collect(Collectors.toList());
when(manager.getAllSorted(DataElement.class)).thenReturn(dataElements);
final List<DataElementOperand> dataElementOperands = rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList());
when(dataElementCategoryService.getOperands(dataElements, true)).thenReturn(rnd.objects(DataElementOperand.class, (int) totalSize).collect(Collectors.toList()));
final List<DataElementOperand> thirdPageElements = dataElementOperands.subList(50, 50 + pageSize);
ArgumentCaptor<FieldFilterParams> filterParamsArgumentCaptor = ArgumentCaptor.forClass(FieldFilterParams.class);
when(fieldFilterService.toCollectionNode(eq(DataElementOperand.class), filterParamsArgumentCaptor.capture())).thenReturn(buildResponse(thirdPageElements));
doReturn(totalSize).when(queryService).count(any(Query.class));
// Then
ResultActions resultActions = mockMvc.perform(get(ENDPOINT).param("totals", "true").param("pageSize", Integer.toString(pageSize)).param("page", Integer.toString(3))).andExpect(status().isOk()).andExpect(content().contentType("application/json")).andExpect(jsonPath("$.pager.pageSize").value(Integer.toString(pageSize))).andExpect(jsonPath("$.pager.page").value("3")).andExpect(jsonPath("$.pager.total").value(Long.toString(totalSize))).andExpect(jsonPath("$.pager.pageCount").value(Long.toString(totalSize / pageSize))).andExpect(jsonPath("$.dataElementOperands", hasSize(pageSize)));
final FieldFilterParams fieldFilterParams = filterParamsArgumentCaptor.getValue();
assertThat(fieldFilterParams.getObjects(), hasSize(pageSize));
assertThat(fieldFilterParams.getFields(), Matchers.is(Lists.newArrayList("*")));
// Make sure that the first and last element in the page matches with
// the
// original list
List<Map<String, Object>> jsonDataElementOperands = convertResponse(resultActions);
assertThat(jsonDataElementOperands.get(0).get("id"), Matchers.is(dataElementOperands.get(50).getDimensionItem()));
assertThat(jsonDataElementOperands.get(pageSize - 1).get("id"), Matchers.is(dataElementOperands.get(74).getDimensionItem()));
}
Aggregations