use of org.openremote.model.rules.GlobalRuleset in project openremote by openremote.
the class RulesetStorageService method mapResultTuple.
@SuppressWarnings("unchecked")
protected <T extends Ruleset> T mapResultTuple(Class<T> rulesetType, RulesetQuery query, ResultSet rs) throws SQLException {
T ruleset;
if (rulesetType == GlobalRuleset.class) {
ruleset = (T) new GlobalRuleset();
} else if (rulesetType == TenantRuleset.class) {
TenantRuleset tenantRuleset = new TenantRuleset();
tenantRuleset.setRealm(rs.getString("REALM"));
tenantRuleset.setAccessPublicRead(rs.getBoolean("ACCESS_PUBLIC_READ"));
ruleset = (T) tenantRuleset;
} else if (rulesetType == AssetRuleset.class) {
AssetRuleset assetRuleset = new AssetRuleset();
assetRuleset.setAssetId(rs.getString("ASSET_ID"));
assetRuleset.setRealm(rs.getString("REALM"));
assetRuleset.setAccessPublicRead(rs.getBoolean("ACCESS_PUBLIC_READ"));
ruleset = (T) assetRuleset;
} else {
throw new UnsupportedOperationException("Ruleset type not supported: " + rulesetType);
}
ruleset.setName(rs.getString("NAME"));
ruleset.setId(rs.getLong("ID"));
ruleset.setVersion(rs.getLong("VERSION"));
ruleset.setLang(Ruleset.Lang.valueOf(rs.getString("RULES_LANG")));
ruleset.setEnabled(rs.getBoolean("ENABLED"));
ruleset.setLastModified(rs.getTimestamp("LAST_MODIFIED"));
ruleset.setCreatedOn(rs.getTimestamp("CREATED_ON"));
if (rs.getString("META") != null) {
ruleset.setMeta(ValueUtil.parse(rs.getString("META"), MetaMap.class).orElse(null));
}
if (query.fullyPopulate) {
ruleset.setRules(rs.getString("RULES"));
}
return ruleset;
}
use of org.openremote.model.rules.GlobalRuleset in project openremote by openremote.
the class RulesetResourceImpl method updateGlobalRuleset.
@Override
public void updateGlobalRuleset(@BeanParam RequestParams requestParams, Long id, GlobalRuleset ruleset) {
if (!isSuperUser()) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
GlobalRuleset existingRuleset = rulesetStorageService.findById(GlobalRuleset.class, id);
if (existingRuleset == null)
throw new WebApplicationException(NOT_FOUND);
rulesetStorageService.merge(ruleset);
}
Aggregations