use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class BaseAnalyticalObjectTest method testGetIdentifier.
@Test
public void testGetIdentifier() {
DataElementGroup oA = new DataElementGroup();
DataElementGroup oB = new DataElementGroup();
DataElementGroup oC = new DataElementGroup();
oA.setUid("a1");
oB.setUid("b1");
oC.setUid("c1");
List<DimensionalItemObject> column = new ArrayList<>();
column.add(oC);
column.add(oA);
List<DimensionalItemObject> row = new ArrayList<>();
row.add(oB);
assertEquals("a1-b1-c1", BaseAnalyticalObject.getIdentifier(column, row));
assertEquals("b1", BaseAnalyticalObject.getIdentifier(new ArrayList<>(), row));
assertEquals("b1", BaseAnalyticalObject.getIdentifier(null, row));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatReferenceConnectAUTO.
@Test
public void testPreheatReferenceConnectAUTO() {
DataElementGroup dataElementGroup = fromJson("preheat/degAAutoRef.json", DataElementGroup.class);
defaultSetup();
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier(PreheatIdentifier.AUTO);
params.setPreheatMode(PreheatMode.REFERENCE);
params.getObjects().put(DataElementGroup.class, Lists.newArrayList(dataElementGroup));
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
preheatService.connectReferences(dataElementGroup, preheat, PreheatIdentifier.AUTO);
List<DataElement> members = new ArrayList<>(dataElementGroup.getMembers());
assertEquals("DataElementA", members.get(0).getName());
assertEquals("DataElementCodeA", members.get(0).getCode());
assertEquals("DataElementB", members.get(1).getName());
assertEquals("DataElementCodeB", members.get(1).getCode());
assertEquals("DataElementC", members.get(2).getName());
assertEquals("DataElementCodeC", members.get(2).getCode());
assertEquals("FirstNameA", dataElementGroup.getUser().getFirstName());
assertEquals("SurnameA", dataElementGroup.getUser().getSurname());
assertEquals("UserCodeA", dataElementGroup.getUser().getCode());
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatAllMetadataUID.
@Test
public void testPreheatAllMetadataUID() {
DataElementGroup dataElementGroup = new DataElementGroup("DataElementGroupA");
dataElementGroup.setAutoFields();
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
dataElementGroup.addDataElement(de1);
dataElementGroup.addDataElement(de2);
dataElementGroup.addDataElement(de3);
dataElementGroup.setUser(user);
manager.save(dataElementGroup);
PreheatParams params = new PreheatParams();
params.setPreheatMode(PreheatMode.ALL);
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
assertFalse(preheat.isEmpty());
assertFalse(preheat.isEmpty(PreheatIdentifier.UID));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElement.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElementGroup.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, User.class));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de1.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de2.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de3.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, User.class, user.getUid()));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class AnalyticalObjectEmbeddedDimensionUpgrader method executeInTransaction.
@Override
public void executeInTransaction() {
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> dataElementGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
DataElementGroupSetDimension dimension = new DataElementGroupSetDimension();
dimension.setDimension((DataElementGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addDataElementGroupSetDimension(dimension);
};
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> orgUnitGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
OrganisationUnitGroupSetDimension dimension = new OrganisationUnitGroupSetDimension();
dimension.setDimension((OrganisationUnitGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addOrganisationUnitGroupSetDimension(dimension);
};
BiConsumer<BaseDimensionalEmbeddedObject, AnalyticalObject> categoryOptionGroupSetConsumer = (embeddedDimension, analyticalObject) -> {
CategoryOptionGroupSetDimension dimension = new CategoryOptionGroupSetDimension();
dimension.setDimension((CategoryOptionGroupSet) embeddedDimension.getDimension());
dimension.setItems(DimensionalObjectUtils.asTypedList(embeddedDimension.getItems()));
analyticalObject.addCategoryOptionGroupSetDimension(dimension);
};
try {
upgradeGrupSetDimensions("reporttable", "orgunitgroupset", "orgunitgroup", ReportTable.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("reporttable", "dataelementgroupset", "dataelementgroup", ReportTable.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
upgradeGrupSetDimensions("reporttable", "categoryoptiongroupset", "categoryoptiongroup", ReportTable.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
upgradeGrupSetDimensions("chart", "orgunitgroupset", "orgunitgroup", Chart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("chart", "dataelementgroupset", "dataelementgroup", Chart.class, DataElementGroupSet.class, DataElementGroup.class, dataElementGroupSetConsumer);
upgradeGrupSetDimensions("chart", "categoryoptiongroupset", "categoryoptiongroup", Chart.class, CategoryOptionGroupSet.class, CategoryOptionGroup.class, categoryOptionGroupSetConsumer);
upgradeGrupSetDimensions("eventreport", "orgunitgroupset", "orgunitgroup", EventReport.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
upgradeGrupSetDimensions("eventchart", "orgunitgroupset", "orgunitgroup", EventChart.class, OrganisationUnitGroupSet.class, OrganisationUnitGroup.class, orgUnitGroupSetConsumer);
} catch (Exception ex) {
log.debug("Error during group set dimensions upgrade of favorite, probably because upgrade was already done", ex);
return;
}
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DataElementOperandController method getObjectList.
@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams) throws QueryParserException {
Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<Order> orders = orderParams.getOrders(schema);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
WebOptions options = new WebOptions(rpParameters);
WebMetadata metadata = new WebMetadata();
List<DataElementOperand> dataElementOperands;
if (options.isTrue("persisted")) {
dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
} else {
boolean totals = options.isTrue("totals");
String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
String ds = options.get("dataSet");
if (deg != null) {
DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
} else if (ds != null) {
DataSet dataSet = manager.get(DataSet.class, ds);
dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
} else {
List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
}
}
Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, options.getRootJunction());
query.setDefaultOrder();
query.setObjects(dataElementOperands);
dataElementOperands = (List<DataElementOperand>) queryService.query(query);
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
linkService.generatePagerLinks(pager, DataElementOperand.class);
dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.filter(DataElementOperand.class, dataElementOperands, fields));
return rootNode;
}
Aggregations