use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class AttributeLink method toObjectValue.
public ObjectValue toObjectValue() {
ObjectValue objectValue = Values.createObject();
objectValue.put("attributeRef", getAttributeRef().toArrayValue());
objectValue.put("converter", converter);
return objectValue;
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class AttributeState method toObjectValue.
public ObjectValue toObjectValue() {
ObjectValue objectValue = Values.createObject();
objectValue.put("attributeRef", getAttributeRef().toArrayValue());
getValue().ifPresent(v -> objectValue.put("value", value));
return objectValue;
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class CalendarEvent method toValue.
public Value toValue() {
ObjectValue objectValue = Values.createObject();
objectValue.put("start", start.getTime() / 1000);
objectValue.put("end", end.getTime() / 1000);
if (recurrence != null) {
objectValue.put("recurrence", recurrence.toValue());
}
return objectValue;
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class RecurrenceRule method fromValue.
public static Optional<RecurrenceRule> fromValue(Value value) {
if (value == null || value.getType() != ValueType.OBJECT) {
return Optional.empty();
}
ObjectValue objectValue = (ObjectValue) value;
Optional<Frequency> frequency = objectValue.getString("frequency").flatMap(s -> EnumUtil.enumFromString(Frequency.class, s));
Integer interval = objectValue.get("interval").flatMap(Values::getIntegerCoerced).orElse(null);
Integer count = objectValue.get("count").flatMap(Values::getIntegerCoerced).orElse(null);
Optional<Long> until = objectValue.get("until").flatMap(Values::getLongCoerced);
if (!frequency.isPresent()) {
return Optional.empty();
}
RecurrenceRule rRule = new RecurrenceRule(frequency.get());
rRule.interval = interval;
rRule.count = count;
until.ifPresent(l -> rRule.until = new Date(1000L * l));
return Optional.of(rRule);
}
use of org.openremote.model.value.ObjectValue in project openremote by openremote.
the class NodeDescriptor method initialize.
public Node initialize(Node node, Supplier<String> idGenerator) {
List<Slot> slots = new ArrayList<>();
addSlots(slots, idGenerator);
node.setSlots(slots.toArray(new Slot[slots.size()]));
node.getEditorSettings().setTypeLabel(getTypeLabel());
node.getEditorSettings().setNodeColor(getColor());
List<String> editorComponents = new ArrayList<>();
addEditorComponents(editorComponents);
node.getEditorSettings().setComponents(editorComponents.toArray(new String[editorComponents.size()]));
ObjectValue initialProperties = getInitialProperties();
try {
if (initialProperties != null) {
node.setProperties(initialProperties.toJson());
} else {
ObjectValue properties = Values.createObject();
configureInitialProperties(properties);
if (properties.hasKeys()) {
node.setProperties(properties.toJson());
}
}
} catch (Exception ex) {
throw new RuntimeException("Error writing initial properties of: " + getType(), ex);
}
List<String> persistentPaths = new ArrayList<>();
addPersistentPropertyPaths(persistentPaths);
if (persistentPaths.size() > 0) {
node.setPersistentPropertyPaths(persistentPaths.toArray(new String[persistentPaths.size()]));
}
return node;
}
Aggregations