use of org.openremote.model.query.AssetQuery in project openremote by openremote.
the class AssetsFacade method dispatch.
public AssetsFacade<T> dispatch(AttributeEvent... events) {
if (events == null || events.length == 0)
return this;
// Check if the asset ID of every event can be found with the default security of this facade
String[] ids = Arrays.stream(events).map(AttributeEvent::getAssetId).toArray(String[]::new);
AssetQuery query = new AssetQuery().ids(ids);
long count = this.getResults(query).count();
if (ids.length != count) {
LOG.warning("Access to asset(s) not allowed for this rule engine scope " + rulesEngineId + " for asset IDs: " + String.join(", ", ids));
return this;
}
for (AttributeEvent event : events) {
eventConsumer.accept(event);
}
return this;
}
use of org.openremote.model.query.AssetQuery in project openremote by openremote.
the class ConsoleResourceImpl method getConsoleParentAsset.
public static Asset<?> getConsoleParentAsset(AssetStorageService assetStorageService, Tenant tenant) {
// Look for a group asset with a child type of console in the realm root
GroupAsset consoleParent = (GroupAsset) assetStorageService.find(new AssetQuery().select(new AssetQuery.Select().excludeAttributes()).names(CONSOLE_PARENT_ASSET_NAME).parents(new ParentPredicate(null)).types(GroupAsset.class).tenant(new TenantPredicate(tenant.getRealm())).attributes(new AttributePredicate("childAssetType", new StringPredicate(ConsoleAsset.DESCRIPTOR.getName()))));
if (consoleParent == null) {
consoleParent = new GroupAsset(CONSOLE_PARENT_ASSET_NAME, ConsoleAsset.class);
consoleParent.setChildAssetType(ConsoleAsset.DESCRIPTOR.getName());
consoleParent.setRealm(tenant.getRealm());
consoleParent = assetStorageService.merge(consoleParent);
}
return consoleParent;
}
Aggregations