Search in sources :

Example 6 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValueSetXml.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
public void testImportDataValueSetXml() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetA.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)

Example 7 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValueSetXmlPreheatCache.

@Test
public void testImportDataValueSetXmlPreheatCache() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setPreheatCache(true);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    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) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class SaveSectionFormAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    Validate.notNull(organisationUnitId);
    Validate.notNull(isoPeriod);
    Validate.notNull(dataSetId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    Period period = periodService.getPeriod(isoPeriod);
    boolean needsValidation = false;
    dataSet = dataSetService.getDataSet(dataSetId);
    String storedBy = currentUserService.getCurrentUsername();
    if (StringUtils.isBlank(storedBy)) {
        storedBy = "[unknown]";
    }
    HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(StrutsStatics.HTTP_REQUEST);
    Map<String, String> parameterMap = ContextUtils.getParameterMap(request);
    for (String key : parameterMap.keySet()) {
        if (key.startsWith("DE") && key.contains("OC")) {
            String[] splitKey = key.split("OC");
            Integer dataElementId = Integer.parseInt(splitKey[0].substring(2));
            Integer optionComboId = Integer.parseInt(splitKey[1]);
            String value = parameterMap.get(key);
            DataElement dataElement = dataElementService.getDataElement(dataElementId);
            DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(optionComboId);
            DataValue dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo);
            value = value.trim();
            Boolean valueIsEmpty = value.length() == 0;
            // validate types
            Boolean correctType = true;
            ValueType valueType = dataElement.getValueType();
            if (!valueIsEmpty) {
                if (valueType.isText()) {
                } else if (ValueType.BOOLEAN == valueType) {
                    if (!ValueUtils.isBoolean(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_boolean"));
                    }
                } else if (ValueType.DATE == valueType) {
                    if (!ValueUtils.isDate(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_date"));
                    }
                } else if (ValueType.NUMBER == valueType) {
                    if (!MathUtils.isNumeric(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_number"));
                    }
                } else if (ValueType.INTEGER == valueType) {
                    if (!MathUtils.isInteger(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_integer"));
                    }
                } else if (ValueType.INTEGER_POSITIVE == valueType) {
                    if (!MathUtils.isPositiveInteger(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_positive_integer"));
                    }
                } else if (ValueType.INTEGER_NEGATIVE == valueType) {
                    if (!MathUtils.isNegativeInteger(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_negative_integer"));
                    }
                } else if (ValueType.INTEGER_ZERO_OR_POSITIVE == valueType) {
                    if (!MathUtils.isZeroOrPositiveInteger(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_zero_or_positive_integer"));
                    }
                } else if (ValueType.COORDINATE == valueType) {
                    if (!MathUtils.isCoordinate(value)) {
                        correctType = false;
                        typeViolations.put(key, "\"" + value + "\"" + " " + i18n.getString("is_invalid_coordinate"));
                    }
                }
            }
            // nothing entered
            if (valueIsEmpty || !correctType) {
                if (dataValue != null) {
                    dataValueService.deleteDataValue(dataValue);
                }
            }
            if (correctType && !valueIsEmpty) {
                if (dataValue == null) {
                    needsValidation = true;
                    dataValue = new DataValue(dataElement, period, organisationUnit, categoryOptionCombo, null, value, storedBy, new Date(), null);
                    dataValueService.addDataValue(dataValue);
                } else {
                    if (!dataValue.getValue().equals(value)) {
                        needsValidation = true;
                        dataValue.setValue(value);
                        dataValue.setLastUpdated(new Date());
                        dataValue.setStoredBy(storedBy);
                        dataValueService.updateDataValue(dataValue);
                    }
                }
            }
        }
    }
    //TODO
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
    if (registration == null && complete) {
        registration = new CompleteDataSetRegistration();
        registration.setDataSet(dataSet);
        registration.setPeriod(period);
        registration.setSource(organisationUnit);
        registration.setDate(new Date());
        registration.setStoredBy(storedBy);
        registrationService.saveCompleteDataSetRegistration(registration);
    } else if (registration != null && !complete) {
        registrationService.deleteCompleteDataSetRegistration(registration);
    }
    if (typeViolations.size() > 0) {
        needsValidation = true;
    }
    if (sectionId != null) {
        for (Section section : dataSet.getSections()) {
            if (section.getId() == sectionId) {
                name = section.getName();
                dataElements = section.getDataElements();
                break;
            }
        }
    } else {
        name = "Default";
        dataElements = new ArrayList<>(dataSet.getDataElements());
        Collections.sort(dataElements);
    }
    dataValues = formUtils.getDataValueMap(organisationUnit, dataSet, period);
    validationViolations = formUtils.getValidationViolations(organisationUnit, dataElements, period);
    if (needsValidation && (!validationViolations.isEmpty() || !typeViolations.isEmpty())) {
        return ERROR;
    }
    validated = true;
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataValue(org.hisp.dhis.datavalue.DataValue) ValueType(org.hisp.dhis.common.ValueType) Period(org.hisp.dhis.period.Period) Section(org.hisp.dhis.dataset.Section) Date(java.util.Date) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataElement(org.hisp.dhis.dataelement.DataElement) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 9 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class UndoCompleteAction method execute.

@Override
public String execute() throws Exception {
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    Period period = periodService.getPeriod(isoPeriod);
    DataSet dataSet = dataSetService.getDataSet(dataSetId);
    //TODO
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
    if (registration != null) {
        registrationService.deleteCompleteDataSetRegistration(registration);
    }
    return SUCCESS;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 10 with CompleteDataSetRegistration

use of org.hisp.dhis.dataset.CompleteDataSetRegistration in project dhis2-core by dhis2.

the class GetPeriodsAction method execute.

// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    Validate.notNull(organisationUnitId);
    Validate.notNull(dataSetId);
    organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    dataSet = dataSetService.getDataSet(dataSetId);
    periods = formUtils.getPeriodsForDataSet(dataSetId);
    markLockedDataSets(organisationUnit, dataSet, periods);
    //TODO
    DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    for (Period period : periods) {
        period.setName(format.formatPeriod(period));
        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dataSet, period, organisationUnit, optionCombo);
        periodCompletedMap.put(period, registration != null);
    }
    return SUCCESS;
}
Also used : Period(org.hisp.dhis.period.Period) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

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