[Major] Total refactoring of StrolchElementVisitor hierarchy
This commit is contained in:
parent
464fa8ac4a
commit
3622339896
|
@ -53,7 +53,7 @@ public class AuditingActivityMap extends AuditingElementMapFacade<Activity> impl
|
|||
DBC.PRE.assertNotNull("activityVisitor on query", activityVisitor);
|
||||
query.setActivityVisitor(activity -> {
|
||||
this.read.add(activity);
|
||||
return activityVisitor.visit(activity);
|
||||
return activity.accept(activityVisitor);
|
||||
});
|
||||
|
||||
return getElementMap().doQuery(tx, query);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class AuditingOrderMap extends AuditingElementMapFacade<Order> implements
|
|||
DBC.PRE.assertNotNull("orderVisitor on query", orderVisitor);
|
||||
query.setOrderVisitor(order -> {
|
||||
this.read.add(order);
|
||||
return orderVisitor.visit(order);
|
||||
return order.accept(orderVisitor);
|
||||
});
|
||||
|
||||
return getElementMap().doQuery(tx, query);
|
||||
|
|
|
@ -22,7 +22,7 @@ import li.strolch.agent.api.ElementMap;
|
|||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.visitor.ResourceVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
|
@ -49,11 +49,11 @@ public class AuditingResourceMap extends AuditingElementMapFacade<Resource> impl
|
|||
|
||||
@Override
|
||||
public <U> List<U> doQuery(StrolchTransaction tx, ResourceQuery<U> query) {
|
||||
ResourceVisitor<U> resourceVisitor = query.getResourceVisitor();
|
||||
StrolchElementVisitor<U> resourceVisitor = query.getResourceVisitor();
|
||||
DBC.PRE.assertNotNull("resourceVisitor on query", resourceVisitor);
|
||||
query.setResourceVisitor(resource -> {
|
||||
this.read.add(resource);
|
||||
return resourceVisitor.visit(resource);
|
||||
return resource.accept(resourceVisitor);
|
||||
});
|
||||
|
||||
return getElementMap().doQuery(tx, query);
|
||||
|
|
|
@ -33,14 +33,14 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
|
||||
private Navigator<T> navigator;
|
||||
private Selector<T> selector;
|
||||
private StrolchElementVisitor<T, U> elementVisitor;
|
||||
private StrolchElementVisitor<U> elementVisitor;
|
||||
private Comparator<T> comparator;
|
||||
|
||||
public InMemoryQuery() {
|
||||
// empty constructor
|
||||
}
|
||||
|
||||
public InMemoryQuery(Navigator<T> navigator, Selector<T> selector, StrolchElementVisitor<T, U> elementVisitor,
|
||||
public InMemoryQuery(Navigator<T> navigator, Selector<T> selector, StrolchElementVisitor<U> elementVisitor,
|
||||
Comparator<T> comparator) {
|
||||
this.navigator = navigator;
|
||||
this.selector = selector;
|
||||
|
@ -68,7 +68,7 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
* @param elementVisitor
|
||||
* the elementVisitor to set
|
||||
*/
|
||||
public void setElementVisitor(StrolchElementVisitor<T, U> elementVisitor) {
|
||||
public void setElementVisitor(StrolchElementVisitor<U> elementVisitor) {
|
||||
this.elementVisitor = elementVisitor;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class InMemoryQuery<T extends StrolchRootElement, U> {
|
|||
while (iter.hasNext()) {
|
||||
T element = iter.next();
|
||||
if (this.selector.select(element)) {
|
||||
U returnValue = this.elementVisitor.visit(element);
|
||||
U returnValue = element.accept(this.elementVisitor);
|
||||
DBC.INTERIM.assertNotNull("Visitor may not return null in query!", returnValue); //$NON-NLS-1$
|
||||
result.add(returnValue);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package li.strolch.model;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import li.strolch.model.json.StrolchElementToFlatJsonVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.xml.StrolchElementToXmlStringVisitor;
|
||||
|
||||
|
@ -21,7 +20,7 @@ public abstract class AbstractStrolchRootElement extends GroupedParameterizedEle
|
|||
|
||||
@Override
|
||||
public String toXmlString() {
|
||||
return this.accept(new StrolchElementToXmlStringVisitor());
|
||||
return accept(new StrolchElementToXmlStringVisitor());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +32,6 @@ public abstract class AbstractStrolchRootElement extends GroupedParameterizedEle
|
|||
@Override
|
||||
public String toFlatJsonString() {
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
return gson.toJson(this.accept(new StrolchElementToFlatJsonVisitor()));
|
||||
return gson.toJson(this.accept(new StrolchElementToJsonVisitor().flat()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import li.strolch.exception.StrolchPolicyException;
|
|||
import li.strolch.model.Locator.LocatorBuilder;
|
||||
import li.strolch.model.policy.PolicyDef;
|
||||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
/**
|
||||
|
@ -188,7 +188,7 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(StrolchRootElementVisitor<T> visitor) {
|
||||
public <T> T accept(StrolchElementVisitor<T> visitor) {
|
||||
return visitor.visitOrder(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import li.strolch.model.policy.PolicyDef;
|
|||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
@ -208,7 +208,7 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(StrolchRootElementVisitor<T> visitor) {
|
||||
public <T> T accept(StrolchElementVisitor<T> visitor) {
|
||||
return visitor.visitResource(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package li.strolch.model;
|
||||
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
|
||||
/**
|
||||
|
@ -68,7 +69,7 @@ public interface StrolchRootElement extends StrolchElement, PolicyContainer, Par
|
|||
*
|
||||
* @return the result of the visitation
|
||||
*/
|
||||
public <T> T accept(StrolchRootElementVisitor<T> visitor);
|
||||
public <T> T accept(StrolchElementVisitor<T> visitor);
|
||||
|
||||
/**
|
||||
* Formats this {@link StrolchRootElement} as an XML string
|
||||
|
|
|
@ -310,6 +310,6 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
|
|||
|
||||
@Override
|
||||
public <T> T accept(IActivityElementVisitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
return visitor.visitAction(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import li.strolch.model.parameter.Parameter;
|
|||
import li.strolch.model.policy.PolicyDef;
|
||||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.visitor.IActivityElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
|
@ -373,13 +373,13 @@ public class Activity extends AbstractStrolchRootElement
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(StrolchRootElementVisitor<T> visitor) {
|
||||
public <T> T accept(StrolchElementVisitor<T> visitor) {
|
||||
return visitor.visitActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(IActivityElementVisitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
return visitor.visitActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.ActivityVisitor;
|
||||
|
||||
public class ActivityToFlatJsonVisitor extends ToFlatJsonVisitor<Activity> implements ActivityVisitor<JsonObject> {
|
||||
|
||||
public ActivityToFlatJsonVisitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityToFlatJsonVisitor withVersion() {
|
||||
super.withVersion();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityToFlatJsonVisitor withoutElementName() {
|
||||
super.withoutElementName();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityToFlatJsonVisitor hook(BiConsumer<Activity, JsonObject> hook) {
|
||||
super.hook(hook);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityToFlatJsonVisitor ignoreBag(String bagId) {
|
||||
super.ignoreBag(bagId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityToFlatJsonVisitor ignoreParameter(String bagId, String paramId) {
|
||||
super.ignoreParameter(bagId, paramId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Activity element) {
|
||||
JsonObject jsonObject = toJson(element);
|
||||
jsonObject.addProperty(Tags.Json.STATE, element.getState().getName());
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.ActivityVisitor;
|
||||
|
||||
public class ActivityToJsonVisitor extends StrolchElementToJsonVisitor implements ActivityVisitor<JsonObject> {
|
||||
|
||||
private JsonObject jsonObject;
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Activity element) {
|
||||
this.jsonObject = toJson(element);
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
public static String toJsonString(Activity element) {
|
||||
ActivityToJsonVisitor visitor = new ActivityToJsonVisitor();
|
||||
JsonObject jsonObject = visitor.visit(element);
|
||||
String entity = new Gson().toJson(jsonObject);
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.visitor.OrderVisitor;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
public class OrderToFlatJsonVisitor extends ToFlatJsonVisitor<Order> implements OrderVisitor<JsonObject> {
|
||||
|
||||
public OrderToFlatJsonVisitor() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderToFlatJsonVisitor withVersion() {
|
||||
super.withVersion();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderToFlatJsonVisitor withoutElementName() {
|
||||
super.withoutElementName();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderToFlatJsonVisitor hook(BiConsumer<Order, JsonObject> hook) {
|
||||
super.hook(hook);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderToFlatJsonVisitor ignoreBag(String bagId) {
|
||||
super.ignoreBag(bagId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderToFlatJsonVisitor ignoreParameter(String bagId, String paramId) {
|
||||
super.ignoreParameter(bagId, paramId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Order element) {
|
||||
JsonObject jsonObject = toJson(element);
|
||||
|
||||
jsonObject.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(element.getDate()));
|
||||
jsonObject.addProperty(Tags.Json.STATE, element.getState().getName());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.visitor.OrderVisitor;
|
||||
|
||||
public class OrderToJsonVisitor extends StrolchElementToJsonVisitor implements OrderVisitor<JsonObject> {
|
||||
|
||||
private JsonObject jsonObject;
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Order element) {
|
||||
this.jsonObject = toJson(element);
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
public static String toJsonString(Order element) {
|
||||
OrderToJsonVisitor visitor = new OrderToJsonVisitor();
|
||||
JsonObject jsonObject = visitor.visit(element);
|
||||
String entity = new Gson().toJson(jsonObject);
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.exception.StrolchModelException;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.ITimeVariable;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.visitor.ResourceVisitor;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
public class ResourceToFlatJsonVisitor extends ToFlatJsonVisitor<Resource> implements ResourceVisitor<JsonObject> {
|
||||
|
||||
private Set<String> ignoredStates;
|
||||
private boolean withoutTimedStates;
|
||||
|
||||
public ResourceToFlatJsonVisitor() {
|
||||
super();
|
||||
this.ignoredStates = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceToFlatJsonVisitor withVersion() {
|
||||
super.withVersion();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceToFlatJsonVisitor withoutTimedStates() {
|
||||
this.withoutTimedStates = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceToFlatJsonVisitor withoutElementName() {
|
||||
super.withoutElementName();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceToFlatJsonVisitor hook(BiConsumer<Resource, JsonObject> hook) {
|
||||
super.hook(hook);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceToFlatJsonVisitor ignoreBag(String bagId) {
|
||||
super.ignoreBag(bagId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceToFlatJsonVisitor ignoreParameter(String bagId, String paramId) {
|
||||
super.ignoreParameter(bagId, paramId);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Resource element) {
|
||||
if (this.withoutTimedStates || !element.hasTimedStates())
|
||||
return toJson(element);
|
||||
|
||||
JsonObject jsonObject = toJson(element);
|
||||
addStates(element, jsonObject);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
private void addStates(Resource element, JsonObject jsonObject) {
|
||||
for (String stateKey : element.getTimedStateKeySet()) {
|
||||
|
||||
// see if we have to ignore this state
|
||||
if (this.ignoredStates.contains(stateKey))
|
||||
continue;
|
||||
|
||||
// get values
|
||||
StrolchTimedState<IValue<?>> stateT = element.getTimedState(stateKey);
|
||||
ITimeVariable<IValue<?>> timeEvolution = stateT.getTimeEvolution();
|
||||
|
||||
if (jsonObject.has(stateKey)) {
|
||||
throw new StrolchModelException(
|
||||
"JsonObject already has a member with ID " + stateKey + ": " + stateT.getLocator());
|
||||
}
|
||||
|
||||
// build JSON data
|
||||
JsonArray arrayJ = new JsonArray();
|
||||
for (ITimeValue<IValue<?>> v : timeEvolution.getValues()) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(v.getTime()));
|
||||
obj.addProperty(Tags.Json.VALUE, v.getValue().getValueAsString());
|
||||
|
||||
arrayJ.add(obj);
|
||||
}
|
||||
|
||||
jsonObject.add(stateKey, arrayJ);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.visitor.ResourceVisitor;
|
||||
|
||||
public class ResourceToJsonVisitor extends StrolchElementToJsonVisitor implements ResourceVisitor<JsonObject> {
|
||||
|
||||
private JsonObject jsonObject;
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visit(Resource element) {
|
||||
this.jsonObject = toJson(element);
|
||||
return this.jsonObject;
|
||||
}
|
||||
|
||||
public static String toJsonString(Resource element) {
|
||||
ResourceToJsonVisitor visitor = new ResourceToJsonVisitor();
|
||||
JsonObject jsonObject = visitor.visit(element);
|
||||
String entity = new Gson().toJson(jsonObject);
|
||||
return entity;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
|
||||
public class StrolchElementToFlatJsonVisitor implements StrolchRootElementVisitor<JsonObject> {
|
||||
|
||||
@Override
|
||||
public JsonObject visitOrder(Order order) {
|
||||
return new OrderToFlatJsonVisitor().toJson(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visitResource(Resource resource) {
|
||||
return new ResourceToFlatJsonVisitor().toJson(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visitActivity(Activity activity) {
|
||||
return new ActivityToFlatJsonVisitor().toJson(activity);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,18 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.exception.StrolchModelException;
|
||||
import li.strolch.model.AbstractStrolchElement;
|
||||
import li.strolch.model.GroupedParameterizedElement;
|
||||
import li.strolch.model.Order;
|
||||
|
@ -16,6 +21,7 @@ import li.strolch.model.PolicyContainer;
|
|||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.StrolchModelConstants;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.StrolchValueType;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.Version;
|
||||
import li.strolch.model.activity.Action;
|
||||
|
@ -26,12 +32,100 @@ import li.strolch.model.policy.PolicyDef;
|
|||
import li.strolch.model.policy.PolicyDefs;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.ITimeValue;
|
||||
import li.strolch.model.timevalue.ITimeVariable;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.timevalue.IValueChange;
|
||||
import li.strolch.model.visitor.IActivityElementVisitor;
|
||||
import li.strolch.model.visitor.StrolchRootElementVisitor;
|
||||
import li.strolch.utils.collections.MapOfSets;
|
||||
import li.strolch.utils.iso8601.ISO8601FormatFactory;
|
||||
|
||||
public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<JsonObject> {
|
||||
public class StrolchElementToJsonVisitor
|
||||
implements StrolchRootElementVisitor<JsonObject>, IActivityElementVisitor<JsonObject> {
|
||||
|
||||
private MapOfSets<String, String> ignoredKeys;
|
||||
private Set<String> ignoredStates;
|
||||
|
||||
private BiConsumer<Resource, JsonObject> resourceHook;
|
||||
private BiConsumer<Order, JsonObject> orderHook;
|
||||
private BiConsumer<Activity, JsonObject> activityHook;
|
||||
private BiConsumer<Action, JsonObject> actionHook;
|
||||
|
||||
private boolean flat;
|
||||
private boolean withoutElementName;
|
||||
private boolean withVersion;
|
||||
private boolean withoutPolicies;
|
||||
|
||||
public StrolchElementToJsonVisitor() {
|
||||
this.ignoredKeys = new MapOfSets<>();
|
||||
this.ignoredStates = new HashSet<>();
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return this.flat;
|
||||
}
|
||||
|
||||
public boolean isWithVersion() {
|
||||
return this.withVersion;
|
||||
}
|
||||
|
||||
public boolean isWithoutElementName() {
|
||||
return this.withoutElementName;
|
||||
}
|
||||
|
||||
public boolean isWithoutPolicies() {
|
||||
return this.withoutPolicies;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor withVersion() {
|
||||
this.withVersion = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor withoutElementName() {
|
||||
this.withoutElementName = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor withoutPolicies() {
|
||||
this.withoutPolicies = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor flat() {
|
||||
this.flat = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor ignoreBag(String bagId) {
|
||||
this.ignoredKeys.addSet(bagId, Collections.emptySet());
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor ignoreParameter(String bagId, String paramId) {
|
||||
this.ignoredKeys.addElement(bagId, paramId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor resourceHook(BiConsumer<Resource, JsonObject> hook) {
|
||||
this.resourceHook = hook;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor orderHook(BiConsumer<Order, JsonObject> hook) {
|
||||
this.orderHook = hook;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor activityHook(BiConsumer<Activity, JsonObject> hook) {
|
||||
this.activityHook = hook;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StrolchElementToJsonVisitor actionHook(BiConsumer<Action, JsonObject> hook) {
|
||||
this.actionHook = hook;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visitResource(Resource resource) {
|
||||
|
@ -48,6 +142,11 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
return toJson(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject visitAction(Action action) {
|
||||
return toJson(action);
|
||||
}
|
||||
|
||||
protected JsonObject toJson(Resource element) {
|
||||
|
||||
JsonObject rootJ = new JsonObject();
|
||||
|
@ -56,10 +155,13 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
toJson(element, rootJ);
|
||||
|
||||
addVersion(element, rootJ);
|
||||
addParameterBags(element, rootJ);
|
||||
addTimedStates(element, rootJ);
|
||||
addParameters(element, rootJ);
|
||||
addStates(element, rootJ);
|
||||
addPolicies(element, rootJ);
|
||||
|
||||
if (this.resourceHook != null)
|
||||
this.resourceHook.accept(element, rootJ);
|
||||
|
||||
return rootJ;
|
||||
}
|
||||
|
||||
|
@ -73,15 +175,17 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
rootJ.addProperty(Tags.Json.STATE, element.getState().getName());
|
||||
|
||||
addVersion(element, rootJ);
|
||||
addParameterBags(element, rootJ);
|
||||
addParameters(element, rootJ);
|
||||
addPolicies(element, rootJ);
|
||||
|
||||
if (this.orderHook != null)
|
||||
this.orderHook.accept(element, rootJ);
|
||||
|
||||
return rootJ;
|
||||
}
|
||||
|
||||
protected JsonObject toJson(Activity element) {
|
||||
JsonObject rootJ = new JsonObject();
|
||||
addVersion(element, rootJ);
|
||||
return toJson(element, rootJ);
|
||||
}
|
||||
|
||||
|
@ -94,16 +198,20 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
|
||||
rootJ.addProperty(Tags.Json.OBJECT_TYPE, Tags.Json.ACTIVITY);
|
||||
|
||||
toJson((AbstractStrolchElement) element, rootJ);
|
||||
rootJ.addProperty(Tags.Json.TIME_ORDERING, element.getTimeOrdering().getName());
|
||||
rootJ.addProperty(Tags.Json.STATE, element.getState().getName());
|
||||
rootJ.addProperty(Tags.Json.START, formatDate(element.getStart()));
|
||||
rootJ.addProperty(Tags.Json.END, formatDate(element.getEnd()));
|
||||
|
||||
toJson((AbstractStrolchElement) element, rootJ);
|
||||
|
||||
addParameterBags(element, rootJ);
|
||||
if (element.isRootElement())
|
||||
addVersion(element, rootJ);
|
||||
addParameters(element, rootJ);
|
||||
addPolicies(element, rootJ);
|
||||
|
||||
if (this.activityHook != null)
|
||||
this.activityHook.accept(element, rootJ);
|
||||
|
||||
Iterator<Entry<String, IActivityElement>> iter = element.elementIterator();
|
||||
if (iter.hasNext()) {
|
||||
|
||||
|
@ -141,9 +249,12 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
rootJ.addProperty(Tags.Json.START, formatDate(element.getStart()));
|
||||
rootJ.addProperty(Tags.Json.END, formatDate(element.getEnd()));
|
||||
|
||||
addParameterBags(element, rootJ);
|
||||
addParameters(element, rootJ);
|
||||
addPolicies(element, rootJ);
|
||||
|
||||
if (this.actionHook != null)
|
||||
this.actionHook.accept(element, rootJ);
|
||||
|
||||
// value changes
|
||||
Iterator<IValueChange<? extends IValue<?>>> iter = element.getChanges().iterator();
|
||||
if (iter.hasNext()) {
|
||||
|
@ -171,6 +282,8 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
protected void addPolicies(PolicyContainer policyContainer, JsonObject rootJ) {
|
||||
if (!policyContainer.hasPolicyDefs() || !policyContainer.getPolicyDefs().hasPolicyDefs())
|
||||
return;
|
||||
if (isWithoutPolicies())
|
||||
return;
|
||||
|
||||
PolicyDefs policyDefs = policyContainer.getPolicyDefs();
|
||||
|
||||
|
@ -186,13 +299,61 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
protected JsonObject toJson(AbstractStrolchElement element, JsonObject rootJ) {
|
||||
|
||||
rootJ.addProperty(Tags.Json.ID, element.getId());
|
||||
rootJ.addProperty(Tags.Json.NAME, element.getName());
|
||||
|
||||
if (!isWithoutElementName())
|
||||
rootJ.addProperty(Tags.Json.NAME, element.getName());
|
||||
|
||||
rootJ.addProperty(Tags.Json.TYPE, element.getType());
|
||||
|
||||
return rootJ;
|
||||
}
|
||||
|
||||
protected void addParameterBags(GroupedParameterizedElement element, JsonObject rootJ) {
|
||||
protected void addParameters(GroupedParameterizedElement element, JsonObject rootJ) {
|
||||
if (isFlat())
|
||||
addParametersFlat(element, rootJ);
|
||||
else
|
||||
addParameterFull(element, rootJ);
|
||||
}
|
||||
|
||||
protected void addParametersFlat(GroupedParameterizedElement element, JsonObject rootJ) {
|
||||
|
||||
Set<String> bagKeySet = element.getParameterBagKeySet();
|
||||
for (String bagId : bagKeySet) {
|
||||
|
||||
// see if we have to ignore this bag i.e. empty set existing
|
||||
Set<String> ignoredParamIds = this.ignoredKeys.getSet(bagId);
|
||||
if (ignoredParamIds != null && ignoredParamIds.isEmpty())
|
||||
continue;
|
||||
|
||||
ParameterBag parameterBag = element.getParameterBag(bagId);
|
||||
|
||||
Set<String> parameterKeySet = parameterBag.getParameterKeySet();
|
||||
for (String paramId : parameterKeySet) {
|
||||
|
||||
// see if this parameter must be ignored
|
||||
if (ignoredParamIds != null && ignoredParamIds.contains(paramId))
|
||||
continue;
|
||||
|
||||
if (rootJ.has(paramId)) {
|
||||
throw new StrolchModelException(
|
||||
"JsonObject already has a member with ID " + paramId + ": " + parameterBag.getLocator());
|
||||
}
|
||||
|
||||
Parameter<?> param = parameterBag.getParameter(paramId);
|
||||
|
||||
StrolchValueType type = StrolchValueType.parse(param.getType());
|
||||
if (type.isBoolean()) {
|
||||
rootJ.addProperty(paramId, (Boolean) param.getValue());
|
||||
} else if (type.isNumber()) {
|
||||
rootJ.addProperty(paramId, (Number) param.getValue());
|
||||
} else {
|
||||
rootJ.addProperty(paramId, param.getValueAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addParameterFull(GroupedParameterizedElement element, JsonObject rootJ) {
|
||||
|
||||
if (!element.hasParameterBags())
|
||||
return;
|
||||
|
@ -239,7 +400,14 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
}
|
||||
}
|
||||
|
||||
protected void addTimedStates(Resource element, JsonObject rootJ) {
|
||||
protected void addStates(Resource resource, JsonObject rootJ) {
|
||||
if (isFlat())
|
||||
addTimedStatesFlat(resource, rootJ);
|
||||
else
|
||||
addTimedStatesFull(resource, rootJ);
|
||||
}
|
||||
|
||||
protected void addTimedStatesFull(Resource element, JsonObject rootJ) {
|
||||
|
||||
if (!element.hasTimedStates())
|
||||
return;
|
||||
|
@ -248,6 +416,11 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
rootJ.add(Tags.Json.TIMED_STATES, timedStatesJ);
|
||||
|
||||
for (String stateKey : element.getTimedStateKeySet()) {
|
||||
|
||||
// see if we have to ignore this state
|
||||
if (this.ignoredStates.contains(stateKey))
|
||||
continue;
|
||||
|
||||
StrolchTimedState<IValue<?>> state = element.getTimedState(stateKey);
|
||||
|
||||
JsonObject stateJ = new JsonObject();
|
||||
|
@ -273,9 +446,45 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
}
|
||||
}
|
||||
|
||||
public static void addVersion(StrolchRootElement element, JsonObject rootJ) {
|
||||
private void addTimedStatesFlat(Resource element, JsonObject jsonObject) {
|
||||
|
||||
if (!element.hasTimedStates())
|
||||
return;
|
||||
|
||||
for (String stateKey : element.getTimedStateKeySet()) {
|
||||
|
||||
// see if we have to ignore this state
|
||||
if (this.ignoredStates.contains(stateKey))
|
||||
continue;
|
||||
|
||||
// get values
|
||||
StrolchTimedState<IValue<?>> stateT = element.getTimedState(stateKey);
|
||||
ITimeVariable<IValue<?>> timeEvolution = stateT.getTimeEvolution();
|
||||
|
||||
if (jsonObject.has(stateKey)) {
|
||||
throw new StrolchModelException(
|
||||
"JsonObject already has a member with ID " + stateKey + ": " + stateT.getLocator());
|
||||
}
|
||||
|
||||
// build JSON data
|
||||
JsonArray arrayJ = new JsonArray();
|
||||
for (ITimeValue<IValue<?>> v : timeEvolution.getValues()) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(v.getTime()));
|
||||
obj.addProperty(Tags.Json.VALUE, v.getValue().getValueAsString());
|
||||
|
||||
arrayJ.add(obj);
|
||||
}
|
||||
|
||||
jsonObject.add(stateKey, arrayJ);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addVersion(StrolchRootElement element, JsonObject rootJ) {
|
||||
if (!element.hasVersion())
|
||||
return;
|
||||
if (!isWithVersion())
|
||||
return;
|
||||
|
||||
Version version = element.getVersion();
|
||||
|
||||
|
@ -286,7 +495,6 @@ public class StrolchElementToJsonVisitor implements StrolchRootElementVisitor<Js
|
|||
versionJ.addProperty(Tags.Json.DELETED, version.isDeleted());
|
||||
rootJ.add(Tags.Json.VERSION, versionJ);
|
||||
}
|
||||
|
||||
|
||||
private static String formatDate(Date date) {
|
||||
return ISO8601FormatFactory.getInstance().formatDate(date);
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
package li.strolch.model.json;
|
||||
|
||||
import static li.strolch.model.Tags.Json.ID;
|
||||
import static li.strolch.model.Tags.Json.NAME;
|
||||
import static li.strolch.model.Tags.Json.OBJECT_TYPE;
|
||||
import static li.strolch.model.Tags.Json.TYPE;
|
||||
import static li.strolch.model.json.StrolchElementToJsonVisitor.addVersion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.exception.StrolchModelException;
|
||||
import li.strolch.model.ParameterBag;
|
||||
import li.strolch.model.StrolchRootElement;
|
||||
import li.strolch.model.StrolchValueType;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.utils.collections.MapOfSets;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Maps a given {@link StrolchRootElement} to a {@link JsonObject}. All {@link Parameter Parameters} are mapped to a
|
||||
* member of the {@link JsonObject}, {@link ParameterBag ParameterBags} are thus removed
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* To ignore {@link Parameter Parameters} or {@link ParameterBag ParameterBags} use the
|
||||
* {@link #ignoreParameter(String, String)} and {@link #ignoreBag(String)} methods
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The mapping can be extended by setting hook:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* visitor.setHook((element, jsonObject) -> {
|
||||
* // do work
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ToFlatJsonVisitor<T extends StrolchRootElement> {
|
||||
|
||||
private MapOfSets<String, String> ignoredKeys;
|
||||
private BiConsumer<T, JsonObject> hook;
|
||||
private boolean withoutElementName;
|
||||
private boolean withVersion;
|
||||
|
||||
public ToFlatJsonVisitor() {
|
||||
this.ignoredKeys = new MapOfSets<>();
|
||||
}
|
||||
|
||||
public boolean isWithVersion() {
|
||||
return this.withVersion;
|
||||
}
|
||||
|
||||
public boolean isWithoutElementName() {
|
||||
return this.withoutElementName;
|
||||
}
|
||||
|
||||
public ToFlatJsonVisitor<T> withVersion() {
|
||||
this.withVersion = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToFlatJsonVisitor<T> withoutElementName() {
|
||||
this.withoutElementName = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToFlatJsonVisitor<T> hook(BiConsumer<T, JsonObject> hook) {
|
||||
this.hook = hook;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToFlatJsonVisitor<T> ignoreBag(String bagId) {
|
||||
this.ignoredKeys.addSet(bagId, Collections.emptySet());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToFlatJsonVisitor<T> ignoreParameter(String bagId, String paramId) {
|
||||
this.ignoredKeys.addElement(bagId, paramId);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected JsonObject toJson(T element) {
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
jsonObject.addProperty(ID, element.getId());
|
||||
if (!this.withoutElementName)
|
||||
jsonObject.addProperty(NAME, element.getName());
|
||||
jsonObject.addProperty(TYPE, element.getType());
|
||||
jsonObject.addProperty(OBJECT_TYPE, element.getClass().getSimpleName());
|
||||
|
||||
Set<String> bagKeySet = element.getParameterBagKeySet();
|
||||
for (String bagId : bagKeySet) {
|
||||
|
||||
// see if we have to ignore this bag i.e. empty set existing
|
||||
Set<String> ignoredParamIds = this.ignoredKeys.getSet(bagId);
|
||||
if (ignoredParamIds != null && ignoredParamIds.isEmpty())
|
||||
continue;
|
||||
|
||||
ParameterBag parameterBag = element.getParameterBag(bagId);
|
||||
|
||||
Set<String> parameterKeySet = parameterBag.getParameterKeySet();
|
||||
for (String paramId : parameterKeySet) {
|
||||
|
||||
// see if this parameter must be ignored
|
||||
if (ignoredParamIds != null && ignoredParamIds.contains(paramId))
|
||||
continue;
|
||||
|
||||
if (jsonObject.has(paramId)) {
|
||||
throw new StrolchModelException(
|
||||
"JsonObject already has a member with ID " + paramId + ": " + parameterBag.getLocator());
|
||||
}
|
||||
|
||||
Parameter<?> param = parameterBag.getParameter(paramId);
|
||||
|
||||
StrolchValueType type = StrolchValueType.parse(param.getType());
|
||||
if (type.isBoolean()) {
|
||||
jsonObject.addProperty(paramId, (Boolean) param.getValue());
|
||||
} else if (type.isNumber()) {
|
||||
jsonObject.addProperty(paramId, (Number) param.getValue());
|
||||
} else {
|
||||
jsonObject.addProperty(paramId, param.getValueAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hook != null)
|
||||
this.hook.accept(element, jsonObject);
|
||||
|
||||
if (this.withVersion)
|
||||
addVersion(element, jsonObject);
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import li.strolch.model.activity.Action;
|
|||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.query.ordering.StrolchQueryOrdering;
|
||||
import li.strolch.model.visitor.ActivityVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +74,12 @@ public class ActivityQuery<U> extends StrolchElementQuery<ActivityQueryVisitor>
|
|||
return this;
|
||||
}
|
||||
|
||||
public ActivityQuery<U> setVisitor(StrolchElementVisitor<U> visitor) {
|
||||
DBC.PRE.assertNotNull("visitor", visitor);
|
||||
this.activityVisitor = visitor.asActivityVisitor();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityQuery<U> setActivityVisitor(ActivityVisitor<U> activityVisitor) {
|
||||
DBC.PRE.assertNotNull("activityVisitor", activityVisitor);
|
||||
this.activityVisitor = activityVisitor;
|
||||
|
|
|
@ -19,6 +19,7 @@ import li.strolch.model.Order;
|
|||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ordering.StrolchQueryOrdering;
|
||||
import li.strolch.model.visitor.OrderVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +74,12 @@ public class OrderQuery<U> extends StrolchElementQuery<OrderQueryVisitor> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public OrderQuery<U> setVisitor(StrolchElementVisitor<U> visitor) {
|
||||
DBC.PRE.assertNotNull("visitor", visitor);
|
||||
this.orderVisitor = visitor.asOrderVisitor();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrderQuery<U> setOrderVisitor(OrderVisitor<U> orderVisitor) {
|
||||
DBC.PRE.assertNotNull("orderVisitor", orderVisitor);
|
||||
this.orderVisitor = orderVisitor;
|
||||
|
|
|
@ -19,6 +19,7 @@ import li.strolch.model.Resource;
|
|||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.query.ordering.StrolchQueryOrdering;
|
||||
import li.strolch.model.visitor.ResourceVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementVisitor;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +74,12 @@ public class ResourceQuery<U> extends StrolchElementQuery<ResourceQueryVisitor>
|
|||
return this;
|
||||
}
|
||||
|
||||
public ResourceQuery<U> setVisitor(StrolchElementVisitor<U> visitor) {
|
||||
DBC.PRE.assertNotNull("visitor", visitor);
|
||||
this.resourceVisitor = visitor.asResourceVisitor();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceQuery<U> setResourceVisitor(ResourceVisitor<U> resourceVisitor) {
|
||||
DBC.PRE.assertNotNull("resourceVisitor", resourceVisitor);
|
||||
this.resourceVisitor = resourceVisitor;
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ActivityDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements
|
||||
ActivityVisitor<List<Locator>> {
|
||||
|
||||
private Activity sourceActivity;
|
||||
|
||||
public ActivityDeepEqualsVisitor(Activity sourceActivity) {
|
||||
this.sourceActivity = sourceActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visit(Activity dstActivity) {
|
||||
deepEquals(this.sourceActivity, dstActivity);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
}
|
|
@ -15,14 +15,28 @@
|
|||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Action;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
* @param <U>
|
||||
*/
|
||||
public interface ActivityVisitor<U> extends StrolchElementVisitor<Activity, U> {
|
||||
public interface ActivityVisitor<U> extends StrolchElementVisitor<U> {
|
||||
|
||||
@Override
|
||||
public U visit(Activity element);
|
||||
public default U visitAction(Action action) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + action.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitOrder(Order order) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + order.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitResource(Resource resource) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + resource.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
|
||||
public interface IActivityElementVisitor<T> {
|
||||
public interface IActivityElementVisitor<T> extends StrolchElementVisitor<T> {
|
||||
|
||||
public T visit(Activity activity);
|
||||
@Override
|
||||
public default T visitOrder(Order order) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + order.getClass());
|
||||
}
|
||||
|
||||
public T visit(Action action);
|
||||
@Override
|
||||
public default T visitResource(Resource resource) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + resource.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2015 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyActivityVisitor implements ActivityVisitor<Activity> {
|
||||
|
||||
@Override
|
||||
public Activity visit(Activity element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyOrderVisitor implements OrderVisitor<Order> {
|
||||
|
||||
@Override
|
||||
public Order visit(Order element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyResourceVisitor implements ResourceVisitor<Resource> {
|
||||
|
||||
@Override
|
||||
public Resource visit(Resource element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyVisitor<T extends StrolchElement> implements StrolchElementVisitor<T, T> {
|
||||
|
||||
@Override
|
||||
public T visit(T element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Order;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements OrderVisitor<List<Locator>> {
|
||||
|
||||
private Order srcOrder;
|
||||
|
||||
public OrderDeepEqualsVisitor(Order srcOrder) {
|
||||
this.srcOrder = srcOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visit(Order dstOrder) {
|
||||
deepEquals(this.srcOrder, dstOrder);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
}
|
|
@ -15,13 +15,27 @@
|
|||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface OrderVisitor<U> extends StrolchElementVisitor<Order, U> {
|
||||
public interface OrderVisitor<U> extends StrolchElementVisitor<U> {
|
||||
|
||||
@Override
|
||||
public U visit(Order element);
|
||||
public default U visitAction(Action action) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + action.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitActivity(Activity activity) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + activity.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitResource(Resource resource) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + resource.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.Locator;
|
||||
import li.strolch.model.Resource;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements
|
||||
ResourceVisitor<List<Locator>> {
|
||||
|
||||
private Resource srcRes;
|
||||
|
||||
public ResourceDeepEqualsVisitor(Resource sourceRes) {
|
||||
this.srcRes = sourceRes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visit(Resource dstRes) {
|
||||
deepEquals(this.srcRes, dstRes);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
}
|
|
@ -15,14 +15,28 @@
|
|||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
* @param <U>
|
||||
*/
|
||||
public interface ResourceVisitor<U> extends StrolchElementVisitor<Resource, U> {
|
||||
public interface ResourceVisitor<U> extends StrolchElementVisitor<U> {
|
||||
|
||||
@Override
|
||||
public U visit(Resource element);
|
||||
public default U visitAction(Action action) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + action.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitActivity(Activity activity) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + activity.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitOrder(Order order) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + order.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,11 +47,13 @@ import li.strolch.utils.dbc.DBC;
|
|||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class StrolchElementDeepEqualsVisitor {
|
||||
public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor<List<Locator>> {
|
||||
|
||||
private List<Locator> mismatchedLocators;
|
||||
private StrolchElement srcElement;
|
||||
|
||||
public StrolchElementDeepEqualsVisitor() {
|
||||
public StrolchElementDeepEqualsVisitor(StrolchElement srcElement) {
|
||||
this.srcElement = srcElement;
|
||||
this.mismatchedLocators = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@ -335,20 +337,42 @@ public class StrolchElementDeepEqualsVisitor {
|
|||
}
|
||||
|
||||
public static boolean isEqual(Order srcOrder, Order dstOrder) {
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||
visitor.visit(dstOrder);
|
||||
return visitor.isEqual();
|
||||
return srcOrder.accept(new StrolchElementDeepEqualsVisitor(dstOrder)).isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isEqual(Resource srcRes, Resource dstRes) {
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
return visitor.isEqual();
|
||||
return srcRes.accept(new StrolchElementDeepEqualsVisitor(dstRes)).isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isEqual(Activity srcAct, Activity dstAct) {
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(srcAct);
|
||||
visitor.visit(dstAct);
|
||||
return visitor.isEqual();
|
||||
return srcAct.accept(new StrolchElementDeepEqualsVisitor(dstAct)).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitOrder(Order order) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), order.getClass());
|
||||
deepEquals((Order) this.srcElement, order);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitResource(Resource resource) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), resource.getClass());
|
||||
deepEquals((Resource) this.srcElement, resource);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitActivity(Activity activity) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), activity.getClass());
|
||||
deepEquals((Activity) this.srcElement, activity);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Locator> visitAction(Action action) {
|
||||
DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), action.getClass());
|
||||
deepEquals((Action) this.srcElement, action);
|
||||
return getMismatchedLocators();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,33 @@
|
|||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface StrolchElementVisitor<T extends StrolchElement, U> extends StrolchVisitor {
|
||||
public interface StrolchElementVisitor<T> extends StrolchVisitor {
|
||||
|
||||
public U visit(T element);
|
||||
public T visitOrder(Order order);
|
||||
|
||||
public T visitResource(Resource resource);
|
||||
|
||||
public T visitActivity(Activity activity);
|
||||
|
||||
public T visitAction(Action action);
|
||||
|
||||
public default ResourceVisitor<T> asResourceVisitor() {
|
||||
return resource -> this.visitResource(resource);
|
||||
}
|
||||
|
||||
public default OrderVisitor<T> asOrderVisitor() {
|
||||
return order -> this.visitOrder(order);
|
||||
}
|
||||
|
||||
public default ActivityVisitor<T> asActivityVisitor() {
|
||||
return activity -> this.visitActivity(activity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,16 +17,22 @@ package li.strolch.model.visitor;
|
|||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Action;
|
||||
import li.strolch.model.activity.Activity;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public interface StrolchRootElementVisitor<T> extends StrolchVisitor {
|
||||
public interface StrolchRootElementVisitor<T> extends StrolchElementVisitor<T> {
|
||||
|
||||
public T visitOrder(Order order);
|
||||
|
||||
public T visitResource(Resource resource);
|
||||
|
||||
public T visitActivity(Activity activity);
|
||||
|
||||
@Override
|
||||
public default T visitAction(Action action) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + action.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,9 +96,7 @@ import li.strolch.model.timevalue.IValueChange;
|
|||
import li.strolch.model.timevalue.impl.BooleanValue;
|
||||
import li.strolch.model.timevalue.impl.IntegerValue;
|
||||
import li.strolch.model.timevalue.impl.ValueChange;
|
||||
import li.strolch.model.visitor.ActivityDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class ModelTest {
|
||||
|
@ -242,18 +240,18 @@ public class ModelTest {
|
|||
public void shouldPerformDeepActivityEquals() {
|
||||
Activity srcActivity = createActivity("@act01", "Test Activity", "MyType", TimeOrdering.SERIES);
|
||||
Activity dstActivity = createActivity("@act01", "Test Activity", "MyType", TimeOrdering.SERIES);
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(srcActivity);
|
||||
visitor.visit(dstActivity);
|
||||
assertTrue("Same Activity should be deep equal!", visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcActivity);
|
||||
List<Locator> mismatches = dstActivity.accept(visitor);
|
||||
assertTrue("Same Activity should be deep equal!", mismatches.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformActivityClone() {
|
||||
Activity srcActivity = createActivity("@act01", "Test Activity", "MyType", TimeOrdering.SERIES);
|
||||
Activity dstActivity = srcActivity.getClone();
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(srcActivity);
|
||||
visitor.visit(dstActivity);
|
||||
assertTrue("Cloned Activity should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcActivity);
|
||||
List<Locator> mismatches = dstActivity.accept(visitor);
|
||||
assertTrue("Cloned Activity should be deep equal: " + mismatches, mismatches.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -267,10 +265,10 @@ public class ModelTest {
|
|||
FloatParameter fParam = bag.getParameter(PARAM_FLOAT_ID);
|
||||
fParam.setValue(23434234.234);
|
||||
fParam.setName("Ohla");
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(srcActivity);
|
||||
visitor.visit(dstActivity);
|
||||
assertFalse("Activity should not be same if something has been changed", visitor.isEqual());
|
||||
assertEquals("Multiple changes should be registered", 6, visitor.getMismatchedLocators().size());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcActivity);
|
||||
List<Locator> mismatches = dstActivity.accept(visitor);
|
||||
assertFalse("Activity should not be same if something has been changed", mismatches.isEmpty());
|
||||
assertEquals("Multiple changes should be registered", 6, mismatches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -297,28 +295,28 @@ public class ModelTest {
|
|||
action = activity.getElement("action1_" + "@act01");
|
||||
action.addChange(new ValueChange<>(1234567890L, new IntegerValue(12345), STATE_INTEGER_ID));
|
||||
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(srcActivity);
|
||||
visitor.visit(dstActivity);
|
||||
assertFalse("Activity should not be same if something has been changed", visitor.isEqual());
|
||||
assertEquals("Multiple changes should be registered", 9, visitor.getMismatchedLocators().size());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcActivity);
|
||||
List<Locator> mismatches = dstActivity.accept(visitor);
|
||||
assertFalse("Activity should not be same if something has been changed", mismatches.isEmpty());
|
||||
assertEquals("Multiple changes should be registered", 9, mismatches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformDeepResourceEquals() {
|
||||
Resource srcRes = createResource("@res01", "Test resource", "MyType");
|
||||
Resource dstRes = createResource("@res01", "Test resource", "MyType");
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
assertTrue("Same Resource should be deep equal!", visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes);
|
||||
List<Locator> mismatches = dstRes.accept(visitor);
|
||||
assertTrue("Same Resource should be deep equal!", mismatches.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformResourceClone() {
|
||||
Resource srcRes = createResource("@res01", "Test resource", "MyType");
|
||||
Resource dstRes = srcRes.getClone();
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
assertTrue("Cloned Resource should be deep equal!", visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes);
|
||||
List<Locator> mismatches = dstRes.accept(visitor);
|
||||
assertTrue("Cloned Resource should be deep equal!", mismatches.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -330,10 +328,10 @@ public class ModelTest {
|
|||
FloatParameter fParam = bag.getParameter(PARAM_FLOAT_ID);
|
||||
fParam.setValue(23434234.234);
|
||||
fParam.setName("Ohla");
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
|
||||
assertEquals("Multiple changes should be registered", 3, visitor.getMismatchedLocators().size());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes);
|
||||
List<Locator> mismatches = dstRes.accept(visitor);
|
||||
assertFalse("Resource should not be same if param is changed!", mismatches.isEmpty());
|
||||
assertEquals("Multiple changes should be registered", 3, mismatches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -343,10 +341,10 @@ public class ModelTest {
|
|||
BooleanTimedState timedState = dstRes.getTimedState(STATE_BOOLEAN_ID);
|
||||
timedState.applyChange(new ValueChange<>(System.currentTimeMillis(), new BooleanValue(Boolean.FALSE)));
|
||||
timedState.setName("Ohla");
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(srcRes);
|
||||
visitor.visit(dstRes);
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcRes);
|
||||
List<Locator> mismatches = dstRes.accept(visitor);
|
||||
assertFalse("Resource should not be same if param is changed!", visitor.isEqual());
|
||||
assertEquals("Multiple change should be registered!", 2, visitor.getMismatchedLocators().size());
|
||||
assertEquals("Multiple change should be registered!", 2, mismatches.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -354,9 +352,9 @@ public class ModelTest {
|
|||
Date date = new Date();
|
||||
Order srcOrder = createOrder("@ord01", "Test Order", "MyType", date, State.CREATED);
|
||||
Order dstOrder = createOrder("@ord01", "Test Order", "MyType", date, State.CREATED);
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||
visitor.visit(dstOrder);
|
||||
assertTrue("Same Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcOrder);
|
||||
List<Locator> mismatches = dstOrder.accept(visitor);
|
||||
assertTrue("Same Order should be deep equal: " + mismatches, visitor.isEqual());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -364,9 +362,9 @@ public class ModelTest {
|
|||
Date date = new Date();
|
||||
Order srcOrder = createOrder("@ord01", "Test Order", "MyType", date, State.CREATED);
|
||||
Order dstOrder = srcOrder.getClone();
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||
visitor.visit(dstOrder);
|
||||
assertTrue("Cloned Order should be deep equal: " + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcOrder);
|
||||
List<Locator> mismatches = dstOrder.accept(visitor);
|
||||
assertTrue("Cloned Order should be deep equal: " + mismatches, visitor.isEqual());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -381,10 +379,10 @@ public class ModelTest {
|
|||
FloatParameter fParam = bag.getParameter(PARAM_FLOAT_ID);
|
||||
fParam.setValue(23434234.234);
|
||||
fParam.setName("Ohla");
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(srcOrder);
|
||||
visitor.visit(dstOrder);
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(srcOrder);
|
||||
List<Locator> mismatches = dstOrder.accept(visitor);
|
||||
assertFalse("Order should not be same if something has been changed", visitor.isEqual());
|
||||
assertEquals("Multiple changes should be registered", 5, visitor.getMismatchedLocators().size());
|
||||
assertEquals("Multiple changes should be registered", 5, mismatches.size());
|
||||
}
|
||||
|
||||
public static void validateBag(ParameterBag bag) {
|
||||
|
|
|
@ -17,12 +17,12 @@ package li.strolch.model;
|
|||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.ActivityDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
import li.strolch.model.xml.ActivityFromDomVisitor;
|
||||
import li.strolch.model.xml.OrderFromDomVisitor;
|
||||
import li.strolch.model.xml.ResourceFromDomVisitor;
|
||||
|
@ -40,10 +40,9 @@ public class ModelToDomTest extends ModelMarshallingTest {
|
|||
|
||||
Resource parsedResource = new ResourceFromDomVisitor().visit(document);
|
||||
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||
visitor.visit(parsedResource);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(resource);
|
||||
List<Locator> mismatches = parsedResource.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedResource;
|
||||
}
|
||||
|
@ -54,9 +53,9 @@ public class ModelToDomTest extends ModelMarshallingTest {
|
|||
|
||||
Order parsedOrder = new OrderFromDomVisitor().visit(document);
|
||||
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||
visitor.visit(parsedOrder);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(order);
|
||||
List<Locator> mismatches = parsedOrder.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedOrder;
|
||||
}
|
||||
|
@ -67,10 +66,9 @@ public class ModelToDomTest extends ModelMarshallingTest {
|
|||
|
||||
Activity parsedActivity = new ActivityFromDomVisitor().visit(document);
|
||||
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(activity);
|
||||
visitor.visit(parsedActivity);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(activity);
|
||||
List<Locator> mismatches = parsedActivity.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedActivity;
|
||||
}
|
||||
|
|
|
@ -17,32 +17,29 @@ package li.strolch.model;
|
|||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.json.ActivityFromJsonVisitor;
|
||||
import li.strolch.model.json.ActivityToJsonVisitor;
|
||||
import li.strolch.model.json.OrderFromJsonVisitor;
|
||||
import li.strolch.model.json.OrderToJsonVisitor;
|
||||
import li.strolch.model.json.ResourceFromJsonVisitor;
|
||||
import li.strolch.model.json.ResourceToJsonVisitor;
|
||||
import li.strolch.model.visitor.ActivityDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
|
||||
public class ModelToJsonTest extends ModelMarshallingTest {
|
||||
|
||||
@Override
|
||||
protected Order formatAndParseOrder(Order order) {
|
||||
OrderToJsonVisitor jsonVisitor = new OrderToJsonVisitor();
|
||||
jsonVisitor.visit(order);
|
||||
JsonObject jsonObject = jsonVisitor.getJsonObject();
|
||||
StrolchElementToJsonVisitor jsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
JsonObject jsonObject = order.accept(jsonVisitor);
|
||||
|
||||
Order parsedOrder = new OrderFromJsonVisitor().visit(jsonObject);
|
||||
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||
visitor.visit(parsedOrder);
|
||||
assertTrue("To JSON and back should equal same Order:\n" + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(order);
|
||||
List<Locator> mismatches = parsedOrder.accept(visitor);
|
||||
assertTrue("To JSON and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedOrder;
|
||||
}
|
||||
|
@ -50,16 +47,14 @@ public class ModelToJsonTest extends ModelMarshallingTest {
|
|||
@Override
|
||||
protected Resource formatAndParseResource(Resource resource) {
|
||||
|
||||
ResourceToJsonVisitor jsonVisitor = new ResourceToJsonVisitor();
|
||||
jsonVisitor.visit(resource);
|
||||
JsonObject jsonObject = jsonVisitor.getJsonObject();
|
||||
StrolchElementToJsonVisitor jsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
JsonObject jsonObject = resource.accept(jsonVisitor);
|
||||
|
||||
Resource parsedResource = new ResourceFromJsonVisitor().visit(jsonObject);
|
||||
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||
visitor.visit(parsedResource);
|
||||
assertTrue("To JSON and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(resource);
|
||||
List<Locator> mismatches = parsedResource.accept(visitor);
|
||||
assertTrue("To JSON and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedResource;
|
||||
}
|
||||
|
@ -67,16 +62,14 @@ public class ModelToJsonTest extends ModelMarshallingTest {
|
|||
@Override
|
||||
protected Activity formatAndParseActivity(Activity activity) {
|
||||
|
||||
ActivityToJsonVisitor jsonVisitor = new ActivityToJsonVisitor();
|
||||
jsonVisitor.visit(activity);
|
||||
JsonObject jsonObject = jsonVisitor.getJsonObject();
|
||||
StrolchElementToJsonVisitor jsonVisitor = new StrolchElementToJsonVisitor().withVersion();
|
||||
JsonObject jsonObject = activity.accept(jsonVisitor);
|
||||
|
||||
Activity parsedActivity = new ActivityFromJsonVisitor().visit(jsonObject);
|
||||
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(activity);
|
||||
visitor.visit(parsedActivity);
|
||||
assertTrue("To JSON and back should equal same Activity:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(activity);
|
||||
List<Locator> mismatches = parsedActivity.accept(visitor);
|
||||
assertTrue("To JSON and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedActivity;
|
||||
}
|
||||
|
|
|
@ -19,11 +19,10 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.ActivityDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
import li.strolch.model.xml.SimpleStrolchElementListener;
|
||||
import li.strolch.model.xml.StrolchElementToSaxVisitor;
|
||||
import li.strolch.model.xml.XmlModelSaxReader;
|
||||
|
@ -47,9 +46,9 @@ public class ModelToSaxTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getActivities());
|
||||
Order parsedOrder = listener.getOrders().get(0);
|
||||
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||
visitor.visit(parsedOrder);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(order);
|
||||
List<Locator> mismatches = parsedOrder.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedOrder;
|
||||
}
|
||||
|
@ -67,10 +66,9 @@ public class ModelToSaxTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getOrders());
|
||||
Resource parsedResource = listener.getResources().get(0);
|
||||
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||
visitor.visit(parsedResource);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(resource);
|
||||
List<Locator> mismatches = parsedResource.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedResource;
|
||||
}
|
||||
|
@ -88,10 +86,9 @@ public class ModelToSaxTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getOrders());
|
||||
Activity parsedActivity = listener.getActivities().get(0);
|
||||
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(activity);
|
||||
visitor.visit(parsedActivity);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(activity);
|
||||
List<Locator> mismatches = parsedActivity.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedActivity;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,12 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.visitor.ActivityDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.OrderDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.ResourceDeepEqualsVisitor;
|
||||
import li.strolch.model.visitor.StrolchElementDeepEqualsVisitor;
|
||||
import li.strolch.model.xml.SimpleStrolchElementListener;
|
||||
import li.strolch.model.xml.StrolchElementToSaxWriterVisitor;
|
||||
import li.strolch.model.xml.StrolchXmlHelper;
|
||||
|
@ -57,9 +56,9 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getActivities());
|
||||
Order parsedOrder = listener.getOrders().get(0);
|
||||
|
||||
OrderDeepEqualsVisitor visitor = new OrderDeepEqualsVisitor(order);
|
||||
visitor.visit(parsedOrder);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + visitor.getMismatchedLocators(), visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(order);
|
||||
List<Locator> mismatches = parsedOrder.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Order:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedOrder;
|
||||
}
|
||||
|
@ -82,10 +81,9 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getOrders());
|
||||
Resource parsedResource = listener.getResources().get(0);
|
||||
|
||||
ResourceDeepEqualsVisitor visitor = new ResourceDeepEqualsVisitor(resource);
|
||||
visitor.visit(parsedResource);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(resource);
|
||||
List<Locator> mismatches = parsedResource.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Resource:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedResource;
|
||||
}
|
||||
|
@ -110,10 +108,9 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
assertEquals(Collections.emptyList(), listener.getOrders());
|
||||
Activity parsedActivity = listener.getActivities().get(0);
|
||||
|
||||
ActivityDeepEqualsVisitor visitor = new ActivityDeepEqualsVisitor(activity);
|
||||
visitor.visit(parsedActivity);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + visitor.getMismatchedLocators(),
|
||||
visitor.isEqual());
|
||||
StrolchElementDeepEqualsVisitor visitor = new StrolchElementDeepEqualsVisitor(activity);
|
||||
List<Locator> mismatches = parsedActivity.accept(visitor);
|
||||
assertTrue("To DOM and back should equal same Activity:\n" + mismatches, mismatches.isEmpty());
|
||||
|
||||
return parsedActivity;
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ public class PostgreSqlActivityDao extends PostgresqlDao<Activity> implements Ac
|
|||
String id = result.getString("id");
|
||||
SQLXML sqlxml = result.getSQLXML("asxml");
|
||||
Activity t = parseFromXml(id, queryVisitor.getType(), sqlxml);
|
||||
list.add(query.getActivityVisitor().visit(t));
|
||||
list.add(t.accept(query.getActivityVisitor()));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -249,7 +249,7 @@ public class PostgreSqlOrderDao extends PostgresqlDao<Order> implements OrderDao
|
|||
String id = result.getString("id");
|
||||
SQLXML sqlxml = result.getSQLXML("asxml");
|
||||
Order t = parseFromXml(id, queryVisitor.getType(), sqlxml);
|
||||
list.add(query.getOrderVisitor().visit(t));
|
||||
list.add(t.accept(query.getOrderVisitor()));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -241,7 +241,7 @@ public class PostgreSqlResourceDao extends PostgresqlDao<Resource> implements Re
|
|||
String id = result.getString("id");
|
||||
SQLXML sqlxml = result.getSQLXML("asxml");
|
||||
Resource t = parseFromXml(id, queryVisitor.getType(), sqlxml);
|
||||
list.add(query.getResourceVisitor().visit(t));
|
||||
list.add(t.accept(query.getResourceVisitor()));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -53,9 +53,7 @@ import li.strolch.model.Order;
|
|||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.json.ActivityToJsonVisitor;
|
||||
import li.strolch.model.json.OrderToJsonVisitor;
|
||||
import li.strolch.model.json.ResourceToJsonVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
|
@ -391,7 +389,7 @@ public class Inspector {
|
|||
RestfulHelper.doOrdering(queryData, resources);
|
||||
|
||||
// build JSON response
|
||||
ResourceToJsonVisitor toJsonVisitor = new ResourceToJsonVisitor();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, resources, toJsonVisitor);
|
||||
|
||||
// marshall result
|
||||
|
@ -441,7 +439,7 @@ public class Inspector {
|
|||
RestfulHelper.doOrdering(queryData, orders);
|
||||
|
||||
// build JSON response
|
||||
OrderToJsonVisitor toJsonVisitor = new OrderToJsonVisitor();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, orders, toJsonVisitor);
|
||||
|
||||
// marshall result
|
||||
|
@ -477,7 +475,7 @@ public class Inspector {
|
|||
RestfulHelper.doOrdering(queryData, activities);
|
||||
|
||||
// build JSON response
|
||||
ActivityToJsonVisitor toJsonVisitor = new ActivityToJsonVisitor();
|
||||
StrolchElementToJsonVisitor toJsonVisitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, activities, toJsonVisitor);
|
||||
|
||||
// marshall result
|
||||
|
@ -502,7 +500,8 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return Response.ok().entity(ResourceToJsonVisitor.toJsonString(resource)).build();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
return Response.ok().entity(resource.accept(visitor)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -584,7 +583,8 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return Response.ok().entity(OrderToJsonVisitor.toJsonString(order)).build();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
return Response.ok().entity(order.accept(visitor)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
@ -684,7 +684,8 @@ public class Inspector {
|
|||
throw new StrolchException(MessageFormat.format("No Activity exists for {0}/{1}", type, id)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return Response.ok().entity(ActivityToJsonVisitor.toJsonString(activity)).build();
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
return Response.ok().entity(activity.accept(visitor)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
@ -23,9 +23,7 @@ import li.strolch.agent.api.ResourceMap;
|
|||
import li.strolch.model.Order;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.activity.Activity;
|
||||
import li.strolch.model.json.ActivityToJsonVisitor;
|
||||
import li.strolch.model.json.OrderToJsonVisitor;
|
||||
import li.strolch.model.json.ResourceToJsonVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.query.ActivityQuery;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
|
@ -87,8 +85,8 @@ public class ModelQuery {
|
|||
RestfulHelper.doOrdering(queryData, resources);
|
||||
|
||||
// build JSON response
|
||||
ResourceToJsonVisitor toJsonVisitor = new ResourceToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, resources, toJsonVisitor);
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, resources, visitor);
|
||||
|
||||
// marshall result
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
@ -142,8 +140,8 @@ public class ModelQuery {
|
|||
RestfulHelper.doOrdering(queryData, orders);
|
||||
|
||||
// build JSON response
|
||||
OrderToJsonVisitor toJsonVisitor = new OrderToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, orders, toJsonVisitor);
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, orders, visitor);
|
||||
|
||||
// marshall result
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
@ -198,8 +196,8 @@ public class ModelQuery {
|
|||
RestfulHelper.doOrdering(queryData, activities);
|
||||
|
||||
// build JSON response
|
||||
ActivityToJsonVisitor toJsonVisitor = new ActivityToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, activities, toJsonVisitor);
|
||||
StrolchElementToJsonVisitor visitor = new StrolchElementToJsonVisitor();
|
||||
JsonObject root = RestfulHelper.toJson(queryData, dataSetSize, activities, visitor);
|
||||
|
||||
// marshall result
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RestfulHelper {
|
|||
}
|
||||
|
||||
public static <T extends StrolchRootElement> JsonObject toJson(QueryData queryData, long dataSetSize,
|
||||
List<T> elements, StrolchElementVisitor<T, JsonObject> toJsonVisitor) {
|
||||
List<T> elements, StrolchElementVisitor<JsonObject> toJsonVisitor) {
|
||||
|
||||
// paging
|
||||
Paging<T> paging = Paging.asPage(elements, queryData.getOffset(), queryData.getLimit());
|
||||
|
@ -83,7 +83,7 @@ public class RestfulHelper {
|
|||
// add items
|
||||
JsonArray data = new JsonArray();
|
||||
for (T t : page) {
|
||||
JsonObject element = toJsonVisitor.visit(t);
|
||||
JsonObject element = t.accept(toJsonVisitor);
|
||||
data.add(element);
|
||||
}
|
||||
root.add("data", data);
|
||||
|
|
|
@ -119,13 +119,13 @@ public abstract class ExecutionCommand extends Command implements TimeOrderingVi
|
|||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Activity activity) {
|
||||
public Void visitActivity(Activity activity) {
|
||||
activity.getTimeOrdering().accept(this, activity);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(Action action) {
|
||||
public Void visitAction(Action action) {
|
||||
ExecutionPolicy executionPolicy = getExecutionPolicy(action);
|
||||
|
||||
if (executionPolicy.isExecutable(action)) {
|
||||
|
|
Loading…
Reference in New Issue