Skip to content

Commit

Permalink
Supporting (optional) geometry object as part of message publish
Browse files Browse the repository at this point in the history
Supporting (optional) geometry object as part of message publish
  • Loading branch information
hirenkp2000 authored Aug 11, 2023
2 parents 398edbc + 9b83e9a commit aa92cfe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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+"', ?, ?, ?, ?) ";

Expand Down Expand Up @@ -206,7 +209,16 @@ public static List<PubTransactionData> 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<String, Object> 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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> jsonDataMap = MessageUtil.fromJson(txnData.getJsonData(), Map.class);
final Map<String, Object> jsonDataMap = MessageUtil.fromJson(txnData.getJsonData(), MAP_TYPE_REFERENCE);
final String action = txnData.getAction();
// prepare final message map
final Map<String, Object> msgMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MessageUtil {

private static Map<String, IPubMsgMapper> instanceMap = new HashMap<>();
final public static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
final public static TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<Map<String, Object>>() {};


public static IPubMsgMapper getMsgMapperInstance(final Subscription sub) throws Exception {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -159,6 +161,7 @@ public static <T> T fromJson(String payloadJson, Class<T> 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;
}
Expand Down Expand Up @@ -190,6 +193,7 @@ public static <T> T fromJson(String payloadJson, TypeReference<T> 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;
}
Expand Down

0 comments on commit aa92cfe

Please sign in to comment.