Commits

Manuel Polo committed 80b9686

Fixed metadata keys

  • Participants
  • Parent commits 09ce4a0

Comments (0)

Files changed (2)

     <groupId>org.mongoste</groupId>
     <artifactId>mongoste-core</artifactId>
     <packaging>jar</packaging>
-    <version>0.3.3</version>
+    <version>0.3.4</version>
     <name>Mongoste</name>
     <description>Mongo STats Engine</description>
     <url>http://bitbucket.org/mrmx/mongoste</url>
         <dependency>
             <groupId>org.mongodb</groupId>
             <artifactId>mongo-java-driver</artifactId>
-            <version>2.4</version>
+            <version>2.5</version>
         </dependency>
         <dependency>
             <groupId>joda-time</groupId>

src/main/java/org/mongoste/core/impl/mongodb/MongoStatsEngine.java

         doc.put(EVENT_TARGET,event.getTarget());
         doc.put(EVENT_TARGET_TYPE,event.getTargetType());
         doc.put(EVENT_ACTION,event.getAction());
-        doc.put(EVENT_DATE,event.getDate());        
-        doc.put(EVENT_METADATA,new BasicDBObject(event.getMetadata()));
+        doc.put(EVENT_DATE,event.getDate());
+        Map<String,Object> metadata = event.getMetadata();
+        if(metadata != null && !metadata.isEmpty()) {
+        	BasicDBObject metadataDoc = new BasicDBObject();
+	        for(String metaKey : metadata.keySet()) {
+	        	metadataDoc.put(replaceKeyDots(metaKey),metaKeyValue(metaKey, metadata.get(metaKey)));
+	        }
+	        doc.put(EVENT_METADATA,metadataDoc);
+        }
         WriteResult ws = events.insert(doc);
         log.debug("saveEvent result: {}",ws.getLastError());
     }
     }
 
     private String metaKeyValue(String key, Object value) {
-        String resultKey = String.valueOf(value);
+        String result = String.valueOf(value);
         if(METAKEY_IP.equals(key)) {
-            String [] parts = resultKey.split("\\.");
+            String [] parts = result.split("\\.");
             long ipValue = 0L;
             if(parts.length == 4) {
                 //IPv4?
             }
             
         }
-        //Avoid dot notation for json key
-        resultKey = resultKey.replace(".", "_");
-
-        return resultKey;
+        return result;
+    }
+    
+    private String replaceKeyDots(String key) {
+        //Avoid dot notation for json keys
+        return key.replace(".", "_");    	
     }
 
 }