use of org.openremote.model.query.RulesetQuery in project openremote by openremote.
the class RulesService method start.
@Override
public void start(Container container) throws Exception {
if (!geofenceAssetAdapters.isEmpty()) {
LOG.info("GeoefenceAssetAdapters found: " + geofenceAssetAdapters.size());
locationPredicateRulesConsumer = this::onEngineLocationRulesChanged;
for (GeofenceAssetAdapter geofenceAssetAdapter : geofenceAssetAdapters) {
geofenceAssetAdapter.start(container);
}
}
LOG.info("Deploying global rulesets");
rulesetStorageService.findAll(GlobalRuleset.class, new RulesetQuery().setEnabledOnly(true).setFullyPopulate(true)).forEach(this::deployGlobalRuleset);
LOG.info("Deploying tenant rulesets");
tenants = Arrays.stream(identityService.getIdentityProvider().getTenants()).filter(Tenant::getEnabled).toArray(Tenant[]::new);
rulesetStorageService.findAll(TenantRuleset.class, new RulesetQuery().setEnabledOnly(true).setFullyPopulate(true)).stream().filter(rd -> Arrays.stream(tenants).anyMatch(tenant -> rd.getRealm().equals(tenant.getRealm()))).forEach(this::deployTenantRuleset);
LOG.info("Deploying asset rulesets");
// Group by asset ID then tenant and check tenant is enabled
// noinspection ResultOfMethodCallIgnored
deployAssetRulesets(rulesetStorageService.findAll(AssetRuleset.class, new RulesetQuery().setEnabledOnly(true).setFullyPopulate(true))).count();
LOG.info("Loading all assets with fact attributes to initialize state of rules engines");
Stream<Pair<Asset<?>, Stream<Attribute<?>>>> stateAttributes = findRuleStateAttributes();
// Push each attribute as an asset update through the rule engine chain
// that will ensure the insert only happens to the engines in scope
stateAttributes.forEach(pair -> {
Asset<?> asset = pair.key;
pair.value.forEach(ruleAttribute -> {
AssetState<?> assetState = new AssetState<>(asset, ruleAttribute, Source.INTERNAL);
updateAssetState(assetState);
});
});
// Start the engines
if (globalEngine != null) {
globalEngine.start();
}
tenantEngines.values().forEach(RulesEngine::start);
assetEngines.values().forEach(RulesEngine::start);
startDone = true;
preInitassetStates.forEach(this::doProcessAssetUpdate);
preInitassetStates.clear();
}
use of org.openremote.model.query.RulesetQuery in project openremote by openremote.
the class RulesResourceImpl method getTenantRulesets.
@Override
public TenantRuleset[] getTenantRulesets(@BeanParam RequestParams requestParams, String realm, List<Ruleset.Lang> languages, boolean fullyPopulate) {
if (isAuthenticated() && !isRealmAccessibleByUser(realm)) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
boolean publicOnly = !isAuthenticated() || isRestrictedUser() | !hasResourceRole(ClientRole.READ_RULES.getValue(), Constants.KEYCLOAK_CLIENT_ID);
List<TenantRuleset> result = rulesetStorageService.findAll(TenantRuleset.class, new RulesetQuery().setRealm(realm).setLanguages(languages.toArray(new Ruleset.Lang[0])).setFullyPopulate(fullyPopulate).setPublicOnly(publicOnly));
// Try and retrieve transient status and error data
result.forEach(ruleset -> rulesService.getRulesetDeployment(ruleset.getId()).ifPresent(rulesetDeployment -> {
ruleset.setStatus(rulesetDeployment.getStatus());
ruleset.setError(rulesetDeployment.getErrorMessage());
}));
return result.toArray(new TenantRuleset[0]);
}
use of org.openremote.model.query.RulesetQuery in project openremote by openremote.
the class RulesResourceImpl method getGlobalRulesets.
@Override
public GlobalRuleset[] getGlobalRulesets(@BeanParam RequestParams requestParams, List<Ruleset.Lang> languages, boolean fullyPopulate) {
if (!isSuperUser()) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
List<GlobalRuleset> result = rulesetStorageService.findAll(GlobalRuleset.class, new RulesetQuery().setLanguages(languages.toArray(new Ruleset.Lang[0])).setFullyPopulate(fullyPopulate));
// Try and retrieve transient status and error data
result.forEach(ruleset -> rulesService.getRulesetDeployment(ruleset.getId()).ifPresent(rulesetDeployment -> {
ruleset.setStatus(rulesetDeployment.getStatus());
ruleset.setError(rulesetDeployment.getErrorMessage());
}));
return result.toArray(new GlobalRuleset[0]);
}
Aggregations