use of org.openremote.model.query.filter.PathPredicate in project openremote by openremote.
the class AgentService method findAssets.
@Override
public List<Asset<?>> findAssets(String assetId, AssetQuery assetQuery) {
if (TextUtil.isNullOrEmpty(assetId)) {
return Collections.emptyList();
}
if (assetQuery == null) {
assetQuery = new AssetQuery();
}
// Ensure agent ID is injected into each path predicate
if (assetQuery.paths != null) {
for (PathPredicate pathPredicate : assetQuery.paths) {
int len = pathPredicate.path.length;
pathPredicate.path = Arrays.copyOf(pathPredicate.path, len + 1);
pathPredicate.path[len] = assetId;
}
} else {
assetQuery.paths(new PathPredicate(assetId));
}
return assetStorageService.findAll(assetQuery);
}
use of org.openremote.model.query.filter.PathPredicate 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);
}
use of org.openremote.model.query.filter.PathPredicate in project openremote by openremote.
the class AssetsFacade method getResults.
@Override
public Stream<Asset<?>> getResults(AssetQuery assetQuery) {
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
// Realm is restricted to rules
assetQuery.tenant = new TenantPredicate(rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm missing: " + rulesEngineId)));
} else if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
// Realm is restricted to assets'
assetQuery.tenant = new TenantPredicate(rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm missing: " + rulesEngineId)));
Asset<?> restrictedAsset = assetStorageService.find(rulesEngineId.getAssetId().orElseThrow(() -> new IllegalStateException("Asset ID missing: " + rulesEngineId)), true);
if (restrictedAsset == null) {
throw new IllegalStateException("Asset is no longer available: " + rulesEngineId);
}
assetQuery.paths(new PathPredicate(restrictedAsset.getPath()));
}
AssetQuery.Select oldValue = assetQuery.select;
assetQuery.select = new AssetQuery.Select().excludeAttributes();
try {
return assetStorageService.findAll(assetQuery).stream();
} finally {
assetQuery.select = oldValue;
}
}
Aggregations