Search in sources :

Example 1 with Select

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);
}
Also used : AssetQuery(org.openremote.model.asset.AssetQuery) Select(org.openremote.model.asset.AssetQuery.Select) AssetAttribute(org.openremote.model.asset.AssetAttribute) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1 AssetAttribute (org.openremote.model.asset.AssetAttribute)1 AssetQuery (org.openremote.model.asset.AssetQuery)1 Select (org.openremote.model.asset.AssetQuery.Select)1