Author: rezan
Date: Wed Jul 29 13:56:53 2015
New Revision: 1693266
URL: http://svn.apache.org/r1693266
Log:
attribute parsing and several fixups
Modified:
devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
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=1693266&r1=1693265&r2=1693266&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Wed Jul 29
13:56:53 2015
@@ -70,51 +70,124 @@ public class DeviceMapClient {
Main.log(" Loading pattern domain: " + patterns.getDomain() + ", version:
" +
patterns.getDomainVersion() + (patch ? ", patch" : ""));
- if(patterns.getJsonNode().get("inputParser").isObject()) {
+ if(patterns.getJsonNode().get("inputParser") != null &&
patterns.getJsonNode().get("inputParser").isObject()) {
JsonNode inputParser = patterns.getJsonNode().get("inputParser");
- if(inputParser.get("transformers").isArray()) {
+ if(inputParser.get("transformers") != null &&
inputParser.get("transformers").isArray()) {
+ if(patch) {
+ transformers = new ArrayList<String>();
+ }
+
for(Iterator<JsonNode> i = inputParser.get("transformers").iterator();
i.hasNext();) {
JsonNode transformer = i.next();
+
transformers.add(transformer.get("type").asText());
+
Main.log(" Found transformer: " + transformer.get("type"));
}
}
- if(inputParser.get("tokenSeperators").isArray()) {
+ if(inputParser.get("tokenSeperators") != null &&
inputParser.get("tokenSeperators").isArray()) {
+ if(patch) {
+ tokenSeperators = new ArrayList<String>();
+ }
+
for(Iterator<JsonNode> i =
inputParser.get("tokenSeperators").iterator(); i.hasNext();) {
JsonNode tokenSeperator = i.next();
+
tokenSeperators.add(tokenSeperator.asText());
+
Main.log(" Found tokenSeperator: '" + tokenSeperator.asText() +
"'");
}
}
- if(inputParser.get("ngramConcatSize").asInt(0) > 0) {
+ if(inputParser.get("ngramConcatSize") != null &&
inputParser.get("ngramConcatSize").asInt(0) > 0) {
ngramConcatSize = inputParser.get("ngramConcatSize").asInt(0);
+
Main.log(" Found ngramConcatSize: " + ngramConcatSize);
}
}
- if(patterns.getJsonNode().get("patternSet").isObject()) {
+ if(patterns.getJsonNode().get("patternSet") != null &&
patterns.getJsonNode().get("patternSet").isObject()) {
JsonNode patternSet = patterns.getJsonNode().get("patternSet");
- if(patternSet.get("defaultId").isTextual()) {
+ if(patternSet.get("defaultId") != null &&
patternSet.get("defaultId").isTextual()) {
defaultId = patternSet.get("defaultId").asText();
+
Main.log(" Found defaultId: " + defaultId);
}
int patternCount = 0;
- if(patternSet.get("patterns").isArray()) {
+
+ if(patternSet.get("patterns") != null &&
patternSet.get("patterns").isArray()) {
for(Iterator<JsonNode> i = patternSet.get("patterns").iterator();
i.hasNext();) {
JsonNode tokenSeperator = i.next();
+
patternCount++;
}
+
Main.log(" Found " + patternCount + " pattern(s)");
}
}
}
- public void loadAttributes(JsonFile attributes) {
+ public void loadAttributes(JsonFile attributes) throws Exception {
+ if(!attributes.getType().equals("pattern") &&
!attributes.getType().equals("attribute")) {
+ throw new Exception("Unknown pattern file type: " +
attributes.getType());
+ }
+
+ if(!attributes.getDomain().equals(domain)) {
+ throw new Exception("Domains do not match: " + domain + " != " +
attributes.getDomain());
+ }
+
+ if(!attributes.getDomainVersion().equals(domainVersion)) {
+ throw new Exception("DomainVersions do not match: " + domainVersion + "
!= " + attributes.getDomainVersion());
+ }
+
+ Main.log(" Loading attributes: " + attributes.getDomain() + ", version: "
+ attributes.getDomainVersion());
+
+ int attributeCount = 0;
+
+ if(attributes.getJsonNode().get("attributes") != null &&
attributes.getJsonNode().get("attributes").isArray()) {
+ for(Iterator<JsonNode> i =
attributes.getJsonNode().get("attributes").iterator(); i.hasNext();) {
+ JsonNode attribute = i.next();
+
+ if(attribute.get("patternId") == null ||
attribute.get("patternId").asText().isEmpty()) {
+ throw new Exception("Bad patternId found, position: " +
attributeCount);
+ }
+
+ String patternId = attribute.get("patternId").asText();
+
+ if(attribute.get("attributes") != null &&
attribute.get("attributes").isObject()) {
+ for(Iterator<String> j =
attribute.get("attributes").getFieldNames(); j.hasNext();) {
+ String key = j.next();
+ String value = attribute.get("attributes").get(key).asText();
+ }
+ }
+
+ if(attribute.get("attributeTransformers") != null &&
attribute.get("attributeTransformers").isArray()) {
+ for(Iterator<JsonNode> j =
attribute.get("attributeTransformers").iterator(); j.hasNext();) {
+ JsonNode attributeTransformer = j.next();
+
+ if(attributeTransformer.get("name") == null ||
attributeTransformer.get("name").asText().isEmpty()) {
+ throw new Exception("Bad attributeTransformer name, position:
" + attributeCount);
+ }
+
+ String name = attributeTransformer.get("name").asText();
+
+ if(attributeTransformer.get("transformers") != null &&
attributeTransformer.get("transformers").isArray()) {
+ for(Iterator<JsonNode> k =
attributeTransformer.get("transformers").iterator(); k.hasNext();) {
+ JsonNode transformer = k.next();
+ }
+ }
+ }
+ }
+
+ attributeCount++;
+ }
+
+ Main.log(" Found " + attributeCount + " attributes(s)");
+ }
}
}