Search in sources :

Example 1 with I18nFormat

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

the class CompleteDataSetRegistrationController method registerCompleteDataSet.

private CompleteDataSetRegistration registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, String storedBy, Date completionDate) throws WebMessageException {
    I18nFormat format = i18nManager.getI18nFormat();
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("dataSet can not be null."));
    }
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("period can not be null"));
    }
    if (orgUnit == null) {
        throw new WebMessageException(WebMessageUtils.conflict("organisationUnit can not be null"));
    }
    if (attributeOptionCombo == null) {
        throw new WebMessageException(WebMessageUtils.conflict("attributeOptionCombo can not be null"));
    }
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
    if (registration == null) {
        registration = new CompleteDataSetRegistration();
        registration.setDataSet(dataSet);
        registration.setPeriod(period);
        registration.setSource(orgUnit);
        registration.setAttributeOptionCombo(attributeOptionCombo);
        registration.setDate(completionDate != null ? completionDate : new Date());
        registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
        registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
        registrationService.saveCompleteDataSetRegistration(registration);
    } else {
        registration.setDate(completionDate != null ? completionDate : new Date());
        registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
        registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
        registrationService.updateCompleteDataSetRegistration(registration);
    }
    return registration;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Date(java.util.Date)

Example 2 with I18nFormat

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

the class DefaultDataQueryService method getFromUrl.

// -------------------------------------------------------------------------
// DataQueryService implementation
// -------------------------------------------------------------------------
@Override
public DataQueryParams getFromUrl(Set<String> dimensionParams, Set<String> filterParams, AggregationType aggregationType, String measureCriteria, String preAggregationMeasureCriteria, Date startDate, Date endDate, boolean skipMeta, boolean skipData, boolean skipRounding, boolean completedOnly, boolean hierarchyMeta, boolean ignoreLimit, boolean hideEmptyRows, boolean hideEmptyColumns, boolean showHierarchy, boolean includeNumDen, DisplayProperty displayProperty, IdScheme outputIdScheme, IdScheme inputIdScheme, boolean duplicatesOnly, String approvalLevel, Date relativePeriodDate, String userOrgUnit, boolean allowAllPeriods, DhisApiVersion apiVersion) {
    I18nFormat format = i18nManager.getI18nFormat();
    DataQueryParams.Builder params = DataQueryParams.newBuilder();
    inputIdScheme = ObjectUtils.firstNonNull(inputIdScheme, IdScheme.UID);
    if (dimensionParams != null && !dimensionParams.isEmpty()) {
        params.addDimensions(getDimensionalObjects(dimensionParams, relativePeriodDate, userOrgUnit, format, allowAllPeriods, inputIdScheme));
    }
    if (filterParams != null && !filterParams.isEmpty()) {
        params.addFilters(getDimensionalObjects(filterParams, relativePeriodDate, userOrgUnit, format, allowAllPeriods, inputIdScheme));
    }
    if (measureCriteria != null && !measureCriteria.isEmpty()) {
        params.withMeasureCriteria(DataQueryParams.getMeasureCriteriaFromParam(measureCriteria));
    }
    if (preAggregationMeasureCriteria != null && !preAggregationMeasureCriteria.isEmpty()) {
        params.withPreAggregationMeasureCriteria(DataQueryParams.getMeasureCriteriaFromParam(preAggregationMeasureCriteria));
    }
    return params.withAggregationType(aggregationType).withStartDate(startDate).withEndDate(endDate).withSkipMeta(skipMeta).withSkipData(skipData).withSkipRounding(skipRounding).withCompletedOnly(completedOnly).withIgnoreLimit(ignoreLimit).withHierarchyMeta(hierarchyMeta).withHideEmptyRows(hideEmptyRows).withHideEmptyColumns(hideEmptyColumns).withShowHierarchy(showHierarchy).withIncludeNumDen(includeNumDen).withDisplayProperty(displayProperty).withOutputIdScheme(outputIdScheme).withOutputFormat(OutputFormat.ANALYTICS).withDuplicatesOnly(duplicatesOnly).withApprovalLevel(approvalLevel).withApiVersion(apiVersion).build();
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 3 with I18nFormat

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

the class DefaultReportTableService method getReportTableGridByUser.

@Override
public Grid getReportTableGridByUser(String uid, Date reportingPeriod, String organisationUnitUid, User user) {
    I18nFormat format = i18nManager.getI18nFormat();
    ReportTable reportTable = getReportTable(uid);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
    List<OrganisationUnit> atLevels = new ArrayList<>();
    List<OrganisationUnit> inGroups = new ArrayList<>();
    if (reportTable.hasOrganisationUnitLevels()) {
        atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(reportTable.getOrganisationUnitLevels(), reportTable.getOrganisationUnits()));
    }
    if (reportTable.hasItemOrganisationUnitGroups()) {
        inGroups.addAll(organisationUnitService.getOrganisationUnits(reportTable.getItemOrganisationUnitGroups(), reportTable.getOrganisationUnits()));
    }
    reportTable.init(user, reportingPeriod, organisationUnit, atLevels, inGroups, format);
    Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(reportTable);
    Grid reportTableGrid = reportTable.getGrid(new ListGrid(), valueMap, DisplayProperty.SHORTNAME, true);
    reportTable.clearTransientState();
    return reportTableGrid;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) ArrayList(java.util.ArrayList) ReportTable(org.hisp.dhis.reporttable.ReportTable) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 4 with I18nFormat

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

