Search in sources :

Example 11 with Uid

use of org.hisp.dhis.smscompression.models.Uid in project dhis2-core by dhis2.

the class AggregateDataSetSMSListener method postProcess.

@Override
protected SmsResponse postProcess(IncomingSms sms, SmsSubmission submission) throws SMSProcessingException {
    AggregateDatasetSmsSubmission subm = (AggregateDatasetSmsSubmission) submission;
    Uid ouid = subm.getOrgUnit();
    Uid dsid = subm.getDataSet();
    String per = subm.getPeriod();
    Uid aocid = subm.getAttributeOptionCombo();
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ouid.getUid());
    User user = userService.getUser(subm.getUserId().getUid());
    DataSet dataSet = dataSetService.getDataSet(dsid.getUid());
    if (dataSet == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_DATASET.set(dsid));
    }
    Period period = PeriodType.getPeriodFromIsoString(per);
    if (period == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_PERIOD.set(per));
    }
    CategoryOptionCombo aoc = categoryService.getCategoryOptionCombo(aocid.getUid());
    if (aoc == null) {
        throw new SMSProcessingException(SmsResponse.INVALID_AOC.set(aocid));
    }
    if (!dataSet.hasOrganisationUnit(orgUnit)) {
        throw new SMSProcessingException(SmsResponse.OU_NOTIN_DATASET.set(ouid, dsid));
    }
    if (!dataSetService.getLockStatus(null, dataSet, period, orgUnit, aoc, null).isOpen()) {
        throw new SMSProcessingException(SmsResponse.DATASET_LOCKED.set(dsid, per));
    }
    List<Object> errorElems = submitDataValues(subm.getValues(), period, orgUnit, aoc, user);
    if (subm.isComplete()) {
        CompleteDataSetRegistration existingReg = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, aoc);
        if (existingReg != null) {
            registrationService.deleteCompleteDataSetRegistration(existingReg);
        }
        Date now = new Date();
        String username = user.getUsername();
        CompleteDataSetRegistration newReg = new CompleteDataSetRegistration(dataSet, period, orgUnit, aoc, now, username, now, username, true);
        registrationService.saveCompleteDataSetRegistration(newReg);
    }
    if (!errorElems.isEmpty()) {
        return SmsResponse.WARN_DVERR.setList(errorElems);
    } else if (subm.getValues() == null || subm.getValues().isEmpty()) {
        // TODO: Should we save if there are no data values?
        return SmsResponse.WARN_DVEMPTY;
    }
    return SmsResponse.SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) Date(java.util.Date) Uid(org.hisp.dhis.smscompression.models.Uid) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) AggregateDatasetSmsSubmission(org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

Uid (org.hisp.dhis.smscompression.models.Uid)11 Date (java.util.Date)6 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 ArrayList (java.util.ArrayList)4 ProgramInstance (org.hisp.dhis.program.ProgramInstance)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 DataElement (org.hisp.dhis.dataelement.DataElement)2 Program (org.hisp.dhis.program.Program)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 SmsDataValue (org.hisp.dhis.smscompression.models.SmsDataValue)2 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)2 HashMap (java.util.HashMap)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 DataSet (org.hisp.dhis.dataset.DataSet)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)1 Period (org.hisp.dhis.period.Period)1