[New] allow to define depth in activity to json
This commit is contained in:
parent
3622339896
commit
78edd08f80
|
@ -55,6 +55,7 @@ public class StrolchElementToJsonVisitor
|
||||||
private boolean withoutElementName;
|
private boolean withoutElementName;
|
||||||
private boolean withVersion;
|
private boolean withVersion;
|
||||||
private boolean withoutPolicies;
|
private boolean withoutPolicies;
|
||||||
|
private int activityDepth = Integer.MAX_VALUE;
|
||||||
|
|
||||||
public StrolchElementToJsonVisitor() {
|
public StrolchElementToJsonVisitor() {
|
||||||
this.ignoredKeys = new MapOfSets<>();
|
this.ignoredKeys = new MapOfSets<>();
|
||||||
|
@ -92,6 +93,11 @@ public class StrolchElementToJsonVisitor
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StrolchElementToJsonVisitor activityDepth(int depth) {
|
||||||
|
this.activityDepth = depth;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public StrolchElementToJsonVisitor flat() {
|
public StrolchElementToJsonVisitor flat() {
|
||||||
this.flat = true;
|
this.flat = true;
|
||||||
return this;
|
return this;
|
||||||
|
@ -186,7 +192,7 @@ public class StrolchElementToJsonVisitor
|
||||||
|
|
||||||
protected JsonObject toJson(Activity element) {
|
protected JsonObject toJson(Activity element) {
|
||||||
JsonObject rootJ = new JsonObject();
|
JsonObject rootJ = new JsonObject();
|
||||||
return toJson(element, rootJ);
|
return toJson(element, rootJ, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JsonObject toJson(Action element) {
|
protected JsonObject toJson(Action element) {
|
||||||
|
@ -194,7 +200,7 @@ public class StrolchElementToJsonVisitor
|
||||||
return toJson(element, rootJ);
|
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);
|
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY);
|
||||||
|
|
||||||
|
@ -212,6 +218,9 @@ public class StrolchElementToJsonVisitor
|
||||||
if (this.activityHook != null)
|
if (this.activityHook != null)
|
||||||
this.activityHook.accept(element, rootJ);
|
this.activityHook.accept(element, rootJ);
|
||||||
|
|
||||||
|
if (currentDepth >= this.activityDepth)
|
||||||
|
return rootJ;
|
||||||
|
|
||||||
Iterator<Entry<String, IActivityElement>> iter = element.elementIterator();
|
Iterator<Entry<String, IActivityElement>> iter = element.elementIterator();
|
||||||
if (iter.hasNext()) {
|
if (iter.hasNext()) {
|
||||||
|
|
||||||
|
@ -225,7 +234,7 @@ public class StrolchElementToJsonVisitor
|
||||||
elementsJ.add(elementJ);
|
elementsJ.add(elementJ);
|
||||||
|
|
||||||
if (activityElement instanceof Activity) {
|
if (activityElement instanceof Activity) {
|
||||||
toJson((Activity) activityElement, elementJ);
|
toJson((Activity) activityElement, elementJ, currentDepth + 1);
|
||||||
} else if (activityElement instanceof Action) {
|
} else if (activityElement instanceof Action) {
|
||||||
toJson((Action) activityElement, elementJ);
|
toJson((Action) activityElement, elementJ);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue