use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.
the class DataAnalysisController method performFollowupAnalysis.
@PostMapping(value = "/followup", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public List<DeflatedDataValue> performFollowupAnalysis(@RequestBody DataAnalysisParams params, HttpSession session) throws WebMessageException {
I18nFormat format = i18nManager.getI18nFormat();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(params.getOu());
if (organisationUnit == null) {
throw new WebMessageException(badRequest("No organisation unit defined"));
}
Collection<Period> periods = periodService.getPeriodsBetweenDates(format.parseDate(params.getStartDate()), format.parseDate(params.getEndDate()));
Set<DataElement> dataElements = new HashSet<>();
if (params.getDs() != null) {
for (String uid : params.getDs()) {
dataElements.addAll(dataSetService.getDataSet(uid).getDataElements());
}
}
List<DeflatedDataValue> dataValues = new ArrayList<>(followupAnalysisService.getFollowupDataValues(Sets.newHashSet(organisationUnit), dataElements, periods, DataAnalysisService.MAX_OUTLIERS + 1));
// +1 to detect overflow
session.setAttribute(KEY_ANALYSIS_DATA_VALUES, dataValues);
session.setAttribute(KEY_ORG_UNIT, organisationUnit);
return deflatedValuesListToResponse(dataValues);
}
use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.
the class EventCategoryOptValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
Program program = context.getProgram(event.getProgram());
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
checkNotNull(context.getBundle().getUser(), TrackerImporterAssertErrors.USER_CANT_BE_NULL);
checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
checkNotNull(event, TrackerImporterAssertErrors.EVENT_CANT_BE_NULL);
CategoryOptionCombo categoryOptionCombo = reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getUid());
checkNotNull(categoryOptionCombo, TrackerImporterAssertErrors.CATEGORY_OPTION_COMBO_CANT_BE_NULL);
Date eventDate;
try {
eventDate = DateUtils.fromInstant(ObjectUtils.firstNonNull(event.getOccurredAt(), event.getScheduledAt(), Instant.now()));
} catch (IllegalArgumentException e) {
log.debug("Failed to parse dates, an error should already be reported.");
return;
}
I18nFormat i18nFormat = i18nManager.getI18nFormat();
for (CategoryOption option : categoryOptionCombo.getCategoryOptions()) {
if (option.getStartDate() != null && eventDate.compareTo(option.getStartDate()) < 0) {
reporter.addError(event, E1056, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getStartDate()), option.getName());
}
if (option.getEndDate() != null && eventDate.compareTo(option.getAdjustedEndDate(program)) > 0) {
reporter.addError(event, E1057, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getAdjustedEndDate(program)), option.getName(), program.getName());
}
}
}
use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.
the class MapController method postProcessResponseEntity.
// --------------------------------------------------------------------------
// Hooks
// --------------------------------------------------------------------------
@Override
public void postProcessResponseEntity(Map map, WebOptions options, java.util.Map<String, String> parameters) throws Exception {
I18nFormat format = i18nManager.getI18nFormat();
Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
for (MapView view : map.getMapViews()) {
view.populateAnalyticalProperties();
for (OrganisationUnit organisationUnit : view.getOrganisationUnits()) {
view.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
}
if (view.getPeriods() != null && !view.getPeriods().isEmpty()) {
for (Period period : view.getPeriods()) {
period.setName(format.formatPeriod(period));
}
}
}
}
use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.
the class DefaultFollowupAnalysisService method getFollowupDataValues.
@Override
@Transactional(readOnly = true)
public FollowupAnalysisResponse getFollowupDataValues(FollowupAnalysisRequest request) {
validate(request);
List<FollowupValue> followupValues = followupValueManager.getFollowupDataValues(currentUserService.getCurrentUser(), request);
I18nFormat format = i18nManager.getI18nFormat();
followupValues.forEach(value -> value.setPeName(format.formatPeriod(value.getPeAsPeriod())));
return new FollowupAnalysisResponse(new FollowupAnalysisMetadata(request), followupValues);
}
use of org.hisp.dhis.i18n.I18nFormat in project dhis2-core by dhis2.
the class ReportTableController method postProcessEntity.
//--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------
@Override
protected void postProcessEntity(ReportTable reportTable) throws Exception {
reportTable.populateAnalyticalProperties();
Set<OrganisationUnit> roots = currentUserService.getCurrentUser().getDataViewOrganisationUnitsWithFallback();
for (OrganisationUnit organisationUnit : reportTable.getOrganisationUnits()) {
reportTable.getParentGraphMap().put(organisationUnit.getUid(), organisationUnit.getParentGraph(roots));
}
I18nFormat format = i18nManager.getI18nFormat();
if (reportTable.getPeriods() != null && !reportTable.getPeriods().isEmpty()) {
for (Period period : reportTable.getPeriods()) {
period.setName(format.formatPeriod(period));
}
}
}
Aggregations