=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/CoordinatesTuple.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/CoordinatesTuple.java 2010-07-14 19:36:41 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/CoordinatesTuple.java 2011-06-29 11:04:32 +0000 @@ -1,8 +1,38 @@ package org.hisp.dhis.organisationunit; +/* + * Copyright (c) 2004-2010, 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; +/** + * @author Lars Helge Overland + */ public class CoordinatesTuple { private List coordinatesTuple = new ArrayList(); @@ -21,6 +51,27 @@ { return coordinatesTuple; } + + public boolean hasCoordinates() + { + return this.coordinatesTuple != null && this.coordinatesTuple.size() > 0; + } + + public static boolean hasCoordinates( List list ) + { + if ( list != null && list.size() > 0 ) + { + for ( CoordinatesTuple tuple : list ) + { + if ( tuple.hasCoordinates() ) + { + return true; + } + } + } + + return false; + } @Override public int hashCode() === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2011-06-13 12:50:20 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2011-06-29 11:04:32 +0000 @@ -275,21 +275,24 @@ { StringBuilder builder = new StringBuilder(); - if ( list != null && list.size() > 0 ) + if ( CoordinatesTuple.hasCoordinates( list ) ) { builder.append( "[" ); for ( CoordinatesTuple tuple : list ) { - builder.append( "[[" ); - - for ( String coordinates : tuple.getCoordinatesTuple() ) + if ( tuple.hasCoordinates() ) { - builder.append( "[" + coordinates + "]," ); + builder.append( "[[" ); + + for ( String coordinates : tuple.getCoordinatesTuple() ) + { + builder.append( "[" + coordinates + "]," ); + } + + builder.deleteCharAt( builder.lastIndexOf( "," ) ); + builder.append( "]]," ); } - - builder.deleteCharAt( builder.lastIndexOf( "," ) ); - builder.append( "]]," ); } builder.deleteCharAt( builder.lastIndexOf( "," ) ); === modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/OrganisationUnitConverter.java' --- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/OrganisationUnitConverter.java 2011-06-27 21:54:19 +0000 +++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/OrganisationUnitConverter.java 2011-06-29 11:04:32 +0000 @@ -129,20 +129,24 @@ writer.writeElement( FIELD_ACTIVE, String.valueOf( unit.isActive() ) ); writer.writeElement( FIELD_COMMENT, unit.getComment() ); writer.writeElement( FIELD_GEO_CODE, unit.getGeoCode() ); + + writer.openElement( FIELD_FEATURE, ATTRIBUTE_TYPE, unit.getFeatureType() ); - writer.openElement( FIELD_FEATURE, ATTRIBUTE_TYPE, unit.getFeatureType() ); for ( CoordinatesTuple tuple : unit.getCoordinatesAsList() ) { - if (tuple.getNumberOfCoordinates() > 0) { + if ( tuple.hasCoordinates() ) + { writer.openElement( FIELD_COORDINATES_TUPLE ); - + for ( String coordinates : tuple.getCoordinatesTuple() ) { writer.writeElement( FIELD_COORDINATES, coordinates ); } + writer.closeElement(); } } + writer.closeElement(); writer.writeElement( FIELD_LAST_UPDATED, DateUtils.getMediumDateString( unit.getLastUpdated(), EMPTY ) ); @@ -198,13 +202,16 @@ if ( unit.getFeatureType() != null ) { List list = new ArrayList(); + while ( reader.moveToStartElement( FIELD_COORDINATES_TUPLE, FIELD_FEATURE ) ) { CoordinatesTuple tuple = new CoordinatesTuple(); + while ( reader.moveToStartElement( FIELD_COORDINATES, FIELD_COORDINATES_TUPLE ) ) { tuple.addCoordinates( reader.getElementValue() ); } + list.add( tuple ); }