Search in sources :

Example 1 with AggregateDatasetSmsSubmission

use of org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission 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)

Example 2 with AggregateDatasetSmsSubmission

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

the class AggregateDataSetSMSListenerTest method createAggregateDatasetSubmission.

private AggregateDatasetSmsSubmission createAggregateDatasetSubmission() {
    AggregateDatasetSmsSubmission subm = new AggregateDatasetSmsSubmission();
    subm.setUserId(user.getUid());
    subm.setOrgUnit(organisationUnit.getUid());
    subm.setDataSet(dataSet.getUid());
    subm.setComplete(true);
    subm.setAttributeOptionCombo(categoryOptionCombo.getUid());
    subm.setPeriod("2019W16");
    ArrayList<SmsDataValue> values = new ArrayList<>();
    values.add(new SmsDataValue(categoryOptionCombo.getUid(), dataElement.getUid(), "12345678"));
    subm.setValues(values);
    subm.setSubmissionId(1);
    return subm;
}
Also used : SmsDataValue(org.hisp.dhis.smscompression.models.SmsDataValue) ArrayList(java.util.ArrayList) AggregateDatasetSmsSubmission(org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission)

Example 3 with AggregateDatasetSmsSubmission

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

the class AggregateDataSetSMSListenerTest method setUpInstances.

private void setUpInstances() throws SmsCompressionException {
    organisationUnit = createOrganisationUnit('O');
    user = createUser('U');
    user.setPhoneNumber(ORIGINATOR);
    user.setOrganisationUnits(Sets.newHashSet(organisationUnit));
    dataSet = createDataSet('D');
    dataSet.getSources().add(organisationUnit);
    categoryOptionCombo = createCategoryOptionCombo('C');
    dataElement = createDataElement('D');
    incomingSmsAggregate = createSMSFromSubmission(createAggregateDatasetSubmission());
    AggregateDatasetSmsSubmission subm = createAggregateDatasetSubmission();
    subm.setValues(null);
    incomingSmsAggregateNoValues = createSMSFromSubmission(subm);
}
Also used : AggregateDatasetSmsSubmission(org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission)

Aggregations

AggregateDatasetSmsSubmission (org.hisp.dhis.smscompression.models.AggregateDatasetSmsSubmission)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)1 DataSet (org.hisp.dhis.dataset.DataSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 SmsDataValue (org.hisp.dhis.smscompression.models.SmsDataValue)1 Uid (org.hisp.dhis.smscompression.models.Uid)1 User (org.hisp.dhis.user.User)1