Search in sources :

Example 1 with RequestParams

use of org.openremote.model.http.RequestParams 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]);
}
Also used : AssetStorageService(org.openremote.manager.asset.AssetStorageService) Tenant(org.openremote.model.security.Tenant) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) UserAssetLink(org.openremote.model.asset.UserAssetLink) org.openremote.model.rules(org.openremote.model.rules) ClientRole(org.openremote.model.security.ClientRole) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) Asset(org.openremote.model.asset.Asset) AssetQuery(org.openremote.model.query.AssetQuery) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) GeofenceDefinition(org.openremote.model.rules.geofence.GeofenceDefinition) Constants(org.openremote.model.Constants) Logger(java.util.logging.Logger) BeanParam(javax.ws.rs.BeanParam) ManagerWebResource(org.openremote.manager.web.ManagerWebResource) List(java.util.List) Response(javax.ws.rs.core.Response) TimerService(org.openremote.container.timer.TimerService) RulesetQuery(org.openremote.model.query.RulesetQuery) WebApplicationException(javax.ws.rs.WebApplicationException) RequestParams(org.openremote.model.http.RequestParams) RulesetQuery(org.openremote.model.query.RulesetQuery) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 2 with RequestParams

use of org.openremote.model.http.RequestParams 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]);
}
Also used : AssetStorageService(org.openremote.manager.asset.AssetStorageService) Tenant(org.openremote.model.security.Tenant) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) UserAssetLink(org.openremote.model.asset.UserAssetLink) org.openremote.model.rules(org.openremote.model.rules) ClientRole(org.openremote.model.security.ClientRole) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) Asset(org.openremote.model.asset.Asset) AssetQuery(org.openremote.model.query.AssetQuery) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) GeofenceDefinition(org.openremote.model.rules.geofence.GeofenceDefinition) Constants(org.openremote.model.Constants) Logger(java.util.logging.Logger) BeanParam(javax.ws.rs.BeanParam) ManagerWebResource(org.openremote.manager.web.ManagerWebResource) List(java.util.List) Response(javax.ws.rs.core.Response) TimerService(org.openremote.container.timer.TimerService) RulesetQuery(org.openremote.model.query.RulesetQuery) WebApplicationException(javax.ws.rs.WebApplicationException) RequestParams(org.openremote.model.http.RequestParams) RulesetQuery(org.openremote.model.query.RulesetQuery) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

List (java.util.List)2 Logger (java.util.logging.Logger)2 BeanParam (javax.ws.rs.BeanParam)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Response (javax.ws.rs.core.Response)2 BAD_REQUEST (javax.ws.rs.core.Response.Status.BAD_REQUEST)2 NOT_FOUND (javax.ws.rs.core.Response.Status.NOT_FOUND)2 TimerService (org.openremote.container.timer.TimerService)2 AssetStorageService (org.openremote.manager.asset.AssetStorageService)2 ManagerIdentityService (org.openremote.manager.security.ManagerIdentityService)2 ManagerWebResource (org.openremote.manager.web.ManagerWebResource)2 Constants (org.openremote.model.Constants)2 Asset (org.openremote.model.asset.Asset)2 UserAssetLink (org.openremote.model.asset.UserAssetLink)2 RequestParams (org.openremote.model.http.RequestParams)2 AssetQuery (org.openremote.model.query.AssetQuery)2 RulesetQuery (org.openremote.model.query.RulesetQuery)2 org.openremote.model.rules (org.openremote.model.rules)2 GeofenceDefinition (org.openremote.model.rules.geofence.GeofenceDefinition)2 ClientRole (org.openremote.model.security.ClientRole)2