use of org.hisp.dhis.dataelementhistory.DataElementHistory in project dhis2-core by dhis2.
the class GetHistoryAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
DataElement dataElement = dataElementService.getDataElement(dataElementId);
CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(optionComboId);
if (categoryOptionCombo == null) {
categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
}
if (dataElement == null) {
throw new IllegalArgumentException("DataElement doesn't exist: " + dataElementId);
}
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
dataElementHistory = historyRetriever.getHistory(dataElement, categoryOptionCombo, attributeOptionCombo, organisationUnit, period, HISTORY_LENGTH);
dataValueAudits = dataValueAuditService.getDataValueAudits(Lists.newArrayList(dataElement), Lists.newArrayList(period), Lists.newArrayList(organisationUnit), categoryOptionCombo, attributeOptionCombo, null);
dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue != null) {
User credentials = userService.getUserByUsername(dataValue.getStoredBy());
storedBy = credentials != null ? credentials.getName() : dataValue.getStoredBy();
}
if (dataElement.isFileType()) {
fileNames = new HashMap<String, String>();
dataValueAudits.removeIf(audit -> fileResourceService.getFileResource(audit.getValue()) == null);
dataValueAudits.stream().filter(audit -> audit != null).map(audit -> fileResourceService.getFileResource(audit.getValue())).forEach(fr -> fileNames.put(fr.getUid(), fr.getName()));
}
historyInvalid = dataElementHistory == null;
minMaxInvalid = !dataElement.getValueType().isNumeric();
commentOptionSet = dataElement.getCommentOptionSet();
attributeOptionComboId = attributeOptionCombo.getUid();
return SUCCESS;
}
Aggregations