From 78edd08f8040efb3fc1064238c336905099e7e60 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 17 May 2017 09:43:31 +0200 Subject: [PATCH] [New] allow to define depth in activity to json --- .../model/json/StrolchElementToJsonVisitor.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java index 423f9b9f1..2ed5aba87 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java @@ -55,6 +55,7 @@ public class StrolchElementToJsonVisitor private boolean withoutElementName; private boolean withVersion; private boolean withoutPolicies; + private int activityDepth = Integer.MAX_VALUE; public StrolchElementToJsonVisitor() { this.ignoredKeys = new MapOfSets<>(); @@ -92,6 +93,11 @@ public class StrolchElementToJsonVisitor return this; } + public StrolchElementToJsonVisitor activityDepth(int depth) { + this.activityDepth = depth; + return this; + } + public StrolchElementToJsonVisitor flat() { this.flat = true; return this; @@ -186,7 +192,7 @@ public class StrolchElementToJsonVisitor protected JsonObject toJson(Activity element) { JsonObject rootJ = new JsonObject(); - return toJson(element, rootJ); + return toJson(element, rootJ, 0); } protected JsonObject toJson(Action element) { @@ -194,7 +200,7 @@ public class StrolchElementToJsonVisitor return toJson(element, rootJ); } - protected JsonObject toJson(Activity element, JsonObject rootJ) { + protected JsonObject toJson(Activity element, JsonObject rootJ, int currentDepth) { rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY); @@ -212,6 +218,9 @@ public class StrolchElementToJsonVisitor if (this.activityHook != null) this.activityHook.accept(element, rootJ); + if (currentDepth >= this.activityDepth) + return rootJ; + Iterator> iter = element.elementIterator(); if (iter.hasNext()) { @@ -225,7 +234,7 @@ public class StrolchElementToJsonVisitor elementsJ.add(elementJ); if (activityElement instanceof Activity) { - toJson((Activity) activityElement, elementJ); + toJson((Activity) activityElement, elementJ, currentDepth + 1); } else if (activityElement instanceof Action) { toJson((Action) activityElement, elementJ); } else {