dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10496
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2876: Trying to beat the web api into some kind of shape (very much work in progress).
------------------------------------------------------------
revno: 2876
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-02-19 01:47:34 +0530
message:
Trying to beat the web api into some kind of shape (very much work in progress).
Also removed extensive api req/resp logging from portal (kept when running just dhis-web-api)
removed:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/
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/DataValueSet.java
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/Dxf.java
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/test/java/org/hisp/dhis/importexport/datavalueset/
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/resources/datavalueset/
dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml
dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java
added:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/
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/DataValueSet.java
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/service/
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/test/java/org/hisp/dhis/importexport/dxf2/
dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/
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/resources/dxf2/
dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/base.xml
dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml
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/DataSetResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml
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/OrgUnit.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml
dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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
- * <p>
- * First checks that:
- * <ul>
- * <li>dataSet exists
- * <li>orgUnit exists
- * <li>orgunit reports dataSet
- * <li>period is a valid period
- * <li>the dataValueSet is not registered as complete or that if it is a
- * complete date is present
- * <li>a present complete date is valid
- * </ul>
- * For all dataValues it checks that:
- * <ul>
- * <li>dataElement exists and is in dataSet
- * <li>optionCombo exists (defaults to 'default' if not specified) and is in
- * dataElement
- * </ul>
- * What isn't checked yet:
- * <ul>
- * <li>That there isn't duplicated value entries (will throw Constraint
- * exception)
- * <li>That the value is valid!
- * </ul>
- * Concerns:
- * <ul>
- * <li>deletion through sending "empty string" value dependant on semantics
- * of add/update in data value store
- * <li>completed semantics, can't uncomplete but can complete and
- * "recomplete"
- * <li>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<DataValueSet> 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<DataSet> 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<DataValue> newDataValues, List<DataValue> 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<DataValue> dataValues;
-
- @XmlElementWrapper( name = "dataValueSets" )
- @XmlElement( name = "dataValueSet" )
- private List<DataValueSet> dataValueSets;
-
- public List<DataValue> getDataValues()
- {
- return dataValues;
- }
-
- public void setDataValues( List<DataValue> dataValues )
- {
- this.dataValues = dataValues;
- }
-
- public List<DataValueSet> getDataValueSets()
- {
- return dataValueSets;
- }
-
- public void setDataValueSets( List<DataValueSet> 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<DataValue> 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<DataValue> getDataValues()
+ {
+ return dataValues;
+ }
+
+ public void setDataValues( List<DataValue> 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
+ * <p>
+ * First checks that:
+ * <ul>
+ * <li>dataSet exists
+ * <li>orgUnit exists
+ * <li>orgunit reports dataSet
+ * <li>period is a valid period
+ * <li>the dataValueSet is not registered as complete or that if it is a
+ * complete date is present
+ * <li>a present complete date is valid
+ * </ul>
+ * For all dataValues it checks that:
+ * <ul>
+ * <li>dataElement exists and is in dataSet
+ * <li>optionCombo exists (defaults to 'default' if not specified) and is in dataElement
+ * </ul>
+ * What isn't checked yet:
+ * <ul>
+ * <li>That there isn't duplicated value entries (will throw Constraint exception)
+ * <li>That the value is valid!
+ * </ul>
+ * Concerns:
+ * <ul>
+ * <li>deletion through sending "empty string" value dependant on semantics of add/update in data value store
+ * <li>completed semantics, can't uncomplete but can complete and "recomplete"
+ * <li>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<DataValue> newDataValues = new ArrayList<DataValue>( dataValueSet.getDataValues().size() );
+ List<DataValue> updatedDataValues = new ArrayList<DataValue>( 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<DataValue> newDataValues, List<DataValue> 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 @@
<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
</bean>
- <bean id="org.hisp.dhis.importexport.datavalueset.DataValueSetService"
- class="org.hisp.dhis.importexport.datavalueset.DataValueSetService">
+ <bean id="org.hisp.dhis.importexport.dxf2.service.DataValueSetService"
+ class="org.hisp.dhis.importexport.dxf2.service.DataValueSetService">
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
=== 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<org.hisp.dhis.importexport.datavalueset.DataValue>() {{ 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<DataValue> 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<DataValue> 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<DataValue> 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<org.hisp.dhis.importexport.dxf2.model.DataValue>()
+ {
+ {
+ 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<DataValue> 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<DataValue> 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<DataValue> 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 @@
-<?xml version='1.0'?>
-<dxf xmlns="http://dhis2.org/schema/dxf/1.0" minorVersion="1.2" exported="2011-02-14">
- <concepts>
- <concept>
- <id>9</id>
- <name>default</name>
- </concept>
- </concepts>
-
- <categoryOptions>
- <categoryOption>
- <id>10</id>
- <name>default</name>
- </categoryOption>
- </categoryOptions>
-
- <categories>
- <category>
- <id>11</id>
- <name>default</name>
- <conceptid>9</conceptid>
- </category>
- </categories>
-
- <categoryCombos>
- <categoryCombo>
- <id>12</id>
- <name>default</name>
- </categoryCombo>
- </categoryCombos>
-
- <categoryOptionCombos>
- <categoryOptionCombo>
- <id>13</id>
- <uuid>AAB2299E-ECD6-46CF-A61F-817D350C180D</uuid>
- <categoryCombo>
- <id>12</id>
- <name>default</name>
- </categoryCombo>
- <categoryOptions>
- <categoryOption>
- <id>10</id>
- <name>default</name>
- </categoryOption>
- </categoryOptions>
- </categoryOptionCombo>
- </categoryOptionCombos>
-
- <categoryCategoryOptionAssociations>
- <categoryCategoryOptionAssociation>
- <category>11</category>
- <categoryOption>10</categoryOption>
- <sortOrder>1</sortOrder>
- </categoryCategoryOptionAssociation>
- </categoryCategoryOptionAssociations>
-
- <categoryComboCategoryAssociations>
- <categoryComboCategoryAssociation>
- <categoryCombo>12</categoryCombo>
- <category>11</category>
- <sortOrder>1</sortOrder>
- </categoryComboCategoryAssociation>
- </categoryComboCategoryAssociations>
-
- <dataElements>
- <dataElement>
- <id>21</id>
- <uuid>56B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
- <name>Data element 1</name>
- <alternativeName></alternativeName>
- <shortName>data element 1</shortName>
- <code>ELEM1</code>
- <description></description>
- <active>true</active>
- <type>int</type>
- <aggregationOperator>sum</aggregationOperator>
- <categoryCombo>12</categoryCombo>
- <lastUpdated>2011-02-14</lastUpdated>
- </dataElement>
- <dataElement>
- <id>99</id>
- <uuid>96B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
- <name>Not in data set</name>
- <shortName>not in</shortName>
- <code>ELEM2</code>
- <description></description>
- <active>true</active>
- <type>int</type>
- <aggregationOperator>sum</aggregationOperator>
- <categoryCombo>12</categoryCombo>
- <lastUpdated>2011-02-14</lastUpdated>
- </dataElement>
- </dataElements>
-
- <dataSets>
- <dataSet>
- <id>20</id>
- <uuid>16B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
- <name><![CDATA[DataSet1]]></name>
- <shortName><![CDATA[shortname1]]></shortName>
- <code>DATASET1</code>
- <periodType>Weekly</periodType>
- </dataSet>
- </dataSets>
-
- <dataSetMembers>
- <dataSetMember>
- <dataSet>20</dataSet>
- <dataElement>21</dataElement>
- </dataSetMember>
- </dataSetMembers>
-
- <organisationUnits>
- <organisationUnit>
- <id>22</id>
- <uuid>9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344</uuid>
- <name>OrgUnit1</name>
- <shortName>OrgUnit1</shortName>
- <code>UNIT1</code>
- <openingDate>1990-01-01</openingDate>
- <closedDate></closedDate>
- <active>true</active>
- <comment></comment>
- <geoCode></geoCode>
- <feature type="">
- </feature>
- <lastUpdated>2011-02-14</lastUpdated>
- </organisationUnit>
- <organisationUnit>
- <id>99</id>
- <uuid>9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345</uuid>
- <name>Not reporting data set</name>
- <shortName>OrgUnit1</shortName>
- <code>UNIT1</code>
- <openingDate>1990-01-01</openingDate>
- <closedDate></closedDate>
- <active>true</active>
- <comment></comment>
- <geoCode></geoCode>
- <feature type="">
- </feature>
- <lastUpdated>2011-02-14</lastUpdated>
- </organisationUnit>
- </organisationUnits>
-
- <organisationUnitRelationships>
- </organisationUnitRelationships>
-
- <groupSets>
- <groupSet>
- <id>14</id>
- <name>Type</name>
- <description>Type of organisation unit, examples are PHU, chiefdom and district</description>
- <compulsory>false</compulsory>
- </groupSet>
- <groupSet>
- <id>15</id>
- <name>Ownership</name>
- <description>Ownership of organisation unit, examples are private and public</description>
- <compulsory>false</compulsory>
- </groupSet>
- </groupSets>
-
- <organisationUnitLevels>
- <organisationUnitLevel>
- <id>0</id>
- <level>1</level>
- <name>Level 1</name>
- </organisationUnitLevel>
- </organisationUnitLevels>
-
- <dataSetSourceAssociations>
- <dataSetSourceAssociation>
- <dataSet>20</dataSet>
- <source>22</source>
- </dataSetSourceAssociation>
- </dataSetSourceAssociations>
-</dxf>
=== 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 @@
-<?xml version='1.0'?>
-<dxf xmlns="http://dhis2.org/schema/dxf/x.x">
- <completeNotDataValueSets>
- <completeNotDataValueSet dataSet="16B2299E-ECD6-46CF-A61F-817D350C180D"
- period="2011W5" orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344" complete="20101010" />
- </completeNotDataValueSets>
- <dataValues>
- <dataValue period="2011W5"
- orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344" dataElement="56B2299E-ECD6-46CF-A61F-817D350C180D"
- storedBy="misterindia" value="11" />
- </dataValues>
-</dxf>
\ 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 @@
+<?xml version='1.0'?>
+<dxf xmlns="http://dhis2.org/schema/dxf/1.0" minorVersion="1.2" exported="2011-02-14">
+ <concepts>
+ <concept>
+ <id>9</id>
+ <name>default</name>
+ </concept>
+ </concepts>
+
+ <categoryOptions>
+ <categoryOption>
+ <id>10</id>
+ <name>default</name>
+ </categoryOption>
+ </categoryOptions>
+
+ <categories>
+ <category>
+ <id>11</id>
+ <name>default</name>
+ <conceptid>9</conceptid>
+ </category>
+ </categories>
+
+ <categoryCombos>
+ <categoryCombo>
+ <id>12</id>
+ <name>default</name>
+ </categoryCombo>
+ </categoryCombos>
+
+ <categoryOptionCombos>
+ <categoryOptionCombo>
+ <id>13</id>
+ <uuid>AAB2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+ <categoryCombo>
+ <id>12</id>
+ <name>default</name>
+ </categoryCombo>
+ <categoryOptions>
+ <categoryOption>
+ <id>10</id>
+ <name>default</name>
+ </categoryOption>
+ </categoryOptions>
+ </categoryOptionCombo>
+ </categoryOptionCombos>
+
+ <categoryCategoryOptionAssociations>
+ <categoryCategoryOptionAssociation>
+ <category>11</category>
+ <categoryOption>10</categoryOption>
+ <sortOrder>1</sortOrder>
+ </categoryCategoryOptionAssociation>
+ </categoryCategoryOptionAssociations>
+
+ <categoryComboCategoryAssociations>
+ <categoryComboCategoryAssociation>
+ <categoryCombo>12</categoryCombo>
+ <category>11</category>
+ <sortOrder>1</sortOrder>
+ </categoryComboCategoryAssociation>
+ </categoryComboCategoryAssociations>
+
+ <dataElements>
+ <dataElement>
+ <id>21</id>
+ <uuid>56B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+ <name>Data element 1</name>
+ <alternativeName></alternativeName>
+ <shortName>data element 1</shortName>
+ <code>ELEM1</code>
+ <description></description>
+ <active>true</active>
+ <type>int</type>
+ <aggregationOperator>sum</aggregationOperator>
+ <categoryCombo>12</categoryCombo>
+ <lastUpdated>2011-02-14</lastUpdated>
+ </dataElement>
+ <dataElement>
+ <id>99</id>
+ <uuid>96B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+ <name>Not in data set</name>
+ <shortName>not in</shortName>
+ <code>ELEM2</code>
+ <description></description>
+ <active>true</active>
+ <type>int</type>
+ <aggregationOperator>sum</aggregationOperator>
+ <categoryCombo>12</categoryCombo>
+ <lastUpdated>2011-02-14</lastUpdated>
+ </dataElement>
+ </dataElements>
+
+ <dataSets>
+ <dataSet>
+ <id>20</id>
+ <uuid>16B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+ <name><![CDATA[DataSet1]]></name>
+ <shortName><![CDATA[shortname1]]></shortName>
+ <code>DATASET1</code>
+ <periodType>Weekly</periodType>
+ </dataSet>
+ </dataSets>
+
+ <dataSetMembers>
+ <dataSetMember>
+ <dataSet>20</dataSet>
+ <dataElement>21</dataElement>
+ </dataSetMember>
+ </dataSetMembers>
+
+ <organisationUnits>
+ <organisationUnit>
+ <id>22</id>
+ <uuid>9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344</uuid>
+ <name>OrgUnit1</name>
+ <shortName>OrgUnit1</shortName>
+ <code>UNIT1</code>
+ <openingDate>1990-01-01</openingDate>
+ <closedDate></closedDate>
+ <active>true</active>
+ <comment></comment>
+ <geoCode></geoCode>
+ <feature type="">
+ </feature>
+ <lastUpdated>2011-02-14</lastUpdated>
+ </organisationUnit>
+ <organisationUnit>
+ <id>99</id>
+ <uuid>9C1B1B5E-3D65-48F2-8D1D-D36C60DD7345</uuid>
+ <name>Not reporting data set</name>
+ <shortName>OrgUnit1</shortName>
+ <code>UNIT1</code>
+ <openingDate>1990-01-01</openingDate>
+ <closedDate></closedDate>
+ <active>true</active>
+ <comment></comment>
+ <geoCode></geoCode>
+ <feature type="">
+ </feature>
+ <lastUpdated>2011-02-14</lastUpdated>
+ </organisationUnit>
+ </organisationUnits>
+
+ <organisationUnitRelationships>
+ </organisationUnitRelationships>
+
+ <groupSets>
+ <groupSet>
+ <id>14</id>
+ <name>Type</name>
+ <description>Type of organisation unit, examples are PHU, chiefdom and district</description>
+ <compulsory>false</compulsory>
+ </groupSet>
+ <groupSet>
+ <id>15</id>
+ <name>Ownership</name>
+ <description>Ownership of organisation unit, examples are private and public</description>
+ <compulsory>false</compulsory>
+ </groupSet>
+ </groupSets>
+
+ <organisationUnitLevels>
+ <organisationUnitLevel>
+ <id>0</id>
+ <level>1</level>
+ <name>Level 1</name>
+ </organisationUnitLevel>
+ </organisationUnitLevels>
+
+ <dataSetSourceAssociations>
+ <dataSetSourceAssociation>
+ <dataSet>20</dataSet>
+ <source>22</source>
+ </dataSetSourceAssociation>
+ </dataSetSourceAssociations>
+</dxf>
=== 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 @@
+<?xml version='1.0'?>
+
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT"
+ dataSet="16B2299E-ECD6-46CF-A61F-817D350C180D" period="2011W5"
+ orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344">
+
+ <dataValue dataElement="56B2299E-ECD6-46CF-A61F-817D350C180D" storedBy="misterindia" value="11" />
+
+</dataValueSet>
=== 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( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> \n<html>" );
+ sb.append( "<head><title>DHIS2 Web API</title></head>\n<body>\n<h1>DHIS2 Web API</h1>\n" );
+
+ sb.append( "<p><b>Warning: This API is in no way ready for public consumption. Radical changes must be expected at any time!</b></p>\n" );
+
+ sb.append( "<p>The api currently supports two specific pilot use cases, posting of data value sets and a mobile GPRS client." );
+
+ sb.append( "<h2>Posting data value sets (experimental)</h2>" );
+ sb.append( "<p>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( "<a href=\"" ).append( uri ).append( "\">the data set list</a>.</p>" );
+
+ DataValueSetResource.xmlTemplate( sb, uriInfo );
+
+ sb.append( "<h2>Mobile GPRS API</h2>" );
+ sb.append( "<p>The <a href=\"mobile\">api/mobile</a> 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.</p>\n" );
+ sb.append( "<p>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.</p>" );
+ sb.append( "<p>If the user you are logged in as are not associated with any org unit, try going directly to one of the <a href=\"orgUnits/\">org units</a></p> " );
+ sb.append( "</body>\n</html>\n" );
+ return sb.toString();
+ }
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,129 @@
+package org.hisp.dhis.web.api.resources;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.springframework.beans.factory.annotation.Required;
+
+@Path( "dataSets" )
+public class DataSetResource
+{
+
+ private DataSetService dataSetService;
+
+ @Context
+ UriInfo uriInfo;
+
+ @GET
+ @Produces( MediaType.TEXT_HTML )
+ public String getDataSetList()
+ {
+ StringBuilder t = new StringBuilder();
+ t.append( head( "Data sets available for reporting" ) );
+
+ t.append( "<h2>Data sets available for reporting</h2>\n<ul>\n" );
+ for ( DataSet dataSet : dataSetService.getAllDataSets() )
+ {
+ URI uri = uriInfo.getAbsolutePathBuilder().path( "{uuid}" ).build( dataSet.getUuid() );
+ t.append( "<li>" ).append( "<a href=\"" ).append( uri ).append( "\">" ).append( dataSet.getName() )
+ .append( "</a></li>\n" );
+ }
+ t.append( "</ul>" );
+ DataValueSetResource.xmlTemplate( t, uriInfo );
+ t.append( tail() );
+
+ return t.toString();
+ }
+
+ @GET
+ @Path( "{uuid}" )
+ @Produces( MediaType.TEXT_HTML )
+ public String getDataSet( @PathParam( "uuid" ) String uuid )
+ {
+
+ DataSet dataSet = dataSetService.getDataSet( uuid );
+
+ if ( dataSet == null )
+ {
+ throw new IllegalArgumentException( "No dataset with uuid " + uuid );
+ }
+
+ StringBuilder t = new StringBuilder();
+
+ t.append( head( "Data set " + dataSet.getName() ) );
+ t.append( "<p>Uuid: " ).append( dataSet.getUuid() ).append( "<br>\n" );
+ t.append( "Period type: " ).append( dataSet.getPeriodType().getName() ).append( " - " )
+ .append( dataSet.getPeriodType().getIsoFormat() );
+ t.append( "</p>\n" );
+
+ t.append( "<h2>Org units reporting data set</h2>\n<ul>" );
+ for ( OrganisationUnit unit : dataSet.getOrganisationUnits() )
+ {
+ t.append( "<li><b>" ).append( unit.getName() ).append( "</b> - " ).append( unit.getUuid() )
+ .append( "</li>" );
+ }
+ t.append( "</ul>\n" );
+
+ t.append( "<h2>Data elements in data set</h2>\n<ul>" );
+ for ( DataElement element : dataSet.getDataElements() )
+ {
+ t.append( "<li><b>" ).append( element.getName() ).append( "</b> (" ).append( element.getType() )
+ .append( ") - " ).append( element.getUuid() );
+
+ Set<DataElementCategoryOptionCombo> optionCombos = element.getCategoryCombo().getOptionCombos();
+ if ( optionCombos.size() > 1 )
+ {
+ t.append( "<br>CategoryOptionCombos\n<ul>\n" );
+ for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
+ {
+ t.append( "<li><b>" ).append( optionCombo.getName() ).append( "</b> - " )
+ .append( optionCombo.getUuid() ).append( "</li>" );
+ }
+ t.append( "</ul>\n" );
+ }
+ t.append( "</li>\n" );
+ }
+ t.append( "</ul>" );
+ t.append( "<h2>Xml template</h2>\n" );
+
+ DataValueSetResource.xmlTemplate( t, uriInfo );
+ t.append( tail() );
+
+ return t.toString();
+ }
+
+ private String head( String title )
+ {
+ return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> \n<html><head><title>"
+ + title + "</title></head>\n" + "<body>\n<h1>" + title + "</h1>\n";
+ }
+
+ private String tail()
+ {
+ return "</body>\n</html>\n";
+ }
+
+
+
+ @Required
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+
+
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetResource.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,75 @@
+package org.hisp.dhis.web.api.resources;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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;
+
+import org.hisp.dhis.importexport.dxf2.model.DataValueSet;
+import org.hisp.dhis.importexport.dxf2.service.DataValueSetService;
+import org.springframework.beans.factory.annotation.Required;
+
+@Path( "dataValueSets" )
+public class DataValueSetResource
+{
+
+ private DataValueSetService dataValueSetService;
+
+ @Context UriInfo uriInfo;
+
+ @GET
+ @Produces( MediaType.TEXT_HTML )
+ public String getDescription() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> \n<html>");
+ sb.append( "<head><title>DHIS2 Web API: Data value sets</title></head>\n<body>\n<h1>Data value sets</h1>\n");
+ URI uri = uriInfo.getBaseUriBuilder().path( DataSetResource.class ).build( );
+ sb.append( "<p>This resource is the place to post data value sets. Take a look at the <a href=\"" );
+ sb.append( uri ).append( "\">data sets</a> to see what to post.." );
+ xmlTemplate( sb, null );
+
+ sb.append( "</body>\n</html>\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( "<p>Post according to the following template" );
+ if (uriInfo != null) {
+ URI uri = uriInfo.getBaseUriBuilder().path( DataValueSetResource.class ).build();
+ t.append( " to <a href=\"" ).append( uri ).append( "\">" ).append( uri ).append( "</a>");
+ }
+ t.append( ":</p>" );
+
+ t.append( "<pre>" ).append( "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0-SNAPSHOT\"\n" );
+ 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\" storedBy=\"string\" value=\"value\"/>" );
+ t.append( "\n</dataValueSet>" );
+ t.append( "</pre>" );
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2011-01-17 06:28:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2011-02-18 20:17:34 +0000
@@ -33,14 +33,12 @@
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.web.api.model.OrgUnit;
@@ -48,9 +46,7 @@
import org.hisp.dhis.web.api.service.NotAllowedException;
import org.springframework.beans.factory.annotation.Required;
-import com.sun.jersey.api.core.ResourceContext;
-
-@Path( "/" )
+@Path( "/mobile" )
@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
public class MobileResource
{
@@ -59,21 +55,15 @@
private CurrentUserService currentUserService;
- private OrganisationUnitService organisationUnitService;
-
@Context
UriInfo uriInfo;
- @Context
- private ResourceContext rc;
-
/**
* Get the units associated with the currently logged in user
*
* @throws NotAllowedException if no user is logged in
*/
@GET
- @Path( "mobile" )
public OrgUnits getOrgUnitsForUser()
throws NotAllowedException
{
@@ -89,52 +79,16 @@
List<OrgUnit> unitList = new ArrayList<OrgUnit>();
for ( OrganisationUnit unit : units )
{
- unitList.add( getOrgUnit( unit ) );
+ unitList.add( OrgUnitResource.getOrgUnit( unit, uriInfo ) );
}
return new OrgUnits( unitList );
}
- @Path( "orgUnits/{id}" )
- public OrgUnitResource getOrgUnit( @PathParam( "id" ) int id )
- {
- OrgUnitResource resource = rc.getResource( OrgUnitResource.class );
- resource.setOrgUnit( organisationUnitService.getOrganisationUnit( id ) );
- return resource;
- }
-
- private OrgUnit getOrgUnit( OrganisationUnit unit )
- {
- OrgUnit orgUnit = new OrgUnit();
-
- orgUnit.setId( unit.getId() );
- orgUnit.setName( unit.getShortName() );
-
- orgUnit.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" )
- .build( unit.getId() ).toString() );
- orgUnit.setDownloadActivityPlanUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activitiyplan" )
- .build( unit.getId() ).toString() );
- orgUnit.setUploadFacilityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "dataSets" )
- .build( unit.getId() ).toString() );
- orgUnit.setUploadActivityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activities" )
- .build( unit.getId() ).toString() );
- orgUnit.setUpdateProgramUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "programs" )
- .build( unit.getId() ).toString() );
- orgUnit.setUpdateDataSetUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "updateDataSets" )
- .build( unit.getId() ).toString() );
- return orgUnit;
- }
-
@Required
public void setCurrentUserService( CurrentUserService currentUserService )
{
this.currentUserService = currentUserService;
}
- @Required
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
- {
- this.organisationUnitService = organisationUnitService;
- }
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-01-24 14:48:48 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-02-18 20:17:34 +0000
@@ -36,12 +36,17 @@
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.web.api.model.ActivityPlan;
import org.hisp.dhis.web.api.model.ActivityValue;
import org.hisp.dhis.web.api.model.DataSet;
@@ -49,6 +54,7 @@
import org.hisp.dhis.web.api.model.DataSetValue;
import org.hisp.dhis.web.api.model.MobileModel;
import org.hisp.dhis.web.api.model.ModelList;
+import org.hisp.dhis.web.api.model.OrgUnit;
import org.hisp.dhis.web.api.service.ActivityReportingService;
import org.hisp.dhis.web.api.service.ActivityReportingServiceImpl;
import org.hisp.dhis.web.api.service.FacilityReportingService;
@@ -58,9 +64,11 @@
@Produces( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
@Consumes( { DhisMediaType.MOBILE_SERIALIZED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
+@Path( "/orgUnits/{id}" )
public class OrgUnitResource
{
-
+ private OrganisationUnitService organisationUnitService;
+
private static Log log = LogFactory.getLog( ActivityReportingServiceImpl.class );
private static final boolean DEBUG = log.isDebugEnabled();
@@ -71,14 +79,19 @@
private FacilityReportingService facilityReportingService;
- // Set by parent resource
- private OrganisationUnit unit;
-
- public void setOrgUnit( OrganisationUnit unit )
- {
- this.unit = unit;
- }
-
+ @PathParam( "id" ) private int id;
+
+ @Context UriInfo uriInfo;
+
+ private OrganisationUnit getUnit() {
+ return organisationUnitService.getOrganisationUnit( id );
+ }
+
+ @GET
+ public OrgUnit getOrgUnit() {
+ return OrgUnitResource.getOrgUnit( getUnit(), uriInfo );
+ }
+
/**
* Get activity plan, program forms and facility forms wrapped in a
* {@link MobileModel}
@@ -92,11 +105,11 @@
MobileModel mobileModel = new MobileModel();
if ( DEBUG )
- log.debug( "Getting all resources for org unit " + unit.getName() );
+ log.debug( "Getting all resources for org unit " + getUnit().getName() );
- mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) );
- mobileModel.setPrograms( programService.getPrograms( unit, locale ) );
- mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
+ mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( getUnit(), locale ) );
+ mobileModel.setPrograms( programService.getPrograms( getUnit(), locale ) );
+ mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( getUnit(), locale ) );
return mobileModel;
}
@@ -106,9 +119,9 @@
public DataSetList checkUpdatedDataSet( DataSetList dataSetList, @HeaderParam( "accept-language" ) String locale )
{
if ( DEBUG )
- log.debug( "Checking updated datasets for org unit " + unit.getName() );
+ log.debug( "Checking updated datasets for org unit " + getUnit().getName() );
DataSetList updatedDataSetList = new DataSetList();
- List<DataSet> dataSets = facilityReportingService.getMobileDataSetsForUnit( unit, locale );
+ List<DataSet> dataSets = facilityReportingService.getMobileDataSetsForUnit( getUnit(), locale );
List<DataSet> currentDataSets = dataSetList.getCurrentDataSets();
// List<DataSet> copyCurrentDataSets = new
// ArrayList<DataSet>(currentDataSets.size());
@@ -158,7 +171,7 @@
}
if ( DEBUG )
- log.debug( "Returning updated datasets for org unit " + unit.getName() );
+ log.debug( "Returning updated datasets for org unit " + getUnit().getName() );
return updatedDataSetList;
}
@@ -170,7 +183,7 @@
@Path( "activitiyplan" )
public ActivityPlan getCurrentActivityPlan( @HeaderParam( "accept-language" ) String locale )
{
- return activityReportingService.getCurrentActivityPlan( unit, locale );
+ return activityReportingService.getCurrentActivityPlan( getUnit(), locale );
}
/**
@@ -184,7 +197,7 @@
public void saveDataSetValues( DataSetValue dataSetValue )
throws NotAllowedException
{
- facilityReportingService.saveDataSetValues( unit, dataSetValue );
+ facilityReportingService.saveDataSetValues( getUnit(), dataSetValue );
}
/**
@@ -199,7 +212,7 @@
public void saveActivityReport( ActivityValue activityValue )
throws NotAllowedException
{
- activityReportingService.saveActivityReport( unit, activityValue );
+ activityReportingService.saveActivityReport( getUnit(), activityValue );
}
@POST
@@ -207,10 +220,39 @@
public MobileModel updatePrograms( @HeaderParam( "accept-language" ) String locale, ModelList programsFromClient )
{
MobileModel model = new MobileModel();
- model.setPrograms( programService.updateProgram( programsFromClient, locale, unit ) );
+ model.setPrograms( programService.updateProgram( programsFromClient, locale, getUnit() ) );
return model;
}
+ public static OrgUnit getOrgUnit( OrganisationUnit unit, UriInfo uriInfo )
+ {
+ OrgUnit orgUnit = new OrgUnit();
+
+ orgUnit.setId( unit.getId() );
+ orgUnit.setName( unit.getShortName() );
+
+ orgUnit.setDownloadAllUrl( getOrgUnitUrlBuilder(uriInfo).path( "all" )
+ .build( unit.getId() ).toString() );
+ orgUnit.setDownloadActivityPlanUrl( getOrgUnitUrlBuilder(uriInfo).path( "activitiyplan" )
+ .build( unit.getId() ).toString() );
+ orgUnit.setUploadFacilityReportUrl( getOrgUnitUrlBuilder(uriInfo).path( "dataSets" )
+ .build( unit.getId() ).toString() );
+ orgUnit.setUploadActivityReportUrl( getOrgUnitUrlBuilder(uriInfo).path( "activities" )
+ .build( unit.getId() ).toString() );
+ orgUnit.setUpdateProgramUrl( getOrgUnitUrlBuilder(uriInfo).path( "programs" )
+ .build( unit.getId() ).toString() );
+ orgUnit.setUpdateDataSetUrl( getOrgUnitUrlBuilder(uriInfo).path( "updateDataSets" )
+ .build( unit.getId() ).toString() );
+ return orgUnit;
+ }
+
+ private static UriBuilder getOrgUnitUrlBuilder(UriInfo uriInfo)
+ {
+ return uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" );
+ }
+
+
+
@Required
public void setProgramService( IProgramService programService )
{
@@ -229,4 +271,10 @@
this.facilityReportingService = facilityReportingService;
}
+ @Required
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java 2011-02-18 20:17:34 +0000
@@ -0,0 +1,44 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.springframework.web.util.HtmlUtils;
+
+@Path( "orgUnits" )
+public class OrgUnitsResource
+{
+ private OrganisationUnitService organisationUnitService;
+
+ @GET
+ @Produces( MediaType.TEXT_HTML )
+ public String getOrgUnits()
+ {
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> \n<html>" );
+ sb.append( "<head><title>DHIS2 Web API: Org units</title></head>\n<body>\n<h1>Data value sets</h1>\n<ul>" );
+
+ for ( OrganisationUnit unit : organisationUnitService.getAllOrganisationUnits() )
+ {
+ sb.append( "<li><a href=\"" ).append( unit.getId() ).append( "/\">" );
+ sb.append( HtmlUtils.htmlEscape( unit.getName()) ).append( "</a></li>" );
+ }
+
+ sb.append( "</ul></body>\n</html>\n" );
+
+ return sb.toString();
+ }
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+
+}
=== removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc'
=== removed 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-17 08:25:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java 1970-01-01 00:00:00 +0000
@@ -1,171 +0,0 @@
-package org.hisp.dhis.web.api.rpc;
-
-import java.net.URI;
-import java.util.Set;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
-
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.importexport.datavalueset.Dxf;
-import org.hisp.dhis.importexport.datavalueset.DataValueSetService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.springframework.beans.factory.annotation.Required;
-
-@Path( "/rpc" )
-public class RPCResource
-{
-
- private DataValueSetService dataValueSetService;
-
- private DataSetService dataSetService;
-
- @Context
- UriInfo uriInfo;
-
- @POST
- @Path( "dataValueSets" )
- @Consumes( MediaType.APPLICATION_XML )
- public void storeDataValueSet( Dxf dataValueSet )
- {
- dataValueSetService.saveDataValueSet( dataValueSet );
- }
-
- @GET
- @Produces( MediaType.TEXT_HTML )
- @Path( "dataSets" )
- public String getDataValueSets()
- {
- return getDataValueSet();
- }
-
- @GET
- @Produces( MediaType.TEXT_HTML )
- public String getDataValueSet()
- {
- StringBuilder t = new StringBuilder();
- t.append( head( "Data sets available for reporting" ) );
-
- t.append( "<h2>Data sets available for reporting</h2>\n<ul>\n" );
- for ( DataSet dataSet : dataSetService.getAllDataSets() )
- {
- URI uri = uriInfo.getBaseUriBuilder().path( "rpc/dataSets/{uuid}" ).build( dataSet.getUuid() );
- t.append( "<li>" ).append( "<a href=\"" ).append( uri ).append( "\">" ).append( dataSet.getName() )
- .append( "</a></li>\n" );
- }
- xmlTemplate( t );
- t.append( tail() );
-
- return t.toString();
- }
-
- @GET
- @Path( "dataSets/{uuid}" )
- @Produces( MediaType.TEXT_HTML )
- public String getDataSet( @PathParam( "uuid" ) String uuid )
- {
-
- DataSet dataSet = dataSetService.getDataSet( uuid );
-
- if ( dataSet == null )
- {
- throw new IllegalArgumentException( "No dataset with uuid " + uuid );
- }
-
- StringBuilder t = new StringBuilder();
-
- t.append( head( "Data set " + dataSet.getName() ) );
- t.append( "<p>Uuid: " ).append( dataSet.getUuid() ).append( "<br>\n" );
- t.append( "Period type: " ).append( dataSet.getPeriodType().getName() ).append( " - " )
- .append( dataSet.getPeriodType().getIsoFormat() );
- t.append( "</p>\n" );
-
- t.append( "<h2>Org units reporting data set</h2>\n<ul>" );
- for ( OrganisationUnit unit : dataSet.getOrganisationUnits() )
- {
- t.append( "<li><b>" ).append( unit.getName() ).append( "</b> - " ).append( unit.getUuid() )
- .append( "</li>" );
- }
- t.append( "</ul>\n" );
-
- t.append( "<h2>Data elements in data set</h2>\n<ul>" );
- for ( DataElement element : dataSet.getDataElements() )
- {
- t.append( "<li><b>" ).append( element.getName() ).append( "</b> (" ).append( element.getType() )
- .append( ") - " ).append( element.getUuid() );
-
- Set<DataElementCategoryOptionCombo> optionCombos = element.getCategoryCombo().getOptionCombos();
- if ( optionCombos.size() > 1 )
- {
- t.append( "<br>CategoryOptionCombos\n<ul>\n" );
- for ( DataElementCategoryOptionCombo optionCombo : optionCombos )
- {
- t.append( "<li><b>" ).append( optionCombo.getName() ).append( "</b> - " )
- .append( optionCombo.getUuid() ).append( "</li>" );
- }
- t.append( "</ul>\n" );
- }
- t.append( "</li>\n" );
- }
- t.append( "</ul>" );
- xmlTemplate( t );
- t.append( tail() );
-
- return t.toString();
- }
-
- private String head( String title )
- {
- return "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"> \n<html><head><title>"
- + title + "</title></head>\n" + "<body>\n<h1>" + title + "</h1>\n";
- }
-
- private void xmlTemplate( StringBuilder t )
- {
- t.append( "<h2>Xml template</h2>\n" );
-
- URI uri = uriInfo.getBaseUriBuilder().path( "rpc/dataValueSets" ).build();
- t.append( "<p>Post according to the following template to " );
- t.append( "<a href=\"" ).append( uri ).append( "\">" ).append( uri ).append( "</a>:</p>" );
-
- t.append( "<pre>" );
- t.append( "<dxf xmlns=\"http://dhis2.org/schema/dxf/x.x\">\n <dataValues>\n <dataValue dataSet=\"uuid - only required if data element is registered to multiple data sets\"\n period=\"201102\"\n orgUnit=\"uuid\"\n storedBy=\"string\"\n dataElement=\"uuid\"\n value=\"value\" />\n </dataValues>\n" );
- t.append( " <dataValueSets>\n <dataValueSet\n dataSet=\"uuid\"\n orgUnit=\"uuid\"\n period=\"period in iso format\"\n complete=\"date (yyyymmdd)\"/>\n </dataValueSets>\n</dxf>" );
- t.append( "</pre>" );
-
- t.append( "<p>Old format</p><pre>" ).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 <dataValue dataElement=\"data element UUID\" categoryOptionCombo=\"UUID, only specify if used\" storedBy=\"string\" value=\"value\"/>" );
- t.append( "\n</dataValueSet>" );
- t.append( "</pre>" );
- }
-
- private String tail()
- {
- return "</body>\n</html>\n";
- }
-
- @Required
- public void setDataValueSetService( DataValueSetService dataValueSetService )
- {
- this.dataValueSetService = dataValueSetService;
- }
-
- @Required
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-02-15 12:55:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-02-18 20:17:34 +0000
@@ -5,17 +5,33 @@
<!-- Resources -->
+ <bean id="org.hisp.dhis.web.api.resources.ApiResource" class="org.hisp.dhis.web.api.resources.ApiResource" />
+
+ <bean id="org.hisp.dhis.web.api.resources.DataSetResource" class="org.hisp.dhis.web.api.resources.DataSetResource"
+ scope="prototype">
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.web.api.resources.DataValueSetResource" class="org.hisp.dhis.web.api.resources.DataValueSetResource">
+ <property name="dataValueSetService" ref="org.hisp.dhis.importexport.dxf2.service.DataValueSetService" />
+ </bean>
+
<bean id="org.hisp.dhis.web.api.resources.MobileResource" class="org.hisp.dhis.web.api.resources.MobileResource"
scope="prototype">
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.web.api.resources.OrgUnitsResource" class="org.hisp.dhis.web.api.resources.OrgUnitsResource"
+ scope="prototype">
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</bean>
-
+
<bean id="org.hisp.dhis.web.api.resources.OrgUnitResource" class="org.hisp.dhis.web.api.resources.OrgUnitResource"
scope="prototype">
<property name="facilityReportingService" ref="org.hisp.dhis.web.api.service.FacilityReportingService" />
<property name="activityReportingService" ref="org.hisp.dhis.web.api.service.ActivityReportingService" />
<property name="programService" ref="org.hisp.dhis.web.api.service.IProgramService" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</bean>
<!-- Services -->
@@ -80,11 +96,6 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
-
- <bean id="org.hisp.dhis.web.api.rpc.RPCResource" class="org.hisp.dhis.web.api.rpc.RPCResource">
- <property name="dataValueSetService" ref="org.hisp.dhis.importexport.datavalueset.DataValueSetService" />
- <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
- </bean>
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2010-12-02 10:53:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2011-02-18 20:17:34 +0000
@@ -85,10 +85,10 @@
<param-value>
com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
-<!-- <init-param> -->
-<!-- <param-name>com.sun.jersey.config.feature.Trace</param-name>-->
-<!-- <param-value>true</param-value>-->
-<!-- </init-param>-->
+ <init-param>
+ <param-name>com.sun.jersey.config.feature.Trace</param-name>
+ <param-value>true</param-value>
+ </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
=== modified file 'dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml'
--- dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-02-18 20:17:34 +0000
@@ -67,14 +67,6 @@
<servlet>
<servlet-name>web-api</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
- <init-param>
- <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
- <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
- </init-param>
- <init-param>
- <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
- <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
- </init-param>
<load-on-startup>1</load-on-startup>
</servlet>