the class DefaultEventDataQueryService method getFromUrl.

@Override
public EventQueryParams getFromUrl(String program, String stage, Date startDate, Date endDate, Set<String> dimension, Set<String> filter, OrganisationUnitSelectionMode ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean skipData, boolean completedOnly, boolean hierarchyMeta, boolean coordinatesOnly, EventStatus eventStatus, ProgramStatus programStatus, DisplayProperty displayProperty, Date relativePeriodDate, String userOrgUnit, String coordinateField, Integer page, Integer pageSize, DhisApiVersion apiVersion) {
    I18nFormat format = i18nManager.getI18nFormat();
    EventQueryParams.Builder params = new EventQueryParams.Builder();
    IdScheme idScheme = IdScheme.UID;
    List<OrganisationUnit> userOrgUnits = dataQueryService.getUserOrgUnits(null, userOrgUnit);
    Program pr = programService.getProgram(program);
    if (pr == null) {
        throw new IllegalQueryException("Program does not exist: " + program);
    }
    ProgramStage ps = programStageService.getProgramStage(stage);
    if (StringUtils.isNotEmpty(stage) && ps == null) {
        throw new IllegalQueryException("Program stage is specified but does not exist: " + stage);
    }
    if (dimension != null) {
        for (String dim : dimension) {
            String dimensionId = getDimensionFromParam(dim);
            List<String> items = getDimensionItemsFromParam(dim);
            DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
            if (dimObj != null) {
                params.addDimension(dimObj);
            } else {
                params.addItem(getQueryItem(dim, pr));
            }
        }
    }
    if (filter != null) {
        for (String dim : filter) {
            String dimensionId = getDimensionFromParam(dim);
            List<String> items = getDimensionItemsFromParam(dim);
            DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
            if (dimObj != null) {
                params.addFilter(dimObj);
            } else {
                params.addItemFilter(getQueryItem(dim, pr));
            }
        }
    }
    if (asc != null) {
        for (String sort : asc) {
            params.addAscSortItem(getSortItem(sort, pr));
        }
    }
    if (desc != null) {
        for (String sort : desc) {
            params.addDescSortItem(getSortItem(sort, pr));
        }
    }
    return params.withProgram(pr).withProgramStage(ps).withStartDate(startDate).withEndDate(endDate).withOrganisationUnitMode(ouMode).withSkipMeta(skipMeta).withSkipData(skipData).withCompletedOnly(completedOnly).withHierarchyMeta(hierarchyMeta).withCoordinatesOnly(coordinatesOnly).withEventStatus(eventStatus).withDisplayProperty(displayProperty).withCoordinateField(getCoordinateField(coordinateField)).withPage(page).withPageSize(pageSize).withProgramStatus(programStatus).withApiVersion(apiVersion).build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 5 with I18nFormat

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

the class EventChartController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
protected void postProcessEntity(EventChart eventChart) throws Exception {
    eventChart.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : eventChart.getOrganisationUnits()) {
        eventChart.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    I18nFormat format = i18nManager.getI18nFormat();
    if (eventChart.getPeriods() != null && !eventChart.getPeriods().isEmpty()) {
        for (Period period : eventChart.getPeriods()) {
            period.setName(format.formatPeriod(period));
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

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