[New] Added *ToJsonVisitor.flatBagsByType()
This commit is contained in:
parent
3959cf4a26
commit
e13ddba67c
|
@ -46,6 +46,7 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
|
|
||||||
private boolean flat;
|
private boolean flat;
|
||||||
private Set<String> flatBags;
|
private Set<String> flatBags;
|
||||||
|
private Set<String> flatBagsByType;
|
||||||
private boolean withoutElementName;
|
private boolean withoutElementName;
|
||||||
private boolean withLocator;
|
private boolean withLocator;
|
||||||
private boolean withoutVersion;
|
private boolean withoutVersion;
|
||||||
|
@ -58,14 +59,15 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
this.ignoredTimedStates = new HashSet<>();
|
this.ignoredTimedStates = new HashSet<>();
|
||||||
this.ignoredBagTypes = new HashSet<>();
|
this.ignoredBagTypes = new HashSet<>();
|
||||||
this.flatBags = new HashSet<>();
|
this.flatBags = new HashSet<>();
|
||||||
|
this.flatBagsByType = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlat() {
|
public boolean isFlat() {
|
||||||
return this.flat;
|
return this.flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBagFlat(String badId) {
|
public boolean isBagFlat(ParameterBag bag) {
|
||||||
return this.flatBags.contains(badId);
|
return this.flatBags.contains(bag.getId()) || this.flatBagsByType.contains(bag.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithVersion() {
|
public boolean isWithVersion() {
|
||||||
|
@ -152,6 +154,11 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StrolchElementToJsonVisitor flatBagsByType(String... bagTypes) {
|
||||||
|
this.flatBagsByType.addAll(asList(bagTypes));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public StrolchElementToJsonVisitor ignoreBag(String bagId) {
|
public StrolchElementToJsonVisitor ignoreBag(String bagId) {
|
||||||
this.ignoredKeys.addSet(bagId, Collections.emptySet());
|
this.ignoredKeys.addSet(bagId, Collections.emptySet());
|
||||||
return this;
|
return this;
|
||||||
|
@ -174,8 +181,8 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StrolchElementToJsonVisitor ignoreBagByType(String type) {
|
public StrolchElementToJsonVisitor ignoreBagByType(String... types) {
|
||||||
this.ignoredBagTypes.add(type);
|
this.ignoredBagTypes.addAll(asList(types));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +368,7 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
@Override
|
@Override
|
||||||
public JsonObject visitParameterBag(ParameterBag bag) {
|
public JsonObject visitParameterBag(ParameterBag bag) {
|
||||||
|
|
||||||
if (isFlat() || isBagFlat(bag.getId())) {
|
if (isFlat() || isBagFlat(bag)) {
|
||||||
|
|
||||||
JsonObject bagJ = new JsonObject();
|
JsonObject bagJ = new JsonObject();
|
||||||
|
|
||||||
|
@ -563,7 +570,13 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor<JsonEl
|
||||||
if (this.ignoredBagTypes.contains(parameterBag.getType()))
|
if (this.ignoredBagTypes.contains(parameterBag.getType()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isFlat() || isBagFlat(bagId)) {
|
if (isBagFlat(bag)) {
|
||||||
|
|
||||||
|
JsonObject bagJ = new JsonObject();
|
||||||
|
addParameterBagFlat(bagJ, ignoredParamIds, parameterBag);
|
||||||
|
rootJ.add(bagId, bagJ);
|
||||||
|
|
||||||
|
} else if (isFlat()) {
|
||||||
|
|
||||||
addParameterBagFlat(rootJ, ignoredParamIds, parameterBag);
|
addParameterBagFlat(rootJ, ignoredParamIds, parameterBag);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||||
|
|
||||||
public class StrolchRootElementToJsonVisitor implements StrolchRootElementVisitor<JsonObject> {
|
public class StrolchRootElementToJsonVisitor implements StrolchRootElementVisitor<JsonObject> {
|
||||||
|
|
||||||
private StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
private final StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonObject visitOrder(Order order) {
|
public JsonObject visitOrder(Order order) {
|
||||||
|
@ -114,6 +114,11 @@ public class StrolchRootElementToJsonVisitor implements StrolchRootElementVisito
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StrolchRootElementToJsonVisitor flatBagsByType(String... bagTypes) {
|
||||||
|
this.visitor.flatBagsByType(bagTypes);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public StrolchRootElementToJsonVisitor ignoreBag(String bagId) {
|
public StrolchRootElementToJsonVisitor ignoreBag(String bagId) {
|
||||||
this.visitor.ignoreBag(bagId);
|
this.visitor.ignoreBag(bagId);
|
||||||
return this;
|
return this;
|
||||||
|
@ -134,7 +139,7 @@ public class StrolchRootElementToJsonVisitor implements StrolchRootElementVisito
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StrolchRootElementToJsonVisitor ignoreBagByType(String type) {
|
public StrolchRootElementToJsonVisitor ignoreBagByType(String... type) {
|
||||||
this.visitor.ignoreBagByType(type);
|
this.visitor.ignoreBagByType(type);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue