use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationBatchHandlerTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
batchHandler = batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class);
periodTypeA = PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME);
dataSetA = createDataSet('A', periodTypeA);
idObjectManager.save(dataSetA);
periodA = createPeriod(periodTypeA, getDate(2000, 1, 1), getDate(2000, 1, 31));
periodB = createPeriod(periodTypeA, getDate(2000, 2, 1), getDate(2000, 2, 28));
periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
idObjectManager.save(unitA);
idObjectManager.save(unitB);
attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
regA = new CompleteDataSetRegistration(dataSetA, periodA, unitA, attributeOptionCombo, now, storedBy);
regB = new CompleteDataSetRegistration(dataSetA, periodA, unitB, attributeOptionCombo, now, storedBy);
regC = new CompleteDataSetRegistration(dataSetA, periodB, unitA, attributeOptionCombo, now, storedBy);
regD = new CompleteDataSetRegistration(dataSetA, periodB, unitB, attributeOptionCombo, now, storedBy);
batchHandler.init();
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method registerCompleteDataSet.
private CompleteDataSetRegistration registerCompleteDataSet(DataSet dataSet, Period period, OrganisationUnit orgUnit, DataElementCategoryOptionCombo attributeOptionCombo, String storedBy, Date completionDate) throws WebMessageException {
I18nFormat format = i18nManager.getI18nFormat();
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("dataSet can not be null."));
}
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("period can not be null"));
}
if (orgUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("organisationUnit can not be null"));
}
if (attributeOptionCombo == null) {
throw new WebMessageException(WebMessageUtils.conflict("attributeOptionCombo can not be null"));
}
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, orgUnit, attributeOptionCombo);
if (registration == null) {
registration = new CompleteDataSetRegistration();
registration.setDataSet(dataSet);
registration.setPeriod(period);
registration.setSource(orgUnit);
registration.setAttributeOptionCombo(attributeOptionCombo);
registration.setDate(completionDate != null ? completionDate : new Date());
registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
registrationService.saveCompleteDataSetRegistration(registration);
} else {
registration.setDate(completionDate != null ? completionDate : new Date());
registration.setStoredBy(storedBy != null ? storedBy : currentUserService.getCurrentUsername());
registration.setPeriodName(format.formatPeriod(registration.getPeriod()));
registrationService.updateCompleteDataSetRegistration(registration);
}
return registration;
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationController method saveCompleteDataSetRegistration.
// Legacy (<= V25)
@ApiVersion({ DhisApiVersion.V23, DhisApiVersion.V24, DhisApiVersion.V25 })
@RequestMapping(method = RequestMethod.POST, produces = "text/plain")
public void saveCompleteDataSetRegistration(@RequestParam String ds, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String cc, @RequestParam(required = false) String cp, @RequestParam(required = false) Date cd, @RequestParam(required = false) String sb, @RequestParam(required = false) boolean multiOu, HttpServletResponse response) throws WebMessageException {
DataSet dataSet = dataSetService.getDataSet(ds);
if (dataSet == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal data set identifier: " + ds));
}
Period period = PeriodType.getPeriodFromIsoString(pe);
if (period == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
}
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou);
if (organisationUnit == null) {
throw new WebMessageException(WebMessageUtils.conflict("Illegal organisation unit identifier: " + ou));
}
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
return;
}
if (dataSetService.isLocked(dataSet, period, organisationUnit, attributeOptionCombo, null, multiOu)) {
throw new WebMessageException(WebMessageUtils.conflict("Data set is locked: " + ds));
}
// ---------------------------------------------------------------------
// Register as completed data set
// ---------------------------------------------------------------------
Set<OrganisationUnit> children = organisationUnit.getChildren();
String storedBy = (sb == null) ? currentUserService.getCurrentUsername() : sb;
Date completionDate = (cd == null) ? new Date() : cd;
List<CompleteDataSetRegistration> registrations = new ArrayList<>();
if (!multiOu) {
CompleteDataSetRegistration completeDataSetRegistration = registerCompleteDataSet(dataSet, period, organisationUnit, attributeOptionCombo, storedBy, completionDate);
if (completeDataSetRegistration != null) {
registrations.add(completeDataSetRegistration);
}
} else {
addRegistrationsForOrgUnits(registrations, Sets.union(children, Sets.newHashSet(organisationUnit)), dataSet, period, attributeOptionCombo, storedBy, completionDate);
}
registrationService.saveCompleteDataSetRegistrations(registrations, true);
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class CompleteDataSetRegistrationBatchHandler method mapRow.
@Override
public CompleteDataSetRegistration mapRow(ResultSet resultSet) throws SQLException {
CompleteDataSetRegistration cdr = new CompleteDataSetRegistration();
cdr.setStoredBy(resultSet.getString("storedby"));
return cdr;
}
use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeA.
@Test
public void testImportDataValuesXmlWithCodeA() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();
ImportSummary summary = dataValueSetService.saveDataValueSet(in);
assertNotNull(summary);
assertNotNull(summary.getImportCount());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
assertNotNull(registration);
assertEquals(dsA, registration.getDataSet());
assertEquals(peA, registration.getPeriod());
assertEquals(ouA, registration.getSource());
assertEquals(getDate(2012, 1, 9), registration.getDate());
assertEquals(0, auditValues.size());
}
Aggregations