Search in sources :

Example 26 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getFromRequest.

@Override
public EventQueryParams getFromRequest(EventDataQueryRequest request, boolean analyzeOnly) {
    I18nFormat format = i18nManager.getI18nFormat();
    EventQueryParams.Builder params = new EventQueryParams.Builder();
    IdScheme idScheme = IdScheme.UID;
    List<OrganisationUnit> userOrgUnits = dataQueryService.getUserOrgUnits(null, request.getUserOrgUnit());
    Program pr = programService.getProgram(request.getProgram());
    if (pr == null) {
        throwIllegalQueryEx(ErrorCode.E7129, request.getProgram());
    }
    ProgramStage ps = programStageService.getProgramStage(request.getStage());
    if (StringUtils.isNotEmpty(request.getStage()) && ps == null) {
        throwIllegalQueryEx(ErrorCode.E7130, request.getStage());
    }
    addDimensionsIntoParams(params, request, userOrgUnits, format, pr, idScheme);
    addFiltersIntoParams(params, request, userOrgUnits, format, pr, idScheme);
    addSortIntoParams(params, request, pr);
    if (request.getAggregationType() != null) {
        params.withAggregationType(AnalyticsAggregationType.fromAggregationType(request.getAggregationType()));
    }
    EventQueryParams.Builder builder = params.withValue(getValueDimension(request.getValue())).withSkipRounding(request.isSkipRounding()).withShowHierarchy(request.isShowHierarchy()).withSortOrder(request.getSortOrder()).withLimit(request.getLimit()).withOutputType(MoreObjects.firstNonNull(request.getOutputType(), EventOutputType.EVENT)).withCollapseDataDimensions(request.isCollapseDataDimensions()).withAggregateData(request.isAggregateData()).withProgram(pr).withProgramStage(ps).withStartDate(request.getStartDate()).withEndDate(request.getEndDate()).withOrganisationUnitMode(request.getOuMode()).withSkipMeta(request.isSkipMeta()).withSkipData(request.isSkipData()).withCompletedOnly(request.isCompletedOnly()).withHierarchyMeta(request.isHierarchyMeta()).withCoordinatesOnly(request.isCoordinatesOnly()).withCoordinateOuFallback(request.isCoordinateOuFallback()).withIncludeMetadataDetails(request.isIncludeMetadataDetails()).withDataIdScheme(request.getDataIdScheme()).withOutputIdScheme(request.getOutputIdScheme()).withEventStatuses(request.getEventStatus()).withDisplayProperty(request.getDisplayProperty()).withTimeField(request.getTimeField()).withOrgUnitField(request.getOrgUnitField()).withCoordinateField(getCoordinateField(request.getCoordinateField())).withFallbackCoordinateField(getFallbackCoordinateField(request.getFallbackCoordinateField())).withHeaders(request.getHeaders()).withPage(request.getPage()).withPageSize(request.getPageSize()).withPaging(request.isPaging()).withProgramStatuses(request.getProgramStatus()).withApiVersion(request.getApiVersion());
    if (analyzeOnly) {
        builder = builder.withSkipData(true).withAnalyzeOrderId();
    }
    EventQueryParams eventQueryParams = builder.build();
    // empty period dimension means default period.
    if (hasPeriodDimension(eventQueryParams) && hasNotDefaultPeriod(eventQueryParams)) {
        builder.withSkipPartitioning(true);
        eventQueryParams = builder.build();
    }
    return eventQueryParams;
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) I18nFormat(org.hisp.dhis.i18n.I18nFormat) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 27 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DefaultI18nManager method getI18nFormat.

@Override
public I18nFormat getI18nFormat() {
    I18nFormat formatter = new I18nFormat(getGlobalResourceBundle());
    formatter.init();
    return formatter;
}
Also used : I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 28 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DefaultReportService method renderHtmlReport.

