=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2012-03-28 18:27:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2012-03-29 16:45:18 +0000 @@ -1,9 +1,5 @@ package org.hisp.dhis.common; -import java.util.Map; - -import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; - /* * Copyright (c) 2004-2005, University of Oslo * All rights reserved. @@ -31,6 +27,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Map; + +import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; + /** * @author Lars Helge Overland */ @@ -46,6 +46,8 @@ Map getIdMap( Class clazz, IdentifiableProperty property ); + T getObject( Class clazz, IdentifiableProperty property, String id ); + IdentifiableObject getObject( String uid, String simpleClassName ); IdentifiableObject getObject( int id, String simpleClassName ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationService.java 2012-03-29 16:45:18 +0000 @@ -47,6 +47,13 @@ * @param registration the CompleteDataSetRegistration to save. */ void saveCompleteDataSetRegistration( CompleteDataSetRegistration registration ); + + /** + * Updates a CompleteDataSetRegistration. + * + * @param registration the CompleteDataSetRegistration to update. + */ + void updateCompleteDataSetRegistration( CompleteDataSetRegistration registration ); /** * Retrieves the CompleteDataSetRegistration for the given DataSet, Period === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStore.java 2012-03-29 16:45:18 +0000 @@ -49,6 +49,13 @@ void saveCompleteDataSetRegistration( CompleteDataSetRegistration registration ); /** + * Updates a CompleteDataSetRegistration. + * + * @param registration the CompleteDataSetRegistration to update. + */ + void updateCompleteDataSetRegistration( CompleteDataSetRegistration registration ); + + /** * Retrieves the CompleteDataSetRegistration for the given DataSet, Period * and Source. * === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-03-28 18:27:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-03-29 16:45:18 +0000 @@ -303,16 +303,21 @@ */ public static Period getPeriodFromIsoString( String isoPeriod ) { - PeriodType periodType = getPeriodTypeFromIsoString( isoPeriod ); + if ( isoPeriod != null ) + { + PeriodType periodType = getPeriodTypeFromIsoString( isoPeriod ); + + try + { + return periodType != null ? periodType.createPeriod() : null; + } + catch ( Exception ex ) + { + // Do nothing and return null + } + } - try - { - return periodType != null ? periodType.createPeriod() : null; - } - catch ( Exception ex ) - { - return null; - } + return null; } /** === removed directory 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue' === added directory 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue' === renamed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java' => 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java' === removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValues.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValues.java 2012-03-28 18:27:56 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValues.java 1970-01-01 00:00:00 +0000 @@ -1,57 +0,0 @@ -package org.hisp.dhis.dxf2.datavalue; - -/* - * 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.ArrayList; -import java.util.List; - -import org.hisp.dhis.common.Dxf2Namespace; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -@JacksonXmlRootElement( localName = "dxf2", namespace = Dxf2Namespace.NAMESPACE ) -public class DataValues -{ - private List dataValues = new ArrayList(); - - @JsonProperty - @JacksonXmlElementWrapper( localName = "dataValues", namespace = Dxf2Namespace.NAMESPACE ) - @JacksonXmlProperty( localName = "dataValue", namespace = Dxf2Namespace.NAMESPACE ) - public List getDataValues() - { - return dataValues; - } - - public void setDataValues( List dataValues ) - { - this.dataValues = dataValues; - } -} === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2012-03-28 18:46:31 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2012-03-29 16:45:18 +0000 @@ -34,45 +34,28 @@ import org.hisp.dhis.dxf2.datavalue.DataValue; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @JacksonXmlRootElement( localName = "dataValueSet", namespace = Dxf2Namespace.NAMESPACE ) public class DataValueSet -{ +{ public enum IdentificationStrategy { INTERNAL, UID, CODE }; - /** - * A default strategy to use. - */ public static final IdentificationStrategy DEFAULT_STRATEGY = IdentificationStrategy.UID; private String dataSet; + private String completeDate; + + private String period; + private String orgUnit; - private String period; - - private String completeDate; - - private IdentificationStrategy idScheme; - private List dataValues = new ArrayList(); - @JsonProperty - @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE ) - public IdentificationStrategy getIdScheme() - { - return (idScheme != null) ? idScheme : DEFAULT_STRATEGY; - } - - public void setIdScheme( IdentificationStrategy idScheme ) - { - this.idScheme = idScheme; - } - - @JsonProperty() //TODO make required + @JsonProperty() @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE ) public String getDataSet() { @@ -86,18 +69,6 @@ @JsonProperty() @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE ) - public String getOrgUnit() - { - return orgUnit; - } - - public void setOrgUnit( String orgUnit ) - { - this.orgUnit = orgUnit; - } - - @JsonProperty() - @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE ) public String getPeriod() { return period; @@ -120,9 +91,20 @@ this.completeDate = completeDate; } + @JsonProperty() + @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE ) + public String getOrgUnit() + { + return orgUnit; + } + + public void setOrgUnit( String orgUnit ) + { + this.orgUnit = orgUnit; + } + @JsonProperty - @JacksonXmlElementWrapper( localName = "dataValues", namespace = Dxf2Namespace.NAMESPACE ) - @JacksonXmlProperty( localName = "dataValue", namespace = Dxf2Namespace.NAMESPACE ) + @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public List getDataValues() { return dataValues; === removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2012-03-28 18:28:57 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 1970-01-01 00:00:00 +0000 @@ -1,33 +0,0 @@ -package org.hisp.dhis.dxf2.datavalueset; - -/* - * Copyright (c) 2004-2005, 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 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. - */ - -public interface DataValueSetService -{ - void saveDataValueSet( DataValueSet dataValueSet ); -} === renamed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java' => 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValueService.java 2012-03-29 09:59:05 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2012-03-29 16:45:18 +0000 @@ -1,4 +1,4 @@ -package org.hisp.dhis.dxf2.datavalue; +package org.hisp.dhis.dxf2.datavalueset; /* * Copyright (c) 2011, University of Oslo @@ -28,10 +28,13 @@ */ import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; +import org.hisp.dhis.dxf2.datavalueset.DataValueSet; import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.hisp.dhis.importexport.ImportStrategy; -public interface DataValueService +public interface DataValueSetService { - ImportSummary saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy ); + ImportSummary saveDataValueSet( DataValueSet dataValueSet ); + + ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy ); } === removed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2012-03-28 18:46:31 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 1970-01-01 00:00:00 +0000 @@ -1,421 +0,0 @@ -package org.hisp.dhis.dxf2.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.HashSet; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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.dxf2.datavalueset.DataValueSet.IdentificationStrategy; -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.hisp.dhis.user.CurrentUserService; -import org.springframework.transaction.annotation.Transactional; - -public class DefaultDataValueSetService - implements DataValueSetService -{ - private static final Log log = LogFactory.getLog( DataValueSetService.class ); - - private OrganisationUnitService organisationUnitService; - - private DataSetService dataSetService; - - private DataElementCategoryService categoryService; - - private DataElementService dataElementService; - - private DataValueService dataValueService; - - private CompleteDataSetRegistrationService registrationService; - - private CurrentUserService currentUserService; - - /** - * Save a dataValueSet. - *

- * Handles the content in the following way - *

    - *
  • if data set is not specified, will resolve it through data elements - * if not ambiguous. - *
  • optionCombo defaults to 'default' if not specified - *
  • storedBy defaults to currently logged in user's name - *
  • if value is empty not present -> delete value - *
- *
    - * Validates the following: - *

    - * First checks that: - *

      - *
    • dataSet exists (tries to resolve it through the data elements if not - * specified) - *
    • orgUnit exists - *
    • orgunit reports dataSet - *
    • period is a valid period - *
    • the dataValueSet is not registered as complete or that if it is a - * complete date is present - *
    • if complete date is empty string - delete completion - *
    • if complete date present checks validity - *
    - * For all dataValues check that: - *
      - *
    • dataElement exists and is in dataSet - *
    • optionCombo exists and is in dataElement - *
    - * What isn't checked yet: - *
      - *
    • The value is valid! - *
    • There isn't duplicated value entries (will throw Constraint - * exception) - *
    • If multiple data sets are possible, evaluate if they are incompatible - * (complete, locking and possibly period) - *
    - * Concerns: - *
      - *
    • deletion through sending "empty string" value dependent on semantics - * of add/update in data value store - *
    • completed semantics: can't uncomplete but can complete and - * "recomplete" - * - * @param dataValueSet - * @throws IllegalArgumentException if there are any inconsistencies - */ - @Transactional - public void saveDataValueSet( DataValueSet dataValueSet ) - { - Date timestamp = new Date(); - - IdentificationStrategy idStrategy = dataValueSet.getIdScheme(); - - if ( idStrategy != DataValueSet.DEFAULT_STRATEGY ) - { - throw new IllegalArgumentException( "Only UID id strategy supported currently" ); - } - - DataSet dataSet = getDataSet( dataValueSet ); - - OrganisationUnit unit = getOrgUnit( dataValueSet.getOrgUnit() ); - - if ( !dataSet.getSources().contains( unit ) ) - { - throw new IllegalArgumentException( "Organisation unit with ID " + unit.getUid() - + " does not report data set with ID " + dataSet.getUid() ); - } - - Period period = getPeriod( dataValueSet.getPeriod(), dataSet.getPeriodType() ); - - handleComplete( dataValueSet, dataSet, unit, period ); - - for ( org.hisp.dhis.dxf2.datavalue.DataValue dxfValue : dataValueSet.getDataValues() ) - { - saveDataValue( timestamp, dataSet, unit, period, dxfValue ); - } - - log( dataValueSet, unit, dataSet ); - } - - private void log( DataValueSet dataValueSet, OrganisationUnit unit, DataSet dataSet ) - { - String message = "Saved data value set for " + dataSet.getName() + ", " + unit.getName() + ", " - + dataValueSet.getPeriod() + " - data values received: "; - - for ( org.hisp.dhis.dxf2.datavalue.DataValue value : dataValueSet.getDataValues() ) - { - message += value.getDataElement() + " = " + value.getValue() + ", "; - } - - log.info( message.substring( 0, message.length() - 3 ) ); - } - - private DataSet getDataSet( DataValueSet dataValueSet ) - { - DataSet dataSet = null; - - String uid = dataValueSet.getDataSet(); - - if ( uid != null ) - { - dataSet = dataSetService.getDataSet( uid ); - - if ( dataSet == null ) - { - throw new IllegalArgumentException( "Data set with ID " + uid + " does not exist" ); - } - } - else - { - dataSet = resolveDataSet( dataValueSet ); - } - - return dataSet; - } - - private DataSet resolveDataSet( DataValueSet dataValueSet ) - { - //TODO make data set required - - if ( dataValueSet.getDataValues() == null ) - { - throw new IllegalArgumentException( "Data value set does not specify a data set and does not contain data values" ); - } - - Set potentialDataSets = new HashSet(); - - for ( org.hisp.dhis.dxf2.datavalue.DataValue value : dataValueSet.getDataValues() ) - { - DataElement dataElement = getDataElement( value.getDataElement() ); - Set dataSets = dataElement.getDataSets(); - - if ( dataSets == null || dataSets.isEmpty() ) - { - throw new IllegalArgumentException( "Data element " + dataElement.getUid() + " is not in a data set" ); - } - else if ( dataSets.size() == 1 ) - { - return dataSets.iterator().next(); - } - else - { - potentialDataSets.addAll( dataSets ); - } - } - - String message = "Ambiguous which of these data set the data values belong to: "; - - for ( DataSet ds : potentialDataSets ) - { - message += ds.getUid() + ", "; - } - - message.substring( 0, message.length() - 2 ); - - throw new IllegalArgumentException( message ); - } - - private void saveDataValue( Date timestamp, DataSet dataSet, OrganisationUnit unit, Period period, - org.hisp.dhis.dxf2.datavalue.DataValue dxfValue ) - { - DataElement dataElement = getDataElement( dxfValue.getDataElement() ); - - if ( !dataSet.getDataElements().contains( dataElement ) ) - { - throw new IllegalArgumentException( "Data element " + dataElement.getUid() + " is not in data set " - + dataSet.getUid() ); - } - - DataElementCategoryOptionCombo combo = getOptionCombo( dxfValue.getCategoryOptionCombo(), dataElement ); - - DataValue dv = dataValueService.getDataValue( unit, dataElement, period, combo ); - - String value = dxfValue.getValue(); - - String storedBy = currentUserService.getCurrentUsername(); - - if ( dv == null ) - { - dv = new DataValue( dataElement, period, unit, value, storedBy, timestamp, null, combo ); - dataValueService.addDataValue( dv ); - } - else - { - dv.setValue( value ); - dv.setTimestamp( timestamp ); - dv.setStoredBy( storedBy ); - dataValueService.updateDataValue( dv ); - } - } - - private void handleComplete( DataValueSet dataValueSet, DataSet dataSet, OrganisationUnit unit, Period period ) - { - CompleteDataSetRegistration alreadyComplete = registrationService.getCompleteDataSetRegistration( dataSet, - period, unit ); - - String completeDateString = dataValueSet.getCompleteDate(); - - if ( alreadyComplete != null && completeDateString == null ) - { - throw new IllegalArgumentException( "Data value set is complete, include a new complete date if you want to recomplete" ); - } - - if ( alreadyComplete != null ) - { - registrationService.deleteCompleteDataSetRegistration( alreadyComplete ); - } - - CompleteDataSetRegistration complete = null; - - if ( completeDateString != null && !completeDateString.trim().isEmpty() ) - { - complete = getComplete( dataSet, unit, period, completeDateString, complete ); - } - - if ( complete != null ) - { - registrationService.saveCompleteDataSetRegistration( complete ); - } - } - - 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, - currentUserService.getCurrentUsername() ); - } - 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 a valid period of type " - + periodType.getName() ); - } - - return period; - } - - private OrganisationUnit getOrgUnit( String uid ) - { - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( uid ); - - if ( unit == null ) - { - throw new IllegalArgumentException( "Org unit with ID " + uid + " does not exist" ); - } - - return unit; - } - - private DataElement getDataElement( String uid ) - { - DataElement dataElement = dataElementService.getDataElement( uid ); - - if ( dataElement == null ) - { - throw new IllegalArgumentException( "Data element with ID " + uid + " does not exist" ); - } - - return dataElement; - } - - private DataElementCategoryOptionCombo getOptionCombo( String uid, DataElement dataElement ) - { - DataElementCategoryOptionCombo combo; - - if ( uid == null ) - { - combo = categoryService.getDefaultDataElementCategoryOptionCombo(); - } - else - { - combo = categoryService.getDataElementCategoryOptionCombo( uid ); - } - - if ( combo == null ) - { - throw new IllegalArgumentException( "Data element category option combo with ID " + uid - + " does not exist" ); - } - - if ( !dataElement.getCategoryCombo().getOptionCombos().contains( combo ) ) - { - throw new IllegalArgumentException( "Data element category option combo with ID " + combo.getUid() - + " is not in data element " + dataElement.getUid() ); - } - return combo; - } - - 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; - } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - public void setRegistrationService( CompleteDataSetRegistrationService registrationService ) - { - this.registrationService = registrationService; - } - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } -} === renamed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java' => 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DefaultDataValueService.java 2012-03-29 12:02:12 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2012-03-29 16:45:18 +0000 @@ -1,4 +1,4 @@ -package org.hisp.dhis.dxf2.datavalue; +package org.hisp.dhis.dxf2.datavalueset; /* * Copyright (c) 2011, University of Oslo @@ -27,9 +27,12 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.importexport.ImportStrategy.NEW; +import static org.hisp.dhis.importexport.ImportStrategy.NEW_AND_UPDATES; +import static org.hisp.dhis.importexport.ImportStrategy.UPDATES; import static org.hisp.dhis.system.util.DateUtils.getDefaultDate; -import static org.hisp.dhis.importexport.ImportStrategy.*; +import java.util.Date; import java.util.Map; import org.amplecode.quick.BatchHandler; @@ -39,6 +42,9 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataset.CompleteDataSetRegistration; +import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; +import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.dxf2.importsummary.ImportConflict; import org.hisp.dhis.dxf2.importsummary.ImportCount; @@ -49,11 +55,13 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.system.util.DateUtils; +import org.hisp.dhis.user.CurrentUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -public class DefaultDataValueService - implements DataValueService +public class DefaultDataValueSetService + implements DataValueSetService { @Autowired private IdentifiableObjectManager identifiableObjectManager; @@ -67,8 +75,20 @@ @Autowired private BatchHandlerFactory batchHandlerFactory; - @Transactional - public ImportSummary saveDataValues( DataValues dataValues, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy ) + @Autowired + private CompleteDataSetRegistrationService registrationService; + + @Autowired + private CurrentUserService currentUserService; + + @Transactional + public ImportSummary saveDataValueSet( DataValueSet dataValueSet ) + { + return saveDataValueSet( dataValueSet, IdentifiableProperty.UID, false, ImportStrategy.NEW_AND_UPDATES ); + } + + @Transactional + public ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty idScheme, boolean dryRun, ImportStrategy strategy ) { ImportSummary summary = new ImportSummary(); @@ -76,6 +96,17 @@ Map orgUnitMap = identifiableObjectManager.getIdMap( OrganisationUnit.class, idScheme ); Map categoryOptionComboMap = identifiableObjectManager.getIdMap( DataElementCategoryOptionCombo.class, IdentifiableProperty.UID ); + DataSet dataSet = dataValueSet.getDataSet() != null ? identifiableObjectManager.getObject( DataSet.class, idScheme, dataValueSet.getDataSet() ) : null; + Date completeDate = getDefaultDate( dataValueSet.getCompleteDate() ); + + Period period = PeriodType.getPeriodFromIsoString( dataValueSet.getPeriod() ); + OrganisationUnit orgUnit = dataValueSet.getOrgUnit() != null ? identifiableObjectManager.getObject( OrganisationUnit.class, idScheme, dataValueSet.getOrgUnit() ) : null; + + if ( dataSet != null ) + { + handleComplete( dataSet, completeDate, orgUnit, period, summary ); + } + DataElementCategoryOptionCombo fallbackCategoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo(); BatchHandler batchHandler = batchHandlerFactory.createBatchHandler( DataValueBatchHandler.class ).init(); @@ -84,22 +115,28 @@ int updateCount = 0; int totalCount = 0; - for ( org.hisp.dhis.dxf2.datavalue.DataValue dataValue : dataValues.getDataValues() ) + for ( org.hisp.dhis.dxf2.datavalue.DataValue dataValue : dataValueSet.getDataValues() ) { DataValue internalValue = new DataValue(); totalCount++; DataElement dataElement = dataElementMap.get( dataValue.getDataElement() ); - OrganisationUnit orgUnit = orgUnitMap.get( dataValue.getOrgUnit() ); DataElementCategoryOptionCombo categoryOptionCombo = categoryOptionComboMap.get( dataValue.getCategoryOptionCombo() ); - Period period = PeriodType.getPeriodFromIsoString( dataValue.getPeriod() ); + period = period != null ? period : PeriodType.getPeriodFromIsoString( dataValue.getPeriod() ); + orgUnit = orgUnit != null ? orgUnit : orgUnitMap.get( dataValue.getOrgUnit() ); if ( dataElement == null ) { summary.getNoneExistingIdentifiers().add( new ImportConflict( DataElement.class.getSimpleName(), dataValue.getDataElement() ) ); continue; } + + if ( period == null ) + { + summary.getNoneExistingIdentifiers().add( new ImportConflict( Period.class.getSimpleName(), dataValue.getPeriod() ) ); + continue; + } if ( orgUnit == null ) { @@ -107,12 +144,6 @@ continue; } - if ( period == null ) - { - summary.getNoneExistingIdentifiers().add( new ImportConflict( Period.class.getSimpleName(), dataValue.getPeriod() ) ); - continue; - } - if ( categoryOptionCombo == null ) { categoryOptionCombo = fallbackCategoryOptionCombo; @@ -162,4 +193,45 @@ return summary; } + + private void handleComplete( DataSet dataSet, Date completeDate, OrganisationUnit orgUnit, Period period, ImportSummary summary ) + { + if ( orgUnit == null ) + { + throw new IllegalArgumentException( "Org unit must be provided on data value set in order to complete data set" ); + } + + if ( period == null ) + { + throw new IllegalArgumentException( "Period must be provided on data value set in order to complete data set" ); + } + + CompleteDataSetRegistration complete = registrationService.getCompleteDataSetRegistration( dataSet, period, orgUnit ); + + String username = currentUserService.getCurrentUsername(); + + if ( completeDate == null && complete != null ) + { + throw new IllegalArgumentException( "Data value set is complete - include a new complete date if you want to update it" ); + } + + if ( completeDate != null ) + { + if ( complete != null ) + { + complete.setStoredBy( username ); + complete.setDate( completeDate ); + + registrationService.updateCompleteDataSetRegistration( complete ); + } + else + { + CompleteDataSetRegistration registration = new CompleteDataSetRegistration( dataSet, period, orgUnit, completeDate, username ); + + registrationService.saveCompleteDataSetRegistration( registration ); + } + + summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) ); + } + } } === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2012-03-29 09:59:05 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/importsummary/ImportSummary.java 2012-03-29 16:45:18 +0000 @@ -42,13 +42,15 @@ private List noneExistingIdentifiers = new ArrayList(); + private String dataSetComplete; + public void increaseImportCount( Class clazz ) { } @JsonProperty - @JacksonXmlElementWrapper( localName = "importCounts" ) - @JacksonXmlProperty( localName = "count" ) + @JacksonXmlElementWrapper + @JacksonXmlProperty public List getCounts() { return counts; @@ -60,8 +62,8 @@ } @JsonProperty - @JacksonXmlElementWrapper( localName = "noneExistingIdentifiers" ) - @JacksonXmlProperty( localName = "conflict" ) + @JacksonXmlElementWrapper + @JacksonXmlProperty public List getNoneExistingIdentifiers() { return noneExistingIdentifiers; @@ -71,4 +73,16 @@ { this.noneExistingIdentifiers = noneExistingIdentifiers; } + + @JsonProperty + @JacksonXmlProperty + public String getDataSetComplete() + { + return dataSetComplete; + } + + public void setDataSetComplete( String dataSetComplete ) + { + this.dataSetComplete = dataSetComplete; + } } === modified file 'dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2012-03-28 18:27:56 +0000 +++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml 2012-03-29 16:45:18 +0000 @@ -2,16 +2,6 @@ - - - - - - - - - - - + === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-03-28 18:27:56 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-03-29 16:45:18 +0000 @@ -118,6 +118,31 @@ return map; } + + @SuppressWarnings("unchecked") + public T getObject( Class clazz, IdentifiableProperty property, String id ) + { + GenericIdentifiableObjectStore store = (GenericIdentifiableObjectStore) objectStoreMap.get( clazz ); + + if ( IdentifiableProperty.ID.equals( property ) ) + { + return store.get( Integer.valueOf( id ) ); + } + else if ( IdentifiableProperty.UID.equals( property ) ) + { + return store.getByUid( id ); + } + else if ( IdentifiableProperty.CODE.equals( property ) ) + { + return store.getByCode( id ); + } + else if ( IdentifiableProperty.NAME.equals( property ) ) + { + return store.getByName( id ); + } + + throw new IllegalArgumentException( String.valueOf( property ) ); + } public IdentifiableObject getObject( String uid, String simpleClassName ) { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultCompleteDataSetRegistrationService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultCompleteDataSetRegistrationService.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultCompleteDataSetRegistrationService.java 2012-03-29 16:45:18 +0000 @@ -58,6 +58,12 @@ { completeDataSetRegistrationStore.saveCompleteDataSetRegistration( registration ); } + + public void updateCompleteDataSetRegistration( CompleteDataSetRegistration registration ) + { + completeDataSetRegistrationStore.updateCompleteDataSetRegistration( registration ); + } + public void deleteCompleteDataSetRegistration( CompleteDataSetRegistration registration ) { completeDataSetRegistrationStore.deleteCompleteDataSetRegistration( registration ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java 2012-03-29 16:45:18 +0000 @@ -92,6 +92,13 @@ sessionFactory.getCurrentSession().save( registration ); } + public void updateCompleteDataSetRegistration( CompleteDataSetRegistration registration ) + { + registration.setPeriod( reloadPeriod( registration.getPeriod() ) ); + + sessionFactory.getCurrentSession().update( registration ); + } + public CompleteDataSetRegistration getCompleteDataSetRegistration( DataSet dataSet, Period period, OrganisationUnit source ) { period = reloadPeriod( period ); === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 2012-03-29 12:02:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueController.java 1970-01-01 00:00:00 +0000 @@ -1,85 +0,0 @@ -package org.hisp.dhis.api.controller; - -/* - * 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.io.IOException; -import java.io.InputStream; - -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; -import org.hisp.dhis.dxf2.datavalue.DataValueService; -import org.hisp.dhis.dxf2.datavalue.DataValues; -import org.hisp.dhis.dxf2.importsummary.ImportSummary; -import org.hisp.dhis.dxf2.utils.JacksonUtils; -import org.hisp.dhis.importexport.ImportStrategy; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; - -import static org.hisp.dhis.api.utils.ContextUtils.*; - -@Controller -@RequestMapping( value = DataValueController.RESOURCE_PATH ) -public class DataValueController -{ - public static final String RESOURCE_PATH = "/dataValues"; - - private static final Log log = LogFactory.getLog( DataValueController.class ); - - @Autowired - private DataValueService dataValueService; - - @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml"} ) - @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" ) - public void postDataValues( @RequestParam(required=false, defaultValue="UID") String idScheme, - @RequestParam(required=false) boolean dryRun, - @RequestParam(required=false, defaultValue="NEW_AND_UPDATES") String strategy, - HttpServletResponse response, - InputStream input, - Model model ) throws IOException - { - IdentifiableProperty _idScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() ); - ImportStrategy _strategy = ImportStrategy.valueOf( strategy.toUpperCase() ); - - DataValues dataValues = JacksonUtils.fromXml( input, DataValues.class ); - - ImportSummary summary = dataValueService.saveDataValues( dataValues, _idScheme, dryRun, _strategy ); - - log.info( "Data values saved using id scheme: " + _idScheme + ", dry run: " + dryRun + ", strategy: " + _strategy ); - - response.setContentType( CONTENT_TYPE_XML ); - JacksonUtils.toXml( response.getOutputStream(), summary ); - } -} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-03-28 18:46:31 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java 2012-03-29 16:45:18 +0000 @@ -27,6 +27,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_XML; + import java.io.IOException; import java.io.InputStream; @@ -34,11 +36,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; +import org.hisp.dhis.dxf2.datavalue.DataValue; import org.hisp.dhis.dxf2.datavalueset.DataValueSet; import org.hisp.dhis.dxf2.datavalueset.DataValueSetService; import org.hisp.dhis.dxf2.datavalueset.DataValueSets; +import org.hisp.dhis.dxf2.importsummary.ImportSummary; import org.hisp.dhis.dxf2.utils.JacksonUtils; +import org.hisp.dhis.importexport.ImportStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; @@ -46,6 +51,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping( value = DataValueSetController.RESOURCE_PATH ) @@ -71,17 +77,24 @@ @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml"} ) @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" ) - public void postDataValueSet( HttpServletResponse response, InputStream input ) - throws IOException + public void postDataValueSet( @RequestParam(required=false, defaultValue="UID") String idScheme, + @RequestParam(required=false) boolean dryRun, + @RequestParam(required=false, defaultValue="NEW_AND_UPDATES") String strategy, + HttpServletResponse response, + InputStream input, + Model model ) throws IOException { + IdentifiableProperty _idScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() ); + ImportStrategy _strategy = ImportStrategy.valueOf( strategy.toUpperCase() ); + DataValueSet dataValueSet = JacksonUtils.fromXml( input, DataValueSet.class ); - dataValueSetService.saveDataValueSet( dataValueSet ); - - log.debug( "Saved data value set for data set: " + dataValueSet.getDataSet() + - ", org unit: " + dataValueSet.getOrgUnit() + ", period: " + dataValueSet.getPeriod() ); - - ContextUtils.okResponse( response, "Saved data value set succesfully" ); + ImportSummary summary = dataValueSetService.saveDataValueSet( dataValueSet, _idScheme, dryRun, _strategy ); + + log.info( "Data values saved using id scheme: " + _idScheme + ", dry run: " + dryRun + ", strategy: " + _strategy ); + + response.setContentType( CONTENT_TYPE_XML ); + JacksonUtils.toXml( response.getOutputStream(), summary ); } @ExceptionHandler( IllegalArgumentException.class ) @@ -90,4 +103,30 @@ { response.sendError( HttpServletResponse.SC_CONFLICT, ex.getMessage() ); } + + @RequestMapping( value = "/test", method = RequestMethod.GET ) + public String getDataValueSetTest( Model model ) throws Exception + { + DataValueSets dataValueSets = new DataValueSets(); + + DataValue v1 = new DataValue(); + v1.setDataElement( "de" ); + v1.setValue( "va" ); + + DataValue v2 = new DataValue(); + v2.setDataElement( "de" ); + v2.setValue( "va" ); + + DataValueSet d = new DataValueSet(); + d.setDataSet( "ds" ); + d.setOrgUnit( "ou" ); + d.setPeriod( "pe" ); + d.getDataValues().add( v1 ); + d.getDataValues().add( v2 ); + dataValueSets.getDataValueSets().add( d ); + + model.addAttribute( "model", dataValueSets ); + + return "dataValueSets"; + } }