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