Search in sources :

Example 1 with SimulatorAttributeInfo

use of org.openremote.model.simulator.SimulatorAttributeInfo in project openremote by openremote.

the class SimulatorService method getSimulatorState.

/**
 * Get info about all attributes linked to this instance (for frontend usage)
 */
protected SimulatorState getSimulatorState(SimulatorProtocol protocolInstance) {
    return withLockReturning(protocolInstance.getProtocolInstanceUri() + "::getSimulatorInfo", () -> {
        LOG.info("Getting simulator info for protocol instance: " + protocolInstance);
        // We need asset names instead of identifiers for user-friendly display
        List<String> linkedAssetIds = protocolInstance.getLinkedAttributes().keySet().stream().map(AttributeRef::getId).distinct().collect(Collectors.toList());
        List<String> assetNames = assetStorageService.findNames(linkedAssetIds.toArray(new String[0]));
        if (assetNames.size() != linkedAssetIds.size()) {
            LOG.warning("Retrieved asset names don't match requested asset IDs");
            return null;
        }
        SimulatorAttributeInfo[] attributeInfos = protocolInstance.getLinkedAttributes().entrySet().stream().map(refAttributeEntry -> {
            String assetName = assetNames.get(linkedAssetIds.indexOf(refAttributeEntry.getKey().getId()));
            return new SimulatorAttributeInfo(assetName, refAttributeEntry.getKey().getId(), refAttributeEntry.getValue(), protocolInstance.getReplayMap().containsKey(refAttributeEntry.getKey()));
        }).toArray(SimulatorAttributeInfo[]::new);
        return new SimulatorState(protocolInstance.getAgent().getId(), attributeInfos);
    });
}
Also used : AssetStorageService(org.openremote.manager.asset.AssetStorageService) MessageBrokerService(org.openremote.container.message.MessageBrokerService) SimulatorState(org.openremote.model.simulator.SimulatorState) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) AuthContext(org.openremote.container.security.AuthContext) Protocol(org.openremote.model.asset.agent.Protocol) CLIENT_EVENT_TOPIC(org.openremote.manager.event.ClientEventService.CLIENT_EVENT_TOPIC) AttributeRef(org.openremote.model.attribute.AttributeRef) SimulatorProtocol(org.openremote.agent.protocol.simulator.SimulatorProtocol) ContainerService(org.openremote.model.ContainerService) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState) Constants(org.openremote.model.Constants) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Container(org.openremote.model.Container) GlobalLock.withLockReturning(org.openremote.container.concurrent.GlobalLock.withLockReturning) ClientEventService(org.openremote.manager.event.ClientEventService) List(java.util.List) RouteBuilder(org.apache.camel.builder.RouteBuilder) ClientEventService.getSessionKey(org.openremote.manager.event.ClientEventService.getSessionKey) AgentService(org.openremote.manager.agent.AgentService) SimulatorAttributeInfo(org.openremote.model.simulator.SimulatorAttributeInfo) AttributeRef(org.openremote.model.attribute.AttributeRef) SimulatorAttributeInfo(org.openremote.model.simulator.SimulatorAttributeInfo) SimulatorState(org.openremote.model.simulator.SimulatorState) RequestSimulatorState(org.openremote.model.simulator.RequestSimulatorState)

Aggregations

List (java.util.List)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 SimulatorProtocol (org.openremote.agent.protocol.simulator.SimulatorProtocol)1 GlobalLock.withLockReturning (org.openremote.container.concurrent.GlobalLock.withLockReturning)1 MessageBrokerService (org.openremote.container.message.MessageBrokerService)1 AuthContext (org.openremote.container.security.AuthContext)1 AgentService (org.openremote.manager.agent.AgentService)1 AssetStorageService (org.openremote.manager.asset.AssetStorageService)1 ClientEventService (org.openremote.manager.event.ClientEventService)1 CLIENT_EVENT_TOPIC (org.openremote.manager.event.ClientEventService.CLIENT_EVENT_TOPIC)1 ClientEventService.getSessionKey (org.openremote.manager.event.ClientEventService.getSessionKey)1 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)1 Constants (org.openremote.model.Constants)1 Container (org.openremote.model.Container)1 ContainerService (org.openremote.model.ContainerService)1 Protocol (org.openremote.model.asset.agent.Protocol)1 AttributeRef (org.openremote.model.attribute.AttributeRef)1 RequestSimulatorState (org.openremote.model.simulator.RequestSimulatorState)1