=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-05-17 14:53:28 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-05-18 06:07:28 +0000 @@ -183,7 +183,8 @@ ImportSummary importSummary = new ImportSummary(); importSummary.setStatus( ImportStatus.SUCCESS ); - ProgramStageInstance programStageInstance = saveExecutionDate( program, organisationUnit, executionDate, event.getCompleted() ); + ProgramStageInstance programStageInstance = saveExecutionDate( program, organisationUnit, executionDate, + event.getCompleted(), event.getCoordinate() ); String storedBy = event.getStoredBy(); @@ -243,7 +244,8 @@ return new ImportSummary(); } - private ProgramStageInstance saveExecutionDate( Program program, OrganisationUnit organisationUnit, Date date, Boolean completed ) + private ProgramStageInstance saveExecutionDate( Program program, OrganisationUnit organisationUnit, Date date, Boolean completed, + Coordinate coordinate ) { ProgramStage programStage = program.getProgramStages().iterator().next(); ProgramInstance programInstance = programInstanceService.getProgramInstances( program ).iterator().next(); @@ -255,6 +257,18 @@ programStageInstance.setExecutionDate( date ); programStageInstance.setOrganisationUnit( organisationUnit ); + if ( programStage.getCaptureCoordinates() ) + { + if ( coordinate.isValid() ) + { + programStageInstance.setCoordinates( coordinate.getCoordinateString() ); + } + else + { + programStageInstance.setCoordinates( null ); + } + } + if ( completed != null ) { programStageInstance.setCompleted( completed ); === added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Coordinate.java 2013-05-18 06:07:28 +0000 @@ -0,0 +1,98 @@ +package org.hisp.dhis.dxf2.event; + +/* + * Copyright (c) 2004-2013, 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 com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.system.util.ValidationUtils; + +/** + * @author Morten Olav Hansen + */ +@JacksonXmlRootElement( localName = "coordinate", namespace = DxfNamespaces.DXF_2_0 ) +public class Coordinate +{ + private Double latitude; + + private Double longitude; + + public Coordinate() + { + } + + public Coordinate( Double latitude, Double longitude ) + { + this.latitude = latitude; + this.longitude = longitude; + } + + @JsonProperty( required = true ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true ) + public Double getLatitude() + { + return latitude; + } + + public void setLatitude( Double latitude ) + { + this.latitude = latitude; + } + + @JsonProperty( required = true ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0, isAttribute = true ) + public Double getLongitude() + { + return longitude; + } + + public void setLongitude( Double longitude ) + { + this.longitude = longitude; + } + + public boolean isValid() + { + return ValidationUtils.coordinateIsValid( getCoordinateString() ); + } + + public String getCoordinateString() + { + return "[" + longitude + "," + latitude + "]"; + } + + @Override + public String toString() + { + return "Coordinate{" + + "latitude=" + latitude + + ", longitude=" + longitude + + '}'; + } +} === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java 2013-05-17 03:29:07 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/event/Event.java 2013-05-18 06:07:28 +0000 @@ -56,6 +56,8 @@ private String storedBy; + private Coordinate coordinate; + private List dataValues = new ArrayList(); public Event() @@ -147,6 +149,18 @@ } @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public Coordinate getCoordinate() + { + return coordinate; + } + + public void setCoordinate( Coordinate coordinate ) + { + this.coordinate = coordinate; + } + + @JsonProperty @JacksonXmlElementWrapper( localName = "dataValues", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "dataValue", namespace = DxfNamespaces.DXF_2_0 ) public List getDataValues() @@ -170,6 +184,7 @@ ", executionDate='" + executionDate + '\'' + ", completed=" + completed + ", storedBy='" + storedBy + '\'' + + ", coordinate=" + coordinate + ", dataValues=" + dataValues + '}'; }