Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump jts.version from 1.18.2 to 1.19.0 in /dhis-2 #11143

Merged
merged 5 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.hisp.dhis.dxf2.events.event.DataValue;
Expand Down Expand Up @@ -61,6 +62,8 @@ public class DefaultCsvEventService
private static final CsvSchema CSV_SCHEMA = CSV_MAPPER.schemaFor( CsvEventDataValue.class )
.withLineSeparator( "\n" );

private static final Pattern TRIM_SINGLE_QUOTES = Pattern.compile( "^'|'$" );

@Override
public void writeEvents( OutputStream outputStream, List<Event> events, boolean withHeader )
throws IOException
Expand Down Expand Up @@ -148,9 +151,10 @@ public List<Event> readEvents( InputStream inputStream, boolean skipFirst )
event.setCompletedDate( dataValue.getCompletedDate() );
event.setCompletedBy( dataValue.getCompletedBy() );

if ( dataValue.getGeometry() != null )
if ( StringUtils.isNotBlank( dataValue.getGeometry() ) )
{
event.setGeometry( new WKTReader().read( dataValue.getGeometry() ) );
event.setGeometry( new WKTReader()
.read( TRIM_SINGLE_QUOTES.matcher( dataValue.getGeometry() ).replaceAll( "" ) ) );
}
else if ( dataValue.getLongitude() != null && dataValue.getLatitude() != null )
{
Expand Down
5 changes: 5 additions & 0 deletions dhis-2/dhis-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-support-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class TrackerCsvEventService
{
private static final CsvMapper CSV_MAPPER = new CsvMapper().enable( CsvParser.Feature.WRAP_AS_ARRAY );

private static final Pattern TRIM_SINGLE_QUOTES = Pattern.compile( "^'|'$" );

@Override
public void writeEvents( OutputStream outputStream, List<Event> events, boolean withHeader )
throws IOException
Expand Down Expand Up @@ -193,9 +196,10 @@ public List<Event> readEvents( InputStream inputStream, boolean skipFirst )
event.setAttributeCategoryOptions( dataValue.getAttributeCategoryOptions() );
event.setAssignedUser( User.builder().username( dataValue.getAssignedUser() ).build() );

if ( dataValue.getGeometry() != null )
if ( StringUtils.isNotBlank( dataValue.getGeometry() ) )
{
event.setGeometry( new WKTReader().read( dataValue.getGeometry() ) );
event.setGeometry( new WKTReader()
.read( TRIM_SINGLE_QUOTES.matcher( dataValue.getGeometry() ).replaceAll( "" ) ) );
}
else if ( dataValue.getLongitude() != null && dataValue.getLatitude() != null )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand All @@ -46,6 +48,11 @@
import org.hisp.dhis.webapi.controller.tracker.view.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;

import com.google.common.io.Files;
Expand All @@ -55,10 +62,13 @@ class TrackerCsvEventServiceTest

private TrackerCsvEventService service;

private GeometryFactory geometryFactory;

@BeforeEach
void setUp()
{
service = new TrackerCsvEventService();
geometryFactory = new GeometryFactory();
}

@Test
Expand Down Expand Up @@ -209,4 +219,25 @@ void testReadEventsFromFileWithoutHeader()
assertFalse( dv.isProvidedElsewhere() );
} );
}

@ValueSource( strings = {
",,,,,,,,,POINT (-11.4283223849698 8.06311527044516)",
",,,,,,,,,\"POINT (-11.4283223849698 8.06311527044516)\"",
",,,,,,,,,'POINT (-11.4283223849698 8.06311527044516)'",
} )
@ParameterizedTest
void testReadEventsParsesGeometryEvenIfQuoted( String csv )
throws IOException,
ParseException
{

InputStream in = new ByteArrayInputStream( csv.getBytes( StandardCharsets.UTF_8 ) );

List<Event> events = service.readEvents( in, false );

assertFalse( events.isEmpty() );
assertEquals( 1, events.size() );
Point expected = geometryFactory.createPoint( new Coordinate( -11.4283223849698, 8.06311527044516 ) );
assertEquals( expected, events.get( 0 ).getGeometry() );
}
}
2 changes: 1 addition & 1 deletion dhis-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<fop.version>2.7</fop.version>
<mapstruct.version>1.5.2.Final</mapstruct.version>
<geotools.version>27.0</geotools.version>
<jts.version>1.18.2</jts.version>
<jts.version>1.19.0</jts.version>

<!-- Apache Artemis -->
<artemis.version>2.23.1</artemis.version>
Expand Down