diff --git a/xyz-txn-handler/src/main/java/com/here/xyz/pub/db/PubDatabaseHandler.java b/xyz-txn-handler/src/main/java/com/here/xyz/pub/db/PubDatabaseHandler.java index ee59022ff..963ebf883 100644 --- a/xyz-txn-handler/src/main/java/com/here/xyz/pub/db/PubDatabaseHandler.java +++ b/xyz-txn-handler/src/main/java/com/here/xyz/pub/db/PubDatabaseHandler.java @@ -3,6 +3,7 @@ import com.here.xyz.models.hub.Subscription; import com.here.xyz.psql.config.PSQLConfig; import com.here.xyz.pub.models.*; +import com.here.xyz.pub.util.MessageUtil; import io.vertx.core.json.Json; import io.vertx.core.json.JsonObject; import org.apache.logging.log4j.LogManager; @@ -12,6 +13,8 @@ import java.util.*; import java.util.concurrent.TimeUnit; +import static com.here.xyz.pub.util.MessageUtil.MAP_TYPE_REFERENCE; + public class PubDatabaseHandler { private static final Logger logger = LogManager.getLogger(); @@ -41,7 +44,7 @@ public class PubDatabaseHandler { final private static String SCHEMA_STR = "{{SCHEMA}}"; final private static String TABLE_STR = "{{TABLE}}"; final private static String FETCH_TXNS_FROM_SPACEDB = - "SELECT txn_id, txn_rec_id, feature_action, feature_id, feature_json, feature_geo " + + "SELECT txn_id, txn_rec_id, feature_action, feature_id, feature_json, REPLACE(ST_AsGeojson(ST_Force3D(feature_geo)),'nan','0') as geometry " + "FROM "+PubConfig.XYZ_ADMIN_DB_CFG_SCHEMA+".naksha_fetch_newer_transactions" + "( '"+SCHEMA_STR+"', '"+TABLE_STR+"', ?, ?, ?, ?) "; @@ -206,7 +209,16 @@ public static List fetchPublishableTransactions( pubTxnData.setTxnRecId(rs.getLong("txn_rec_id")); pubTxnData.setAction(rs.getString("feature_action")); pubTxnData.setFeatureId(rs.getString("feature_id")); - pubTxnData.setJsonData(rs.getString("feature_json")); + // Combine feature + geometry (if available) + final String featureJson = rs.getString("feature_json"); + final String featureGeometry = rs.getString("geometry"); + final Map jsonDataMap = MessageUtil.fromJson(featureJson, MAP_TYPE_REFERENCE); + if (featureGeometry!=null) { + jsonDataMap.put("geometry", MessageUtil.fromJson(featureGeometry, MAP_TYPE_REFERENCE)); + } + final String jsonData = MessageUtil.toJson(jsonDataMap); + // store combined feature + geometry + pubTxnData.setJsonData(jsonData); // add to the list if (txnList == null) { txnList = new ArrayList<>(); diff --git a/xyz-txn-handler/src/main/java/com/here/xyz/pub/mapper/DefaultPubMsgMapper.java b/xyz-txn-handler/src/main/java/com/here/xyz/pub/mapper/DefaultPubMsgMapper.java index 0f57f90a6..d13ee3010 100644 --- a/xyz-txn-handler/src/main/java/com/here/xyz/pub/mapper/DefaultPubMsgMapper.java +++ b/xyz-txn-handler/src/main/java/com/here/xyz/pub/mapper/DefaultPubMsgMapper.java @@ -6,10 +6,12 @@ import java.util.HashMap; import java.util.Map; +import static com.here.xyz.pub.util.MessageUtil.MAP_TYPE_REFERENCE; + public class DefaultPubMsgMapper implements IPubMsgMapper { public String mapToPublishableFormat(final Subscription sub, final PubTransactionData txnData) { - final Map jsonDataMap = MessageUtil.fromJson(txnData.getJsonData(), Map.class); + final Map jsonDataMap = MessageUtil.fromJson(txnData.getJsonData(), MAP_TYPE_REFERENCE); final String action = txnData.getAction(); // prepare final message map final Map msgMap = new HashMap<>(); diff --git a/xyz-txn-handler/src/main/java/com/here/xyz/pub/util/MessageUtil.java b/xyz-txn-handler/src/main/java/com/here/xyz/pub/util/MessageUtil.java index 37f85aa42..4b88718fb 100644 --- a/xyz-txn-handler/src/main/java/com/here/xyz/pub/util/MessageUtil.java +++ b/xyz-txn-handler/src/main/java/com/here/xyz/pub/util/MessageUtil.java @@ -24,6 +24,7 @@ public class MessageUtil { private static Map instanceMap = new HashMap<>(); final public static ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + final public static TypeReference> MAP_TYPE_REFERENCE = new TypeReference>() {}; public static IPubMsgMapper getMsgMapperInstance(final Subscription sub) throws Exception { @@ -130,6 +131,7 @@ public static String toJson(Object object) { } catch (Exception ex) { payloadJson = null; logger.error("Exception converting Object to Json {} {}", object, ex.getMessage(), ex); + throw new RuntimeException(ex); } return payloadJson; } @@ -159,6 +161,7 @@ public static T fromJson(String payloadJson, Class type) { } catch (Exception ex) { payloadObj = null; logger.error("Exception converting Json to Object of type {} - {} , Error:{}", type, payloadJson, ex.getMessage(), ex); + throw new RuntimeException(ex); } return payloadObj; } @@ -190,6 +193,7 @@ public static T fromJson(String payloadJson, TypeReference ref) { } catch (Exception ex) { payloadObj = null; logger.error("Exception converting Json to Object of type {} - {}, Error:{}", ref.getClass().getComponentType(), payloadJson, ex.getMessage(), ex); + throw new RuntimeException(ex); } return payloadObj; }