Search in sources :

Example 16 with AssetQuery

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;
}
Also used : AssetQuery(org.openremote.model.query.AssetQuery) AttributeEvent(org.openremote.model.attribute.AttributeEvent)

Example 17 with AssetQuery

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;
}
Also used : ConsoleAsset(org.openremote.model.asset.impl.ConsoleAsset) ParentPredicate(org.openremote.model.query.filter.ParentPredicate) StringPredicate(org.openremote.model.query.filter.StringPredicate) AssetQuery(org.openremote.model.query.AssetQuery) GroupAsset(org.openremote.model.asset.impl.GroupAsset) TenantPredicate(org.openremote.model.query.filter.TenantPredicate) AttributePredicate(org.openremote.model.query.filter.AttributePredicate)

Aggregations

AssetQuery (org.openremote.model.query.AssetQuery)17 Asset (org.openremote.model.asset.Asset)9 Level (java.util.logging.Level)8 Logger (java.util.logging.Logger)8 Collectors (java.util.stream.Collectors)8 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)7 java.util (java.util)6 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 MessageBrokerService (org.openremote.container.message.MessageBrokerService)6 AssetStorageService (org.openremote.manager.asset.AssetStorageService)6 Container (org.openremote.model.Container)6 TextUtil (org.openremote.model.util.TextUtil)6 EntityManager (javax.persistence.EntityManager)5 PERSISTENCE_TOPIC (org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC)5 PersistenceService.isPersistenceEventForEntityType (org.openremote.container.persistence.PersistenceService.isPersistenceEventForEntityType)5 TimerService (org.openremote.container.timer.TimerService)5 ClientEventService (org.openremote.manager.event.ClientEventService)5 GatewayService (org.openremote.manager.gateway.GatewayService)5 ContainerService (org.openremote.model.ContainerService)5 AttributeEvent (org.openremote.model.attribute.AttributeEvent)5