@Override
@Transactional(readOnly = true)
public void renderHtmlReport(Writer writer, String uid, Date date, String ou) {
    Report report = getReport(uid);
    OrganisationUnit organisationUnit = null;
    List<OrganisationUnit> organisationUnitHierarchy = new ArrayList<>();
    List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
    List<String> periods = new ArrayList<>();
    I18nFormat format = i18nManager.getI18nFormat();
    if (ou != null) {
        organisationUnit = organisationUnitService.getOrganisationUnit(ou);
        if (organisationUnit != null) {
            organisationUnitHierarchy.add(organisationUnit);
            OrganisationUnit parent = organisationUnit;
            while (parent.getParent() != null) {
                parent = parent.getParent();
                organisationUnitHierarchy.add(parent);
            }
            organisationUnitChildren.addAll(organisationUnit.getChildren());
        }
    }
    Calendar calendar = PeriodType.getCalendar();
    if (report != null && report.hasRelativePeriods()) {
        AnalyticsFinancialYearStartKey financialYearStart = systemSettingManager.getSystemSetting(SettingKey.ANALYTICS_FINANCIAL_YEAR_START, AnalyticsFinancialYearStartKey.class);
        if (calendar.isIso8601()) {
            for (Period period : report.getRelatives().getRelativePeriods(date, format, true, financialYearStart)) {
                periods.add(period.getIsoDate());
            }
        } else {
            periods = IdentifiableObjectUtils.getLocalPeriodIdentifiers(report.getRelatives().getRelativePeriods(date, format, true, financialYearStart), calendar);
        }
    }
    String dateString = DateUtils.getMediumDateString(date);
    if (date != null && !calendar.isIso8601()) {
        dateString = calendar.formattedDate(calendar.fromIso(date));
    }
    final VelocityContext context = new VelocityContext();
    context.put("report", report);
    context.put("organisationUnit", organisationUnit);
    context.put("organisationUnitHierarchy", organisationUnitHierarchy);
    context.put("organisationUnitChildren", organisationUnitChildren);
    context.put("date", dateString);
    context.put("periods", periods);
    context.put("format", format);
    context.put("encoder", ENCODER);
    new VelocityManager().getEngine().getTemplate("html-report.vm").merge(context, writer);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) AnalyticsFinancialYearStartKey(org.hisp.dhis.analytics.AnalyticsFinancialYearStartKey) JasperReport(net.sf.jasperreports.engine.JasperReport) Report(org.hisp.dhis.report.Report) VelocityContext(org.apache.velocity.VelocityContext) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager) Calendar(org.hisp.dhis.calendar.Calendar) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) TextUtils.getCommaDelimitedString(org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class DefaultVisualizationGridService method getVisualizationGridByUser.

@Override
@Transactional(readOnly = true)
public Grid getVisualizationGridByUser(final String uid, final Date relativePeriodDate, final String organisationUnitUid, final User user) {
    Visualization visualization = visualizationService.getVisualization(uid);
    final boolean hasPermission = visualization != null;
    if (hasPermission) {
        I18nFormat format = i18nManager.getI18nFormat();
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
        List<OrganisationUnit> atLevels = new ArrayList<>();
        List<OrganisationUnit> inGroups = new ArrayList<>();
        if (visualization.hasOrganisationUnitLevels()) {
            atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(visualization.getOrganisationUnitLevels(), visualization.getOrganisationUnits()));
        }
        if (visualization.hasItemOrganisationUnitGroups()) {
            inGroups.addAll(organisationUnitService.getOrganisationUnits(visualization.getItemOrganisationUnitGroups(), visualization.getOrganisationUnits()));
        }
        visualization.init(user, relativePeriodDate, organisationUnit, atLevels, inGroups, format);
        Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(visualization);
        Grid visualizationGrid = visualization.getGrid(new ListGrid(), valueMap, SHORTNAME, true);
        visualization.clearTransientState();
        return visualizationGrid;
    } else {
        return new ListGrid();
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with I18nFormat

use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.

the class LockExceptionController method getLockExceptions.

// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@GetMapping(produces = ContextUtils.CONTENT_TYPE_JSON)
@ResponseBody
public RootNode getLockExceptions(@RequestParam(required = false) String key, @RequestParam Map<String, String> rpParameters, HttpServletRequest request, HttpServletResponse response) throws WebMessageException {
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<LockException> lockExceptions = new ArrayList<>();
    if (key != null) {
        LockException lockException = dataSetService.getLockException(MathUtils.parseInt(key));
        if (lockException == null) {
            throw new WebMessageException(notFound("Cannot find LockException with key: " + key));
        }
        lockExceptions.add(lockException);
    } else if (!filters.isEmpty()) {
        lockExceptions = dataSetService.filterLockExceptions(filters);
    } else {
        lockExceptions = dataSetService.getAllLockExceptions();
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        pager = new Pager(options.getPage(), lockExceptions.size(), options.getPageSize());
        lockExceptions = PagerUtils.pageCollection(lockExceptions, pager);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    I18nFormat format = this.i18nManager.getI18nFormat();
    for (LockException lockException : lockExceptions) {
        lockException.getPeriod().setName(format.formatPeriod(lockException.getPeriod()));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(LockException.class, new FieldFilterParams(lockExceptions, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) LockException(org.hisp.dhis.dataset.LockException) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) ArrayList(java.util.ArrayList) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

I18nFormat (org.hisp.dhis.i18n.I18nFormat)37 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)24 Period (org.hisp.dhis.period.Period)19 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 Grid (org.hisp.dhis.common.Grid)5 IdScheme (org.hisp.dhis.common.IdScheme)5 I18n (org.hisp.dhis.i18n.I18n)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)4 User (org.hisp.dhis.user.User)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 HashMap (java.util.HashMap)3