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);
}
}
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations