Search in sources :

Example 1 with DataElementHistory

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;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataValueAuditService(org.hisp.dhis.datavalue.DataValueAuditService) DataElementService(org.hisp.dhis.dataelement.DataElementService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataElement(org.hisp.dhis.dataelement.DataElement) DataValueService(org.hisp.dhis.datavalue.DataValueService) Lists(com.google.common.collect.Lists) DataElementHistory(org.hisp.dhis.dataelementhistory.DataElementHistory) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) User(org.hisp.dhis.user.User) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) Period(org.hisp.dhis.period.Period) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) HistoryRetriever(org.hisp.dhis.dataelementhistory.HistoryRetriever) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Action(com.opensymphony.xwork2.Action) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

Lists (com.google.common.collect.Lists)1 Action (com.opensymphony.xwork2.Action)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CategoryService (org.hisp.dhis.category.CategoryService)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 DataElementService (org.hisp.dhis.dataelement.DataElementService)1 DataElementHistory (org.hisp.dhis.dataelementhistory.DataElementHistory)1 HistoryRetriever (org.hisp.dhis.dataelementhistory.HistoryRetriever)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)1 DataValueAuditService (org.hisp.dhis.datavalue.DataValueAuditService)1 DataValueService (org.hisp.dhis.datavalue.DataValueService)1 InputUtils (org.hisp.dhis.dxf2.util.InputUtils)1 FileResourceService (org.hisp.dhis.fileresource.FileResourceService)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitService (org.hisp.dhis.organisationunit.OrganisationUnitService)1