Search in sources :

Example 21 with I18nFormat

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

the class EventReportController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
protected void postProcessEntity(EventReport report) throws Exception {
    report.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : report.getOrganisationUnits()) {
        report.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    I18nFormat format = i18nManager.getI18nFormat();
    if (report.getPeriods() != null && !report.getPeriods().isEmpty()) {
        for (Period period : report.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)

Example 22 with I18nFormat

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

the class ChartController method postProcessEntity.

//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
public void postProcessEntity(Chart chart) throws Exception {
    chart.populateAnalyticalProperties();
    Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
    for (OrganisationUnit organisationUnit : chart.getOrganisationUnits()) {
        chart.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
    }
    if (chart.getPeriods() != null && !chart.getPeriods().isEmpty()) {
        I18nFormat format = i18nManager.getI18nFormat();
        for (Period period : chart.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)

Example 23 with I18nFormat

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

the class I18nInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    Action action = (Action) invocation.getAction();
    I18n i18n = i18nManager.getI18n(action.getClass());
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    Locale locale = localeManager.getCurrentLocale();
    // ---------------------------------------------------------------------
    // Make the objects available for web templates
    // ---------------------------------------------------------------------
    Map<String, Object> i18nMap = new HashMap<>(3);
    i18nMap.put(KEY_I18N, i18n);
    i18nMap.put(KEY_I18N_FORMAT, i18nFormat);
    i18nMap.put(KEY_LOCALE, locale);
    invocation.getStack().push(i18nMap);
    // ---------------------------------------------------------------------
    // Set the objects in the action class if the properties exist
    // ---------------------------------------------------------------------
    Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
    try {
        Ognl.setValue(KEY_I18N, contextMap, action, i18n);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_I18N_FORMAT, contextMap, action, i18nFormat);
    } catch (NoSuchPropertyException ignored) {
    }
    try {
        Ognl.setValue(KEY_LOCALE, contextMap, action, locale);
    } catch (NoSuchPropertyException ignored) {
    }
    return invocation.invoke();
}
Also used : Locale(java.util.Locale) Action(com.opensymphony.xwork2.Action) HashMap(java.util.HashMap) NoSuchPropertyException(ognl.NoSuchPropertyException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) I18n(org.hisp.dhis.i18n.I18n)

Example 24 with I18nFormat

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

the class DefaultDataQueryService method getFromRequest.

// -------------------------------------------------------------------------
// DataQueryService implementation
// -------------------------------------------------------------------------
@Override
public DataQueryParams getFromRequest(DataQueryRequest request) {
    I18nFormat format = i18nManager.getI18nFormat();
    DataQueryParams.Builder params = DataQueryParams.newBuilder();
    IdScheme inputIdScheme = ObjectUtils.firstNonNull(request.getInputIdScheme(), IdScheme.UID);
    if (request.getDimension() != null && !request.getDimension().isEmpty()) {
        params.addDimensions(getDimensionalObjects(request.getDimension(), request.getRelativePeriodDate(), request.getUserOrgUnit(), format, request.isAllowAllPeriods(), inputIdScheme));
    }
    if (request.getFilter() != null && !request.getFilter().isEmpty()) {
        params.addFilters(getDimensionalObjects(request.getFilter(), request.getRelativePeriodDate(), request.getUserOrgUnit(), format, request.isAllowAllPeriods(), inputIdScheme));
    }
    if (request.getMeasureCriteria() != null && !request.getMeasureCriteria().isEmpty()) {
        params.withMeasureCriteria(getMeasureCriteriaFromParam(request.getMeasureCriteria()));
    }
    if (request.getPreAggregationMeasureCriteria() != null && !request.getPreAggregationMeasureCriteria().isEmpty()) {
        params.withPreAggregationMeasureCriteria(getMeasureCriteriaFromParam(request.getPreAggregationMeasureCriteria()));
    }
    if (request.getAggregationType() != null) {
        params.withAggregationType(AnalyticsAggregationType.fromAggregationType(request.getAggregationType()));
    }
    return params.withStartDate(request.getStartDate()).withEndDate(request.getEndDate()).withOrder(request.getOrder()).withTimeField(request.getTimeField()).withOrgUnitField(request.getOrgUnitField()).withSkipMeta(request.isSkipMeta()).withSkipData(request.isSkipData()).withSkipRounding(request.isSkipRounding()).withCompletedOnly(request.isCompletedOnly()).withIgnoreLimit(request.isIgnoreLimit()).withHierarchyMeta(request.isHierarchyMeta()).withHideEmptyRows(request.isHideEmptyRows()).withHideEmptyColumns(request.isHideEmptyColumns()).withShowHierarchy(request.isShowHierarchy()).withIncludeNumDen(request.isIncludeNumDen()).withIncludeMetadataDetails(request.isIncludeMetadataDetails()).withDisplayProperty(request.getDisplayProperty()).withOutputIdScheme(request.getOutputIdScheme()).withOutputDataElementIdScheme(request.getOutputDataElementIdScheme()).withOutputOrgUnitIdScheme(request.getOutputOrgUnitIdScheme()).withOutputFormat(OutputFormat.ANALYTICS).withDuplicatesOnly(request.isDuplicatesOnly()).withApprovalLevel(request.getApprovalLevel()).withApiVersion(request.getApiVersion()).withUserOrgUnitType(request.getUserOrgUnitType()).build();
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) IdScheme(org.hisp.dhis.common.IdScheme)

Example 25 with I18nFormat

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

the class DefaultEventDataQueryService method getFromAnalyticalObject.

@Override
public EventQueryParams getFromAnalyticalObject(EventAnalyticalObject object) {
    Assert.notNull(object, "Event analytical object cannot be null");
    Assert.notNull(object.getProgram(), "Event analytical object must specify a program");
    EventQueryParams.Builder params = new EventQueryParams.Builder();
    I18nFormat format = i18nManager.getI18nFormat();
    IdScheme idScheme = IdScheme.UID;
    Date date = object.getRelativePeriodDate();
    object.populateAnalyticalProperties();
    for (DimensionalObject dimension : ListUtils.union(object.getColumns(), object.getRows())) {
        DimensionalObject dimObj = dataQueryService.getDimension(dimension.getDimension(), getDimensionalItemIds(dimension.getItems()), date, null, format, true, false, idScheme);
        if (dimObj != null) {
            params.addDimension(dimObj);
        } else {
            params.addItem(getQueryItem(dimension.getDimension(), dimension.getFilter(), object.getProgram(), object.getOutputType()));
        }
    }
    for (DimensionalObject filter : object.getFilters()) {
        DimensionalObject dimObj = dataQueryService.getDimension(filter.getDimension(), getDimensionalItemIds(filter.getItems()), date, null, format, true, false, idScheme);
        if (dimObj != null) {
            params.addFilter(dimObj);
        } else {
            params.addItemFilter(getQueryItem(filter.getDimension(), filter.getFilter(), object.getProgram(), object.getOutputType()));
        }
    }
    return params.withProgram(object.getProgram()).withProgramStage(object.getProgramStage()).withStartDate(object.getStartDate()).withEndDate(object.getEndDate()).withValue(object.getValue()).withOutputType(object.getOutputType()).build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) I18nFormat(org.hisp.dhis.i18n.I18nFormat) IdScheme(org.hisp.dhis.common.IdScheme) Date(java.util.Date) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

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