use of org.openremote.model.asset.AssetQuery.Select in project openremote by openremote.
the class AssetAttributeLinkingService method getCurrentValue.
protected static Value getCurrentValue(EntityManager em, AssetStorageService assetStorageService, AttributeRef attributeRef) throws NoSuchElementException {
ServerAsset asset = assetStorageService.find(em, new AssetQuery().id(attributeRef.getEntityId()).select(new Select(Include.ALL, false, attributeRef.getAttributeName())));
Optional<AssetAttribute> attribute;
if (asset == null || !(attribute = asset.getAttribute(attributeRef.getAttributeName())).isPresent()) {
throw new NoSuchElementException("Attribute or asset could not be found: " + attributeRef);
}
return attribute.get().getValue().orElse(null);
}
Aggregations