Search in sources :

Example 11 with RootNode

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

the class ExcelNodeSerializer method startSerialize.

@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
    workbook = new XSSFWorkbook();
    sheet = workbook.createSheet("Sheet1");
    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold(true);
    XSSFCellStyle boldCellStyle = workbook.createCellStyle();
    boldCellStyle.setFont(boldFont);
    // build schema
    for (Node child : rootNode.getChildren()) {
        if (child.isCollection()) {
            if (!child.getChildren().isEmpty()) {
                Node node = child.getChildren().get(0);
                XSSFRow row = sheet.createRow(0);
                int cellIdx = 0;
                for (Node property : node.getChildren()) {
                    if (property.isSimple()) {
                        XSSFCell cell = row.createCell(cellIdx++);
                        cell.setCellValue(property.getName());
                        cell.setCellStyle(boldCellStyle);
                    }
                }
            }
        }
    }
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Example 12 with RootNode

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

the class DefaultMetadataVersionService method getMetadataVersionsAsNode.

@Override
public RootNode getMetadataVersionsAsNode(List<MetadataVersion> versions) {
    RootNode rootNode = NodeUtils.createRootNode("metadataversions");
    CollectionNode collectionNode = new CollectionNode("metadataversions", true);
    rootNode.addChild(collectionNode);
    for (MetadataVersion version : versions) {
        ComplexNode complexNode = new ComplexNode("");
        complexNode.addChild(new SimpleNode("name", version.getName()));
        complexNode.addChild(new SimpleNode("type", version.getType()));
        complexNode.addChild(new SimpleNode("created", version.getCreated()));
        complexNode.addChild(new SimpleNode("id", version.getUid()));
        complexNode.addChild(new SimpleNode("importdate", version.getImportDate()));
        complexNode.addChild(new SimpleNode("hashCode", version.getHashCode()));
        collectionNode.addChild(complexNode);
    }
    return rootNode;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) RootNode(org.hisp.dhis.node.types.RootNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Example 13 with RootNode

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

the class AuditController method getDataApprovalAudit.

@RequestMapping(value = "dataApproval", method = RequestMethod.GET)
@ResponseBody
public RootNode getDataApprovalAudit(@RequestParam(required = false, defaultValue = "") List<String> dal, @RequestParam(required = false, defaultValue = "") List<String> wf, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false, defaultValue = "") List<String> aoc, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @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());
    }
    DataApprovalAuditQueryParams params = new DataApprovalAuditQueryParams();
    params.setLevels(new HashSet<>(getDataApprovalLevel(dal)));
    params.setWorkflows(new HashSet<>(getDataApprovalWorkflow(wf)));
    params.setOrganisationUnits(new HashSet<>(getOrganisationUnit(ou)));
    params.setAttributeOptionCombos(new HashSet<>(getCategoryOptionCombo(aoc)));
    params.setStartDate(startDate);
    params.setEndDate(endDate);
    List<DataApprovalAudit> audits = dataApprovalAuditService.getDataApprovalAudits(params);
    Pager pager = null;
    RootNode rootNode = NodeUtils.createMetadata();
    if (!skipPaging) {
        pager = new Pager(page, audits.size(), pageSize);
        audits = audits.subList(pager.getOffset(), pager.getOffset() + pager.getPageSize() < audits.size() ? pager.getOffset() + pager.getPageSize() : audits.size());
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode dataApprovalAudits = rootNode.addChild(new CollectionNode("dataApprovalAudits", true));
    dataApprovalAudits.addChildren(fieldFilterService.filter(DataApprovalAudit.class, audits, fields).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataApprovalAuditQueryParams(org.hisp.dhis.dataapproval.DataApprovalAuditQueryParams) Pager(org.hisp.dhis.common.Pager) DataApprovalAudit(org.hisp.dhis.dataapproval.DataApprovalAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with RootNode

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

the class CompleteDataSetRegistrationController method getCompleteDataSetRegistrationsJson.

// Legacy (>= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.GET, produces = CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getCompleteDataSetRegistrationsJson(@RequestParam Set<String> dataSet, @RequestParam(required = false) String period, @RequestParam Date startDate, @RequestParam Date endDate, @RequestParam Set<String> orgUnit, @RequestParam(required = false) boolean children, HttpServletResponse response) throws IOException {
    List<String> fields = Lists.newArrayList(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],attributeOptionCombo[code,name,created,lastUpdated,id]");
        fields.addAll(defaults);
    }
    response.setContentType(CONTENT_TYPE_JSON);
    CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations(dataSet, period, startDate, endDate, orgUnit, children);
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(CompleteDataSetRegistration.class, completeDataSetRegistrations.getCompleteDataSetRegistrations(), fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) CompleteDataSetRegistrations(org.hisp.dhis.dataset.CompleteDataSetRegistrations) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with RootNode

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

the class AbstractCrudController method getObjectList.

//--------------------------------------------------------------------------
// GET
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams, HttpServletResponse response, HttpServletRequest request, User currentUser) throws QueryParserException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(getSchema());
    if (fields.isEmpty()) {
        fields.addAll(Preset.defaultPreset().getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    if (!aclService.canRead(currentUser, getEntityClass())) {
        throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
    }
    List<T> entities = getEntityList(metadata, options, filters, orders);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), entities.size(), options.getPageSize());
        entities = PagerUtils.pageCollection(entities, pager);
    }
    postProcessEntities(entities);
    postProcessEntities(entities, options, rpParameters);
    handleLinksAndAccess(entities, fields, false, currentUser);
    linkService.generatePagerLinks(pager, getEntityClass());
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.getConfig().setInclusionStrategy(getInclusionStrategy(rpParameters.get("inclusionStrategy")));
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.filter(getEntityClass(), entities, fields));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) 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