From 866f9d3d7ed1cee5575d070b5641895b067dc3b6 Mon Sep 17 00:00:00 2001 From: marcomeretta <121177306+marcomeretta@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:39:00 +0200 Subject: [PATCH] fix partition key (#5) --- .../FdrReEventToDataStore.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/it/gov/pagopa/fdrretodatastore/FdrReEventToDataStore.java b/src/main/java/it/gov/pagopa/fdrretodatastore/FdrReEventToDataStore.java index ddd10fb..c2b3642 100644 --- a/src/main/java/it/gov/pagopa/fdrretodatastore/FdrReEventToDataStore.java +++ b/src/main/java/it/gov/pagopa/fdrretodatastore/FdrReEventToDataStore.java @@ -38,7 +38,8 @@ public class FdrReEventToDataStore { private Pattern replaceDashPattern = Pattern.compile("-([a-zA-Z])"); private static String idField = "uniqueId"; private static String tableName = System.getenv("TABLE_STORAGE_TABLE_NAME"); - private static String partitionKey = "created"; + private static String columnCreated = "created"; + private static String partitionKeyColumnCreated = "PartitionKey"; private static MongoClient mongoClient = null; @@ -62,20 +63,14 @@ private static TableServiceClient getTableServiceClient(){ private void toTableStorage(Logger logger,TableClient tableClient,Map reEvent) throws JsonProcessingException { - if(reEvent.get(partitionKey) == null){ - logger.warning("event has no '"+partitionKey+"' field"); - }else if(reEvent.get(idField) == null) { - logger.warning("event has no '"+idField+"' field"); - }else{ - for(Map.Entry entry: reEvent.entrySet()){ - if(entry.getValue() instanceof Map){ - reEvent.put(entry.getKey(),ObjectMapperUtils.writeValueAsString(entry.getValue())); - } + for(Map.Entry entry: reEvent.entrySet()){ + if(entry.getValue() instanceof Map){ + reEvent.put(entry.getKey(),ObjectMapperUtils.writeValueAsString(entry.getValue())); } - TableEntity entity = new TableEntity(((String)reEvent.get(partitionKey)).substring(0,10), (String)reEvent.get(idField)); - entity.setProperties(reEvent); - tableClient.createEntity(entity); } + TableEntity entity = new TableEntity((String)reEvent.get(partitionKeyColumnCreated), (String)reEvent.get(idField)); + entity.setProperties(reEvent); + tableClient.createEntity(entity); } private String replaceDashWithUppercase(String input) { @@ -119,6 +114,8 @@ public void processNodoReEvent ( for(int index=0;index< properties.length;index++){ logger.info("processing "+(index+1)+" of "+properties.length); final Map reEvent = ObjectMapperUtils.readValue(reEvents.get(index), Map.class); + String partitionKey = ((String)reEvent.get(columnCreated)).substring(0,10); + reEvent.put(partitionKeyColumnCreated,partitionKey); properties[index].forEach((p,v)->{ String s = replaceDashWithUppercase(p); reEvent.put(s,v);