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;
}
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;
}
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);
}
Aggregations