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);
});
}
Aggregations