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; ...@@ -45,6 +45,7 @@ import com.fasterxml.jackson.databind.node.DoubleNode;
import com.fasterxml.jackson.databind.node.LongNode; import com.fasterxml.jackson.databind.node.LongNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode; import com.fasterxml.jackson.databind.node.TextNode;
import org.genesys2.anno.util.CoordinateConversionException;
public class RowConverter { public class RowConverter {
private static final Logger _log = Logger.getLogger(RowConverter.class); private static final Logger _log = Logger.getLogger(RowConverter.class);
...@@ -202,7 +203,7 @@ public class RowConverter { ...@@ -202,7 +203,7 @@ public class RowConverter {
return list; 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(); ArrayNode result = mapper.createArrayNode();
for (Map<String, ?> row : list) { for (Map<String, ?> row : list) {
...@@ -216,7 +217,7 @@ public class RowConverter { ...@@ -216,7 +217,7 @@ public class RowConverter {
return result; 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) if (row == null)
return null; return null;
...@@ -226,7 +227,11 @@ public class RowConverter { ...@@ -226,7 +227,11 @@ public class RowConverter {
if (!row.containsKey(jsonField.getRdfTerm())) if (!row.containsKey(jsonField.getRdfTerm()))
continue; continue;
Object rdfValues = row.get(jsonField.getRdfTerm()); Object rdfValues = row.get(jsonField.getRdfTerm());
add(rowNode, jsonField, rdfValues); try {
add(rowNode, jsonField, rdfValues);
} catch (CoordinateConversionException e) {
_log.warn(e.getMessage() + " in row " + row);
}
} }
for (GenesysJSON.JsonField jsonField : genesysJson.getRequiredFields()) { for (GenesysJSON.JsonField jsonField : genesysJson.getRequiredFields()) {
...@@ -238,7 +243,7 @@ public class RowConverter { ...@@ -238,7 +243,7 @@ public class RowConverter {
return rowNode; 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(); String fieldName = jsonField.getFieldName();
ObjectNode containerNode = ensureNode(rowNode, fieldName); ObjectNode containerNode = ensureNode(rowNode, fieldName);
int dotPost = fieldName.lastIndexOf('.'); int dotPost = fieldName.lastIndexOf('.');
...@@ -319,7 +324,7 @@ public class RowConverter { ...@@ -319,7 +324,7 @@ public class RowConverter {
return node != null && !node.isNull() && !node.isMissingNode() && !node.isArray() && node.isValueNode(); 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) { if (rdfValues == null) {
return null; return null;
} }
...@@ -327,7 +332,7 @@ public class RowConverter { ...@@ -327,7 +332,7 @@ public class RowConverter {
try { try {
return coerce(jsonField.getType(), ((ConvertingJsonField<?>) jsonField).convert(rdfValues)); return coerce(jsonField.getType(), ((ConvertingJsonField<?>) jsonField).convert(rdfValues));
} catch (DataConversionException e) { } catch (DataConversionException e) {
throw new GenesysJSONException(e.getMessage()); throw e;
} }
} }
return coerce(jsonField.getType(), rdfValues); return coerce(jsonField.getType(), rdfValues);
......
...@@ -24,8 +24,8 @@ import org.apache.log4j.Logger; ...@@ -24,8 +24,8 @@ import org.apache.log4j.Logger;
public class GeoUtils { public class GeoUtils {
private static final Logger _log = Logger.getLogger(GeoUtils.class); 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 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 LONGITUDE = Pattern.compile("([\\d\\- ]{3})([\\d\\- ]{2})([\\d\\- ]{2})(E|W)");
/** /**
* Convert DDMMSS[NS] to decimal latitude * Convert DDMMSS[NS] to decimal latitude
...@@ -40,11 +40,11 @@ public class GeoUtils { ...@@ -40,11 +40,11 @@ public class GeoUtils {
if (StringUtils.isBlank(str)) { if (StringUtils.isBlank(str)) {
return null; return null;
} }
if (str.matches("^-+$")) { if (str.matches("^[\\- ]+$")) {
return null; return null;
} }
Matcher m = LATITUDE.matcher(str.replace('-', '0')); Matcher m = LATITUDE.matcher(str.replace('-', '0').replace(' ', '0'));
if (m.matches()) { if (m.matches()) {
_log.trace("Latitude " + str + " matches format DDMMSS[EW]"); _log.trace("Latitude " + str + " matches format DDMMSS[EW]");
String deg = m.group(1); String deg = m.group(1);
...@@ -78,11 +78,11 @@ public class GeoUtils { ...@@ -78,11 +78,11 @@ public class GeoUtils {
if (StringUtils.isBlank(str)) { if (StringUtils.isBlank(str)) {
return null; return null;
} }
if (str.matches("^-+$")) { if (str.matches("^[\\- ]+$")) {
return null; return null;
} }
Matcher m = LONGITUDE.matcher(str.replace('-', '0')); Matcher m = LONGITUDE.matcher(str.replace('-', '0').replace(' ', '0'));
if (m.matches()) { if (m.matches()) {
_log.trace("Longitude " + str + " matches format DDDMMSS[EW]"); _log.trace("Longitude " + str + " matches format DDDMMSS[EW]");
String deg = m.group(1); 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