Skip to content

Commit

Permalink
Merge pull request #37 from vjrj/locale-string-format
Browse files Browse the repository at this point in the history
Fix for #36
  • Loading branch information
nickdos authored Jul 10, 2024
2 parents f7a5a4f + cc70255 commit aee4609
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/main/java/au/org/ala/sds/util/GeneralisedLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.math.BigDecimal;
import java.util.List;
import java.util.Locale;

import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -188,7 +189,7 @@ private String round(String number, int decimalPlaces) {
} else {
BigDecimal bd = new BigDecimal(number);
if (bd.scale() > decimalPlaces) {
return String.format("%." + decimalPlaces + "f", bd);
return String.format(Locale.ROOT,"%." + decimalPlaces + "f", bd);
} else {
return number;
}
Expand Down
59 changes: 31 additions & 28 deletions src/test/java/au/org/ala/sds/SensitiveDataServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.Test;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -99,34 +100,36 @@ public void testConservationSpecies (){
facts.put("month", "10");
facts.put("year", "2010");
facts.put("verbatimCoordinates", "These need to be withheld");

ValidationOutcome outcome = sds.testMapDetails(finder,facts,"Crex crex", "urn:lsid:biodiversity.org.au:afd.taxon:2ef4ac9c-7dfb-4447-8431-e337355ac1ca");

assertTrue(outcome.isValid());
assertTrue(outcome.isSensitive());
Map<String, Object> result = outcome.getResult();
assertNotNull(result);

assertEquals("Latitude", "-35.3", result.get("decimalLatitude"));
assertEquals("Longitude", "149.1", result.get("decimalLongitude"));
assertEquals("InMetres", "10000", result.get("generalisationInMetres"));
assertEquals("eventID", "", result.get("eventID"));
assertEquals("locationRemarks", "", result.get("locationRemarks"));
assertEquals("day", "", result.get("day"));
assertEquals("informationWithheld", "The eventID and day information has been withheld in accordance with Birds Australia data policy", result.get("informationWithheld"));
assertEquals("dataGeneralizations", "Location in Australian Capital Territory, Australia generalised to 0.1 degrees. \n" +
"Sensitive in AUS, Name: Australia, Zone: COUNTRY [Endangered, Birds Australia]", result.get("dataGeneralizations"));

Map<String, String> originalSenstiveValues = (Map<String, String>) outcome.getResult().get("originalSensitiveValues");
assertNotNull(originalSenstiveValues);

assertTrue(outcome.getResult().get("verbatimCoordinates").toString().length()==0);

assertEquals("Original latitude", "-35.276771", originalSenstiveValues.get("decimalLatitude"));
assertEquals("Original longitude", "149.112539", originalSenstiveValues.get("decimalLongitude"));
assertEquals("Original eventID", "1234", originalSenstiveValues.get("eventID"));
assertEquals("Original locationRemarks", "remarks", originalSenstiveValues.get("locationRemarks"));
assertEquals("Original day", "10", originalSenstiveValues.get("day"));
for (Locale loc : new Locale[]{Locale.ENGLISH, Locale.FRENCH, Locale.forLanguageTag("es-ES") }) {
Locale.setDefault(loc);
ValidationOutcome outcome = sds.testMapDetails(finder, facts, "Crex crex", "urn:lsid:biodiversity.org.au:afd.taxon:2ef4ac9c-7dfb-4447-8431-e337355ac1ca");

assertTrue(outcome.isValid());
assertTrue(outcome.isSensitive());
Map<String, Object> result = outcome.getResult();
assertNotNull(result);

assertEquals("Latitude", "-35.3", result.get("decimalLatitude"));
assertEquals("Longitude", "149.1", result.get("decimalLongitude"));
assertEquals("InMetres", "10000", result.get("generalisationInMetres"));
assertEquals("eventID", "", result.get("eventID"));
assertEquals("locationRemarks", "", result.get("locationRemarks"));
assertEquals("day", "", result.get("day"));
assertEquals("informationWithheld", "The eventID and day information has been withheld in accordance with Birds Australia data policy", result.get("informationWithheld"));
assertEquals("dataGeneralizations", "Location in Australian Capital Territory, Australia generalised to 0.1 degrees. \n" +
"Sensitive in AUS, Name: Australia, Zone: COUNTRY [Endangered, Birds Australia]", result.get("dataGeneralizations"));

Map<String, String> originalSenstiveValues = (Map<String, String>) outcome.getResult().get("originalSensitiveValues");
assertNotNull(originalSenstiveValues);

assertTrue(outcome.getResult().get("verbatimCoordinates").toString().length() == 0);

assertEquals("Original latitude", "-35.276771", originalSenstiveValues.get("decimalLatitude"));
assertEquals("Original longitude", "149.112539", originalSenstiveValues.get("decimalLongitude"));
assertEquals("Original eventID", "1234", originalSenstiveValues.get("eventID"));
assertEquals("Original locationRemarks", "remarks", originalSenstiveValues.get("locationRemarks"));
assertEquals("Original day", "10", originalSenstiveValues.get("day"));
}
}

@Test
Expand Down

0 comments on commit aee4609

Please sign in to comment.