=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2011-01-31 19:47:04 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2011-02-16 17:16:18 +0000 @@ -251,6 +251,9 @@ */ DataElementCategoryOptionCombo getDataElementCategoryOptionCombo( int id ); + DataElementCategoryOptionCombo getDataElementCategoryOptionCombo( String uuid ); + + /** * Retrieves the DataElementCategoryOptionCombos with the given identifiers. * @@ -371,4 +374,5 @@ int getDataElementCategoryComboCount(); int getDataElementCategoryComboCountByName( String name ); -} + +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java 2011-02-15 06:22:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java 2011-02-16 17:16:18 +0000 @@ -44,7 +44,7 @@ public class DailyPeriodType extends CalendarPeriodType { - private static final String ISO_FORMAT = "yyyyMMdd"; + public static final String ISO_FORMAT = "yyyyMMdd"; /** * The name of the DailyPeriodType, which is "Daily". === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2011-02-15 06:38:47 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2011-02-16 17:16:18 +0000 @@ -80,10 +80,10 @@ this.dataElementCategoryComboStore = dataElementCategoryComboStore; } - private GenericStore dataElementCategoryOptionComboStore; + private GenericIdentifiableObjectStore dataElementCategoryOptionComboStore; public void setDataElementCategoryOptionComboStore( - GenericStore dataElementCategoryOptionComboStore ) + GenericIdentifiableObjectStore dataElementCategoryOptionComboStore ) { this.dataElementCategoryOptionComboStore = dataElementCategoryOptionComboStore; } @@ -228,7 +228,7 @@ { return dataElementCategoryComboStore.get( id ); } - + public Collection getDataElementCategoryCombos( final Collection identifiers ) { Collection categoryCombo = getAllDataElementCategoryCombos(); @@ -277,6 +277,12 @@ return dataElementCategoryOptionComboStore.get( id ); } + public DataElementCategoryOptionCombo getDataElementCategoryOptionCombo( String uuid ) { + return dataElementCategoryOptionComboStore.getByUuid( uuid ); + } + + + public Collection getDataElementCategoryOptionCombos( final Collection identifiers ) { @@ -735,4 +741,5 @@ { return dataElementCategoryComboStore.getBetweenByName( name, first, max ); } + } === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java 2011-02-15 06:46:27 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java 2011-02-16 17:16:18 +0000 @@ -30,7 +30,6 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlValue; @XmlAccessorType( XmlAccessType.FIELD ) public class DataValue @@ -42,7 +41,10 @@ @XmlAttribute( name = "categoryOptionCombo" ) private String categoryOptionComboUuid; - @XmlValue + @XmlAttribute + private String storedBy; + + @XmlAttribute private String value; public String getDataElementUuid() @@ -75,4 +77,14 @@ this.value = value; } + public String getStoredBy() + { + return storedBy; + } + + public void setStoredBy( String storedBy ) + { + this.storedBy = storedBy; + } + } \ No newline at end of file === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java 2011-02-15 06:46:27 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java 2011-02-16 17:16:18 +0000 @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Date; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -49,12 +50,13 @@ @XmlAttribute( name = "period", required = true ) private String periodIsoDate; - @XmlAttribute - private String storedBy; + @XmlAttribute( name = "complete" ) + private String completeDate; @XmlElement( name = "dataValue" ) private List dataValues; + public String getDataSetUuid() { return dataSetUuid; @@ -85,14 +87,14 @@ this.periodIsoDate = periodIsoDate; } - public String getStoredBy() + public String getCompleteDate() { - return storedBy; + return completeDate; } - public void setStoredBy( String storedBy ) + public void setCompleteDate( String completeDate ) { - this.storedBy = storedBy; + this.completeDate = completeDate; } public List getDataValues() === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetService.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetService.java 2011-02-15 12:55:14 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetService.java 2011-02-16 17:16:18 +0000 @@ -27,6 +27,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -35,14 +37,19 @@ import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataset.CompleteDataSetRegistration; +import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.DailyPeriodType; import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodType; import org.springframework.beans.factory.annotation.Required; +import org.springframework.transaction.annotation.Transactional; public class DataValueSetService { @@ -57,108 +64,232 @@ private DataValueService dataValueService; + private CompleteDataSetRegistrationService registrationService; + + /** + * Save a dataValueSet if all of the following is valid + *

+ * First checks that: + *

    + *
  • dataSet exists + *
  • orgUnit exists + *
  • orgunit reports dataSet + *
  • period is a valid period + *
  • the dataValueSet is not registered as complete or that if it is a + * complete date is present + *
  • a present complete date is valid + *
+ * For all dataValues it checks that: + *
    + *
  • dataElement exists and is in dataSet + *
  • optionCombo exists (defaults to 'default' if not specified) and is in dataElement + *
+ * What isn't checked yet: + *
    + *
  • That there isn't duplicated value entries (will throw Constraint exception) + *
  • That the value is valid! + *
+ * Concerns: + *
    + *
  • deletion through sending "empty string" value dependant on semantics of add/update in data value store + *
  • completed semantics, can't uncomplete but can complete and "recomplete" + *
  • what is 'comment' really? + * + * @param dataValueSet + * @throws IllegalArgumentException if + */ public void saveDataValueSet( DataValueSet dataValueSet ) + throws IllegalArgumentException { Date timestamp = new Date(); - DataSet dataSet = dataSetService.getDataSet( dataValueSet.getDataSetUuid() ); - - if ( dataSet == null ) - { - throw new IllegalArgumentException( "Data set with UUID " + dataValueSet.getDataSetUuid() - + " does not exist" ); - } - - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( dataValueSet.getOrganisationUnitUuid() ); - - if ( unit == null ) - { - throw new IllegalArgumentException( "Org unit with UUID " + dataValueSet.getOrganisationUnitUuid() - + " does not exist" ); - } + DataSet dataSet = getDataSet( dataValueSet.getDataSetUuid() ); + + OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitUuid() ); if ( !dataSet.getSources().contains( unit ) ) { - throw new IllegalArgumentException( "Org unit with UUID " + dataValueSet.getOrganisationUnitUuid() + throw new IllegalArgumentException( "Org unit with UUID " + unit.getUuid() + " does not report data set with UUID " + dataSet.getUuid() ); } - Period period; - - try - { - period = dataSet.getPeriodType().createPeriod( dataValueSet.getPeriodIsoDate() ); - } - catch ( Exception e ) - { - throw new IllegalArgumentException( "Period " + dataValueSet.getPeriodIsoDate() - + " is not valid period of type " + dataSet.getPeriodType().getName() ); - } - - List dxfDataValues = dataValueSet.getDataValues(); - List dataValues = new ArrayList( dxfDataValues.size() ); - - for ( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue : dxfDataValues ) - { - DataElement dataElement = dataElementService.getDataElement( dxfValue.getDataElementUuid() ); - - if ( dataElement == null ) - { - throw new IllegalArgumentException( "Data value with UUID " + dxfValue.getDataElementUuid() - + " does not exist" ); - } - - if ( !dataSet.getDataElements().contains( dataElement ) ) - { - throw new IllegalArgumentException( "Data element '" + dataElement.getUuid() + "' isn't in data set " - + dataSet.getUuid() ); - } - - DataElementCategoryOptionCombo combo = getCombo( dxfValue.getCategoryOptionComboUuid() ); - - if ( !dataElement.getCategoryCombo().getOptionCombos().contains( combo ) ) - { - throw new IllegalArgumentException( "DataElementCategoryOptionCombo with UUID '" + combo.getUuid() - + "' isn't in DataElement '" + dataElement.getUuid() + "'" ); - } - + Period period = getPeriod( dataValueSet.getPeriodIsoDate(), dataSet.getPeriodType() ); + + CompleteDataSetRegistration alreadyComplete = registrationService.getCompleteDataSetRegistration( dataSet, + period, unit ); + String completeDateString = dataValueSet.getCompleteDate(); + + if ( alreadyComplete != null && completeDateString == null ) + { + throw new IllegalArgumentException( + "DataValueSet is complete, include a new complete date if you want to recomplete" ); + } + + CompleteDataSetRegistration complete = null; + + if ( completeDateString != null ) + { + complete = getComplete( dataSet, unit, period, completeDateString, complete ); + } + + List newDataValues = new ArrayList( dataValueSet.getDataValues().size() ); + List updatedDataValues = new ArrayList( dataValueSet.getDataValues().size() ); + + for ( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue : dataValueSet.getDataValues() ) + { + DataElement dataElement = getDataElement( dxfValue.getDataElementUuid(), dataSet ); + + DataElementCategoryOptionCombo combo = getOptionCombo( dxfValue.getCategoryOptionComboUuid(), dataElement ); + + + DataValue dv = dataValueService.getDataValue( unit, dataElement, period, combo ); + String value = dxfValue.getValue(); + + // dataElement.isValidValue(value); + if ( dv == null ) { - dv = new DataValue( dataElement, period, unit, dxfValue.getValue(), dataValueSet.getStoredBy(), - timestamp, null, combo ); - dataValueService.addDataValue( dv ); + dv = new DataValue( dataElement, period, unit, value, dxfValue.getStoredBy(), timestamp, + null, combo ); + newDataValues.add( dv ); } else { - dv.setValue( dxfValue.getValue() ); + dv.setValue( value ); dv.setTimestamp( timestamp ); - dv.setStoredBy( dataValueSet.getStoredBy() ); - dataValueService.updateDataValue( dv ); + dv.setStoredBy( dxfValue.getStoredBy() ); + updatedDataValues.add( dv ); } } - } - - private DataElementCategoryOptionCombo getCombo( String comboId ) - { - if ( comboId == null ) - { - return categoryService.getDefaultDataElementCategoryOptionCombo(); - } - - DataElementCategoryOptionCombo combo = categoryService.getDataElementCategoryOptionCombo( Integer - .parseInt( comboId ) ); + + save( alreadyComplete, complete, newDataValues, updatedDataValues ); + } + + private CompleteDataSetRegistration getComplete( DataSet dataSet, OrganisationUnit unit, Period period, + String completeDateString, CompleteDataSetRegistration complete ) + { + SimpleDateFormat format = new SimpleDateFormat( DailyPeriodType.ISO_FORMAT ); + try + { + Date completeDate = format.parse( completeDateString ); + complete = new CompleteDataSetRegistration( dataSet, period, unit, completeDate ); + } + catch ( ParseException e ) + { + throw new IllegalArgumentException( "Complete date not in valid format: " + DailyPeriodType.ISO_FORMAT ); + } + return complete; + } + + private Period getPeriod( String periodIsoDate, PeriodType periodType ) + { + Period period; + + try + { + period = periodType.createPeriod( periodIsoDate ); + } + catch ( Exception e ) + { + throw new IllegalArgumentException( "Period " + periodIsoDate + " is not valid period of type " + + periodType.getName() ); + } + return period; + } + + private OrganisationUnit getOrgUnit( String uuid ) + { + OrganisationUnit unit = organisationUnitService.getOrganisationUnit( uuid ); + + if ( unit == null ) + { + throw new IllegalArgumentException( "Org unit with UUID " + uuid + " does not exist" ); + } + return unit; + } + + private DataSet getDataSet( String uuid ) + { + DataSet dataSet = dataSetService.getDataSet( uuid ); + + if ( dataSet == null ) + { + throw new IllegalArgumentException( "Data set with UUID " + uuid + " does not exist" ); + } + return dataSet; + } + + private DataElement getDataElement( String uuid, DataSet dataSet ) + { + DataElement dataElement = dataElementService.getDataElement( uuid ); + + if ( dataElement == null ) + { + throw new IllegalArgumentException( "Data element with UUID " + uuid + " does not exist" ); + } + + if ( !dataSet.getDataElements().contains( dataElement ) ) + { + throw new IllegalArgumentException( "Data element '" + dataElement.getUuid() + "' isn't in data set " + + dataSet.getUuid() ); + } + return dataElement; + } + + private DataElementCategoryOptionCombo getOptionCombo( String uuid, DataElement dataElement ) + { + DataElementCategoryOptionCombo combo; + + if ( uuid == null ) + { + combo = categoryService.getDefaultDataElementCategoryOptionCombo(); + } + else + { + combo = categoryService.getDataElementCategoryOptionCombo( uuid ); + } if ( combo == null ) { - throw new IllegalArgumentException( "DataElementCategoryOptionCombo with UUID '" + comboId + throw new IllegalArgumentException( "DataElementCategoryOptionCombo with UUID '" + uuid + "' does not exist" ); } + if ( !dataElement.getCategoryCombo().getOptionCombos().contains( combo ) ) + { + throw new IllegalArgumentException( "DataElementCategoryOptionCombo with UUID '" + combo.getUuid() + + "' isn't in DataElement '" + dataElement.getUuid() + "'" ); + } return combo; } + @Transactional + private void save( CompleteDataSetRegistration alreadyComplete, CompleteDataSetRegistration complete, + List newDataValues, List updatedDataValues ) + { + if ( alreadyComplete != null ) + { + registrationService.deleteCompleteDataSetRegistration( alreadyComplete ); + } + + for ( DataValue dataValue : newDataValues ) + { + dataValueService.addDataValue( dataValue ); + } + + for ( DataValue dataValue : updatedDataValues ) + { + dataValueService.updateDataValue( dataValue ); + } + + if ( complete != null ) + { + registrationService.saveCompleteDataSetRegistration( complete ); + } + } + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) { this.organisationUnitService = organisationUnitService; @@ -185,4 +316,10 @@ this.dataValueService = dataValueService; } + @Required + public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) + { + this.registrationService = registrationService; + } + } === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2011-02-15 12:55:14 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2011-02-16 17:16:18 +0000 @@ -412,6 +412,7 @@ + === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetServiceTest.java' --- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetServiceTest.java 2011-02-15 12:55:14 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetServiceTest.java 2011-02-16 17:16:18 +0000 @@ -27,10 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static junit.framework.Assert.*; import java.io.IOException; import java.io.InputStream; @@ -55,19 +52,25 @@ import org.hisp.dhis.importexport.ImportStrategy; import org.hisp.dhis.importexport.util.ImportExportUtils; import org.hisp.dhis.period.WeeklyPeriodType; +import org.junit.Ignore; import org.junit.Test; /** - * Messy test class checking that jaxb produces the expected java - * @link{DataValueSet data value set} structure, that the set is converted and - * stored into a correct set of {@link DataValue data values}. + * Messy test class checking that jaxb produces the expected java + * @link{DataValueSet data value set} structure, that the set is converted, validated and + * stored into a correct set of {@link DataValue data values} + * . */ public class DataValueSetServiceTest extends DhisTest { + private static final String DEFAULT_COMBO_UUID = "AAB2299E-ECD6-46CF-A61F-817D350C180D"; + private static final String ORGANISATION_UNIT_UUID = "9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344"; + private static final String ORGANISATION_UNIT_NOT_IN_SET_UUID = "9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345"; + private static final String DATA_SET_UUID = "16B2299E-ECD6-46CF-A61F-817D350C180D"; private static final String DATA_ELEMENT_UUID = "56B2299E-ECD6-46CF-A61F-817D350C180D"; @@ -99,7 +102,7 @@ dataSetService = (DataSetService) getBean( DataSetService.ID ); dataValueService = (DataValueService) getBean( DataValueService.ID ); - service = (DataValueSetService) getBean( "org.hisp.dhis.importexport.datavalueset.DataValueSetMapper" ); + service = (DataValueSetService) getBean( "org.hisp.dhis.importexport.datavalueset.DataValueSetService" ); classLoader = Thread.currentThread().getContextClassLoader(); @@ -113,11 +116,11 @@ dataValueSet.setDataSetUuid( DATA_SET_UUID ); dataValueSet.setPeriodIsoDate( "2011W5" ); dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID ); - dataValueSet.setStoredBy( "misterindia" ); final org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue(); dv.setDataElementUuid( DATA_ELEMENT_UUID ); dv.setValue( "11" ); + dv.setStoredBy( "misterindia" ); dataValueSet.setDataValues( new ArrayList() { @@ -127,7 +130,8 @@ } ); defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo(); - + defaultCombo.setUuid( DEFAULT_COMBO_UUID ); + categoryService.updateDataElementCategoryOptionCombo( defaultCombo ); } // ------------------------------------------------------------------------- @@ -149,13 +153,14 @@ assertEquals( dataValueSet.getDataSetUuid(), dxfDataValueSet.getDataSetUuid() ); assertEquals( dataValueSet.getPeriodIsoDate(), dxfDataValueSet.getPeriodIsoDate() ); assertEquals( dataValueSet.getOrganisationUnitUuid(), dxfDataValueSet.getOrganisationUnitUuid() ); - assertEquals( dataValueSet.getStoredBy(), dxfDataValueSet.getStoredBy() ); assertEquals( 1, dxfDataValueSet.getDataValues().size() ); org.hisp.dhis.importexport.datavalueset.DataValue dv = dxfDataValueSet.getDataValues().get( 0 ); + org.hisp.dhis.importexport.datavalueset.DataValue dataValue = dataValueSet.getDataValues().get( 0 ); - assertEquals( dataValueSet.getDataValues().get( 0 ).getDataElementUuid(), dv.getDataElementUuid() ); + assertEquals( dataValue.getDataElementUuid(), dv.getDataElementUuid() ); + assertEquals( dataValue.getStoredBy(), dv.getStoredBy() ); assertNull( dv.getCategoryOptionComboUuid() ); } @@ -179,10 +184,53 @@ } - @Test - public void missingThingsFromInput() + @Test @Ignore + public void testValidvalue() { + setValue( "" ); + + try + { + service.saveDataValueSet( dataValueSet ); + } + catch ( NumberFormatException e ) + { + // Expected + } + + } + + @Test @Ignore + public void testDuplicatedDataValues() { + + } + + @Test @Ignore + public void testExistingComboButNotInDataElement() { + + } + + @Test + public void deleteDataValue() { + service.saveDataValueSet( dataValueSet ); + + Collection dataValues = dataValueService.getAllDataValues(); + assertEquals( 1, dataValues.size() ); + + dataValues = dataValueService.getAllDataValues(); + assertEquals( 1, dataValues.size() ); + + setValue( null ); + + service.saveDataValueSet( dataValueSet ); + + dataValues = dataValueService.getAllDataValues(); + assertEquals( 0, dataValues.size() ); + + } + + @Test + public void dataSetMissing() { - dataValueSet.setDataSetUuid( null ); try { @@ -194,8 +242,11 @@ { // Expected } + } - dataValueSet.setDataSetUuid( DATA_SET_UUID ); + @Test + public void orgunitMissingOrNotInSet() + { dataValueSet.setOrganisationUnitUuid( "ladlalad" ); try { @@ -208,28 +259,127 @@ // Expected } - dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID ); - - final org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue(); + dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_NOT_IN_SET_UUID ); + + try + { + service.saveDataValueSet( dataValueSet ); + fail( "Should miss org unit association to data set" ); + + } + catch ( IllegalArgumentException e ) + { + // Expected + } + } + + @Test + public void illegalPeriod() { + + dataValueSet.setPeriodIsoDate( "2011" ); + + try + { + service.saveDataValueSet( dataValueSet ); + fail( "should not accept yearly period" ); + + } + catch ( IllegalArgumentException e ) + { + // Expected + } + } + + @Test + public void completeness() { + + service.saveDataValueSet( dataValueSet ); + + dataValueSet.setCompleteDate( "20110101" ); + service.saveDataValueSet( dataValueSet ); + + dataValueSet.setCompleteDate( null ); + + try + { + service.saveDataValueSet( dataValueSet ); + fail("Shouldn't allow saving to a completed set"); + } + catch ( IllegalArgumentException e ) + { + // TODO: Expected + } + + dataValueSet.setCompleteDate( "201lala" ); + + try + { + service.saveDataValueSet( dataValueSet ); + } + catch ( IllegalArgumentException e ) + { + // Expected + } + + dataValueSet.setCompleteDate( "20101010" ); + service.saveDataValueSet( dataValueSet ); + + } + + @Test + public void elementExistsAndNotInSet() { + + org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue(); + dv.setDataElementUuid( "ladida" ); + dv.setValue( "11" ); + dataValueSet.getDataValues().add( dv ); + + try + { + service.saveDataValueSet( dataValueSet ); + fail( "Should not accept non existing data element" ); + } + catch ( IllegalArgumentException e ) + { + // Expected + } + dv.setDataElementUuid( DATA_ELEMENT_NOT_IN_SET_UUID ); - dv.setValue( "11" ); - dataValueSet.getDataValues().add( dv ); - - try - { - service.saveDataValueSet( dataValueSet ); - fail( "Should not accept extra data value" ); - - } - catch ( IllegalArgumentException e ) - { - // Expected - } - - dataValueSet.getDataValues().remove( dv ); - - } - + + try + { + service.saveDataValueSet( dataValueSet ); + fail( "Should not accept data element not in set" ); + } + catch ( IllegalArgumentException e ) + { + // Expected + } + } + + @Test + public void optionComboExistsAndInDataElement() { + + dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboUuid( DEFAULT_COMBO_UUID ); + + service.saveDataValueSet( dataValueSet ); + + dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboUuid( "AAB2299E-ECD6-46CF-A61F-817D350" ); + + try + { + service.saveDataValueSet( dataValueSet ); + fail( "Shouldn't allow non existing option combo" ); + } + catch ( IllegalArgumentException e ) + { + // Expected + } + + } + + + @Test public void testUpdate() { @@ -247,8 +397,8 @@ verifyDataValue( before, after, dataValue ); // Update - dataValueSet.getDataValues().get( 0 ).setValue( "101" ); - + setValue("101"); + before = new Date().getTime(); service.saveDataValueSet( dataValueSet ); @@ -264,11 +414,16 @@ } - private void verifyDataValue( long before, long after, DataValue dv) + private void setValue(String value) + { + dataValueSet.getDataValues().get( 0 ).setValue( value ); + } + + private void verifyDataValue( long before, long after, DataValue dv ) { verifyDataValue( before, after, dv, "11" ); } - + private void verifyDataValue( long before, long after, DataValue dv, String value ) { assertEquals( DATA_ELEMENT_UUID, dv.getDataElement().getUuid() ); @@ -284,4 +439,11 @@ assertEquals( defaultCombo, dv.getOptionCombo() ); } + @Override + protected boolean emptyDatabaseAfterTest() + { + return true; + } + + } === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml' --- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml 2011-02-15 09:03:06 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml 2011-02-16 17:16:18 +0000 @@ -32,6 +32,7 @@ 13 + AAB2299E-ECD6-46CF-A61F-817D350C180D 12 default @@ -125,6 +126,21 @@ 2011-02-14 + + 99 + 9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345 + Not reporting data set + OrgUnit1 + UNIT1 + 1990-01-01 + + true + + + + + 2011-02-14 + === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml' --- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml 2011-02-15 09:03:06 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml 2011-02-16 17:16:18 +0000 @@ -2,7 +2,8 @@ - - 11 + orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344"> + + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java 2011-02-15 12:55:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java 2011-02-16 17:16:18 +0000 @@ -139,10 +139,9 @@ t.append( "" ).append( uri ).append( ":

    " ); t.append( "
    " ).append( "<dataValueSet xmlns=\"http://dhis2.org/schema/dataValueSet/0.1\"\n" );
    -        t.append( "    dataSet=\"dataSet UUID\" \n    period=\"periodInIsoFormat\"\n    orgUnit=\"unit UUID\"" );
    -        t.append( "\n    storedBy=\"user\">" );
    +        t.append( "    dataSet=\"dataSet UUID\" \n    period=\"periodInIsoFormat\"\n    orgUnit=\"unit UUID\">" );
     
    -        t.append( "\n  <dataValue dataElement=\"data element UUID\" categoryOptionCombo=\"UUID, only specify if used\" >value</dataValue>" );
    +        t.append( "\n  <dataValue dataElement=\"data element UUID\" categoryOptionCombo=\"UUID, only specify if used\" storedBy=\"string\" value=\"value\"/>" );
             t.append( "\n</dataValueSet>" );
             t.append( "
    " ); }