Search in sources :

Example 6 with TenantPredicate

use of org.openremote.model.query.filter.TenantPredicate in project openremote by openremote.

the class UsersFacade method getResults.

@Override
public Stream<String> getResults(UserQuery userQuery) {
    // No restriction for global rulesets
    if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
        // Restrict tenant
        userQuery.tenantPredicate = new TenantPredicate(rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId)));
    } else if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
        userQuery.tenantPredicate = null;
        String assetId = rulesEngineId.getAssetId().orElseThrow(() -> new IllegalArgumentException("Asset ID missing: " + rulesEngineId));
        // Asset<?> must be this engines asset or a child
        if (userQuery.assetPredicate != null) {
            if (assetId.equals(userQuery.assetPredicate.id)) {
                userQuery.pathPredicate = null;
            } else {
                userQuery.pathPredicate = new PathPredicate(rulesEngineId.getAssetId().orElseThrow(IllegalArgumentException::new));
            }
        } else if (userQuery.pathPredicate != null) {
            // Path must contain this engines asset ID
            List<String> path = new ArrayList<>(Arrays.asList(userQuery.pathPredicate.path));
            if (!path.contains(assetId)) {
                path.add(assetId);
                userQuery.pathPredicate.path = path.toArray(new String[userQuery.pathPredicate.path.length + 1]);
            }
        } else {
            // Force scope to this asset
            userQuery.assetPredicate = new UserAssetPredicate(assetId);
        }
    }
    // Prevent system users being retrieved
    userQuery.select(new UserQuery.Select().excludeSystemUsers(true));
    return Arrays.stream(identityService.getIdentityProvider().queryUsers(userQuery)).map(User::getId);
}
Also used : PathPredicate(org.openremote.model.query.filter.PathPredicate) User(org.openremote.model.security.User) UserAssetPredicate(org.openremote.model.query.filter.UserAssetPredicate) ArrayList(java.util.ArrayList) TenantPredicate(org.openremote.model.query.filter.TenantPredicate)

Example 7 with TenantPredicate

use of org.openremote.model.query.filter.TenantPredicate 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

TenantPredicate (org.openremote.model.query.filter.TenantPredicate)7 AssetQuery (org.openremote.model.query.AssetQuery)5 Asset (org.openremote.model.asset.Asset)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 PathPredicate (org.openremote.model.query.filter.PathPredicate)2 ArrayList (java.util.ArrayList)1 OptimisticLockException (javax.persistence.OptimisticLockException)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 BadRequestException (javax.ws.rs.BadRequestException)1 AuthContext (org.openremote.container.security.AuthContext)1 UserAssetLink (org.openremote.model.asset.UserAssetLink)1 ConsoleAsset (org.openremote.model.asset.impl.ConsoleAsset)1 GroupAsset (org.openremote.model.asset.impl.GroupAsset)1 AttributeEvent (org.openremote.model.attribute.AttributeEvent)1 EventRequestResponseWrapper (org.openremote.model.event.shared.EventRequestResponseWrapper)1 SharedEvent (org.openremote.model.event.shared.SharedEvent)1 GatewayDisconnectEvent (org.openremote.model.gateway.GatewayDisconnectEvent)1 UserQuery (org.openremote.model.query.UserQuery)1 AttributePredicate (org.openremote.model.query.filter.AttributePredicate)1 ParentPredicate (org.openremote.model.query.filter.ParentPredicate)1