Search in sources :

Example 1 with CompleteDataSetRegistration

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();
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration)

Example 2 with CompleteDataSetRegistration

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;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) I18nFormat(org.hisp.dhis.i18n.I18nFormat) Date(java.util.Date)

Example 3 with CompleteDataSetRegistration

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CompleteDataSetRegistration

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;
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration)

Example 5 with CompleteDataSetRegistration

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());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)31 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)12 Test (org.junit.Test)12 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 Period (org.hisp.dhis.period.Period)10 Date (java.util.Date)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 DataSet (org.hisp.dhis.dataset.DataSet)6 DataValue (org.hisp.dhis.datavalue.DataValue)4 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)3 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)2 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Criteria (org.hibernate.Criteria)1