Search in sources :

Example 16 with ObjectValue

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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 17 with 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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 18 with 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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 19 with 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);
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue) Values(org.openremote.model.value.Values) Date(java.util.Date)

Example 20 with ObjectValue

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;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue) ArrayList(java.util.ArrayList) Slot(org.openremote.model.flow.Slot)

Aggregations

ObjectValue (org.openremote.model.value.ObjectValue)21 java.util (java.util)3 Logger (java.util.logging.Logger)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 EntityManager (javax.persistence.EntityManager)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 Container (org.openremote.container.Container)3 ContainerService (org.openremote.container.ContainerService)3 GlobalLock.withLock (org.openremote.container.concurrent.GlobalLock.withLock)3 GlobalLock.withLockReturning (org.openremote.container.concurrent.GlobalLock.withLockReturning)3 MessageBrokerSetupService (org.openremote.container.message.MessageBrokerSetupService)3 PersistenceEvent (org.openremote.container.persistence.PersistenceEvent)3 TimerService (org.openremote.container.timer.TimerService)3 org.openremote.manager.asset (org.openremote.manager.asset)3 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)3 VALUE_TIMESTAMP_FIELD_NAME (org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME)3 AssetAttribute.attributesFromJson (org.openremote.model.asset.AssetAttribute.attributesFromJson)3 AssetAttribute.getAddedOrModifiedAttributes (org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes)3 Source (org.openremote.model.attribute.AttributeEvent.Source)3