Commit eedff62d authored by Matija Obreza's avatar Matija Obreza
Browse files

Don't fail on faulty LATITUDE, LONGITUDE - just report

Allow space (not in MCPD) to be used in LAT/LON instead of '-' or '0'
parent 0949036a
......@@ -45,6 +45,7 @@ import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import org.genesys2.anno.util.CoordinateConversionException;
public class RowConverter {
private static final Logger _log = Logger.getLogger(RowConverter.class);
......@@ -202,7 +203,7 @@ public class RowConverter {
return list;
}
public static ArrayNode toGenesysJson(List<Map<String, ?>> list) throws GenesysJSONException, JsonGenerationException {
public static ArrayNode toGenesysJson(List<Map<String, ?>> list) throws GenesysJSONException, JsonGenerationException, DataConversionException {
ArrayNode result = mapper.createArrayNode();
for (Map<String, ?> row : list) {
......@@ -216,7 +217,7 @@ public class RowConverter {
return result;
}
public static ObjectNode toJson(Map<String, ?> row) throws GenesysJSONException, JsonGenerationException {
public static ObjectNode toJson(Map<String, ?> row) throws GenesysJSONException, JsonGenerationException, DataConversionException {
if (row == null)
return null;
......@@ -226,7 +227,11 @@ public class RowConverter {
if (!row.containsKey(jsonField.getRdfTerm()))
continue;
Object rdfValues = row.get(jsonField.getRdfTerm());
try {
add(rowNode, jsonField, rdfValues);
} catch (CoordinateConversionException e) {
_log.warn(e.getMessage() + " in row " + row);
}
}
for (GenesysJSON.JsonField jsonField : genesysJson.getRequiredFields()) {
......@@ -238,7 +243,7 @@ public class RowConverter {
return rowNode;
}
private static void add(ObjectNode rowNode, JsonField jsonField, Object rdfValues) throws GenesysJSONException, JsonGenerationException {
private static void add(ObjectNode rowNode, JsonField jsonField, Object rdfValues) throws GenesysJSONException, JsonGenerationException, DataConversionException {
String fieldName = jsonField.getFieldName();
ObjectNode containerNode = ensureNode(rowNode, fieldName);
int dotPost = fieldName.lastIndexOf('.');
......@@ -319,7 +324,7 @@ public class RowConverter {
return node != null && !node.isNull() && !node.isMissingNode() && !node.isArray() && node.isValueNode();
}
static JsonNode coerce(JsonField jsonField, Object rdfValues) throws GenesysJSONException {
static JsonNode coerce(JsonField jsonField, Object rdfValues) throws DataConversionException {
if (rdfValues == null) {
return null;
}
......@@ -327,7 +332,7 @@ public class RowConverter {
try {
return coerce(jsonField.getType(), ((ConvertingJsonField<?>) jsonField).convert(rdfValues));
} catch (DataConversionException e) {
throw new GenesysJSONException(e.getMessage());
throw e;
}
}
return coerce(jsonField.getType(), rdfValues);
......
......@@ -24,8 +24,8 @@ import org.apache.log4j.Logger;
public class GeoUtils {
private static final Logger _log = Logger.getLogger(GeoUtils.class);
private static final Pattern LATITUDE = Pattern.compile("([\\d\\-]{2})([\\d\\-]{2})([\\d\\-]{2})(N|S)");
private static final Pattern LONGITUDE = Pattern.compile("([\\d\\-]{3})([\\d\\-]{2})([\\d\\-]{2})(E|W)");
private static final Pattern LATITUDE = Pattern.compile("([\\d\\- ]{2})([\\d\\- ]{2})([\\d\\- ]{2})(N|S)");
private static final Pattern LONGITUDE = Pattern.compile("([\\d\\- ]{3})([\\d\\- ]{2})([\\d\\- ]{2})(E|W)");
/**
* Convert DDMMSS[NS] to decimal latitude
......@@ -40,11 +40,11 @@ public class GeoUtils {
if (StringUtils.isBlank(str)) {
return null;
}
if (str.matches("^-+$")) {
if (str.matches("^[\\- ]+$")) {
return null;
}
Matcher m = LATITUDE.matcher(str.replace('-', '0'));
Matcher m = LATITUDE.matcher(str.replace('-', '0').replace(' ', '0'));
if (m.matches()) {
_log.trace("Latitude " + str + " matches format DDMMSS[EW]");
String deg = m.group(1);
......@@ -78,11 +78,11 @@ public class GeoUtils {
if (StringUtils.isBlank(str)) {
return null;
}
if (str.matches("^-+$")) {
if (str.matches("^[\\- ]+$")) {
return null;
}
Matcher m = LONGITUDE.matcher(str.replace('-', '0'));
Matcher m = LONGITUDE.matcher(str.replace('-', '0').replace(' ', '0'));
if (m.matches()) {
_log.trace("Longitude " + str + " matches format DDDMMSS[EW]");
String deg = m.group(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment