package ca.omny.ecs;

import ca.omny.documentdb.IDocumentQuerier;
import java.util.Map;
import javax.inject.Inject;

public class EcsVersionMapper {
    @Inject
    IDocumentQuerier querier;
    
    Map<String,String> familyMap;
    
    public String getCurrentVersion(String family) {
        String key = querier.getKey("services",family,"current");
        return querier.get(key, Map.class).get("version").toString();
    }
    
    public String getFamily(String api) {
        if(familyMap.containsKey(api)) {
            return familyMap.get(api);
        }
        String key = querier.getKey("service_families",api);
        Map map = querier.get(key, Map.class);
        if(map!=null) {
            String family = map.get("family").toString();
            familyMap.put(api, family);
            return family;
        }
        if(familyMap.containsKey("default")) {
            return familyMap.get("default");
        }
        key = querier.getKey("service_families","default");
        String family = querier.get(key, Map.class).get("family").toString();
        familyMap.put(api, family);
        return family;
    }
}

@@ -59,16 +59,42 @@
 uerier;%0A
+import java.util.HashMap;%0A
 import j
@@ -103,24 +103,24 @@
 a.util.Map;%0A
-
 import javax
@@ -168,16 +168,21 @@
 apper %7B%0A
+    %0A
     @Inj
@@ -216,24 +216,24 @@
 erier;%0A    %0A
-
     Map%3CStri
@@ -252,16 +252,34 @@
 amilyMap
+ = new HashMap%3C%3E()
 ;%0A    %0A 

initialize map