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