Search in sources :

Example 16 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class AuditController method getAggregateDataValueAudit.

@RequestMapping(value = "dataValue", method = RequestMethod.GET)
@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, 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);
    DataElementCategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
    DataElementCategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
    List<DataValueAudit> dataValueAudits;
    Pager pager = null;
    if (skipPaging) {
        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.filter(DataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class AuditController method getTrackedEntityAttributeValueAudit.

@RequestMapping(value = "trackedEntityAttributeValue", method = RequestMethod.GET)
@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, 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 (skipPaging) {
        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.filter(TrackedEntityAttributeValueAudit.class, attributeValueAudits, fields).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Pager(org.hisp.dhis.common.Pager) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class MeController method getCurrentUser.

@RequestMapping(value = "", method = RequestMethod.GET)
public void getCurrentUser(HttpServletResponse response) throws Exception {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    User currentUser = currentUserService.getCurrentUser();
    if (currentUser == null) {
        throw new NotAuthenticatedException();
    }
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    CollectionNode collectionNode = fieldFilterService.filter(User.class, Collections.singletonList(currentUser), fields);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    RootNode rootNode = NodeUtils.createRootNode(collectionNode.getChildren().get(0));
    if (fieldsContains("settings", fields)) {
        rootNode.addChild(new ComplexNode("settings")).addChildren(NodeUtils.createSimples(userSettingService.getUserSettingsWithFallbackByUserAsMap(currentUser, USER_SETTING_NAMES, true)));
    }
    if (fieldsContains("authorities", fields)) {
        rootNode.addChild(new CollectionNode("authorities")).addChildren(NodeUtils.createSimples(currentUser.getUserCredentials().getAllAuthorities()));
    }
    nodeService.serialize(rootNode, "application/json", response.getOutputStream());
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) NotAuthenticatedException(org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode)

Example 19 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class SystemController method getUuid.

@RequestMapping(value = "/uuid", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode getUuid(@RequestParam(required = false, defaultValue = "1") Integer limit) throws IOException, InvalidTypeException {
    limit = Math.min(limit, 10000);
    RootNode rootNode = new RootNode("codes");
    CollectionNode collectionNode = rootNode.addChild(new CollectionNode("codes"));
    collectionNode.setWrapping(false);
    for (int i = 0; i < limit; i++) {
        collectionNode.addChild(new SimpleNode("code", UUID.randomUUID().toString()));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with RootNode

use of org.hisp.dhis.node.types.RootNode in project dhis2-core by dhis2.

the class SystemController method getObjectCounts.

@RequestMapping(value = "/objectCounts", method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectCounts() {
    Map<Objects, Integer> objectCounts = statisticsProvider.getObjectCounts();
    RootNode rootNode = NodeUtils.createRootNode("objectCounts");
    for (Objects objects : objectCounts.keySet()) {
        rootNode.addChild(new SimpleNode(objects.getValue(), objectCounts.get(objects)));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) Objects(org.hisp.dhis.common.Objects) SimpleNode(org.hisp.dhis.node.types.SimpleNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RootNode (org.hisp.dhis.node.types.RootNode)112 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)59 CollectionNode (org.hisp.dhis.node.types.CollectionNode)50 SimpleNode (org.hisp.dhis.node.types.SimpleNode)40 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)30 GetMapping (org.springframework.web.bind.annotation.GetMapping)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)27 Pager (org.hisp.dhis.common.Pager)26 User (org.hisp.dhis.user.User)25 WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)24 ComplexNode (org.hisp.dhis.node.types.ComplexNode)20 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)17 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 Node (org.hisp.dhis.node.Node)11 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)10 List (java.util.List)9 Query (org.hisp.dhis.query.Query)9 DataSet (org.hisp.dhis.dataset.DataSet)7