diff --git a/li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java index 56d73bc93..2ea106aed 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java +++ b/li.strolch.model/src/main/java/li/strolch/model/StrolchModelConstants.java @@ -62,6 +62,7 @@ public class StrolchModelConstants { public static final String SUFFIX_REF = "-Ref"; public static final String BAG_RELATIONS = "relations"; public static final String BAG_PARAMETERS = "parameters"; + public static final String TYPE_PARAMETERS = "Parameters"; /** * ID of the admin role which has access to all resources diff --git a/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java index 583e2b1eb..d62ac26e2 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java +++ b/li.strolch.model/src/main/java/li/strolch/model/StrolchRootElement.java @@ -20,6 +20,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import li.strolch.model.activity.Activity; import li.strolch.model.json.StrolchRootElementToJsonVisitor; +import li.strolch.model.parameter.Parameter; import li.strolch.model.visitor.StrolchElementVisitor; import li.strolch.model.visitor.StrolchRootElementVisitor; import li.strolch.model.xml.StrolchElementToXmlStringVisitor; @@ -174,4 +175,56 @@ public interface StrolchRootElement extends StrolchElement, PolicyContainer, Par default Activity asActivity() { return (Activity) this; } + + /** + * Set or add a parameter to this element from a {@link JsonObject} + * + * @param jsonObject + * the object from which to get the value + * @param bagId + * the bag ID on which to set the value + * @param bagName + * the name of the bag, if the bag is to be created + * @param bagType + * the type of the bag, if the bag is to be created + * @param paramId + * the ID of the parameter on which to set the value, and also the Json reference ID + * @param paramName + * the name of the parameter, if the parameter is to be created + * @param type + * the type of Parameter to create + * @param ignoreOnEmpty + * if true, and the json object is missing the field, then the parameter is not changed, otherwise the parameter + * is cleared if the json field is missing or null + */ + default void setOrAddParamFromFlatJson(JsonObject jsonObject, String bagId, String bagName, String bagType, + String paramId, String paramName, StrolchValueType type, boolean ignoreOnEmpty) { + + if (!jsonObject.has(paramId) && ignoreOnEmpty) + return; + + ParameterBag bag = getParameterBag(bagId); + if (bag == null) { + bag = new ParameterBag(bagId, bagName, bagType); + addParameterBag(bag); + } + + Parameter param = bag.getParameter(paramId); + boolean valueNotSet = !jsonObject.has(paramId) || jsonObject.get(paramId).isJsonNull(); + if (param == null && valueNotSet) + return; + + if (param == null) { + param = type.parameterInstance(); + param.setId(paramId); + param.setName(paramName); + bag.addParameter(param); + } + + if (valueNotSet) { + param.clear(); + } else { + param.setValueFromString(jsonObject.get(paramId).getAsString()); + } + } } diff --git a/li.strolch.model/src/main/java/li/strolch/model/StrolchValueType.java b/li.strolch.model/src/main/java/li/strolch/model/StrolchValueType.java index 7067fbfa3..749a703d2 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/StrolchValueType.java +++ b/li.strolch.model/src/main/java/li/strolch/model/StrolchValueType.java @@ -152,14 +152,12 @@ public enum StrolchValueType { @Override public StrolchTimedState> timedStateInstance() { - throw new UnsupportedOperationException( - MessageFormat.format("TimeStates of type {0} are not supported!", getType())); //$NON-NLS-1$ + return new LongTimedState(); } @Override public IValue valueInstance(String valueAsString) { - throw new UnsupportedOperationException( - MessageFormat.format("Parameters of type {0} are not supported!", getType())); //$NON-NLS-1$ + return new LongValue(valueAsString); } @Override diff --git a/li.strolch.model/src/main/java/li/strolch/model/Tags.java b/li.strolch.model/src/main/java/li/strolch/model/Tags.java index 427fb25a5..15a9f19fa 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/Tags.java +++ b/li.strolch.model/src/main/java/li/strolch/model/Tags.java @@ -151,6 +151,35 @@ public class Tags { public static final String AGENT_VERSION = "agentVersion"; public static final String COMPONENT_VERSIONS = "componentVersions"; public static final String ERRORS = "errors"; + + public static final String OPERATING_SYSTEM = "operatingSystem"; + public static final String OS_NAME = "osName"; + public static final String OS_ARCH = "osArch"; + public static final String OS_VERSION = "osVersion"; + public static final String JAVA_VENDOR = "javaVendor"; + public static final String JAVA_VERSION = "javaVersion"; + + public static final String AVAILABLE_PROCESSORS = "availableProcessors"; + public static final String SYSTEM_LOAD_AVERAGE = "systemLoadAverage"; + + public static final String START_TIME = "startTime"; + public static final String UPTIME = "uptime"; + + public static final String MEMORY = "memory"; + public static final String TOTAL_PHYSICAL_MEMORY_SIZE = "totalPhysicalMemorySize"; + public static final String FREE_PHYSICAL_MEMORY_SIZE = "freePhysicalMemorySize"; + public static final String FREE_SWAP_SPACE_SIZE = "freeSwapSpaceSize"; + public static final String COMMITTED_VIRTUAL_MEMORY_SIZE = "committedVirtualMemorySize"; + public static final String HEAP_MEMORY_USAGE_INIT = "heapMemoryUsageInit"; + public static final String HEAP_MEMORY_USAGE_USED = "heapMemoryUsageUsed"; + public static final String HEAP_MEMORY_USAGE_MAX = "heapMemoryUsageMax"; + public static final String HEAP_MEMORY_USAGE_COMMITTED = "heapMemoryUsageCommitted"; + public static final String ROOTS = "roots"; + public static final String PATH = "path"; + public static final String USABLE_SPACE = "usableSpace"; + public static final String USED_SPACE = "usedSpace"; + public static final String FREE_SPACE = "freeSpace"; + public static final String TOTAL_SPACE = "totalSpace"; } public static class Audit { diff --git a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java index 7d5b59660..037de5bec 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java @@ -305,6 +305,13 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor + * + * 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.timedstate; + +import li.strolch.model.StrolchValueType; +import li.strolch.model.timevalue.impl.LongValue; +import li.strolch.model.visitor.StrolchElementVisitor; + +/** + * @author Robert von Burg + */ +public class LongTimedState extends AbstractStrolchTimedState { + + public LongTimedState() { + super(); + } + + public LongTimedState(String id, String name) { + super(id, name); + } + + @Override + public void setStateFromStringAt(Long time, String value) { + assertNotReadonly(); + getTimeEvolution().setValueAt(time, new LongValue(value)); + } + + @Override + public String getType() { + return StrolchValueType.LONG.getType(); + } + + @Override + public U accept(StrolchElementVisitor visitor) { + return visitor.visitLongState(this); + } + + @Override + public LongTimedState getClone() { + LongTimedState clone = new LongTimedState(); + fillClone(clone); + return clone; + } +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/LongValue.java b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/LongValue.java new file mode 100644 index 000000000..c646a1b6c --- /dev/null +++ b/li.strolch.model/src/main/java/li/strolch/model/timevalue/impl/LongValue.java @@ -0,0 +1,119 @@ +/* + * Copyright 2013 Martin Smock + * + * 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.timevalue.impl; + +import java.io.Serializable; + +import li.strolch.model.StrolchValueType; +import li.strolch.model.timevalue.ITimeValue; +import li.strolch.model.timevalue.IValue; + +/** + * {@link IValue} implementation to work with Long valued {@link ITimeValue} objects + * + * @author Martin Smock + */ +public class LongValue implements IValue, Serializable { + + public static final LongValue NEUTRAL = new LongValue(0L); + + private Long value; + + public LongValue(Long value) { + this.value = value; + } + + public LongValue(String valueAsString) throws NumberFormatException { + this.value = Long.parseLong(valueAsString); + } + + @Override + public String getType() { + return StrolchValueType.LONG.getType(); + } + + @Override + public LongValue add(Long o) { + this.value += o; + return this; + } + + @Override + public boolean matches(IValue other) { + return this.value.equals(other.getValue()); + } + + @Override + public Long getValue() { + return this.value; + } + + @Override + public LongValue getInverse() { + return new LongValue(-getValue()); + } + + @Override + public String getValueAsString() { + return this.value.toString(); + } + + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("LongValue [value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + + @Override + public LongValue getCopy() { + return new LongValue(this.value); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LongValue other = (LongValue) obj; + if (this.value == null) { + if (other.value != null) { + return false; + } + } else if (!this.value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/IActivityElementVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/IActivityElementVisitor.java index 0cfe2fcb2..c29bdd475 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/IActivityElementVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/IActivityElementVisitor.java @@ -93,6 +93,11 @@ public interface IActivityElementVisitor extends StrolchElementVisitor { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); } + @Override + default U visitLongState(LongTimedState state) { + throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); + } + @Override default U visitStringState(StringSetTimedState state) { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java index 481f77380..b18b8e4c5 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/ParameterVisitor.java @@ -67,6 +67,11 @@ public interface ParameterVisitor extends StrolchElementVisitor { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); } + @Override + default U visitLongState(LongTimedState state) { + throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); + } + @Override default U visitStringState(StringSetTimedState state) { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java index e4dcd0a9c..a667c75ac 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementDeepEqualsVisitor.java @@ -475,6 +475,13 @@ public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor
  • visitLongState(LongTimedState state) { + DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), state.getClass()); + deepEquals((StrolchTimedState) this.srcElement, state); + return getMismatchedLocators(); + } + @Override public List visitStringState(StringSetTimedState state) { DBC.PRE.assertEquals("Can't compare apples with pairs =)", this.srcElement.getClass(), state.getClass()); diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java index 05f9926af..bad93d977 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchElementVisitor.java @@ -62,6 +62,8 @@ public interface StrolchElementVisitor extends StrolchVisitor { U visitFloatState(FloatTimedState state); + U visitLongState(LongTimedState state); + U visitFloatListState(FloatListTimedState state); U visitIntegerState(IntegerTimedState state); diff --git a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java index 377cf5faa..fcf7fd368 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/visitor/StrolchRootElementVisitor.java @@ -105,6 +105,11 @@ public interface StrolchRootElementVisitor extends StrolchElementVisitor { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); } + @Override + default U visitLongState(LongTimedState state) { + throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass()); + } + @Override default U visitStringState(StringSetTimedState state) { throw new UnsupportedOperationException(getClass().getName() + " can not handle " + state.getClass());