=== removed directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset'
=== removed 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-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java 1970-01-01 00:00:00 +0000
@@ -1,129 +0,0 @@
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-
-@XmlAccessorType( XmlAccessType.FIELD )
-public class DataValue
-{
-
- @XmlAttribute( name = "dataSet" )
- private String dataSetUuid;
-
- @XmlAttribute( name = "orgUnit", required = true )
- private String organisationUnitUuid;
-
- @XmlAttribute( name = "period", required = true )
- private String periodIsoDate;
-
- @XmlAttribute( name = "dataElement", required = true )
- private String dataElementUuid;
-
- @XmlAttribute( name = "categoryOptionCombo" )
- private String categoryOptionComboUuid;
-
- @XmlAttribute
- private String storedBy;
-
- @XmlAttribute
- private String value;
-
- public String getDataSetUuid()
- {
- return dataSetUuid;
- }
-
- public void setDataSetUuid( String dataSetUuid )
- {
- this.dataSetUuid = dataSetUuid;
- }
-
- public String getOrganisationUnitUuid()
- {
- return organisationUnitUuid;
- }
-
- public void setOrganisationUnitUuid( String organisationUnitUuid )
- {
- this.organisationUnitUuid = organisationUnitUuid;
- }
-
- public String getPeriodIsoDate()
- {
- return periodIsoDate;
- }
-
- public void setPeriodIsoDate( String periodIsoDate )
- {
- this.periodIsoDate = periodIsoDate;
- }
-
- public String getDataElementUuid()
- {
- return dataElementUuid;
- }
-
- public void setDataElementUuid( String dataElementUuid )
- {
- this.dataElementUuid = dataElementUuid;
- }
-
- public String getCategoryOptionComboUuid()
- {
- return categoryOptionComboUuid;
- }
-
- public void setCategoryOptionComboUuid( String categoryOptionComboUuid )
- {
- this.categoryOptionComboUuid = categoryOptionComboUuid;
- }
-
- public String getValue()
- {
- return value;
- }
-
- public void setValue( String value )
- {
- this.value = value;
- }
-
- public String getStoredBy()
- {
- return storedBy;
- }
-
- public void setStoredBy( String storedBy )
- {
- this.storedBy = storedBy;
- }
-
-}
\ No newline at end of file
=== removed 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-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java 1970-01-01 00:00:00 +0000
@@ -1,91 +0,0 @@
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-
-@XmlAccessorType( XmlAccessType.FIELD )
-public class DataValueSet
-{
-
- @XmlAttribute( name = "dataSet" )
- private String dataSetUuid;
-
- @XmlAttribute( name = "orgUnit", required = true )
- private String organisationUnitUuid;
-
- @XmlAttribute( name = "period", required = true )
- private String periodIsoDate;
-
- @XmlAttribute( name = "complete" )
- private String completeDate;
-
- public String getDataSetUuid()
- {
- return dataSetUuid;
- }
-
- public void setDataSetUuid( String dataSetUuid )
- {
- this.dataSetUuid = dataSetUuid;
- }
-
- public String getOrganisationUnitUuid()
- {
- return organisationUnitUuid;
- }
-
- public void setOrganisationUnitUuid( String organisationUnitUuid )
- {
- this.organisationUnitUuid = organisationUnitUuid;
- }
-
- public String getPeriodIsoDate()
- {
- return periodIsoDate;
- }
-
- public void setPeriodIsoDate( String periodIsoDate )
- {
- this.periodIsoDate = periodIsoDate;
- }
-
- public String getCompleteDate()
- {
- return completeDate;
- }
-
- public void setCompleteDate( String completeDate )
- {
- this.completeDate = completeDate;
- }
-
-
-}
=== removed 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-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetService.java 1970-01-01 00:00:00 +0000
@@ -1,401 +0,0 @@
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import org.hisp.dhis.dataelement.DataElement;
-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
-{
-
- private OrganisationUnitService organisationUnitService;
-
- private DataSetService dataSetService;
-
- private DataElementCategoryService categoryService;
-
- private DataElementService dataElementService;
-
- 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 dxf
- * @throws IllegalArgumentException if
- */
- @Transactional
- public void saveDataValueSet( Dxf dxf )
- throws IllegalArgumentException
- {
- handleComplete( dxf.getDataValueSets() );
- for ( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue : dxf.getDataValues() )
- {
- saveDataValue( dxfValue );
- }
- }
-
- private void handleComplete( List completeNotDataSets )
- {
- if ( completeNotDataSets == null )
- {
- return;
- }
-
- for ( DataValueSet nds : completeNotDataSets )
- {
- CompleteDataSetRegistration complete = null;
-
- DataSet dataSet = getDataSet( nds.getDataSetUuid() );
-
- OrganisationUnit unit = getOrgUnit( nds.getOrganisationUnitUuid() );
-
- if ( !dataSet.getSources().contains( unit ) )
- {
- throw new IllegalArgumentException( "Org unit with UUID " + unit.getUuid()
- + " does not report data set with UUID " + dataSet.getUuid() );
- }
-
- Period period = getPeriod( nds.getPeriodIsoDate(), dataSet.getPeriodType() );
-
- CompleteDataSetRegistration alreadyComplete = registrationService.getCompleteDataSetRegistration( dataSet,
- period, unit );
- String completeDateString = nds.getCompleteDate();
-
- if ( alreadyComplete != null && completeDateString == null )
- {
- throw new IllegalArgumentException(
- "DataValueSet is complete, include a new complete date if you want to recomplete" );
- }
-
- if ( completeDateString != null )
- {
- complete = getComplete( dataSet, unit, period, completeDateString, complete );
- }
-
- if ( alreadyComplete != null )
- {
- registrationService.deleteCompleteDataSetRegistration( alreadyComplete );
- }
- if ( complete != null )
- {
- registrationService.saveCompleteDataSetRegistration( complete );
- }
-
- }
- }
-
- private void saveDataValue( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue )
- {
- Date timestamp = new Date();
-
- OrganisationUnit unit = getOrgUnit( dxfValue.getOrganisationUnitUuid() );
-
- DataElement dataElement = getDataElement( dxfValue.getDataElementUuid() );
-
- DataSet dataSet = null;
- if ( dxfValue.getDataSetUuid() != null )
- {
- dataSet = getDataSet( dxfValue.getDataSetUuid() );
-
- if ( !dataSet.getDataElements().contains( dataElement ) )
- {
- throw new IllegalArgumentException( "Data element '" + dataElement.getUuid() + "' isn't in data set "
- + dataSet.getUuid() );
- }
-
- }
- else
- {
- dataSet = resolveDataSet( dataElement, unit );
- }
-
- if ( !dataSet.getSources().contains( unit ) )
- {
- throw new IllegalArgumentException( "Org unit with UUID " + unit.getUuid()
- + " does not report data set with UUID " + dataSet.getUuid() );
- }
-
- Period period = getPeriod( dxfValue.getPeriodIsoDate(), dataSet.getPeriodType() );
-
- DataElementCategoryOptionCombo combo = getOptionCombo( dxfValue.getCategoryOptionComboUuid(), dataElement );
-
- String value = dxfValue.getValue();
-
- // dataElement.isValidValue(value);
-
- DataValue dv = dataValueService.getDataValue( unit, dataElement, period, combo );
-
- if ( dv == null )
- {
- dv = new DataValue( dataElement, period, unit, value, dxfValue.getStoredBy(), timestamp, null, combo );
- dataValueService.addDataValue( dv );
- }
- else
- {
- dv.setValue( value );
- dv.setTimestamp( timestamp );
- dv.setStoredBy( dxfValue.getStoredBy() );
- dataValueService.updateDataValue( dv );
- }
- }
-
- private DataSet resolveDataSet( DataElement dataElement, OrganisationUnit unit )
- {
-
- Set dataSets = dataElement.getDataSets();
-
- if ( dataSets == null || dataSets.isEmpty() )
- {
- throw new IllegalArgumentException( "data element '" + dataElement.getName() + "' with UUID '"
- + dataElement.getUuid() + "' isn't assigned to any data set" );
- }
- else if ( dataSets.size() == 1 )
- {
- return dataSets.iterator().next();
- }
- else
- {
- for ( DataSet dataSet : dataSets )
- {
- if ( dataSet.getOrganisationUnits().contains( unit ) )
- {
- return dataSet;
- }
- }
- }
- throw new IllegalArgumentException( "data element '" + dataElement.getName() + "' with UUID '"
- + dataElement.getUuid() + "' isn't assigned to any data set that in turn is assigned to org unit '"
- + unit.getName() + "', uuid '" + unit.getUuid() + "'" );
- }
-
- 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 )
- {
- DataElement dataElement = dataElementService.getDataElement( uuid );
-
- if ( dataElement == null )
- {
- throw new IllegalArgumentException( "Data element with UUID " + uuid + " does not exist" );
- }
-
- 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 '" + 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;
- }
-
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- public void setCategoryService( DataElementCategoryService categoryService )
- {
- this.categoryService = categoryService;
- }
-
- public void setDataElementService( DataElementService dataElementService )
- {
- this.dataElementService = dataElementService;
- }
-
- @Required
- public void setDataValueService( DataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
- @Required
- public void setRegistrationService( CompleteDataSetRegistrationService registrationService )
- {
- this.registrationService = registrationService;
- }
-
-}
=== removed file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/Dxf.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/Dxf.java 2011-02-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/Dxf.java 1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlAccessorType( XmlAccessType.FIELD )
-@XmlRootElement
-public class Dxf
-{
-
- @XmlElementWrapper( name = "dataValues" )
- @XmlElement( name = "dataValue" )
- private List dataValues;
-
- @XmlElementWrapper( name = "dataValueSets" )
- @XmlElement( name = "dataValueSet" )
- private List dataValueSets;
-
- public List getDataValues()
- {
- return dataValues;
- }
-
- public void setDataValues( List dataValues )
- {
- this.dataValues = dataValues;
- }
-
- public List getDataValueSets()
- {
- return dataValueSets;
- }
-
- public void setDataValueSets( List dataValueSets )
- {
- this.dataValueSets = dataValueSets;
- }
-
-
-}
=== removed file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java 2011-02-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java 1970-01-01 00:00:00 +0000
@@ -1,32 +0,0 @@
-@javax.xml.bind.annotation.XmlSchema(
- namespace = "http://dhis2.org/schema/dxf/x.x",
- xmlns = { @javax.xml.bind.annotation.XmlNs( prefix = "xs", namespaceURI = "http://www.w3.org/2001/XMLSchema" ) },
- elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2'
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,90 @@
+package org.hisp.dhis.importexport.dxf2.model;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+
+@XmlAccessorType( XmlAccessType.FIELD )
+public class DataValue
+{
+
+ @XmlAttribute( name = "dataElement", required = true )
+ private String dataElementUuid;
+
+ @XmlAttribute( name = "categoryOptionCombo" )
+ private String categoryOptionComboUuid;
+
+ @XmlAttribute
+ private String storedBy;
+
+ @XmlAttribute
+ private String value;
+
+ public String getDataElementUuid()
+ {
+ return dataElementUuid;
+ }
+
+ public void setDataElementUuid( String dataElementUuid )
+ {
+ this.dataElementUuid = dataElementUuid;
+ }
+
+ public String getCategoryOptionComboUuid()
+ {
+ return categoryOptionComboUuid;
+ }
+
+ public void setCategoryOptionComboUuid( String categoryOptionComboUuid )
+ {
+ this.categoryOptionComboUuid = categoryOptionComboUuid;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+
+ public String getStoredBy()
+ {
+ return storedBy;
+ }
+
+ public void setStoredBy( String storedBy )
+ {
+ this.storedBy = storedBy;
+ }
+
+}
\ No newline at end of file
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,110 @@
+package org.hisp.dhis.importexport.dxf2.model;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlAccessorType( XmlAccessType.FIELD )
+@XmlRootElement
+public class DataValueSet
+{
+
+ @XmlAttribute( name = "dataSet", required = true )
+ private String dataSetUuid;
+
+ @XmlAttribute( name = "orgUnit", required = true )
+ private String organisationUnitUuid;
+
+ @XmlAttribute( name = "period", required = true )
+ private String periodIsoDate;
+
+ @XmlAttribute( name = "complete" )
+ private String completeDate;
+
+ @XmlElement( name = "dataValue" )
+ private List dataValues;
+
+
+ public String getDataSetUuid()
+ {
+ return dataSetUuid;
+ }
+
+ public void setDataSetUuid( String dataSetUuid )
+ {
+ this.dataSetUuid = dataSetUuid;
+ }
+
+ public String getOrganisationUnitUuid()
+ {
+ return organisationUnitUuid;
+ }
+
+ public void setOrganisationUnitUuid( String organisationUnitUuid )
+ {
+ this.organisationUnitUuid = organisationUnitUuid;
+ }
+
+ public String getPeriodIsoDate()
+ {
+ return periodIsoDate;
+ }
+
+ public void setPeriodIsoDate( String periodIsoDate )
+ {
+ this.periodIsoDate = periodIsoDate;
+ }
+
+ public String getCompleteDate()
+ {
+ return completeDate;
+ }
+
+ public void setCompleteDate( String completeDate )
+ {
+ this.completeDate = completeDate;
+ }
+
+ public List getDataValues()
+ {
+ return dataValues;
+ }
+
+ public void setDataValues( List dataValues )
+ {
+ this.dataValues = dataValues;
+ }
+
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/package-info.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/package-info.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/package-info.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,32 @@
+@javax.xml.bind.annotation.XmlSchema(
+ namespace = "http://dhis2.org/schema/dxf/2.0-SNAPSHOT",
+ xmlns = { @javax.xml.bind.annotation.XmlNs( prefix = "xs", namespaceURI = "http://www.w3.org/2001/XMLSchema" ) },
+ elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )
+package org.hisp.dhis.importexport.dxf2.model;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,326 @@
+package org.hisp.dhis.importexport.dxf2.service;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * 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;
+
+import org.hisp.dhis.dataelement.DataElement;
+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.importexport.dxf2.model.DataValueSet;
+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
+{
+
+ private OrganisationUnitService organisationUnitService;
+
+ private DataSetService dataSetService;
+
+ private DataElementCategoryService categoryService;
+
+ private DataElementService dataElementService;
+
+ 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 = getDataSet( dataValueSet.getDataSetUuid() );
+
+ OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitUuid() );
+
+ if ( !dataSet.getSources().contains( unit ) )
+ {
+ throw new IllegalArgumentException( "Org unit with UUID " + unit.getUuid()
+ + " does not report data set with UUID " + dataSet.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.dxf2.model.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, value, dxfValue.getStoredBy(), timestamp,
+ null, combo );
+ newDataValues.add( dv );
+ }
+ else
+ {
+ dv.setValue( value );
+ dv.setTimestamp( timestamp );
+ dv.setStoredBy( dxfValue.getStoredBy() );
+ updatedDataValues.add( dv );
+ }
+ }
+
+ 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 '" + 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;
+ }
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ public void setCategoryService( DataElementCategoryService categoryService )
+ {
+ this.categoryService = categoryService;
+ }
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ @Required
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ 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-17 07:01:28 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2011-02-18 20:17:34 +0000
@@ -408,8 +408,8 @@
-
+
=== removed directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset'
=== removed 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-17 20:35:09 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetServiceTest.java 1970-01-01 00:00:00 +0000
@@ -1,436 +0,0 @@
-package org.hisp.dhis.importexport.datavalueset;
-
-/*
- * Copyright (c) 2011, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import static junit.framework.Assert.*;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-
-import org.hisp.dhis.DhisTest;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
-import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.datavalue.DataValueService;
-import org.hisp.dhis.importexport.ImportException;
-import org.hisp.dhis.importexport.ImportParams;
-import org.hisp.dhis.importexport.ImportService;
-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, 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";
-
- private static final String DATA_ELEMENT_NOT_IN_SET_UUID = "96B2299E-ECD6-46CF-A61F-817D350C180D";
-
- private DataValueSetService service;
-
- private Dxf dxf;
- private org.hisp.dhis.importexport.datavalueset.DataValue dv;
-
- private ImportService importService;
-
- private ClassLoader classLoader;
-
- private DataElementCategoryOptionCombo defaultCombo;
-
- private DataValueSet dataValueSet;
-
- // -------------------------------------------------------------------------
- // Fixture
- // -------------------------------------------------------------------------
-
- @SuppressWarnings( "serial" )
- @Override
- public void setUpTest()
- throws JAXBException, IOException, ImportException
- {
- importService = (ImportService) getBean( "org.hisp.dhis.importexport.ImportService" );
- categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
- dataElementService = (DataElementService) getBean( DataElementService.ID );
- dataSetService = (DataSetService) getBean( DataSetService.ID );
- dataValueService = (DataValueService) getBean( DataValueService.ID );
-
- service = (DataValueSetService) getBean( "org.hisp.dhis.importexport.datavalueset.DataValueSetService" );
-
- classLoader = Thread.currentThread().getContextClassLoader();
-
- InputStream is = classLoader.getResourceAsStream( "datavalueset/base.xml" );
- ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false,
- false );
- importService.importData( importParams, is );
- is.close();
-
- defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
- defaultCombo.setUuid( DEFAULT_COMBO_UUID );
- categoryService.updateDataElementCategoryOptionCombo( defaultCombo );
-
- dxf = new Dxf();
-
- dv = new org.hisp.dhis.importexport.datavalueset.DataValue();
-// dv.setDataSetUuid( DATA_SET_UUID );
- dv.setPeriodIsoDate( "2011W5" );
- dv.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
- dv.setDataElementUuid( DATA_ELEMENT_UUID );
- dv.setValue( "11" );
- dv.setStoredBy( "misterindia" );
-
- dxf.setDataValues( new ArrayList() {{ add( dv ); }} );
-
- dataValueSet = new DataValueSet();
- dataValueSet.setCompleteDate( "20101010" );
- dataValueSet.setDataSetUuid( DATA_SET_UUID );
- dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
- dataValueSet.setPeriodIsoDate( "201009" );
- }
-
- // -------------------------------------------------------------------------
- // Tests
- // -------------------------------------------------------------------------
-
- @Test
- public void testJaxb()
- throws JAXBException, IOException
- {
- JAXBContext jc = JAXBContext.newInstance( Dxf.class );
- Unmarshaller u = jc.createUnmarshaller();
- InputStream is = classLoader.getResourceAsStream( "datavalueset/dataValueSet.xml" );
-
- Dxf dxfDataValueSet = (Dxf) u.unmarshal( is );
- is.close();
-
- assertEquals( 1, dxfDataValueSet.getDataValues().size() );
-
- org.hisp.dhis.importexport.datavalueset.DataValue dxfValue = dxfDataValueSet.getDataValues().get( 0 );
-
- assertEquals( dv.getDataSetUuid(), dxfValue.getDataSetUuid() );
- assertEquals( dv.getPeriodIsoDate(), dxfValue.getPeriodIsoDate() );
- assertEquals( dv.getOrganisationUnitUuid(), dxfValue.getOrganisationUnitUuid() );
-
- assertEquals( dv.getDataElementUuid(), dxfValue.getDataElementUuid() );
- assertEquals( dv.getStoredBy(), dxfValue.getStoredBy() );
-
- assertNull( dxfValue.getCategoryOptionComboUuid() );
- }
-
- @Test
- public void simpleMapping()
- throws Exception
- {
- long before = new Date().getTime();
-
- service.saveDataValueSet( dxf );
-
- long after = new Date().getTime();
-
- Collection dataValues = dataValueService.getAllDataValues();
- assertEquals( 1, dataValues.size() );
-
- DataValue dataValue = dataValues.iterator().next();
-
- verifyDataValue( before, after, dataValue );
-
- }
-
- @Test @Ignore
- public void testValidvalue() {
- setValue( "" );
-
- try
- {
- service.saveDataValueSet( dxf );
- }
- catch ( NumberFormatException e )
- {
- // Expected
- }
-
- }
-
- @Test @Ignore
- public void testDuplicatedDataValues() {
-
- }
-
- @Test @Ignore
- public void testExistingComboButNotInDataElement() {
-
- }
-
- @Test
- public void deleteDataValue() {
- service.saveDataValueSet( dxf );
-
- Collection dataValues = dataValueService.getAllDataValues();
- assertEquals( 1, dataValues.size() );
-
- dataValues = dataValueService.getAllDataValues();
- assertEquals( 1, dataValues.size() );
-
- setValue( null );
-
- service.saveDataValueSet( dxf );
-
- dataValues = dataValueService.getAllDataValues();
- assertEquals( 0, dataValues.size() );
-
- }
-
- @Test
- public void orgunitMissingOrNotInSet()
- {
- dv.setOrganisationUnitUuid( "ladlalad" );
- try
- {
- service.saveDataValueSet( dxf );
- fail( "Should miss org unit" );
-
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
-
- dv.setOrganisationUnitUuid( ORGANISATION_UNIT_NOT_IN_SET_UUID );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail( "Should miss org unit association to data set" );
-
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
- }
-
- @Test
- public void illegalPeriod() {
-
- dv.setPeriodIsoDate( "2011" );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail( "should not accept yearly period" );
-
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
- }
-
- @Test
- public void completeness() {
-
- dxf.setDataValueSets( new ArrayList() {{ add(dataValueSet); }} );
- service.saveDataValueSet( dxf );
-
- dataValueSet.setCompleteDate( "20110101" );
- service.saveDataValueSet( dxf );
-
- dataValueSet.setCompleteDate( null );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail("Shouldn't allow saving to a completed set");
- }
- catch ( IllegalArgumentException e )
- {
- // TODO: Expected
- }
-
- dataValueSet.setCompleteDate( "201lala" );
-
- try
- {
- service.saveDataValueSet( dxf );
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
-
- dataValueSet.setCompleteDate( "20101010" );
- service.saveDataValueSet( dxf );
-
- }
-
- @Test
- public void elementExistsAndNotInSet() {
-
- org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue();
- dv.setDataElementUuid( "ladida" );
- dv.setValue( "11" );
- dxf.getDataValues().add( dv );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail( "Should not accept non existing data element" );
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
-
- dv.setDataElementUuid( DATA_ELEMENT_NOT_IN_SET_UUID );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail( "Should not accept data element not in set" );
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
- }
-
- @Test
- public void optionComboExistsAndInDataElement() {
-
- dxf.getDataValues().get( 0 ).setCategoryOptionComboUuid( DEFAULT_COMBO_UUID );
-
- service.saveDataValueSet( dxf );
-
- dxf.getDataValues().get( 0 ).setCategoryOptionComboUuid( "AAB2299E-ECD6-46CF-A61F-817D350" );
-
- try
- {
- service.saveDataValueSet( dxf );
- fail( "Shouldn't allow non existing option combo" );
- }
- catch ( IllegalArgumentException e )
- {
- // Expected
- }
-
- }
-
-
-
- @Test
- public void testUpdate()
- {
- long before = new Date().getTime();
-
- service.saveDataValueSet( dxf );
-
- long after = new Date().getTime();
-
- Collection dataValues = dataValueService.getAllDataValues();
- assertEquals( 1, dataValues.size() );
-
- DataValue dataValue = dataValues.iterator().next();
-
- verifyDataValue( before, after, dataValue );
-
- // Update
- setValue("101");
-
- before = new Date().getTime();
-
- service.saveDataValueSet( dxf );
-
- after = new Date().getTime();
-
- dataValues = dataValueService.getAllDataValues();
- assertEquals( 1, dataValues.size() );
-
- dataValue = dataValues.iterator().next();
-
- verifyDataValue( before, after, dataValue, "101" );
-
- }
-
- private void setValue(String value)
- {
- dxf.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() );
- assertEquals( ORGANISATION_UNIT_UUID, dv.getSource().getUuid() );
- assertEquals( new WeeklyPeriodType().createPeriod( "2011W5" ), dv.getPeriod() );
- assertEquals( "misterindia", dv.getStoredBy() );
- assertEquals( value, dv.getValue() );
-
- long time = dv.getTimestamp().getTime();
- assertTrue( time >= before );
- assertTrue( time <= after );
-
- assertEquals( defaultCombo, dv.getOptionCombo() );
- }
-
- @Override
- protected boolean emptyDatabaseAfterTest()
- {
- return true;
- }
-
-
-}
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2'
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,451 @@
+package org.hisp.dhis.importexport.dxf2.service;
+
+/*
+ * Copyright (c) 2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static junit.framework.Assert.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.importexport.ImportException;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.importexport.ImportService;
+import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.importexport.dxf2.model.DataValueSet;
+import org.hisp.dhis.importexport.dxf2.service.DataValueSetService;
+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, 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";
+
+ private static final String DATA_ELEMENT_NOT_IN_SET_UUID = "96B2299E-ECD6-46CF-A61F-817D350C180D";
+
+ private DataValueSetService service;
+
+ private DataValueSet dataValueSet;
+
+ private ImportService importService;
+
+ private ClassLoader classLoader;
+
+ private DataElementCategoryOptionCombo defaultCombo;
+
+ // -------------------------------------------------------------------------
+ // Fixture
+ // -------------------------------------------------------------------------
+
+ @SuppressWarnings( "serial" )
+ @Override
+ public void setUpTest()
+ throws JAXBException, IOException, ImportException
+ {
+ importService = (ImportService) getBean( "org.hisp.dhis.importexport.ImportService" );
+ categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
+ dataValueService = (DataValueService) getBean( DataValueService.ID );
+
+ service = (DataValueSetService) getBean( "org.hisp.dhis.importexport.dxf2.service.DataValueSetService" );
+
+ classLoader = Thread.currentThread().getContextClassLoader();
+
+ InputStream is = classLoader.getResourceAsStream( "dxf2/base.xml" );
+ ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false,
+ false );
+ importService.importData( importParams, is );
+ is.close();
+
+ dataValueSet = new DataValueSet();
+ dataValueSet.setDataSetUuid( DATA_SET_UUID );
+ dataValueSet.setPeriodIsoDate( "2011W5" );
+ dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
+
+ final org.hisp.dhis.importexport.dxf2.model.DataValue dv = new org.hisp.dhis.importexport.dxf2.model.DataValue();
+ dv.setDataElementUuid( DATA_ELEMENT_UUID );
+ dv.setValue( "11" );
+ dv.setStoredBy( "misterindia" );
+
+ dataValueSet.setDataValues( new ArrayList()
+ {
+ {
+ add( dv );
+ }
+ } );
+
+ defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+ defaultCombo.setUuid( DEFAULT_COMBO_UUID );
+ categoryService.updateDataElementCategoryOptionCombo( defaultCombo );
+ }
+
+ // -------------------------------------------------------------------------
+ // Tests
+ // -------------------------------------------------------------------------
+
+ @Test
+ public void testJaxb()
+ throws JAXBException, IOException
+ {
+ JAXBContext jc = JAXBContext.newInstance( DataValueSet.class,
+ org.hisp.dhis.importexport.dxf2.model.DataValue.class );
+ Unmarshaller u = jc.createUnmarshaller();
+ InputStream is = classLoader.getResourceAsStream( "dxf2/dataValueSet.xml" );
+
+ DataValueSet dxfDataValueSet = (DataValueSet) u.unmarshal( is );
+ is.close();
+
+ assertEquals( dataValueSet.getDataSetUuid(), dxfDataValueSet.getDataSetUuid() );
+ assertEquals( dataValueSet.getPeriodIsoDate(), dxfDataValueSet.getPeriodIsoDate() );
+ assertEquals( dataValueSet.getOrganisationUnitUuid(), dxfDataValueSet.getOrganisationUnitUuid() );
+
+ assertEquals( 1, dxfDataValueSet.getDataValues().size() );
+
+ org.hisp.dhis.importexport.dxf2.model.DataValue dv = dxfDataValueSet.getDataValues().get( 0 );
+ org.hisp.dhis.importexport.dxf2.model.DataValue dataValue = dataValueSet.getDataValues().get( 0 );
+
+ assertEquals( dataValue.getDataElementUuid(), dv.getDataElementUuid() );
+ assertEquals( dataValue.getStoredBy(), dv.getStoredBy() );
+
+ assertNull( dv.getCategoryOptionComboUuid() );
+ }
+
+ @Test
+ public void simpleMapping()
+ throws Exception
+ {
+ long before = new Date().getTime();
+
+ service.saveDataValueSet( dataValueSet );
+
+ long after = new Date().getTime();
+
+ Collection dataValues = dataValueService.getAllDataValues();
+ assertEquals( 1, dataValues.size() );
+
+ DataValue dataValue = dataValues.iterator().next();
+
+ verifyDataValue( before, after, dataValue );
+
+ }
+
+ @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
+ {
+ service.saveDataValueSet( dataValueSet );
+ fail( "Should miss data set" );
+
+ }
+ catch ( IllegalArgumentException e )
+ {
+ // Expected
+ }
+ }
+
+ @Test
+ public void orgunitMissingOrNotInSet()
+ {
+ dataValueSet.setOrganisationUnitUuid( "ladlalad" );
+ try
+ {
+ service.saveDataValueSet( dataValueSet );
+ fail( "Should miss org unit" );
+
+ }
+ catch ( IllegalArgumentException e )
+ {
+ // Expected
+ }
+
+ 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.dxf2.model.DataValue dv = new org.hisp.dhis.importexport.dxf2.model.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 );
+
+ 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()
+ {
+ long before = new Date().getTime();
+
+ service.saveDataValueSet( dataValueSet );
+
+ long after = new Date().getTime();
+
+ Collection dataValues = dataValueService.getAllDataValues();
+ assertEquals( 1, dataValues.size() );
+
+ DataValue dataValue = dataValues.iterator().next();
+
+ verifyDataValue( before, after, dataValue );
+
+ // Update
+ setValue("101");
+
+ before = new Date().getTime();
+
+ service.saveDataValueSet( dataValueSet );
+
+ after = new Date().getTime();
+
+ dataValues = dataValueService.getAllDataValues();
+ assertEquals( 1, dataValues.size() );
+
+ dataValue = dataValues.iterator().next();
+
+ verifyDataValue( before, after, dataValue, "101" );
+
+ }
+
+ 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() );
+ assertEquals( ORGANISATION_UNIT_UUID, dv.getSource().getUuid() );
+ assertEquals( new WeeklyPeriodType().createPeriod( "2011W5" ), dv.getPeriod() );
+ assertEquals( "misterindia", dv.getStoredBy() );
+ assertEquals( value, dv.getValue() );
+
+ long time = dv.getTimestamp().getTime();
+ assertTrue( time >= before );
+ assertTrue( time <= after );
+
+ assertEquals( defaultCombo, dv.getOptionCombo() );
+ }
+
+ @Override
+ protected boolean emptyDatabaseAfterTest()
+ {
+ return true;
+ }
+
+
+}
=== removed directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset'
=== removed 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-16 17:16:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml 1970-01-01 00:00:00 +0000
@@ -1,178 +0,0 @@
-
-
-
-
- 9
- default
-
-
-
-
-
- 10
- default
-
-
-
-
-
- 11
- default
- 9
-
-
-
-
-
- 12
- default
-
-
-
-
-
- 13
- AAB2299E-ECD6-46CF-A61F-817D350C180D
-
- 12
- default
-
-
-
- 10
- default
-
-
-
-
-
-
-
- 11
- 10
- 1
-
-
-
-
-
- 12
- 11
- 1
-
-
-
-
-
- 21
- 56B2299E-ECD6-46CF-A61F-817D350C180D
- Data element 1
-
- data element 1
- ELEM1
-
- true
- int
- sum
- 12
- 2011-02-14
-
-
- 99
- 96B2299E-ECD6-46CF-A61F-817D350C180D
- Not in data set
- not in
- ELEM2
-
- true
- int
- sum
- 12
- 2011-02-14
-
-
-
-
-
- 20
- 16B2299E-ECD6-46CF-A61F-817D350C180D
-
-
- DATASET1
- Weekly
-
-
-
-
-
- 20
- 21
-
-
-
-
-
- 22
- 9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344
- OrgUnit1
- OrgUnit1
- UNIT1
- 1990-01-01
-
- true
-
-
-
-
- 2011-02-14
-
-
- 99
- 9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345
- Not reporting data set
- OrgUnit1
- UNIT1
- 1990-01-01
-
- true
-
-
-
-
- 2011-02-14
-
-
-
-
-
-
-
-
- 14
- Type
- Type of organisation unit, examples are PHU, chiefdom and district
- false
-
-
- 15
- Ownership
- Ownership of organisation unit, examples are private and public
- false
-
-
-
-
-
- 0
- 1
- Level 1
-
-
-
-
-
- 20
-
-
-
-
=== removed 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-17 08:25:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml 1970-01-01 00:00:00 +0000
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/base.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/base.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/base.xml 2011-02-18 20:17:34 +0000
@@ -0,0 +1,178 @@
+
+
+
+
+ 9
+ default
+
+
+
+
+
+ 10
+ default
+
+
+
+
+
+ 11
+ default
+ 9
+
+
+
+
+
+ 12
+ default
+
+
+
+
+
+ 13
+ AAB2299E-ECD6-46CF-A61F-817D350C180D
+
+ 12
+ default
+
+
+
+ 10
+ default
+
+
+
+
+
+
+
+ 11
+ 10
+ 1
+
+
+
+
+
+ 12
+ 11
+ 1
+
+
+
+
+
+ 21
+ 56B2299E-ECD6-46CF-A61F-817D350C180D
+ Data element 1
+
+ data element 1
+ ELEM1
+
+ true
+ int
+ sum
+ 12
+ 2011-02-14
+
+
+ 99
+ 96B2299E-ECD6-46CF-A61F-817D350C180D
+ Not in data set
+ not in
+ ELEM2
+
+ true
+ int
+ sum
+ 12
+ 2011-02-14
+
+
+
+
+
+ 20
+ 16B2299E-ECD6-46CF-A61F-817D350C180D
+
+
+ DATASET1
+ Weekly
+
+
+
+
+
+ 20
+ 21
+
+
+
+
+
+ 22
+ 9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344
+ OrgUnit1
+ OrgUnit1
+ UNIT1
+ 1990-01-01
+
+ true
+
+
+
+
+ 2011-02-14
+
+
+ 99
+ 9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345
+ Not reporting data set
+ OrgUnit1
+ UNIT1
+ 1990-01-01
+
+ true
+
+
+
+
+ 2011-02-14
+
+
+
+
+
+
+
+
+ 14
+ Type
+ Type of organisation unit, examples are PHU, chiefdom and district
+ false
+
+
+ 15
+ Ownership
+ Ownership of organisation unit, examples are private and public
+ false
+
+
+
+
+
+ 0
+ 1
+ Level 1
+
+
+
+
+
+ 20
+
+
+
+
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml 2011-02-18 20:17:34 +0000
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2010-12-22 04:05:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2011-02-18 20:17:34 +0000
@@ -118,7 +118,6 @@
public void deSerialize( DataInputStream dataInputStream )
throws IOException
{
- // FIXME: Get implementation from client
this.setId( dataInputStream.readInt() );
this.setName( dataInputStream.readUTF() );
this.setVersion( dataInputStream.readInt() );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2011-01-12 09:13:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2011-02-18 20:17:34 +0000
@@ -32,7 +32,9 @@
import java.io.IOException;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+@XmlRootElement
public class OrgUnit
implements DataStreamSerializable
{
@@ -159,4 +161,5 @@
this.updateProgramUrl = dataInputStream.readUTF();
this.updateDataSetUrl = dataInputStream.readUTF();
}
+
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.web.api.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+@Path( "/" )
+public class ApiResource
+{
+
+ @Context
+ UriInfo uriInfo;
+
+ @GET
+ @Produces( MediaType.TEXT_HTML )
+ public String getDescription()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( " \n" );
+ sb.append( "DHIS2 Web API\n\n
DHIS2 Web API
\n" );
+
+ sb.append( "
Warning: This API is in no way ready for public consumption. Radical changes must be expected at any time!
\n" );
+
+ sb.append( "
The api currently supports two specific pilot use cases, posting of data value sets and a mobile GPRS client." );
+
+ sb.append( "
Posting data value sets (experimental)
" );
+ sb.append( "
To find the needed information about the data sets you want to post data about, go to " );
+ URI uri = uriInfo.getBaseUriBuilder().path( DataSetResource.class ).build();
+ sb.append( "the data set list.
The api/mobile path will return a list of the currently logged in user's" );
+ sb.append( " associated org units, with links to a set of specific url's needed by the client on an org " );
+ sb.append( "unit basis.
\n" );
+ sb.append( "
The url's, and their content is quite specifically tailored for the mobile client, and the serialization" );
+ sb.append( " format for the mobile solution is java's native data serialization, zipped. But it does send xml (and potentially json)" );
+ sb.append( " if you request that in your Accept header (xml would be chosen by browsers by default), so have a look if you like.
" );
+ sb.append( "
If the user you are logged in as are not associated with any org unit, try going directly to one of the org units
\n");
+ URI uri = uriInfo.getBaseUriBuilder().path( DataSetResource.class ).build( );
+ sb.append( "
This resource is the place to post data value sets. Take a look at the data sets to see what to post.." );
+ xmlTemplate( sb, null );
+
+ sb.append( "\n\n" );
+
+ return sb.toString();
+ }
+
+ @POST
+ @Consumes( MediaType.APPLICATION_XML )
+ public void storeDataValueSet( DataValueSet dataValueSet )
+ {
+ dataValueSetService.saveDataValueSet( dataValueSet );
+ }
+
+ @Required
+ public void setDataValueSetService( DataValueSetService dataValueSetService )
+ {
+ this.dataValueSetService = dataValueSetService;
+ }
+
+
+ public static void xmlTemplate( StringBuilder t, UriInfo uriInfo )
+ {
+
+ t.append( "
Post according to the following template" );
+ if (uriInfo != null) {
+ URI uri = uriInfo.getBaseUriBuilder().path( DataValueSetResource.class ).build();
+ t.append( " to " ).append( uri ).append( "");
+ }
+ t.append( ":