devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693495 - in /devicemap/trunk/clients/2.0/reference/src: Attributes.java DeviceMapClient.java Main.java
Date Thu, 30 Jul 2015 20:37:52 GMT
Author: rezan
Date: Thu Jul 30 20:37:52 2015
New Revision: 1693495

URL: http://svn.apache.org/r1693495
Log:
parentId in attributes

Modified:
    devicemap/trunk/clients/2.0/reference/src/Attributes.java
    devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
    devicemap/trunk/clients/2.0/reference/src/Main.java

Modified: devicemap/trunk/clients/2.0/reference/src/Attributes.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Attributes.java?rev=1693495&r1=1693494&r2=1693495&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Attributes.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Attributes.java Thu Jul 30 20:37:52 2015
@@ -25,9 +25,10 @@ import java.util.Map;
 import org.codehaus.jackson.JsonNode;
 
 public class Attributes {
-  private String patternId;
-  private Map<String, String> attributes;
-  private Map<String, AttributeTransformer> attributeTransformers;
+  private final String patternId;
+  private final String parentId;
+  private final Map<String, String> attributes;
+  private final Map<String, AttributeTransformer> attributeTransformers;
 
   public Attributes(JsonNode json) throws Exception {
     if(JsonFile.empty(json, "patternId")) {
@@ -35,21 +36,23 @@ public class Attributes {
     }
 
     patternId = json.get("patternId").asText();
-    attributes = new HashMap<>();
+    parentId = (JsonFile.empty(json, "parentId") ? null : json.get("parentId").asText());
     attributeTransformers = new HashMap<>();
 
     //ATTRIBUTES
 
+    Map<String, String> attributeMap = new HashMap<>();
+
     if(JsonFile.get(json, "attributes").isObject()) {
       for(Iterator<String> j = json.get("attributes").getFieldNames(); j.hasNext();)
{
         String key = j.next();
         String value = json.get("attributes").get(key).asText();
 
-        attributes.put(key, value);
+        attributeMap.put(key, value);
       }
     }
 
-    attributes.put("patternId", patternId);
+    attributeMap.put("patternId", patternId);
 
     //ATTRIBUTE TRANFORMERS
 
@@ -68,9 +71,7 @@ public class Attributes {
       }
     }
 
-    if(attributeTransformers.isEmpty()) {
-      attributes = Collections.unmodifiableMap(attributes);
-    }
+    attributes = Collections.unmodifiableMap(attributeMap);
   }
 
   public Map<String, String> getAttributes(String input) {
@@ -78,12 +79,9 @@ public class Attributes {
       return attributes;
     }
 
-    Map<String, String> custom = new HashMap<>();
-
-    for(String key : attributes.keySet()) {
-      String value = attributes.get(key);
-      custom.put(key, value);
-    }
+    //ADD TRANSFORMED ATTRIBUTES
+    
+    Map<String, String> custom = new HashMap<>(attributes);
 
     for(String key : attributeTransformers.keySet()) {
       AttributeTransformer attributeTransformer = attributeTransformers.get(key);
@@ -111,4 +109,8 @@ public class Attributes {
   public String getPatternId() {
     return patternId;
   }
+
+  public String getParentId() {
+    return parentId;
+  }
 }

Modified: devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java?rev=1693495&r1=1693494&r2=1693495&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Thu Jul 30 20:37:52 2015
@@ -343,10 +343,38 @@ public class DeviceMapClient {
   private Map<String, String> getPatternAttributes(String patternId, String input)
{
     Attributes patternAttributes = attributes.get(patternId);
 
+    //FOUND ATTRIBUTE MAP
+
     if(patternAttributes != null) {
-      return patternAttributes.getAttributes(input);
+      Map<String, String> attributeMap = patternAttributes.getAttributes(input);
+      Attributes parent = patternAttributes;
+
+      //COPY PARENT ATTRIBUTES
+
+      if(patternAttributes.getParentId() != null) {
+        attributeMap = new HashMap<>(attributeMap);
+      }
+
+      while(parent.getParentId() != null) {
+        parent = attributes.get(parent.getParentId());
+
+        if(parent == null) {
+          break;
+        }
+
+        Map<String, String> parentMap = parent.getAttributes(input);
+
+        for(String key : parentMap.keySet()) {
+          if(!attributeMap.containsKey(key)) {
+            attributeMap.put(key, parentMap.get(key));
+          }
+        }
+      }
+
+      return attributeMap;
     }
 
+    //NO ATTRIBUTES, RETURN MAP WITH JUST PATTERN ID
     Map<String, String> custom = new HashMap<>();
 
     custom.put("patternId", patternId);

Modified: devicemap/trunk/clients/2.0/reference/src/Main.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Main.java?rev=1693495&r1=1693494&r2=1693495&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Thu Jul 30 20:37:52 2015
@@ -172,13 +172,6 @@ public class Main {
             resultPatternId = JsonFile.get(test, "resultPatternId").asText();
           }
 
-          if(JsonFile.get(test, "resultAttributes").isObject()) {
-            for(Iterator<String> j = test.get("resultAttributes").getFieldNames();
j.hasNext();) {
-              String key = j.next();
-              String value = test.get("resultAttributes").get(key).asText();
-            }
-          }
-
           Map<String, String> result = client.classify(input);
           String patternId = null;
 
@@ -187,6 +180,7 @@ public class Main {
           }
 
           boolean pass = false;
+          int failedAttributes = 0;
 
           if(resultPatternId == null) {
             if(patternId == null) {
@@ -196,11 +190,28 @@ public class Main {
             pass = true;
           }
 
-          if(pass) {
+          if(pass && JsonFile.get(test, "resultAttributes").isObject()) {
+            for(Iterator<String> j = test.get("resultAttributes").getFieldNames();
j.hasNext();) {
+              String key = j.next();
+              String expectedValue = test.get("resultAttributes").get(key).asText();
+              String value = null;
+
+              if(result != null) {
+                value = result.get(key);
+              }
+
+              if(!expectedValue.equals(value)) {
+                log("FAILED, expected attribute for " + key + ": " + expectedValue + ", found:
" + value, 2);
+                failedAttributes++;
+              }
+            }
+          }
+
+          if(pass && failedAttributes == 0) {
             passCount++;
-            log("Passed, expected: " + resultPatternId, 2);
-          } else {
-            log("FAILED, expected: " + resultPatternId + ", result: " + patternId, 2);
+            log("Passed, expected patternId: " + resultPatternId, 2);
+          } else if(!pass) {
+            log("FAILED, expected patternId: " + resultPatternId + ", found: " + patternId,
2);
           }
 
           testCount++;



Mime
View raw message