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, @CurrentUser User currentUser) 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);
}
}
// This is needed for two reasons:
// 1) We are doing in-memory paging;
// 2) We have to count all items respecting the filtering and the
// initial universe of elements. In this case, the variable
// "dataElementOperands".
Query queryForCount = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders);
queryForCount.setObjects(dataElementOperands);
List<DataElementOperand> totalOfItems = (List<DataElementOperand>) queryService.query(queryForCount);
Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, PaginationUtils.getPaginationData(options), options.getRootJunction());
query.setDefaultOrder();
query.setObjects(dataElementOperands);
dataElementOperands = (List<DataElementOperand>) queryService.query(query);
Pager pager = metadata.getPager();
if (options.hasPaging() && pager == null) {
final long countTotal = isNotEmpty(totalOfItems) ? totalOfItems.size() : 0;
// fetch the count for the current query from a short-lived cache
long cachedCountTotal = paginationCountCache.computeIfAbsent(calculatePaginationCountKey(currentUser, filters, options), () -> countTotal);
pager = new Pager(options.getPage(), cachedCountTotal, options.getPageSize());
linkService.generatePagerLinks(pager, DataElementOperand.class);
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
rootNode.addChild(fieldFilterService.toCollectionNode(DataElementOperand.class, new FieldFilterParams(dataElementOperands, fields)));
return rootNode;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class ConfigurationController method setInfrastructuralDataElements.
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/infrastructuralDataElements")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setInfrastructuralDataElements(@RequestBody String uid) throws NotFoundException {
uid = trim(uid);
DataElementGroup group = identifiableObjectManager.get(DataElementGroup.class, uid);
if (group == null) {
throw new NotFoundException("Data element group", uid);
}
Configuration configuration = configurationService.getConfiguration();
configuration.setInfrastructuralDataElements(group);
configurationService.setConfiguration(configuration);
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testObjectBundleShouldAddToObjectAndPreheat.
@Test
void testObjectBundleShouldAddToObjectAndPreheat() {
DataElementGroup dataElementGroup = fromJson("dxf2/degAUidRef.json", DataElementGroup.class);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
params.addObject(dataElementGroup);
ObjectBundle bundle = objectBundleService.create(params);
bundle.getPreheat().put(bundle.getPreheatIdentifier(), dataElementGroup);
assertTrue(StreamSupport.stream(bundle.getObjects(DataElementGroup.class).spliterator(), false).anyMatch(dataElementGroup::equals));
assertTrue(bundle.getPreheat().containsKey(PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid()));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class GetDataElementsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
canReadType(DataElement.class);
if (id != null && id != ALL) {
DataElementGroup dataElementGroup = dataElementService.getDataElementGroup(id);
if (dataElementGroup != null) {
dataElements = new ArrayList<>(dataElementGroup.getMembers());
}
} else if (categoryComboId != null && categoryComboId != ALL) {
CategoryCombo categoryCombo = categoryService.getCategoryCombo(categoryComboId);
if (categoryCombo != null) {
dataElements = new ArrayList<>(dataElementService.getDataElementByCategoryCombo(categoryCombo));
}
} else if (dataSetId != null) {
DataSet dataset = dataSetService.getDataSet(dataSetId);
if (dataset != null) {
dataElements = new ArrayList<>(dataset.getDataElements());
}
} else if (periodTypeName != null) {
PeriodType periodType = periodService.getPeriodTypeByName(periodTypeName);
if (periodType != null) {
dataElements = new ArrayList<>(dataElementService.getDataElementsByPeriodType(periodType));
}
} else if (domain != null) {
if (domain.equals(DataElementDomain.AGGREGATE.getValue())) {
dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.AGGREGATE));
} else {
dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.TRACKER));
}
} else {
dataElements = new ArrayList<>(dataElementService.getAllDataElements());
ContextUtils.clearIfNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataElements);
}
if (key != null) {
dataElements = IdentifiableObjectUtils.filterNameByKey(dataElements, key, true);
}
if (dataElements == null) {
dataElements = new ArrayList<>();
}
Collections.sort(dataElements);
if (aggregate) {
FilterUtils.filter(dataElements, new AggregatableDataElementFilter());
}
User currentUser = currentUserService.getCurrentUser();
dataElements.forEach(instance -> canReadInstance(instance, currentUser));
if (usePaging) {
this.paging = createPaging(dataElements.size());
dataElements = dataElements.subList(paging.getStartPos(), paging.getEndPos());
}
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatAllUID.
@Test
@SuppressWarnings("unchecked")
public void testPreheatAllUID() {
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);
params.setClasses(Sets.newHashSet(DataElement.class, DataElementGroup.class, User.class));
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()));
}
Aggregations