use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AuditController method getAggregateDataValueAudit.
@GetMapping("dataValue")
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<DataElement> dataElements = new ArrayList<>();
dataElements.addAll(getDataElements(de));
dataElements.addAll(getDataElementsByDataSet(ds));
List<Period> periods = getPeriods(pe);
List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
CategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
List<DataValueAudit> dataValueAudits;
Pager pager = null;
if (PagerUtils.isSkipPaging(skipPaging, paging)) {
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
} else {
int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(DataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AuditController method getTrackedEntityAttributeValueAudit.
@GetMapping("trackedEntityAttributeValue")
@ResponseBody
public RootNode getTrackedEntityAttributeValueAudit(@RequestParam(required = false, defaultValue = "") List<String> tea, @RequestParam(required = false, defaultValue = "") List<String> tei, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes(tea);
List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances(tei);
List<TrackedEntityAttributeValueAudit> attributeValueAudits;
Pager pager = null;
if (PagerUtils.isSkipPaging(skipPaging, paging)) {
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
} else {
int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType);
pager = new Pager(page, total, pageSize);
attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityAttributeValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityAttributeValueAudit.class, new FieldFilterParams(attributeValueAudits, fields)).getChildren());
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class AuditController method getTrackedEntityDataValueAudit.
@GetMapping("trackedEntityDataValue")
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<DataElement> dataElements = getDataElements(de);
List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
List<TrackedEntityDataValueAudit> dataValueAudits;
Pager pager = null;
if (PagerUtils.isSkipPaging(skipPaging, paging)) {
dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
} else {
int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityDataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DataApprovalController method getApproval.
@GetMapping(value = STATUS_PATH, produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getApproval(@RequestParam Set<String> ds, @RequestParam(required = false) String pe, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam Set<String> ou, @RequestParam(required = false) boolean children, HttpServletResponse response) throws WebMessageException, BadRequestException {
List<String> fields = new ArrayList<>(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
List<String> defaults = new ArrayList<>();
defaults.add("period[id,name,code],organisationUnit[id,name,created,lastUpdated],dataSet[code,name,created,lastUpdated,id]");
fields.addAll(defaults);
}
Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
Set<Period> periods = parsePeriods(pe, startDate, endDate);
Set<OrganisationUnit> organisationUnits = new HashSet<>();
if (children) {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsWithChildren(ou));
} else {
organisationUnits.addAll(organisationUnitService.getOrganisationUnitsByUid(ou));
}
List<DataApprovalStateResponse> responses = new ArrayList<>();
for (DataSet dataSet : dataSets) {
for (OrganisationUnit organisationUnit : organisationUnits) {
for (Period period : periods) {
responses.add(getDataApprovalStateResponse(dataSet, organisationUnit, period));
}
}
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(DataApprovalStateResponse.class, new FieldFilterParams(responses, fields)));
return rootNode;
}
use of org.hisp.dhis.fieldfilter.FieldFilterParams in project dhis2-core by dhis2.
the class DataSetController method getCategoryCombinations.
@GetMapping("/{uid}/categoryCombos")
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
setUserContext(translateParams);
DataSet dataSet = manager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(conflict("Data set does not exist: " + uid));
}
List<CategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
Collections.sort(categoryCombos);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
return rootNode;
}
Aggregations