Search in sources :

Example 6 with ObjectValue

use of org.openremote.model.value.ObjectValue in project openremote by openremote.

the class MapWidget method initFeatureLayers.

protected void initFeatureLayers() {
    LOG.fine("Adding GeoJSON feature sources and layers on map load");
    ObjectValue sourceOptionsSelection = prepareSourceOptions(FEATURE_SOURCE_DROPPED_PIN);
    mapboxMap.addSource(FEATURE_SOURCE_DROPPED_PIN, sourceOptionsSelection.asAny());
    mapboxMap.addLayer(LAYER_DROPPED_PIN.asAny());
    ObjectValue sourceOptionsAll = prepareSourceOptions(FEATURE_SOURCE_CIRCLE);
    sourceOptionsAll.put("maxzoom", create(20));
    sourceOptionsAll.put("buffer", create(128));
    sourceOptionsAll.put("tolerance", create(0.375));
    sourceOptionsAll.put("cluster", create(false));
    sourceOptionsAll.put("clusterRadius", create(50));
    sourceOptionsAll.put("clusterMaxZoom", create(15));
    mapboxMap.addSource(FEATURE_SOURCE_CIRCLE, sourceOptionsAll.asAny());
    mapboxMap.addLayer(LAYER_CIRCLE.asAny(), FEATURE_LAYER_DROPPED_PIN);
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 7 with ObjectValue

use of org.openremote.model.value.ObjectValue in project openremote by openremote.

the class UserPasswordCredentials method toObjectValue.

public ObjectValue toObjectValue() {
    ObjectValue value = Values.createObject();
    value.put(USERNAME_KEY, Values.create(getUsername()));
    value.put(PASSWORD_KEY, Values.create(getPassword()));
    return value;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

Example 8 with ObjectValue

use of org.openremote.model.value.ObjectValue in project openremote by openremote.

the class AgentService method processAssetChange.

/**
 * Looks for new, modified and obsolete AGENT_LINK attributes and links / unlinks them
 * with the protocol
 */
protected void processAssetChange(Asset asset, PersistenceEvent persistenceEvent) {
    LOG.finest("Processing asset persistence event: " + persistenceEvent.getCause());
    switch(persistenceEvent.getCause()) {
        case INSERT:
            // Asset insert persistence events can be fired before the agent insert persistence event
            // so need to check that all protocol configs exist - any that don't we will exclude here
            // and handle in agent insert
            // If an agent insert just occurred then we will end up trying to link the attribute again
            // so we keep track of linked attributes to avoid this
            // Link any AGENT_LINK attributes to their referenced protocol
            Map<AssetAttribute, List<AssetAttribute>> groupedAgentLinksAttributes = getGroupedAgentLinkAttributes(asset.getAttributesStream(), attribute -> true, attribute -> LOG.warning("Linked protocol configuration not found: " + attribute));
            groupedAgentLinksAttributes.forEach(this::linkAttributes);
            break;
        case UPDATE:
            List<String> propertyNames = Arrays.asList(persistenceEvent.getPropertyNames());
            // Check if attributes of the asset have been modified
            int attributesIndex = propertyNames.indexOf("attributes");
            if (attributesIndex < 0) {
                return;
            }
            // Attributes have possibly changed so need to compare old and new state to determine any changes to
            // AGENT_LINK attributes
            List<AssetAttribute> oldAgentLinkedAttributes = attributesFromJson((ObjectValue) persistenceEvent.getPreviousState()[attributesIndex], asset.getId()).filter(AgentLink::hasAgentLink).collect(Collectors.toList());
            List<AssetAttribute> newAgentLinkedAttributes = attributesFromJson((ObjectValue) persistenceEvent.getCurrentState()[attributesIndex], asset.getId()).filter(AgentLink::hasAgentLink).collect(Collectors.toList());
            // Unlink thing attributes that are in old but not in new
            getGroupedAgentLinkAttributes(getAddedOrModifiedAttributes(newAgentLinkedAttributes, oldAgentLinkedAttributes, key -> key.equals(VALUE_TIMESTAMP_FIELD_NAME)), attribute -> true).forEach(this::unlinkAttributes);
            // Link thing attributes that are in new but not in old
            getGroupedAgentLinkAttributes(getAddedOrModifiedAttributes(oldAgentLinkedAttributes, newAgentLinkedAttributes, key -> key.equals(VALUE_TIMESTAMP_FIELD_NAME)), attribute -> true, attribute -> LOG.warning("Linked protocol configuration not found: " + attribute)).forEach(this::linkAttributes);
            break;
        case DELETE:
            {
                // Unlink any AGENT_LINK attributes from the referenced protocol
                Map<AssetAttribute, List<AssetAttribute>> groupedAgentLinkAndProtocolAttributes = getGroupedAgentLinkAttributes(asset.getAttributesStream(), attribute -> true);
                groupedAgentLinkAndProtocolAttributes.forEach(this::unlinkAttributes);
                break;
            }
    }
}
Also used : PersistenceEvent(org.openremote.container.persistence.PersistenceEvent) java.util(java.util) ClientRole(org.openremote.model.security.ClientRole) WebService(org.openremote.container.web.WebService) AssetAttribute.getAddedOrModifiedAttributes(org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes) ConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus) AttributeRef(org.openremote.model.attribute.AttributeRef) SENSOR_QUEUE(org.openremote.agent.protocol.Protocol.SENSOR_QUEUE) ASSET_QUEUE(org.openremote.manager.asset.AssetProcessingService.ASSET_QUEUE) ObjectValue(org.openremote.model.value.ObjectValue) Point(com.vividsolutions.jts.geom.Point) Level(java.util.logging.Level) ACTUATOR_TOPIC(org.openremote.agent.protocol.Protocol.ACTUATOR_TOPIC) GlobalLock.withLockReturning(org.openremote.container.concurrent.GlobalLock.withLockReturning) Container(org.openremote.container.Container) TenantFilter(org.openremote.model.event.shared.TenantFilter) ContainerService(org.openremote.container.ContainerService) AttributeEvent(org.openremote.model.attribute.AttributeEvent) org.openremote.model.asset(org.openremote.model.asset) AGENT(org.openremote.model.asset.AssetType.AGENT) AgentLink.getAgentLink(org.openremote.model.asset.agent.AgentLink.getAgentLink) MessageBrokerService(org.openremote.container.message.MessageBrokerService) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) SENSOR(org.openremote.model.attribute.AttributeEvent.Source.SENSOR) Predicate(java.util.function.Predicate) Pair(org.openremote.model.util.Pair) VALUE_TIMESTAMP_FIELD_NAME(org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME) AssetAttribute.attributesFromJson(org.openremote.model.asset.AssetAttribute.attributesFromJson) ProtocolAssetService(org.openremote.agent.protocol.ProtocolAssetService) EntityManager(javax.persistence.EntityManager) Logger(java.util.logging.Logger) MessageBrokerSetupService(org.openremote.container.message.MessageBrokerSetupService) Collectors(java.util.stream.Collectors) HEADER_SOURCE(org.openremote.model.attribute.AttributeEvent.HEADER_SOURCE) TextUtil.isValidURN(org.openremote.model.util.TextUtil.isValidURN) org.openremote.manager.asset(org.openremote.manager.asset) Consumer(java.util.function.Consumer) ClientEventService(org.openremote.manager.event.ClientEventService) Stream(java.util.stream.Stream) org.openremote.model.asset.agent(org.openremote.model.asset.agent) RouteBuilder(org.apache.camel.builder.RouteBuilder) TimerService(org.openremote.container.timer.TimerService) Source(org.openremote.model.attribute.AttributeEvent.Source) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) GlobalLock(org.openremote.container.concurrent.GlobalLock) Protocol(org.openremote.agent.protocol.Protocol) GlobalLock.withLock(org.openremote.container.concurrent.GlobalLock.withLock) Point(com.vividsolutions.jts.geom.Point)

Example 9 with ObjectValue

use of org.openremote.model.value.ObjectValue in project openremote by openremote.

the class AgentService method processAgentChange.

/**
 * Looks for new, modified and obsolete protocol configurations and links / unlinks any associated attributes
 */
protected void processAgentChange(Asset agent, PersistenceEvent persistenceEvent) {
    LOG.finest("Processing agent persistence event: " + persistenceEvent.getCause());
    switch(persistenceEvent.getCause()) {
        case INSERT:
            addReplaceAgent(agent);
            linkProtocolConfigurations(agent.getAttributesStream().filter(ProtocolConfiguration::isProtocolConfiguration));
            break;
        case UPDATE:
            addReplaceAgent(agent);
            // Check if any protocol config attributes have been added/removed or modified
            int attributesIndex = Arrays.asList(persistenceEvent.getPropertyNames()).indexOf("attributes");
            if (attributesIndex < 0) {
                return;
            }
            // Attributes have possibly changed so need to compare old and new state to determine
            // which protocol configs are affected
            List<AssetAttribute> oldProtocolConfigurations = attributesFromJson((ObjectValue) persistenceEvent.getPreviousState()[attributesIndex], agent.getId()).filter(ProtocolConfiguration::isProtocolConfiguration).collect(Collectors.toList());
            List<AssetAttribute> newProtocolConfigurations = attributesFromJson((ObjectValue) persistenceEvent.getCurrentState()[attributesIndex], agent.getId()).filter(ProtocolConfiguration::isProtocolConfiguration).collect(Collectors.toList());
            // Compare protocol configurations by JSON value
            // Unlink protocols that are in oldConfigs but not in newConfigs
            unlinkProtocolConfigurations(oldProtocolConfigurations.stream().filter(oldProtocolAttribute -> newProtocolConfigurations.stream().noneMatch(oldProtocolAttribute::equals)));
            // Link protocols that are in newConfigs but not in oldConfigs
            linkProtocolConfigurations(newProtocolConfigurations.stream().filter(newProtocolAttribute -> oldProtocolConfigurations.stream().noneMatch(newProtocolAttribute::equals)));
            break;
        case DELETE:
            removeAgent(agent);
            // Unlink any attributes that have an agent link to this agent
            unlinkProtocolConfigurations(agent.getAttributesStream().filter(ProtocolConfiguration::isProtocolConfiguration));
            break;
    }
}
Also used : PersistenceEvent(org.openremote.container.persistence.PersistenceEvent) java.util(java.util) ClientRole(org.openremote.model.security.ClientRole) WebService(org.openremote.container.web.WebService) AssetAttribute.getAddedOrModifiedAttributes(org.openremote.model.asset.AssetAttribute.getAddedOrModifiedAttributes) ConnectionStatus(org.openremote.model.asset.agent.ConnectionStatus) AttributeRef(org.openremote.model.attribute.AttributeRef) SENSOR_QUEUE(org.openremote.agent.protocol.Protocol.SENSOR_QUEUE) ASSET_QUEUE(org.openremote.manager.asset.AssetProcessingService.ASSET_QUEUE) ObjectValue(org.openremote.model.value.ObjectValue) Point(com.vividsolutions.jts.geom.Point) Level(java.util.logging.Level) ACTUATOR_TOPIC(org.openremote.agent.protocol.Protocol.ACTUATOR_TOPIC) GlobalLock.withLockReturning(org.openremote.container.concurrent.GlobalLock.withLockReturning) Container(org.openremote.container.Container) TenantFilter(org.openremote.model.event.shared.TenantFilter) ContainerService(org.openremote.container.ContainerService) AttributeEvent(org.openremote.model.attribute.AttributeEvent) org.openremote.model.asset(org.openremote.model.asset) AGENT(org.openremote.model.asset.AssetType.AGENT) AgentLink.getAgentLink(org.openremote.model.asset.agent.AgentLink.getAgentLink) MessageBrokerService(org.openremote.container.message.MessageBrokerService) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) SENSOR(org.openremote.model.attribute.AttributeEvent.Source.SENSOR) Predicate(java.util.function.Predicate) Pair(org.openremote.model.util.Pair) VALUE_TIMESTAMP_FIELD_NAME(org.openremote.model.AbstractValueTimestampHolder.VALUE_TIMESTAMP_FIELD_NAME) AssetAttribute.attributesFromJson(org.openremote.model.asset.AssetAttribute.attributesFromJson) ProtocolAssetService(org.openremote.agent.protocol.ProtocolAssetService) EntityManager(javax.persistence.EntityManager) Logger(java.util.logging.Logger) MessageBrokerSetupService(org.openremote.container.message.MessageBrokerSetupService) Collectors(java.util.stream.Collectors) HEADER_SOURCE(org.openremote.model.attribute.AttributeEvent.HEADER_SOURCE) TextUtil.isValidURN(org.openremote.model.util.TextUtil.isValidURN) org.openremote.manager.asset(org.openremote.manager.asset) Consumer(java.util.function.Consumer) ClientEventService(org.openremote.manager.event.ClientEventService) Stream(java.util.stream.Stream) org.openremote.model.asset.agent(org.openremote.model.asset.agent) RouteBuilder(org.apache.camel.builder.RouteBuilder) TimerService(org.openremote.container.timer.TimerService) Source(org.openremote.model.attribute.AttributeEvent.Source) TextUtil.isNullOrEmpty(org.openremote.model.util.TextUtil.isNullOrEmpty) GlobalLock(org.openremote.container.concurrent.GlobalLock) Protocol(org.openremote.agent.protocol.Protocol) GlobalLock.withLock(org.openremote.container.concurrent.GlobalLock.withLock) Point(com.vividsolutions.jts.geom.Point)

Example 10 with ObjectValue

use of org.openremote.model.value.ObjectValue in project openremote by openremote.

the class AttributeLinkEditor method convertMetaToConverter.

protected static ObjectValue convertMetaToConverter(Meta meta) {
    if (meta == null || meta.isEmpty()) {
        return null;
    }
    ObjectValue converter = Values.createObject();
    meta.forEach(metaItem -> converter.put(metaItem.getName().orElse(null), metaItem.getValue().orElse(null)));
    return converter;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue)

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